From bb569d5778984f9fd8d4be9b2712313a8c96c5d4 Mon Sep 17 00:00:00 2001 From: Aaron Cuevas Lopez <aacuelo@teleco.upv.es> Date: Mon, 23 Mar 2015 22:42:56 +0100 Subject: [PATCH] Automatically add timestamps in filter nodes that send events if not done manually --- .../Processors/GenericProcessor/GenericProcessor.cpp | 12 +++++++++++- .../Processors/GenericProcessor/GenericProcessor.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/Processors/GenericProcessor/GenericProcessor.cpp b/Source/Processors/GenericProcessor/GenericProcessor.cpp index 3dfbba6b7..3bfc75654 100755 --- a/Source/Processors/GenericProcessor/GenericProcessor.cpp +++ b/Source/Processors/GenericProcessor/GenericProcessor.cpp @@ -30,7 +30,7 @@ GenericProcessor::GenericProcessor(const String& name_) : AccessClass(), sourceNode(0), destNode(0), isEnabled(true), wasConnected(false), nextAvailableChannel(0), saveOrder(-1), loadOrder(-1), currentChannel(-1), editor(0), parametersAsXml(nullptr), sendSampleCount(true), name(name_), - paramsWereLoaded(false), needsToSendTimestampMessage(false) + paramsWereLoaded(false), needsToSendTimestampMessage(false), timestampSet(false) { settings.numInputs = settings.numOutputs = settings.sampleRate = 0; @@ -601,6 +601,7 @@ void GenericProcessor::setTimestamp(MidiBuffer& events, int64 timestamp) { //std::cout << "Setting timestamp to " << timestamp << std:;endl; + timestampSet = true; uint8 data[8]; memcpy(data, ×tamp, 8); @@ -760,6 +761,13 @@ void GenericProcessor::addEvent(MidiBuffer& eventBuffer, uint8* eventData, bool isTimestamp) { + + /*If the processor doesn't generates timestamps, but needs to add events to the buffer anyway + add the timestamp of the first input channel so the event is properly timestamped. We avoid this step for + source modules that must always provide a timestamp, even if they don't generate it*/ + if (!isTimestamp && !timestampSet && !isSource() && !generatesTimestamps()) + setTimestamp(eventBuffer, getTimestamp(0)); + uint8* data = new uint8[6+numBytes]; data[0] = type; // event type @@ -797,6 +805,8 @@ void GenericProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& event processEventBuffer(eventBuffer); // extract buffer sizes and timestamps, // set flag on all TTL events to zero + timestampSet = false; + process(buffer, eventBuffer); } diff --git a/Source/Processors/GenericProcessor/GenericProcessor.h b/Source/Processors/GenericProcessor/GenericProcessor.h index ccc9265b6..1e2c9976d 100755 --- a/Source/Processors/GenericProcessor/GenericProcessor.h +++ b/Source/Processors/GenericProcessor/GenericProcessor.h @@ -658,6 +658,8 @@ private: bool paramsWereLoaded; bool needsToSendTimestampMessage; + bool timestampSet; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(GenericProcessor); }; -- GitLab