Skip to content
Snippets Groups Projects
Commit 8b037709 authored by Aaron Cuevas Lopez's avatar Aaron Cuevas Lopez
Browse files

Update SpikeRaster plugin

parent 53aa1cd5
No related branches found
No related tags found
No related merge requests found
...@@ -63,30 +63,25 @@ void SpikeRaster::updateSettings() ...@@ -63,30 +63,25 @@ void SpikeRaster::updateSettings()
electrodes.clear(); electrodes.clear();
for (int i = 0; i < eventChannels.size(); i++) for (int i = 0; i < spikeChannelArray.size(); i++)
{ {
ChannelType type = eventChannels[i]->getType();
if (type == ELECTRODE_CHANNEL)
{
Electrode elec; Electrode* elec = new Electrode();
elec.numChannels = static_cast<SpikeChannel*>(eventChannels[i]->extraData.get())->numChannels; elec->numChannels = spikeChannelArray[i]->getNumChannels();
elec.name = eventChannels[i]->getName(); elec->name = spikeChannelArray[i]->getName();
elec.currentSpikeIndex = 0; elec->currentSpikeIndex = 0;
elec.mostRecentSpikes.ensureStorageAllocated(displayBufferSize); elec->mostRecentSpikes.ensureStorageAllocated(displayBufferSize);
for (int j = 0; j < elec.numChannels; j++) for (int j = 0; j < elec->numChannels; j++)
{ {
elec.displayThresholds.add(0); elec->displayThresholds.add(0);
elec.detectorThresholds.add(0); elec->detectorThresholds.add(0);
} }
electrodes.add(elec); electrodes.add(elec);
} }
}
} }
...@@ -128,13 +123,14 @@ int SpikeRaster::getNumElectrodes() ...@@ -128,13 +123,14 @@ int SpikeRaster::getNumElectrodes()
void SpikeRaster::setRasterPlot(RasterPlot* r) void SpikeRaster::setRasterPlot(RasterPlot* r)
{ {
canvas = r; canvas = r;
r->setSampleRate(settings.sampleRate); //A bit of a hack since a processor doesn't actually have a sample rate unless it is a source one
r->setSampleRate(dataChannelArray[0]->getSampleRate());
} }
void SpikeRaster::process(AudioSampleBuffer& buffer, MidiBuffer& events) void SpikeRaster::process(AudioSampleBuffer& buffer)
{ {
checkForEvents(events); // automatically calls 'handleEvent checkForEvents(true); // automatically calls 'handleEvent
if (redrawRequested) if (redrawRequested)
{ {
...@@ -144,14 +140,14 @@ void SpikeRaster::process(AudioSampleBuffer& buffer, MidiBuffer& events) ...@@ -144,14 +140,14 @@ void SpikeRaster::process(AudioSampleBuffer& buffer, MidiBuffer& events)
for (int i = 0; i < getNumElectrodes(); i++) for (int i = 0; i < getNumElectrodes(); i++)
{ {
Electrode& e = electrodes.getReference(i); Electrode* e = electrodes[i];
// transfer buffered spikes to spike plot // transfer buffered spikes to spike plot
for (int j = 0; j < e.currentSpikeIndex; j++) for (int j = 0; j < e->currentSpikeIndex; j++)
{ {
//std::cout << "Transferring spikes." << std::endl; //std::cout << "Transferring spikes." << std::endl;
canvas->processSpikeObject(e.mostRecentSpikes[j]); canvas->processSpikeObject(e->mostRecentSpikes[j]);
e.currentSpikeIndex = 0; e->currentSpikeIndex = 0;
} }
} }
...@@ -163,58 +159,47 @@ void SpikeRaster::process(AudioSampleBuffer& buffer, MidiBuffer& events) ...@@ -163,58 +159,47 @@ void SpikeRaster::process(AudioSampleBuffer& buffer, MidiBuffer& events)
} }
void SpikeRaster::handleEvent(int eventType, MidiMessage& event, int samplePosition) void SpikeRaster::handleSpike(const SpikeChannel* channelInfo, const MidiMessage& event, int samplePosition)
{ {
//std::cout << "Received event of type " << eventType << std::endl; //std::cout << "Received event of type " << eventType << std::endl;
if (eventType == SPIKE)
{
const uint8_t* dataptr = event.getRawData();
int bufferSize = event.getRawDataSize();
if (bufferSize > 0) SpikeEventPtr newSpike = SpikeEvent::deserializeFromMessage(event, channelInfo);
{
SpikeObject newSpike; if (newSpike > 0)
{
bool isValid = unpackSpike(&newSpike, dataptr, bufferSize);
if (isValid) int electrodeNum = spikeChannelArray.indexOf(channelInfo);
{ if (electrodeNum < 0) return;
int electrodeNum = newSpike.source;
Electrode& e = electrodes.getReference(electrodeNum); Electrode* e = electrodes[electrodeNum];
// std::cout << electrodeNum << std::endl; // std::cout << electrodeNum << std::endl;
// add to buffer // add to buffer
if (e.currentSpikeIndex < displayBufferSize) if (e->currentSpikeIndex < displayBufferSize)
{ {
// std::cout << "Adding spike " << e.currentSpikeIndex + 1 << std::endl; // std::cout << "Adding spike " << e.currentSpikeIndex + 1 << std::endl;
e.mostRecentSpikes.set(e.currentSpikeIndex, newSpike); e->mostRecentSpikes.set(e->currentSpikeIndex, newSpike.release());
e.currentSpikeIndex++; e->currentSpikeIndex++;
} }
} }
} }
} else if (eventType == TTL)
{
const uint8* dataptr = event.getRawData();
//int eventNodeId = *(dataptr+1);
int eventId = *(dataptr+2);
int eventChannel = *(dataptr+3);
uint8 sourceNodeId = event.getNoteNumber();
int64 timestamp = timestamps[sourceNodeId] + samplePosition;
if (eventId == 1) void SpikeRaster::handleEvent(const EventChannel* channelInfo, const MidiMessage& event, int samplePosition)
{ {
canvas->processEvent(eventChannel, timestamp); if (Event::getEventType(event) == EventChannel::TTL)
} {
} TTLEventPtr ttl = TTLEvent::deserializeFromMessage(event, channelInfo);
int64 timestamp = getSourceTimestamp(ttl->getSourceID(), ttl->getSubProcessorIdx()) + samplePosition;
}
if (ttl->getState())
{
canvas->processEvent(ttl->getChannel(), timestamp);
}
}
}
\ No newline at end of file
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#endif #endif
#include <ProcessorHeaders.h> #include <ProcessorHeaders.h>
#include <SpikeLib.h>
class RasterPlot; class RasterPlot;
...@@ -53,37 +52,38 @@ public: ...@@ -53,37 +52,38 @@ public:
~SpikeRaster(); ~SpikeRaster();
/** Determines whether the processor is treated as a source. */ /** Determines whether the processor is treated as a source. */
bool isSource() bool isSource() const override
{ {
return false; return false;
} }
/** Determines whether the processor is treated as a sink. */ /** Determines whether the processor is treated as a sink. */
bool isSink() bool isSink() const override
{ {
return false; return false;
} }
/** Indicates if the processor has a custom editor. Defaults to false */ /** Indicates if the processor has a custom editor. Defaults to false */
bool hasEditor() const bool hasEditor() const override
{ {
return true; return true;
} }
void updateSettings(); void updateSettings() override;
int getNumElectrodes(); int getNumElectrodes();
AudioProcessorEditor* createEditor(); AudioProcessorEditor* createEditor() override;
void process(AudioSampleBuffer& buffer, MidiBuffer& events); void process(AudioSampleBuffer& buffer) override;
void handleEvent(int, MidiMessage&, int); void handleSpike(const SpikeChannel*, const MidiMessage&, int) override;
void handleEvent(const EventChannel*, const MidiMessage&, int) override;
void setParameter(int parameterIndex, float newValue); void setParameter(int parameterIndex, float newValue) override;
bool enable(); bool enable() override;
bool disable(); bool disable() override;
void setRasterPlot(RasterPlot*); void setRasterPlot(RasterPlot*);
...@@ -98,7 +98,7 @@ private: ...@@ -98,7 +98,7 @@ private:
Array<float> displayThresholds; Array<float> displayThresholds;
Array<float> detectorThresholds; Array<float> detectorThresholds;
Array<SpikeObject> mostRecentSpikes; OwnedArray<SpikeEvent> mostRecentSpikes;
int currentSpikeIndex; int currentSpikeIndex;
int recordIndex; int recordIndex;
...@@ -108,7 +108,7 @@ private: ...@@ -108,7 +108,7 @@ private:
RasterPlot* canvas; RasterPlot* canvas;
Array<Electrode> electrodes; OwnedArray<Electrode> electrodes;
int displayBufferSize; int displayBufferSize;
bool redrawRequested; bool redrawRequested;
......
...@@ -293,7 +293,8 @@ void SpikeRasterCanvas::buttonClicked(Button* b) ...@@ -293,7 +293,8 @@ void SpikeRasterCanvas::buttonClicked(Button* b)
RasterPlot::RasterPlot(SpikeRasterCanvas*) RasterPlot::RasterPlot(SpikeRasterCanvas* c)
:processor(c->getProcessor())
{ {
rasterWidth = 500; rasterWidth = 500;
...@@ -558,11 +559,12 @@ void RasterPlot::setSampleRate(float sr) ...@@ -558,11 +559,12 @@ void RasterPlot::setSampleRate(float sr)
sampleRate = sr; sampleRate = sr;
} }
void RasterPlot::processSpikeObject(const SpikeObject& s) void RasterPlot::processSpikeObject(const SpikeEvent* s)
{ {
int electrode = s.source;
int electrode = processor->getSpikeChannelIndex(s);
//int unit = s.sortedId; //int unit = s.sortedId;
int timestamp = s.timestamp; // absolute time int timestamp = s->getTimestamp(); // absolute time
float bufferPos = float(timestamp - rasterStartTimestamp) / (sampleRate * rasterTimebase); float bufferPos = float(timestamp - rasterStartTimestamp) / (sampleRate * rasterTimebase);
......
...@@ -26,7 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -26,7 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <VisualizerEditorHeaders.h> #include <VisualizerEditorHeaders.h>
#include <VisualizerWindowHeaders.h> #include <VisualizerWindowHeaders.h>
#include <SpikeLib.h>
#include "SpikeRaster.h" #include "SpikeRaster.h"
...@@ -181,7 +180,7 @@ public: ...@@ -181,7 +180,7 @@ public:
void resized(); void resized();
RasterPlot* getRasterPlot() {return rasterPlot.get();} RasterPlot* getRasterPlot() {return rasterPlot.get();}
SpikeRaster* getProcessor() { return processor; }
private: private:
SpikeRaster* processor; SpikeRaster* processor;
ScopedPointer<RasterPlot> rasterPlot; ScopedPointer<RasterPlot> rasterPlot;
...@@ -227,7 +226,7 @@ public: ...@@ -227,7 +226,7 @@ public:
void resized(); void resized();
void reset(); void reset();
void processSpikeObject(const SpikeObject& s); void processSpikeObject(const SpikeEvent* s);
void processEvent(int eventChan, int64 ts); void processEvent(int eventChan, int64 ts);
Random random; Random random;
...@@ -272,6 +271,8 @@ public: ...@@ -272,6 +271,8 @@ public:
float sampleRate; float sampleRate;
Colour getColourForChannel(int ch); Colour getColourForChannel(int ch);
private:
const SpikeRaster* const processor;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment