Open Ephys GUI
 All Classes Functions Variables
SpikeDetector.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 __SPIKEDETECTOR_H_3F920F95__
25 #define __SPIKEDETECTOR_H_3F920F95__
26 
27 #include "../../JuceLibraryCode/JuceHeader.h"
28 
29 #include "GenericProcessor.h"
30 #include "Editors/SpikeDetectorEditor.h"
31 
32 #include "Visualization/SpikeObject.h"
33 
45 
47 
48 {
49 public:
50 
51  // CONSTRUCTOR AND DESTRUCTOR //
52 
54  SpikeDetector();
55 
58 
59 
60  // PROCESSOR METHODS //
61 
64  void process(AudioSampleBuffer &buffer, MidiBuffer &events, int& nSamples);
65 
67  void setParameter (int parameterIndex, float newValue);
68 
70  void updateSettings();
71 
73  bool enable();
74 
76  bool disable();
77 
79  AudioProcessorEditor* createEditor();
80 
81 
82  // INTERNAL BUFFERS //
83 
86  AudioSampleBuffer overflowBuffer;
87 
89  AudioSampleBuffer& dataBuffer;
90 
91 
92  // CREATE AND DELETE ELECTRODES //
93 
95  bool addElectrode(int nChans);
96 
98  bool removeElectrode(int index);
99 
100 
101  // EDIT AND QUERY ELECTRODE SETTINGS //
102 
104  int getNumChannels(int index);
105 
107  bool setChannel(int electrodeIndex, int channelNum, int newChannel);
108 
111  int getChannel(int index, int chan);
112 
114  bool setElectrodeName(int index, String newName);
115 
116 
117  // RETURN STRING ARRAYS //
118 
120  StringArray getElectrodeNames();
121 
123  StringArray electrodeTypes;
124 
125  void setChannelThreshold(int electrodeNum, int channelNum, float threshold);
126 
127  double getChannelThreshold(int electrodeNum, int channelNum);
128 
129 private:
130 
131  float getDefaultThreshold();
132 
133  int overflowBufferSize;
134 
135  int sampleIndex;
136 
137  Array<int> electrodeCounter;
138 
139  float getNextSample(int& chan);
140  float getCurrentSample(int& chan);
141  bool samplesAvailable(int& nSamples);
142 
143  bool useOverflowBuffer;
144 
145  int currentElectrode;
146  int currentChannelIndex;
147  int currentIndex;
148 
149  struct Electrode {
150 
151  String name;
152 
153  int numChannels;
154  int prePeakSamples, postPeakSamples;
155  int lastBufferIndex;
156 
157  int* channels;
158  double* thresholds;
159  bool* isActive;
160 
161  };
162 
163  uint8_t* spikeBuffer;
164 
165  Array<Electrode*> electrodes;
166 
167  // void createSpikeEvent(int& peakIndex,
168  // int& electrodeNumber,
169  // int& currentChannel,
170  // MidiBuffer& eventBuffer);
171 
172  void addSpikeEvent(SpikeObject* s, MidiBuffer& eventBuffer, int peakIndex);
173  void addWaveformToSpikeObject(SpikeObject* s,
174  int& peakIndex,
175  int& electrodeNumber,
176  int& currentChannel);
177 
178  void resetElectrode(Electrode*);
179 
180  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SpikeDetector);
181 
182 };
183 
184 
185 
186 #endif // __SPIKEDETECTOR_H_3F920F95__