Repository navigation
Expand file tree
/
Copy pathGenericProcessor.h
More file actions
executable file
·850 lines (616 loc) · 32.6 KB
/
Copy pathGenericProcessor.h
File metadata and controls
executable file
·850 lines (616 loc) · 32.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
/*
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2024 Open Ephys
------------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GENERICPROCESSOR_H_1F469DAF__
#define __GENERICPROCESSOR_H_1F469DAF__
#include <JuceHeader.h>
#include "GenericProcessorBase.h"
#include "../../CoreServices.h"
#include "../../Processors/Dsp/LinearSmoothedValueAtomic.h"
#include "../../Processors/PluginManager/PluginIDs.h"
#include "../Parameter/Parameter.h"
#include "../Parameter/ParameterOwner.h"
#include "../PluginManager/PluginClass.h"
#include "../Settings/ContinuousChannel.h"
#include "../Settings/DataStream.h"
#include "../Settings/EventChannel.h"
#include "../Settings/InfoObject.h"
#include "../Settings/SpikeChannel.h"
#include "../Events/Event.h"
#include "../Events/Spike.h"
#include "../Actions/ProcessorAction.h"
#include <limits>
#include <map>
#include <stdio.h>
#include <time.h>
#include <unordered_map>
class EditorViewport;
class DataViewport;
class UIComponent;
class GenericEditor;
class Parameter;
class GenericProcessorBase;
class GenericEditor;
class ConfigurationObject;
class ParameterOwner;
class DeviceInfo;
class Spike;
/**
Measures the time elapsed between the start of each processing
cycle and the end of a GenericProcessor's work.
*/
class LatencyMeter
{
public:
/** Constructor */
LatencyMeter (GenericProcessor* processor);
/** Sets the latest latency values for each data stream */
void setLatestLatency (std::map<uint16, juce::int64>& processStartTimes, bool headlessMode);
/** Returns the latest latency values for each data stream */
float getLatestLatency (uint16 streamId);
/** Updates the available data streams */
void update(const Array<const DataStream*>& dataStreams);
private:
int counter;
std::map<uint16, std::vector<int>> latencies;
std::map<uint16, float> latestLatencies;
GenericProcessor* processor;
std::mutex latencyMutex;
};
using namespace Plugin;
namespace AccessClass
{
class ExternalProcessorAccessor;
};
/**
Abstract base class for creating processors.
All processors must be derived from this class, and must provide an
implementation of the process() method.
@see ProcessorGraph, GenericEditor, SourceNode, FilterNode, LfpDisplayNode
*/
class PLUGIN_API GenericProcessor : public GenericProcessorBase, public PluginClass, public ParameterOwner
{
friend AccessClass::ExternalProcessorAccessor;
friend class RecordEngine;
friend class MessageCenter;
friend class ProcessorGraph;
friend class GenericEditor;
friend class Splitter;
friend class Merger;
public:
/** Constructor (sets the processor's name). */
GenericProcessor (const String& name, bool headlessMode = false);
/** Destructor. */
virtual ~GenericProcessor();
// --------------------------------------------
// PROCESS METHOD -- must be implemented
// --------------------------------------------
/** This method defines a processor's functionality.
This is the most important function for each
processor, as it determines how it creates, modifies, or responds to incoming data
streams. Rather than use the default JUCE processBlock() method, processBlock()
automatically calls process() in order to add the 'nSamples' variable to indicate
the number of samples in the current buffer.
*/
virtual void process (AudioBuffer<float>& continuousBuffer) = 0;
/** Allows parameters to change while acquisition is active. If the user wants
to change ANY variables that are used within the process() method, this must
be done through setParameter(). */
virtual void setParameter (int parameterIndex, float newValue) override;
// --------------------------------------------
// QUERYING INFO ABOUT THIS PROCESSOR
// --------------------------------------------
/** Pointer to a processor's immediate source node.*/
GenericProcessor* sourceNode;
/** Pointer to a processor's immediate destination.*/
GenericProcessor* destNode;
/** Returns a pointer to the processor immediately preceding a given processor in the signal chain. */
GenericProcessor* getSourceNode() const;
/** Returns a pointer to the processor immediately following a given processor in the signal chain. */
GenericProcessor* getDestNode() const;
/** Returns a pointer to the processor's editor. */
GenericEditor* getEditor() const;
/** Returns the sample rate for a given data stream.*/
virtual float getSampleRate (int streamIndex) const;
/** Returns the default sample rate, in case a processor has no source (or is itself a source).*/
virtual float getDefaultSampleRate() const;
/** Returns the name of processor */
const String getName() const override;
/** Returns the total number of inputs to a processor.*/
int getNumInputs() const;
/** Returns the total number of outputs from a processor.*/
int getNumOutputs() const;
/** Returns the total number of data streams handled by this processor.*/
int getNumDataStreams() const;
/** Returns the number of outputs from a specific data stream.*/
int getNumOutputsForStream (int streamIndex) const;
/** Returns the unique integer ID for a processor. */
int getNodeId() const;
/** Sets the unique integer ID for a processor. */
void setNodeId (int id);
/** Registers the parameters for a given processor */
virtual void registerParameters() {};
// --------------------------------------------
// CREATING THE EDITOR
// --------------------------------------------
/** Creates a GenericEditor.*/
virtual AudioProcessorEditor* createEditor() override;
// --------------------------------------------
// BUILDING THE SIGNAL CHAIN
// --------------------------------------------
/** Returns the next available continuous channel (and increments the channel if the input is set to 'true'). */
virtual int getNextChannel (bool increment);
/** Resets all inter-processor connections prior to the start of data acquisition.*/
virtual void resetConnections();
/** Sets the current channel (for purposes of updating parameters).*/
virtual void setCurrentChannel (int chan);
/** Sets the input or output of a splitter or merger.*/
virtual void switchIO (int);
/** Switches the input or output of a splitter or merger.*/
virtual void switchIO();
/** Sets the input to a merger a given processor.*/
virtual void setPathToProcessor (GenericProcessor* p);
/** Sets a processor's source node.*/
virtual void setSourceNode (GenericProcessor* sn);
/** Sets a processor's destination node.*/
virtual void setDestNode (GenericProcessor* dn);
/** Sets one of two possible source nodes for a merger.*/
virtual void setMergerSourceNode (GenericProcessor* sn);
/** Sets one of two possible source nodes for a splitter.*/
virtual void setSplitterDestNode (GenericProcessor* dn);
/** Returns trus if a processor generates its own timestamps, false otherwise.*/
virtual bool generatesTimestamps() const;
/** Returns true if a processor is a filter processor, false otherwise. */
bool isFilter() const;
/** Returns true if a processor is a source, false otherwise.*/
bool isSource() const;
/** Returns true if a processor is a sink, false otherwise.*/
bool isSink() const;
/** Returns true if a processor is a splitter, false otherwise.*/
bool isSplitter() const;
/** Returns true if a processor is a merger, false otherwise.*/
bool isMerger() const;
/** Returns true if a processor is a audio monitor, false otherwise.*/
bool isAudioMonitor() const;
/** Returns true if a processor is a utility (non-merger or splitter), false otherwise.*/
bool isUtility() const;
/** Returns true if a processor is a record node, false otherwise. */
bool isRecordNode() const;
/** Returns true if a processor is an Empty processor, false otherwise. */
bool isEmpty() const;
/** Returns true if a processor is ready to acquire or process data */
virtual bool isReady() { return true; }
/** Returns true if a processor is able to send its output to a given processor.
Ideally, this should always return true, but there may be special cases
when this is not possible.
*/
virtual bool canSendSignalTo (GenericProcessor*) const;
// --------------------------------------------
// ACQ / RECORD STATUS NOTIFICATIONS
// --------------------------------------------
/** Called immediately prior to the start of data acquisition, once all processors in the signal chain have
indicated they are ready to process data.
Returns: true if processor is ready to acquire, false otherwise
*/
virtual bool startAcquisition();
/** Called immediately after the end of data acquisition.*/
virtual bool stopAcquisition();
/** Called from whenever recording has started. */
virtual void startRecording() {}
/** Called from whenever recording has stopped. */
virtual void stopRecording() {}
/** Indicates whether a source node is connected to a processor (used for mergers).*/
virtual bool stillHasSource() const { return true; }
// --------------------------------------------
// PARAMETERS
// --------------------------------------------
using ParameterOwner::addParameter;
using ParameterOwner::getParameter;
using ParameterOwner::getParameters;
/** Adds a boolean parameter, which will later be accessed by name*/
void addBooleanParameter (Parameter::ParameterScope scope,
const String& name,
const String& displayName,
const String& description,
bool defaultValue,
bool deactivateDuringAcquisition = false);
/** Adds an integer parameter, which will later be accessed by name*/
void addIntParameter (Parameter::ParameterScope scope,
const String& name,
const String& displayName,
const String& description,
int defaultValue,
int minValue,
int maxValue,
bool deactivateDuringAcquisition = false);
/** Adds a string parameter, which will later be accessed by name*/
void addStringParameter (Parameter::ParameterScope scope,
const String& name,
const String& displayName,
const String& description,
String defaultValue,
bool deactivateDuringAcquisition = false);
/** Adds an float parameter, which will later be accessed by name*/
void addFloatParameter (Parameter::ParameterScope scope,
const String& name,
const String& displayName,
const String& description,
const String& unit,
float defaultValue,
float minValue,
float maxValue,
float stepSize,
bool deactivateDuringAcquisition = false);
/** Adds a selected channels parameter, which will later be accessed by name*/
void addSelectedChannelsParameter (Parameter::ParameterScope scope,
const String& name,
const String& displayName,
const String& description,
int maxSelectedChannels = std::numeric_limits<int>::max(),
bool deactivateDuringAcquisition = false);
/** Adds a mask channels parameter, which will later be accessed by name*/
void addMaskChannelsParameter (Parameter::ParameterScope scope,
const String& name,
const String& displayName,
const String& description,
bool deactivateDuringAcquisition = false);
/** Adds a categorical parameter, which will later be accessed by name*/
void addCategoricalParameter (Parameter::ParameterScope scope,
const String& name,
const String& displayName,
const String& description,
Array<String> categories,
int defaultIndex,
bool deactivateDuringAcquisition = false);
/** Adds a path parameter which holds a path to a folder or file */
void addPathParameter (Parameter::ParameterScope scope,
const String& name,
const String& displayName,
const String& description,
const File& defaultValue,
const StringArray& validFileExtensions,
bool isDirectory,
bool isRequired,
bool deactivateDuringAcquisition = true);
/** Adds a selected stream parameter which holds the currentlu selected stream */
void addSelectedStreamParameter (Parameter::ParameterScope scope,
const String& name,
const String& displayName,
const String& description,
Array<String> streamNames,
const int defaultIndex,
bool syncWithStreamSelector = false,
bool deactivateDuringAcquisition = true);
/** Adds a time parameter with microsecond precision in the form HH:MM:SS.sss */
void addTimeParameter (Parameter::ParameterScope scope,
const String& name,
const String& displayName,
const String& description,
const String& defaultValue = "00:00:00",
bool deactivateDuringAcquisition = true);
/** Adds a path parameter which holds a path to a folder or file */
void addNotificationParameter (Parameter::ParameterScope scope,
const String& name,
const String& displayName,
const String& description,
bool deactivateDuringAcquisition = true);
/** Adds a parameter that allows the user to select a TTL Line
* @param maxAvailableLines The number of TTL lines available for selection
* @param syncMode Set to true if the ttl line will be used for synchronization
* @param canSelectNone Set to true if the user can select no TTL line (can't be used with syncMode = true)
*/
void addTtlLineParameter (Parameter::ParameterScope scope,
const String& name,
const String& displayName,
const String& description,
int maxAvailableLines = 8,
bool syncMode = false,
bool canSelectNone = false,
bool deactivateDuringAcquisition = false);
/** Returns a pointer to a parameter created inside this processor
Includes processor, stream, & channel scoped parameters
*/
/** Returns a pointer to a Parameter object for a given stream (0 = no stream)*/
Parameter* getStreamParameter (const String& parameterName);
/** Returns a list of parameters for a given stream within this processor*/
Array<Parameter*> getParameters (uint16 streamId);
/** Returns a list of parameters for a given event channel within this processor*/
Array<Parameter*> getParameters (EventChannel* channelInfo);
/** Returns a list of parameters for a given continuous channel within this processor*/
Array<Parameter*> getParameters (ContinuousChannel* channelInfo);
/** Returns a list of parameters for a given spike channel within this processor*/
Array<Parameter*> getParameters (SpikeChannel* channelInfo);
/** Initiates parameter value update */
void parameterChangeRequest (Parameter*) override;
/** Called when a parameter value is updated, to allow plugin-specific responses*/
// virtual void parameterValueChanged(Parameter*) { }
// BUFFER ACCESS
/** Returns a pointer to the processor's internal continuous buffer, if it exists. */
virtual AudioBuffer<float>* getContinuousBuffer() const;
/** Returns a pointer to the processor's internal event buffer, if it exists. */
virtual MidiBuffer* getEventBuffer() const;
/** Returns an array of this processor's event channels*/
Array<const EventChannel*> getEventChannels();
int nextAvailableChannel;
/** Variable used to orchestrate saving the ProcessorGraph. */
int saveOrder;
/** Variable used to orchestrate loading the ProcessorGraph. */
int loadOrder;
/** The channel that will be updated the next time a parameter is changed. */
int currentChannel;
// --------------------------------------------
// UPDATING SETTINGS
// --------------------------------------------
/** Allows the processor to load its default state after the editor is created.
The "signalChainIsLoading" flag can be used to prevent the processor from
performing unnecessary steps before it receives information
about its previous settings.
*/
virtual void initialize (bool signalChainIsLoading) {}
/** Method for updating settings, called by ProcessorGraph.*/
void update();
// --------------------------------------------
// LOADING / SAVING SETTINGS
// --------------------------------------------
/** Save generic settings to XML (called by all processors).*/
void saveToXml (XmlElement* parentElement);
/** Load generic settings from XML (called by all processors). */
void loadFromXml();
// --------------------------------------------
// SAVING + LOADING SETTINGS
// --------------------------------------------
/** Saving custom settings to XML. */
virtual void saveCustomParametersToXml (XmlElement* parentElement);
/** Load custom settings from XML*/
virtual void loadCustomParametersFromXml (XmlElement* customParamsXml);
/** Holds loaded parameters */
XmlElement* parametersAsXml;
// --------------------------------------------
// ACCESSING CHANNEL INFO OBJECTS
// --------------------------------------------
const ContinuousChannel* getContinuousChannel (int globalIndex) const;
int getIndexOfMatchingChannel (const ContinuousChannel* channel) const;
int getIndexOfMatchingChannel (const EventChannel* channel) const;
int getIndexOfMatchingChannel (const SpikeChannel* channel) const;
const EventChannel* getEventChannel (int globalIndex) const;
const SpikeChannel* getSpikeChannel (int globalIndex) const;
const ContinuousChannel* getContinuousChannel (uint16 processorId, uint16 streamId, uint16 localIndex) const;
const EventChannel* getEventChannel (uint16 processorId, uint16 streamId, uint16 localIndex) const;
const EventChannel* getMessageChannel() const;
const SpikeChannel* getSpikeChannel (uint16 processorId, uint16 streamId, uint16 localIndex) const;
DataStream* getDataStream (uint16 streamId) const;
DataStream* getDataStream (String streamKey) const;
uint16 findSimilarStream (int sourceNodeId, String name, float sample_rate, bool sourceNodeIdMustMatch = false);
virtual Array<const DataStream*> getStreamsForDestNode (GenericProcessor* processor);
Array<const DataStream*> getDataStreams() const;
const ConfigurationObject* getConfigurationObject (int index) const;
int getTotalContinuousChannels() const;
int getTotalEventChannels() const;
int getTotalSpikeChannels() const;
int getTotalConfigurationObjects() const;
Plugin::Processor::Type getProcessorType() const;
String getProcessorTypeString() const;
static Plugin::Processor::Type typeFromString (String typeName);
String getDisplayName() { return m_name; }
void updateDisplayName (String name);
class PLUGIN_API DefaultEventInfo
{
public:
DefaultEventInfo();
DefaultEventInfo (EventChannel::Type type, unsigned int nChans, unsigned int length, float SampleRate);
EventChannel::Type type { EventChannel::INVALID };
unsigned int nChannels { 0 };
unsigned int length { 0 };
float sampleRate { 44100 };
String name;
String description;
String identifier;
};
/** Determines whether the processor is ready to start acquisition
If set to false, the editor will be greyed out
*/
bool isEnabled;
/** Pointer to the processor's editor. */
std::unique_ptr<GenericEditor> editor;
/** Sets whether processor will have behaviour like Source, Sink, Splitter, Utility or Merge */
void setProcessorType (Plugin::Processor::Type processorType);
/** Sets whether the processor is operating in headless mode */
void setHeadlessMode (bool mode) { headlessMode = mode; }
/** Registers a custom undoable action associated with this processor */
static void registerUndoableAction (int nodeId, ProcessorAction* action) { undoableActions[nodeId].push_back (action); }
/** Returns a list of undoable actions for a given processor ID */
static std::vector<ProcessorAction*> getUndoableActions (int nodeId) { return undoableActions[nodeId]; }
/** Returns the most recent latency measurement for a given stream in this processor */
double getLatency (uint16 streamId) const { return latencyMeter->getLatestLatency (streamId); }
/** Returns the plugin specific recording directory derived from the global recording path */
File getPluginRecordingDirectory();
protected:
static std::map<int, std::vector<ProcessorAction*>> undoableActions;
// --------------------------------------------
// SAMPLES + TIMESTAMPS
// --------------------------------------------
/** Used to get the number of samples available in a current block, for a given stream */
uint32 getNumSamplesInBlock (uint16 streamId) const;
/** Used to get the current sample number for a given stream */
int64 getFirstSampleNumberForBlock (uint16 streamId) const;
/** Used to get the current timestamp for a given stream.*/
double getFirstTimestampForBlock (uint16 streamId) const;
/** Returns per-sample timestamps for the current block, or nullptr if unavailable. */
const double* getTimestampsForBlock (uint16 streamId) const;
/** Resolves a sample number within the current block to a timestamp. */
bool getTimestampForSample (uint16 streamId, int64 sampleNumber, double& timestamp) const;
/** Used to set the timestamp for a given buffer, for a given DataStream. */
void setTimestampAndSamples (int64 startSampleForBlock,
double startTimestampForBlock,
uint32 nSamples,
uint16 streamId,
uint16 syncStreamId = 0);
/** Emits per-sample timestamps for the current buffer. */
void setTimestampArrayForBlock (int64 startSampleForBlock,
const double* timestampsForBlock,
uint32 nSamples,
uint16 streamId,
uint16 syncStreamId = 0);
// --------------------------------------------
// CHANNEL INDEXING
// --------------------------------------------
int getGlobalChannelIndex (uint16 streamId, int localIndex) const;
// --------------------------------------------
// HANDLING EVENTS AND MESSAGES
// --------------------------------------------
/** Handles a configuration message sent to this processor, while acquisition is not active.*/
virtual String handleConfigMessage (const String& msg);
/** Handles broadcast message sent to all processors, while acquisition is active.*/
virtual void handleBroadcastMessage (const String& msg, const int64 systemTimeMillis) {}
/** Can be called by processors that need to respond to incoming events.
Set respondToSpikes to true if the processor should also search for spikes*/
virtual int checkForEvents (bool respondToSpikes = false);
/** Allows processors to respond to incoming TTL events; called by checkForEvents() */
virtual void handleTTLEvent (TTLEventPtr event) {}
/** Allows processors to respond to incoming spikes; called by checkForEvents(true) */
virtual void handleSpike (SpikePtr spike) {}
/** Returns info about the default events a specific subprocessor generates.
Called by createEventChannels(). It is not needed to implement if createEventChannels() is overridden */
virtual void getDefaultEventInfo (Array<DefaultEventInfo>& events, int subProcessorIdx = 0) const;
// --------------------------------------------
// ADDING SPIKES AND EVENTS
// --------------------------------------------
/** Add an event (usually a TTLEventPtr) to the processing buffer */
void addEvent (const Event* event, int sampleNum);
/** Sends a TEXT event to all other processors, via the MessageCenter, while acquisition is active.
If recording is active, this message will be recorded */
void broadcastMessage (String msg);
/** Sends a message String to another processor node in the ProcessorGraph while acquisition
not active */
void sendConfigMessage (GenericProcessor* destination, String message);
/** Add a Spike event to the outgoing buffer */
void addSpike (const Spike* event);
/// OPTIONAL HELPER FUNCTIONS ///
/** Create a simple TTL event channel with 8 lines on the first incoming data stream
-- Must be called during updateSettings() --
*/
void addTTLChannel (String name);
/** Flip the state of one of the TTL lines
-- Must be called during the process() method --
*/
void flipTTLState (int sampleIndex, int lineIndex);
/** Set the state of one of the TTL lines
-- Must be called during the process() method --
*/
void setTTLState (int sampleIndex, int lineIndex, bool state);
/** Get the state of one of the TTL lines
-- Must be called during the process() method --
*/
bool getTTLState (int lineIndex);
// --------------------------------------------
// UPDATING SETTINGS
// --------------------------------------------
/** Custom method for updating settings, called automatically by update() after creating the info objects.*/
virtual void updateSettings() {}
/** Holds information about continuous channels handled by this processor */
OwnedArray<ContinuousChannel> continuousChannels;
/** Holds information about event channels handled by this processor */
OwnedArray<EventChannel> eventChannels;
/** Holds information about spike channels handled by this processor */
OwnedArray<SpikeChannel> spikeChannels;
/** Holds additional configuration information*/
OwnedArray<ConfigurationObject> configurationObjects;
/** Holds information about data streams handled by this processor*/
OwnedArray<DataStream> dataStreams;
/** Copies DataStream settings from a source processor*/
int copyDataStreamSettings (const DataStream*, int continuousChannelGlobalIndex);
/** Finds the parameters that most likely belong to this stream */
int findMatchingStreamParameters (DataStream* stream);
/** Sets whether or not a given stream is enabled*/
void setStreamEnabled (uint16 streamId, bool isEnabled);
/** Updates the data channel map objects*/
void updateChannelIndexMaps();
// /** Holds info about this processor.*/
// std::unique_ptr<ProcessorInfoObject> processorInfo;
/** Holds info about available devices.*/
OwnedArray<DeviceInfo> devices;
/** When set to false, this disables the sending of sample counts through the event buffer (used by Mergers and Splitters). */
bool sendSampleCount;
/** An array of stream- and schannel-scoped parameters for this processor.*/
OwnedArray<Parameter> dataStreamParameters;
/** An array of parameter collections from deleted dataStreams*/
OwnedArray<ParameterCollection> savedDataStreamParameters;
/** Holds a pointer to the event channel for sending messages**/
std::unique_ptr<EventChannel> messageChannel;
/** Set to true if GUI is running in headless mode*/
bool headlessMode;
private:
/** Clears the settings arrays.*/
void clearSettings();
/** Map between stream IDs and buffer sample counts. */
std::map<uint16, uint32> numSamplesInBlock;
/** Map between stream IDs and buffer timestamps. */
std::map<uint16, double> startTimestampsForBlock;
/** Map between stream IDs and buffer timestamps. */
std::map<uint16, int64> startSamplesForBlock;
/** Map between stream IDs main clock stream IDs. */
std::map<uint16, uint16> syncStreamIds;
/** Map between stream IDs and start time of process callbacks. */
std::map<uint16, int64> processStartTimes;
/** First software timestamp of process() callback. */
juce::int64 m_initialProcessTime;
/** Built-in method for creating continuous channels. */
void createDataChannelsByType (ContinuousChannel::Type type);
/** Each processor has a unique integer ID that can be used to identify it.*/
int nodeId;
/** Automatically extracts the number of samples in the buffer, then
calls the process(), where custom actions take place.*/
void processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages) override;
/** Extracts sample counts and timestamps from the MidiBuffer. */
int processEventBuffer();
/** The type of the processor. */
Plugin::Processor::Type m_processorType;
/** The name of the processor.*/
String m_name;
/** For getInputChannelName() and getOutputChannelName() */
static const String m_unusedNameString;
bool m_paramsWereLoaded;
std::map<int, bool> m_needsToSendTimestampMessages;
MidiBuffer* m_currentMidiBuffer;
MidiBuffer messageCenterBuffer;
typedef std::unordered_map<uint16,
std::unordered_map<uint16,
std::unordered_map<uint16,
ContinuousChannel*>>>
ContinuousChannelIndexMap;
typedef std::unordered_map<uint16,
std::unordered_map<uint16,
std::unordered_map<uint16,
EventChannel*>>>
EventChannelIndexMap;
typedef std::unordered_map<uint16,
std::unordered_map<uint16,
std::unordered_map<uint16,
SpikeChannel*>>>
SpikeChannelIndexMap;
typedef std::unordered_map<uint16, DataStream*> DataStreamMap;
ContinuousChannelIndexMap continuousChannelMap;
EventChannelIndexMap eventChannelMap;
SpikeChannelIndexMap spikeChannelMap;
DataStreamMap dataStreamMap;
Parameter* currentParameter;
EventChannel* ttlEventChannel;
Array<bool> ttlLineStates;
bool wasConnected;
std::unique_ptr<LatencyMeter> latencyMeter;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GenericProcessor);
};
#endif // __GENERICPROCESSOR_H_1F469DAF__