Skip to content

Commit

Permalink
JUCE 6 & Plugin API updates
Browse files Browse the repository at this point in the history
  • Loading branch information
anjaldoshi committed Nov 23, 2021
1 parent c78ac4e commit 13df191
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 50 deletions.
4 changes: 2 additions & 2 deletions Source/OpenEphysLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ extern "C" EXPORT int getPluginInfo(int index, Plugin::PluginInfo* info)
{
//one case per plugin. This example is for a processor which connects directly to the signal chain
case 0:
info->type = PLUGIN_TYPE_PROCESSOR; //Type of plugin. See "Source/Processors/PluginManager/OpenEphysPlugin.h" for complete info about the different type structures
info->type = Plugin::PROCESSOR; //Type of plugin. See "Source/Processors/PluginManager/OpenEphysPlugin.h" for complete info about the different type structures
//For processor
info->processor.name = "ZMQ Interface"; //Processor name shown in the GUI
info->processor.type = Plugin::FilterProcessor; //Type of processor. Can be FilterProcessor, SourceProcessor, SinkProcessor or UtilityProcessor. Specifies where on the processor list will appear
info->processor.type = Plugin::Processor::FILTER; //Type of processor. Can be FilterProcessor, SourceProcessor, SinkProcessor or UtilityProcessor. Specifies where on the processor list will appear
info->processor.creator = &(Plugin::createProcessor<ZmqInterface>); //Class factory pointer. Replace "ExampleProcessor" with the name of your class.
break;
default:
Expand Down
50 changes: 21 additions & 29 deletions Source/ZmqInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ZmqInterface::ZmqInterface(const String& processorName)
dataPort = 5556; //TODO make this editable
listenPort = 5557;

setProcessorType(PROCESSOR_TYPE_FILTER);
setProcessorType(Plugin::Processor::FILTER);

createContext();
threadRunning = false;
Expand Down Expand Up @@ -396,16 +396,16 @@ int ZmqInterface::sendData(float *data, int nChannels, int nSamples, int nRealSa
}

// todo
int ZmqInterface::sendSpikeEvent(const SpikeChannel* spikeInfo, const MidiMessage& event)
int ZmqInterface::sendSpikeEvent(const SpikeChannel* spikeInfo, const EventPacket& packet)
{
messageNumber++;
int size = 0;

const uint8_t* dataptr = event.getRawData();
int bufferSize = event.getRawDataSize();
const uint8_t* dataptr = packet.getRawData();
int bufferSize = packet.getRawDataSize();
if (bufferSize)
{
SpikeEventPtr spike = SpikeEvent::deserializeFromMessage(event, spikeInfo);
SpikePtr spike = Spike::deserialize(packet, spikeInfo);

if (spike)
{
Expand All @@ -423,7 +423,7 @@ int ZmqInterface::sendSpikeEvent(const SpikeChannel* spikeInfo, const MidiMessag
c_obj->setProperty("n_samples", (int64)nSamples);

// todo
c_obj->setProperty("electrode_id", getSpikeChannelIndex(spike));
c_obj->setProperty("electrode_id", spike->getChannelIndex());
#if 0
c_obj->setProperty("channel", spike.channel);
c_obj->setProperty("source", spike.source);
Expand Down Expand Up @@ -593,8 +593,8 @@ AudioProcessorEditor* ZmqInterface::createEditor()
{

// std::cout << "in PythonEditor::createEditor()" << std::endl;
editor = new ZmqInterfaceEditor(this, true);
return editor;
editor = std::make_unique<ZmqInterfaceEditor>(this);
return editor.get();
}

bool ZmqInterface::isReady()
Expand All @@ -604,36 +604,28 @@ bool ZmqInterface::isReady()

void ZmqInterface::setParameter(int parameterIndex, float newValue)
{
editor->updateParameterButtons(parameterIndex);
// editor->updateParameterButtons(parameterIndex);

//Parameter& p = parameters.getReference(parameterIndex);
//p.setValue(newValue, 0);

//threshold = newValue;

//std::cout << float(p[0]) << std::endl;
editor->updateParameterButtons(parameterIndex);
// editor->updateParameterButtons(parameterIndex);
}

void ZmqInterface::resetConnections()
{
nextAvailableChannel = 0;

wasConnected = false;

return;
}

void ZmqInterface::handleEvent(const EventChannel* eventInfo, const MidiMessage& event, int samplePosition)
void ZmqInterface::handleEvent(const EventChannel* eventInfo, const EventPacket& packet, int samplePosition)
{
//std::cout << "Event handling, type: " << Event::getEventType(event) << "\n" << std::flush;

if (Event::getEventType(event) == EventChannel::TTL)
if (Event::getEventType(packet) == EventChannel::TTL)
{
TTLEventPtr ttl = TTLEvent::deserializeFromMessage(event, eventInfo);
TTLEventPtr ttl = TTLEvent::deserialize(packet, eventInfo);

const uint8* dataptr = event.getRawData();
int size = event.getRawDataSize();
const uint8* dataptr = packet.getRawData();
int size = packet.getRawDataSize();
//std::cout << "event data size " << size << std::endl;
uint8 numBytes;
if (size > 6)
Expand All @@ -644,12 +636,12 @@ void ZmqInterface::handleEvent(const EventChannel* eventInfo, const MidiMessage&

//int eventNodeId = *(dataptr+1);
const int eventId = ttl->getState() ? 1 : 0;
const int eventChannel = ttl->getChannel();
const int eventChannel = ttl->getChannelIndex();
//const int eventTime = samplePosition;
//std::cout << "ZMQ TTL timestamp " << event.getTimeStamp() << " samplepos " << samplePosition << std::endl << std::flush;
//std::cout << "TTL TS " << *(uint64_t*)(dataptr + 8) << " vs " << ttl->getTimestamp() << " vs " << event.getTimeStamp() << std::endl;

sendEvent(Event::getEventType(event),
sendEvent(Event::getEventType(packet),
samplePosition,
eventId,
eventChannel,
Expand All @@ -659,10 +651,10 @@ void ZmqInterface::handleEvent(const EventChannel* eventInfo, const MidiMessage&
}
}

void ZmqInterface::handleSpike(const SpikeChannel* spikeInfo, const MidiMessage& event, int samplePosition)
void ZmqInterface::handleSpike(const SpikeChannel* spikeInfo, const EventPacket& packet, int samplePosition)
{
std::cout << "spike" << std::endl;
sendSpikeEvent(spikeInfo, event);
sendSpikeEvent(spikeInfo, packet);
}

int ZmqInterface::receiveEvents()
Expand Down Expand Up @@ -781,9 +773,9 @@ void ZmqInterface::process(AudioSampleBuffer& buffer)

// Simplified sample rate detection (could check channel type or report
// sampling rate of all channels separately in case they differ)
if (dataChannelArray.size() > 0)
if (getTotalContinuousChannels() > 0)
{
sampleRate = dataChannelArray[0]->getSampleRate();
sampleRate = continuousChannels[0]->getSampleRate();
}
else
{ // this should never run - if no data channels, then no data...
Expand Down
19 changes: 3 additions & 16 deletions Source/ZmqInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,6 @@ class ZmqInterface : public GenericProcessor, public Thread
/** The class destructor, used to deallocate memory */
~ZmqInterface();

/** Determines whether the processor is treated as a source. */
virtual bool isSource()
{
return false;
}

/** Determines whether the processor is treated as a sink. */
virtual bool isSink()
{
return false;
}

/** Defines the functionality of the processor.
The process method is called every time a new data buffer is available.
Expand Down Expand Up @@ -105,7 +93,6 @@ class ZmqInterface : public GenericProcessor, public Thread

bool isReady();

void resetConnections();
void run();

OwnedArray<ZmqApplication> *getApplicationList();
Expand All @@ -130,8 +117,8 @@ class ZmqInterface : public GenericProcessor, public Thread
int createDataSocket();
int closeDataSocket();

void handleEvent(const EventChannel* eventInfo, const MidiMessage& event, int samplePosition);
void handleSpike(const SpikeChannel* spikeInfo, const MidiMessage& event, int samplePosition);
void handleEvent(const EventChannel* eventInfo, const EventPacket& packet, int samplePosition) override;
void handleSpike(const SpikeChannel* spikeInfo, const EventPacket& packet, int samplePosition) override;
int sendData(float *data, int nChannels, int nSamples, int nRealSamples,
int64 timestamp, int sampleRate);
int sendEvent( uint8 type,
Expand All @@ -141,7 +128,7 @@ class ZmqInterface : public GenericProcessor, public Thread
uint8 numBytes,
const uint8* eventData,
int64 timestamp);
int sendSpikeEvent(const SpikeChannel* spikeInfo, const MidiMessage &event);
int sendSpikeEvent(const SpikeChannel* spikeInfo, const EventPacket& packet);

// Currently only supports events related to keeping track of connected Applications
int receiveEvents();
Expand Down
4 changes: 2 additions & 2 deletions Source/ZmqInterfaceEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private ListBoxModel, public AsyncUpdater
{
public:
ZmqInterfaceEditorListBox(const String noItemsText, ZmqInterfaceEditor *e):
ListBox(String::empty, nullptr), noItemsMessage(noItemsText)
ListBox(String(), nullptr), noItemsMessage(noItemsText)
{
editor = e;
setModel(this);
Expand Down Expand Up @@ -152,7 +152,7 @@ private ListBoxModel, public AsyncUpdater
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ZmqInterfaceEditorListBox)
};

ZmqInterfaceEditor::ZmqInterfaceEditor(GenericProcessor *parentNode, bool useDefaultParameters): GenericEditor(parentNode, useDefaultParameters)
ZmqInterfaceEditor::ZmqInterfaceEditor(GenericProcessor *parentNode): GenericEditor(parentNode)
{
ZmqProcessor = (ZmqInterface *)parentNode;
listBox = new ZmqInterfaceEditorListBox(String("No App connected"), this);
Expand Down
2 changes: 1 addition & 1 deletion Source/ZmqInterfaceEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct ZmqApplication;
class ZmqInterfaceEditor: public GenericEditor
{
public:
ZmqInterfaceEditor(GenericProcessor *parentNode, bool useDefaultParameters);
ZmqInterfaceEditor(GenericProcessor *parentNode);
virtual ~ZmqInterfaceEditor();
void saveCustomParameters(XmlElement *xml);
void loadCustomParameters(XmlElement* xml);
Expand Down

0 comments on commit 13df191

Please sign in to comment.