Open Ephys GUI
 All Classes Functions Variables
GenericProcessor.h
1 /*
2  ------------------------------------------------------------------
3 
4  This file is part of the Open Ephys GUI
5  Copyright (C) 2012 Open Ephys
6 
7  ------------------------------------------------------------------
8 
9  This program is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifndef __GENERICPROCESSOR_H_1F469DAF__
25 #define __GENERICPROCESSOR_H_1F469DAF__
26 
27 
28 #include "../../JuceLibraryCode/JuceHeader.h"
29 #include "Editors/GenericEditor.h"
30 #include "Parameter.h"
31 #include "../AccessClass.h"
32 
33 #include <time.h>
34 #include <stdio.h>
35 
50 class EditorViewport;
51 class DataViewport;
52 class UIComponent;
53 class GenericEditor;
54 class Parameter;
55 
56 class GenericProcessor : public AudioProcessor,
57  public AccessClass
58 
59 {
60 public:
61 
62  //-----------------------------------------------------------------------
63  // Juce methods:
64 
65  GenericProcessor(const String& name_);
66  virtual ~GenericProcessor();
67 
68  const String getName() const {return name;}
69 
70  virtual void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
71  void releaseResources();
72 
73  virtual void setParameter (int parameterIndex, float newValue);
74 
75  virtual AudioProcessorEditor* createEditor();
76  bool hasEditor() const {return true;}
77 
78  void reset() {}
79  void setCurrentProgramStateInformation(const void* data, int sizeInBytes) {}
80  void setStateInformation(const void* data, int sizeInBytes) {}
81  void getCurrentProgramStateInformation(MemoryBlock &destData) {}
82  void getStateInformation (MemoryBlock &destData) {}
83  void changeProgramName (int index, const String &newName) {}
84  void setCurrentProgram (int index) {}
85 
86  const String getInputChannelName (int channelIndex) const {return settings.inputChannelNames[channelIndex];}
87  const String getOutputChannelName (int channelIndex) const {return settings.outputChannelNames[channelIndex];}
88  const String getParameterName (int parameterIndex); //{return parameters[parameterIndex]->getName();}
89  const String getParameterText (int parameterIndex); //{return parameters[parameterIndex]->getDescription();}
90  const String getProgramName (int index) {return "";}
91 
92  bool isInputChannelStereoPair (int index) const {return true;}
93  bool isOutputChannelStereoPair (int index) const {return true;}
94  bool acceptsMidi () const {return true;}
95  bool producesMidi () const {return true;}
96 
97  bool isParameterAutomatable(int parameterIndex) {return false;}
98  bool isMetaParameter(int parameterIndex) {return false;}
99 
100  int getNumParameters() {return parameters.size();}
101  int getNumPrograms() {return 0;}
102  int getCurrentProgram() {return 0;}
103 
104  float getParameter (int parameterIndex) {return 1.0;}
105  Parameter& getParameterByName(String parameterName);
106  Parameter& getParameterReference(int parameterIndex);
107 
108  //----------------------------------------------------------------------
109  // Custom methods:
110 
111  // pure virtual function (must be implemented by sub-classes)
112  virtual void process(AudioSampleBuffer& /*buffer*/,
113  MidiBuffer& /*buffer*/,
114  int& /*nSamples*/) = 0;
115 
116  GenericProcessor* sourceNode;
117  GenericProcessor* destNode;
118 
119  virtual float getSampleRate() {return settings.sampleRate;}
120  virtual float getDefaultSampleRate() {return 44100.0;}
121 
122  virtual int getNumInputs() {return settings.numInputs;}
123  virtual int getNumOutputs() {return settings.numOutputs;}
124  virtual int getDefaultNumOutputs() {return 2;}
125 
126  //virtual float getBitVolts() {return settings.bitVolts;}
127  virtual float getDefaultBitVolts() {return 1.0;}
128 
129  virtual int getNextChannel(bool);
130  virtual void resetConnections();
131 
132  virtual void setCurrentChannel(int chan) {currentChannel = chan;}
133 
134  int getNodeId() {return nodeId;}
135  void setNodeId(int id) {nodeId = id;}
136 
137  // get/set source node functions
138  GenericProcessor* getSourceNode() {return sourceNode;}
139  GenericProcessor* getDestNode() {return destNode;}
140 
141  virtual void switchIO(int) { }
142  virtual void switchIO() { }
143  virtual void setPathToProcessor(GenericProcessor* p) { }
144 
145  virtual void setSourceNode(GenericProcessor* sn);
146  virtual void setDestNode(GenericProcessor* dn);
147  virtual void setMergerSourceNode(GenericProcessor* sn) { }
148  virtual void setSplitterDestNode(GenericProcessor* dn) { }
149 
150  virtual bool isSource() {return false;}
151  virtual bool isSink() {return false;}
152  virtual bool isSplitter() {return false;}
153  virtual bool isMerger() {return false;}
154 
155  virtual bool canSendSignalTo(GenericProcessor*) {return true;}
156 
157  virtual bool isReady() {return isEnabled;}
158  virtual bool enable() {return isEnabled;}
159  virtual bool disable() {return true;}
160 
161  virtual bool enabledState() {return isEnabled;}
162  virtual void enabledState(bool t) {isEnabled = t;}
163 
164  virtual void enableCurrentChannel(bool) {}
165 
166  virtual bool stillHasSource() {return true;}
167 
168  bool isEnabled;
169  bool wasConnected;
170 
171  virtual AudioSampleBuffer* getContinuousBuffer() {return 0;}
172  virtual MidiBuffer* getEventBuffer() {return 0;}
173 
174  int nextAvailableChannel;
175 
176  // event buffers
177  virtual int checkForEvents(MidiBuffer& mb);
178  virtual void addEvent(MidiBuffer& mb,
179  uint8 type,
180  int sampleNum,
181  uint8 eventID = 0,
182  uint8 eventChannel = 0,
183  uint8 numBytes = 0,
184  uint8* data = 0);
185 
186  virtual void handleEvent(int eventType, MidiMessage& event) {}
187 
188  enum eventTypes
189  {
190  TIMESTAMP = 0,
191  BUFFER_SIZE = 1,
192  PARAMETER_CHANGE = 2,
193  TTL = 3,
194  SPIKE = 4,
195  EEG = 5,
196  CONTINUOUS = 6
197  };
198 
199  enum eventChannelTypes
200  {
201  GENERIC_EVENT = 999,
202  SINGLE_ELECTRODE = 1,
203  STEREOTRODE = 2,
204  TETRODE = 4
205  };
206 
207  int saveOrder;
208  int loadOrder;
209 
210  int currentChannel;
211 
212  virtual GenericEditor* getEditor() {return editor;}
213  ScopedPointer<GenericEditor> editor;
214 
216 
217  GenericProcessor* originalSource;
218 
219  int numInputs;
220  int numOutputs;
221  StringArray inputChannelNames;
222  StringArray outputChannelNames;
223 
224  float sampleRate;
225  Array<float> bitVolts;
226 
227  Array<int> eventChannelIds;
228  StringArray eventChannelNames;
229  Array<int> eventChannelTypes;
230 
231  };
232 
233  ProcessorSettings settings;
234 
235  virtual bool isAudioOrRecordNode() {return false;}
236 
237  virtual bool recordStatus (int chan);
238  virtual bool audioStatus (int chan);
239 
240  virtual void clearSettings();
241 
242  virtual void generateDefaultChannelNames(StringArray&);
243 
244  virtual void update(); // default node updating
245  virtual void updateSettings() {} // custom node updating
246 
247  int nodeId;
248 
249  // parameters:
250  Array<Parameter> parameters;
251  StringArray parameterNames;
252 
253  Parameter nullParam;
254 
255  void setStartChannel(int i) {audioAndRecordNodeStartChannel = i;}
256  int getStartChannel() {return audioAndRecordNodeStartChannel;}
257 
258 private:
259 
260  int audioAndRecordNodeStartChannel;
261 
262  void processBlock (AudioSampleBuffer &buffer, MidiBuffer &midiMessages);
263 
264  const String name;
265 
266  int getNumSamples(MidiBuffer&);
267  void setNumSamples(MidiBuffer&, int);
268 
269  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GenericProcessor);
270 
271 };
272 
273 
274 
275 
276 #endif // __GENERICPROCESSOR_H_1F469DAF__