diff --git a/Source/Processors/Channel/Channel.cpp b/Source/Processors/Channel/Channel.cpp index d7f7ec265734b0310c7d4fc56ec50eef66d8ab61..843cc340c7f5977d0bf913ddbec95e68d5f7e97a 100644 --- a/Source/Processors/Channel/Channel.cpp +++ b/Source/Processors/Channel/Channel.cpp @@ -121,8 +121,6 @@ void Channel::setName(String name_) name = name_; } - - void Channel::createDefaultName() { switch (type) @@ -148,6 +146,8 @@ void Channel::createDefaultName() case TETRODE: name = String("TT"); break; + case MESSAGE_CHANNEL: + name = String("MSG"); } name += index; diff --git a/Source/Processors/GenericProcessor/GenericProcessor.cpp b/Source/Processors/GenericProcessor/GenericProcessor.cpp index 8b08e4e6491a5fea5fbce56e9a4b1022b66d4a65..33f2234b8d282c5b91759bc891a3d9ca5b6ace31 100755 --- a/Source/Processors/GenericProcessor/GenericProcessor.cpp +++ b/Source/Processors/GenericProcessor/GenericProcessor.cpp @@ -734,7 +734,7 @@ void GenericProcessor::addEvent(MidiBuffer& eventBuffer, data[2] = eventId; // event ID (1 = on, 0 = off, usually) data[3] = eventChannel; // event channel data[4] = 1; // saving flag - data[5] = (uint8) channels[0]->sourceNodeId; // source node ID (for nSamples) + data[5] = (uint8) eventChannels[eventChannel]->sourceNodeId; // source node ID (for nSamples) memcpy(data + 6, eventData, numBytes); //std::cout << "Node id: " << data[1] << std::endl; diff --git a/Source/Processors/GenericProcessor/GenericProcessor.h b/Source/Processors/GenericProcessor/GenericProcessor.h index ce62e607d0a5d2bc61302b92b4dc26397994ba5d..22bd222286299f4f0725374c25164e098ea798ad 100755 --- a/Source/Processors/GenericProcessor/GenericProcessor.h +++ b/Source/Processors/GenericProcessor/GenericProcessor.h @@ -25,7 +25,7 @@ #define __GENERICPROCESSOR_H_1F469DAF__ enum ChannelType {HEADSTAGE_CHANNEL = 0, AUX_CHANNEL = 1, ADC_CHANNEL = 2, EVENT_CHANNEL = 3, - SINGLE_ELECTRODE = 4, STEREOTRODE = 5, TETRODE = 6 + SINGLE_ELECTRODE = 4, STEREOTRODE = 5, TETRODE = 6, MESSAGE_CHANNEL = 7 }; #include "../../../JuceLibraryCode/JuceHeader.h" diff --git a/Source/Processors/LfpDisplayNode/LfpDisplayNode.cpp b/Source/Processors/LfpDisplayNode/LfpDisplayNode.cpp index 747fa6e05e38b4ab756d7fb9532bfb3c13bc6827..5092af2869b63c8bcfb2fb34b9a0369f52241d5e 100755 --- a/Source/Processors/LfpDisplayNode/LfpDisplayNode.cpp +++ b/Source/Processors/LfpDisplayNode/LfpDisplayNode.cpp @@ -65,12 +65,12 @@ void LfpDisplayNode::updateSettings() for (int i = 0; i < eventChannels.size(); i++) { - if (!eventSourceNodes.contains(eventChannels[i]->sourceNodeId)) + if (!eventSourceNodes.contains(eventChannels[i]->sourceNodeId) && eventChannels[i]->type == EVENT_CHANNEL) { eventSourceNodes.add(eventChannels[i]->sourceNodeId); } - } + }\ numEventChannels = eventSourceNodes.size(); @@ -241,9 +241,14 @@ void LfpDisplayNode::initializeEventChannels() int chan = channelForEventSource[eventSourceNodes[i]]; int index = displayBufferIndex[15]; //displayBufferIndex[chan]; + //std::cout << "Event source node " << i << ", channel " << chan << std::endl; + int samplesLeft = displayBuffer->getNumSamples() - index; + int nSamples = numSamples.at(eventSourceNodes[i]); + + if (nSamples < samplesLeft) { diff --git a/Source/Processors/MessageCenter/MessageCenter.cpp b/Source/Processors/MessageCenter/MessageCenter.cpp index 30c7615b6b9708591a24fd09434b510c92cf0cb3..e0bba5c8c8c0ec27faf11ef6aafaae5456d531b9 100644 --- a/Source/Processors/MessageCenter/MessageCenter.cpp +++ b/Source/Processors/MessageCenter/MessageCenter.cpp @@ -35,6 +35,10 @@ MessageCenter::MessageCenter() : 44100.0, // sampleRate 128); // blockSize + Channel* ch = new Channel(this, 0, EVENT_CHANNEL); + ch->sourceNodeId = nodeId; + eventChannels.add(ch); + } MessageCenter::~MessageCenter() @@ -68,6 +72,7 @@ void MessageCenter::setParameter(int parameterIndex, float newValue) void MessageCenter::setSourceNodeId(int id) { sourceNodeId = id; + eventChannels[0]->sourceNodeId = id; } int MessageCenter::getSourceNodeId() diff --git a/Source/Processors/NetworkEvents/NetworkEvents.cpp b/Source/Processors/NetworkEvents/NetworkEvents.cpp index 0687532b7c4ee28b42642a22acef7150470bba40..835d1b2e1f9c3d5b0e2c6d45d61e7f98f31958b0 100644 --- a/Source/Processors/NetworkEvents/NetworkEvents.cpp +++ b/Source/Processors/NetworkEvents/NetworkEvents.cpp @@ -159,7 +159,7 @@ NetworkEvents::NetworkEvents(void *zmq_context) void NetworkEvents::setNewListeningPort(int port) { // first, close existing thread. - disable(); + closesocket(); // allow some time for thread to quit #ifdef WIN32 Sleep(300); @@ -175,11 +175,14 @@ void NetworkEvents::setNewListeningPort(int port) NetworkEvents::~NetworkEvents() { shutdown = true; - disable(); + closesocket(); } -bool NetworkEvents::disable() +bool NetworkEvents::closesocket() { + +std::cout << "Disabling network node" << std::endl; + #ifdef ZEROMQ if (threadRunning) { @@ -193,6 +196,16 @@ bool NetworkEvents::disable() return true; } +int NetworkEvents::getNumEventChannels() +{ + return 1; +} + +void NetworkEvents::updateSettings() +{ + eventChannels[0]->type = MESSAGE_CHANNEL; // so it's ignored by LFP Viewer +} + AudioProcessorEditor* NetworkEvents::createEditor( ){ editor = new NetworkEventsEditor(this, true); @@ -265,6 +278,7 @@ void NetworkEvents::postTimestamppedStringToMidiBuffer(StringTS s, MidiBuffer& e uint8* msg_with_ts = new uint8[s.len+8]; // for the two timestamps memcpy(msg_with_ts, s.str, s.len); memcpy(msg_with_ts+s.len, &s.timestamp, 8); + addEvent(events, (uint8) NETWORK, 0, @@ -440,7 +454,7 @@ void NetworkEvents::run() { networkMessagesQueue.push(Msg); lock.exit(); - std::cout << "Received message!" << std::endl; + //std::cout << "Received message!" << std::endl; // handle special messages String response = handleSpecialMessages(Msg); @@ -448,7 +462,7 @@ void NetworkEvents::run() { } else { String zeroMessageError = "Recieved Zero Message?!?!?"; - std::cout << "Received Zero Message!" << std::endl; + //std::cout << "Received Zero Message!" << std::endl; zmq_send (responder, zeroMessageError.getCharPointer(), zeroMessageError.length(), 0); } diff --git a/Source/Processors/NetworkEvents/NetworkEvents.h b/Source/Processors/NetworkEvents/NetworkEvents.h index 92f780fc1a7400cca272352928dd9d10a12fcc49..64d235f231f5e68efbafa582352baeba66e4d405 100644 --- a/Source/Processors/NetworkEvents/NetworkEvents.h +++ b/Source/Processors/NetworkEvents/NetworkEvents.h @@ -90,10 +90,11 @@ public: void simulateStartRecord(); void simulateStopRecord(); - bool disable(); + bool closesocket(); void run(); void opensocket(); + void updateSettings(); bool isReady(); float getDefaultSampleRate(); @@ -101,7 +102,7 @@ public: float getDefaultBitVolts(); void enabledState(bool t); - + int getNumEventChannels(); void postTimestamppedStringToMidiBuffer(StringTS s, MidiBuffer& events); void setNewListeningPort(int port); diff --git a/Source/Processors/PSTH/PeriStimulusTimeHistogramNode.cpp b/Source/Processors/PSTH/PeriStimulusTimeHistogramNode.cpp index b4659e074b5e3d89f8ecb3f209facc77b0cea0d5..3aa78eb1f00041fb0f5d7c618082e53eca96e898 100644 --- a/Source/Processors/PSTH/PeriStimulusTimeHistogramNode.cpp +++ b/Source/Processors/PSTH/PeriStimulusTimeHistogramNode.cpp @@ -39,7 +39,7 @@ PeriStimulusTimeHistogramNode::PeriStimulusTimeHistogramNode() trialCircularBuffer = nullptr; eventFile = nullptr; isRecording = false; - saveEyeTracking = saveTTLs = saveNetworkEvents = true; + saveEyeTracking = saveTTLs = saveNetworkEvents = false; saveNetworkEventsWhenNotRecording = false; spikeSavingMode = 2; syncCounter = 0; diff --git a/Source/Processors/RecordNode/HDF5Recording.cpp b/Source/Processors/RecordNode/HDF5Recording.cpp index 4a4938553a3fb728c4f1bf5db58b56fe4e72ae7d..253662aedc3bdcd8eb39e71d4f42b50e91d2393f 100644 --- a/Source/Processors/RecordNode/HDF5Recording.cpp +++ b/Source/Processors/RecordNode/HDF5Recording.cpp @@ -172,8 +172,8 @@ void HDF5Recording::writeEvent(int eventType, MidiMessage& event, int samplePosi const uint8* dataptr = event.getRawData(); if (eventType == GenericProcessor::TTL) mainFile->writeEvent(0,*(dataptr+2),*(dataptr+1),(void*)(dataptr+3),timestamp+samplePosition); - else if (eventType == GenericProcessor::MESSAGE) - mainFile->writeEvent(1,*(dataptr+2),*(dataptr+1),(void*)(dataptr+4),timestamp+samplePosition); + else if (eventType == GenericProcessor::MESSAGE || eventType == GenericProcessor::NETWORK) + mainFile->writeEvent(1,*(dataptr+2),*(dataptr+1),(void*)(dataptr+6),timestamp+samplePosition); } void HDF5Recording::addSpikeElectrode(int index, SpikeRecordInfo* elec) diff --git a/Source/Processors/RecordNode/OriginalRecording.cpp b/Source/Processors/RecordNode/OriginalRecording.cpp index d0d3eb0a945dad1f1333405eb4c3b2f0111015f6..f6c95fd54c31d90c7654a6a1ba6e892763df169e 100644 --- a/Source/Processors/RecordNode/OriginalRecording.cpp +++ b/Source/Processors/RecordNode/OriginalRecording.cpp @@ -368,7 +368,7 @@ void OriginalRecording::writeEvent(int eventType, MidiMessage& event, int sample { if (eventType == GenericProcessor::TTL) writeTTLEvent(event,samplePosition); - else if (eventType == GenericProcessor::MESSAGE) + else if (eventType == GenericProcessor::MESSAGE || eventType == GenericProcessor::NETWORK) writeMessage(event,samplePosition); } @@ -381,8 +381,8 @@ void OriginalRecording::writeMessage(MidiMessage& event, int samplePosition) int64 eventTimestamp = (*timestamps)[sourceNodeId] + samplePos; - int msgLength = event.getRawDataSize() - 5; - const char* dataptr = (const char*)event.getRawData() + 4; + int msgLength = event.getRawDataSize() - 6; + const char* dataptr = (const char*)event.getRawData() + 6; String timestampText(eventTimestamp); diff --git a/Source/Processors/RecordNode/RecordNode.cpp b/Source/Processors/RecordNode/RecordNode.cpp index 48b283eee7c446071bb6ee376814e92e34c51551..f51f361e3fc2199467c3e1b2c5ed87f97024ecc9 100755 --- a/Source/Processors/RecordNode/RecordNode.cpp +++ b/Source/Processors/RecordNode/RecordNode.cpp @@ -412,7 +412,7 @@ void RecordNode::handleEvent(int eventType, MidiMessage& event, int samplePositi { if (isRecording && allFilesOpened) { - if ((eventType == TTL) || (eventType == MESSAGE)) + if ((eventType == TTL) || (eventType == MESSAGE) || (eventType == NETWORK)) { if (event.getRawData()+4 > 0) // saving flag > 0 (i.e., event has not already been processed) {