From 8da69f94b06877bc1f8ed9682c982d5a86ebd20f Mon Sep 17 00:00:00 2001 From: Aaron Cuevas Lopez <aacuelo@teleco.upv.es> Date: Mon, 12 Dec 2016 16:32:02 +0100 Subject: [PATCH] Working commit --- Source/Processors/Channel/InfoObjects.cpp | 2 +- Source/Processors/Channel/InfoObjects.h | 1 - Source/Processors/Channel/MetaData.cpp | 2 +- Source/Processors/Channel/MetaData.h | 2 +- Source/Processors/Editors/GenericEditor.h | 4 +- Source/Processors/Events/Events.cpp | 65 +++++++++++++------ Source/Processors/Events/Events.h | 8 +-- .../GenericProcessor/GenericProcessor.h | 4 +- 8 files changed, 57 insertions(+), 31 deletions(-) diff --git a/Source/Processors/Channel/InfoObjects.cpp b/Source/Processors/Channel/InfoObjects.cpp index 0d3beae8e..05e77fa60 100644 --- a/Source/Processors/Channel/InfoObjects.cpp +++ b/Source/Processors/Channel/InfoObjects.cpp @@ -261,7 +261,7 @@ void EventChannel::setLength(unsigned int length) m_length = length; m_dataSize = length * getTypeByteSize(m_type); //for messages, add 1 byte to account for the null terminator - if (m_type == MESSAGE) m_dataSize += 1; + if (m_type == TEXT) m_dataSize += 1; } unsigned int EventChannel::getLength() const diff --git a/Source/Processors/Channel/InfoObjects.h b/Source/Processors/Channel/InfoObjects.h index cc2ea7154..b4f782f4a 100644 --- a/Source/Processors/Channel/InfoObjects.h +++ b/Source/Processors/Channel/InfoObjects.h @@ -154,7 +154,6 @@ private: const uint16 m_sourceIndex; /** Index of this particular subtype in the source processor */ const uint16 m_sourceTypeIndex; - float m_sampleRate{ 44100.0f }; }; diff --git a/Source/Processors/Channel/MetaData.cpp b/Source/Processors/Channel/MetaData.cpp index c5b872696..d07a050f9 100644 --- a/Source/Processors/Channel/MetaData.cpp +++ b/Source/Processors/Channel/MetaData.cpp @@ -231,7 +231,7 @@ template <typename T> void MetaDataValue::getValue(Array<T>& data) const { jassert(checkMetaDataType<T>(m_type)); - data.addArray(m_data.getData(), m_length); + data.addArray(reinterpret_cast<const T*>(m_data.getData()), m_length); } //Actual template instantiations at the end of the file diff --git a/Source/Processors/Channel/MetaData.h b/Source/Processors/Channel/MetaData.h index 379c51a0e..7d732932e 100644 --- a/Source/Processors/Channel/MetaData.h +++ b/Source/Processors/Channel/MetaData.h @@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #ifndef METADATA_H_INCLUDED #define METADATA_H_INCLUDED -#include <JuceHeader.h> +#include "../../../JuceLibraryCode/JuceHeader.h" #include "../PluginManager/OpenEphysPlugin.h" class GenericProcessor; diff --git a/Source/Processors/Editors/GenericEditor.h b/Source/Processors/Editors/GenericEditor.h index 0a877f7dd..c023b3c71 100755 --- a/Source/Processors/Editors/GenericEditor.h +++ b/Source/Processors/Editors/GenericEditor.h @@ -245,10 +245,10 @@ public: Array<ParameterEditor*> parameterEditors; /** Returns the Channel object for a given continuous channel number. */ - Channel* getChannel (int chan); + DataChannel* getChannel (int chan); /** Returns the Channel object for a given event channel number. */ - Channel* getEventChannel (int chan); + EventChannel* getEventChannel (int chan); /** Stores the font used to display the editor's name. */ Font titleFont; diff --git a/Source/Processors/Events/Events.cpp b/Source/Processors/Events/Events.cpp index 9736213db..b2d6f4730 100644 --- a/Source/Processors/Events/Events.cpp +++ b/Source/Processors/Events/Events.cpp @@ -124,6 +124,28 @@ uint16 Event::getChannel() const return m_channel; } +bool Event::serializeHeader(EventChannel::EventChannelTypes type, char* buffer, size_t dstSize) const +{ + size_t dataSize = m_channelInfo->getDataSize(); + size_t eventSize = dataSize + EVENT_BASE_SIZE; + size_t totalSize = eventSize + m_channelInfo->getTotalEventMetaDataSize(); + if (totalSize < dstSize) + { + jassertfalse; + return false; + } + + *(buffer + 0) = PROCESSOR_EVENT; + *(buffer + 1) = static_cast<char>(type); + *(reinterpret_cast<uint16*>(buffer + 2)) = m_channelInfo->getSourceNodeID(); + *(reinterpret_cast<uint16*>(buffer + 4)) = m_channelInfo->getSubProcessorIdx(); + *(reinterpret_cast<uint16*>(buffer + 6)) = m_channelInfo->getSourceIndex(); + *(reinterpret_cast<uint64*>(buffer + 8)) = m_timestamp; + *(reinterpret_cast<uint64*>(buffer + 16)) = m_channel; + return true; +} + + //TTLEvent TTLEvent::TTLEvent(const EventChannel* channelInfo, uint64 timestamp, uint16 channel, const void* eventData) @@ -150,24 +172,12 @@ const void* TTLEvent::getTTLWordPointer() const void TTLEvent::serialize(void* dstBuffer, size_t dstSize) const { - size_t dataSize = m_channelInfo->getDataSize(); - size_t eventSize = dataSize + EVENT_BASE_SIZE; - size_t totalSize = eventSize + m_channelInfo->getTotalEventMetaDataSize(); - if (totalSize < dstSize) - { - jassertfalse; - return; - } - char* buffer = static_cast<char*>(dstBuffer); - - *(buffer + 0) = PROCESSOR_EVENT; - *(buffer + 1) = EventChannel::TTL; - *(reinterpret_cast<uint16*>(buffer + 2)) = m_channelInfo->getSourceNodeID(); - *(reinterpret_cast<uint16*>(buffer + 4)) = m_channelInfo->getSubProcessorIdx(); - *(reinterpret_cast<uint16*>(buffer + 6)) = m_channelInfo->getSourceIndex(); - *(reinterpret_cast<uint64*>(buffer + 8)) = m_timestamp; - *(reinterpret_cast<uint64*>(buffer + 16)) = m_channel; + if (!serializeHeader(EventChannel::TTL, buffer, dstSize)) + return; + + size_t dataSize = m_channelInfo->getDataSize(); + size_t eventSize = dataSize + EVENT_BASE_SIZE; memcpy((buffer + 18), m_data.getData(), dataSize); serializeMetaData(buffer + eventSize); } @@ -226,9 +236,26 @@ TTLEvent* TTLEvent::deserializeFromMessage(const MidiMessage& msg, const EventCh } //TextEvent +TextEvent::TextEvent(const EventChannel* channelInfo, uint64 timestamp, uint16 channel, const String& text) + : Event(channelInfo, timestamp, channel), + m_text(text) +{ +} -TextEvent(const EventChannel* channelInfo, uint64 timestamp, uint16 channel, const String& msg) - : Event(channelInfo, timestamp, channel) +String TextEvent::getText() const +{ + return m_text; +} + +void TextEvent::serialize(void* dstBuffer, size_t dstSize) const { + char* buffer = static_cast<char*>(dstBuffer); + if (!serializeHeader(EventChannel::TTL, buffer, dstSize)) + return; + + size_t dataSize = m_channelInfo->getDataSize(); + size_t eventSize = dataSize + EVENT_BASE_SIZE; + memcpy((buffer + 18), m_data.getData(), dataSize); + serializeMetaData(buffer + eventSize); } \ No newline at end of file diff --git a/Source/Processors/Events/Events.h b/Source/Processors/Events/Events.h index ec289e1d6..3472d2c97 100644 --- a/Source/Processors/Events/Events.h +++ b/Source/Processors/Events/Events.h @@ -24,8 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #ifndef EVENTS_H_INCLUDED #define EVENTS_H_INCLUDED -#include "../../../JuceLibraryCode/JuceHeader.h" -#include "../PluginManager/OpenEphysPlugin.h" +#include <JuceHeader.h> #include "../Channel/InfoObjects.h" class GenericProcessor; @@ -92,6 +91,7 @@ public: protected: Event(const EventChannel* channelInfo, uint64 timestamp, uint16 channel); Event() = delete; + bool serializeHeader(EventChannel::EventChannelTypes type, char* buffer, size_t dstSize) const; const uint16 m_channel; const EventChannel* m_channelInfo; @@ -133,9 +133,9 @@ public: static TextEvent* deserializeFromMessage(const MidiMessage& msg, const EventChannel* channelInfo); private: TextEvent() = delete; - TextEvent(const EventChannel* channelInfo, uint64 timestamp, uint16 channel, const String& msg); + TextEvent(const EventChannel* channelInfo, uint64 timestamp, uint16 channel, const String& text); - const String m_msg; + const String m_text; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TextEvent); }; diff --git a/Source/Processors/GenericProcessor/GenericProcessor.h b/Source/Processors/GenericProcessor/GenericProcessor.h index 3f5d96ce0..3086eee3c 100755 --- a/Source/Processors/GenericProcessor/GenericProcessor.h +++ b/Source/Processors/GenericProcessor/GenericProcessor.h @@ -37,7 +37,7 @@ enum ChannelType //defines which events are writable to files #define isWritableEvent(ev) (((int)(ev) == GenericProcessor::TTL) || ((int)(ev) == GenericProcessor::MESSAGE) || ((int)(ev) == GenericProcessor::BINARY_MSG)) -#include "../../../JuceLibraryCode/JuceHeader.h" +#include <JuceHeader.h> #include "../Editors/GenericEditor.h" #include "../Parameter/Parameter.h" #include "../../CoreServices.h" @@ -255,7 +255,7 @@ public: virtual float getDefaultBitVolts() const; /** Returns the bit volts for a given channel **/ - virtual float getBitVolts (Channel* chan) const; + virtual float getBitVolts (DataChannel* chan) const; /** Returns the next available channel (and increments the channel if the input is set to 'true'. */ virtual int getNextChannel (bool t); -- GitLab