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

Source processors send messages with timestamp at the beggining of a recording

parent 1813d9c8
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,8 @@
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)
editor(0), parametersAsXml(nullptr), sendSampleCount(true), name(name_),
paramsWereLoaded(false), needsToSendTimestampMessage(false)
{
settings.numInputs = settings.numOutputs = settings.sampleRate = 0;
......@@ -480,12 +481,17 @@ void GenericProcessor::setRecording(bool state)
if (ed != 0)
ed->startRecording();
startRecording();
if (generatesTimestamps())
{
needsToSendTimestampMessage = true;
}
}
else
{
if (ed != 0)
ed->stopRecording();
stopRecording();
needsToSendTimestampMessage = false;
}
}
......@@ -608,6 +614,23 @@ void GenericProcessor::setTimestamp(MidiBuffer& events, int64 timestamp)
//since the processor generating the timestamp won't get the event, add it to the map
timestamps[nodeId] = timestamp;
if (needsToSendTimestampMessage)
{
String eventString = "Processor: " + String(getNodeId()) + " start time: " + String(timestamp);
CharPointer_UTF8 data = eventString.toUTF8();
addEvent(events,
MESSAGE,
0,
0,
0,
data.length() + 1, //It doesn't hurt to send the end-string null and can help avoid issues
(uint8*)data.getAddress());
needsToSendTimestampMessage = false;
}
}
int GenericProcessor::processEventBuffer(MidiBuffer& events)
......
......@@ -675,7 +675,7 @@ private:
static const String unusedNameString;
bool paramsWereLoaded;
bool needsToSendTimestampMessage;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(GenericProcessor);
......
......@@ -109,9 +109,9 @@ int MessageCenter::getSourceNodeId()
return sourceNodeId;
}
int64 MessageCenter::getTimestamp()
int64 MessageCenter::getTimestamp(bool softwareTime)
{
if (sourceNodeId > 0)
if (!softwareTime && sourceNodeId > 0)
return timestampSource->getTimestamp(0);
else
return (Time::currentTimeMillis() - msTime);
......@@ -120,6 +120,22 @@ int64 MessageCenter::getTimestamp()
void MessageCenter::process(AudioSampleBuffer& buffer, MidiBuffer& eventBuffer)
{
setTimestamp(eventBuffer,getTimestamp());
if (needsToSendTimestampMessage)
{
String eventString = "Software time: " + String(getTimestamp(true));
CharPointer_UTF8 data = eventString.toUTF8();
addEvent(eventBuffer,
MESSAGE,
0,
0,
0,
data.length() + 1, //It doesn't hurt to send the end-string null and can help avoid issues
(uint8*)data.getAddress());
needsToSendTimestampMessage = false;
}
if (newEventAvailable)
{
int numBytes = 0;
......@@ -127,7 +143,6 @@ void MessageCenter::process(AudioSampleBuffer& buffer, MidiBuffer& eventBuffer)
String eventString = messageCenterEditor->getLabelString();
CharPointer_UTF8 data = eventString.toUTF8();
int realId = getNodeId();
addEvent(eventBuffer,
MESSAGE,
......
......@@ -67,10 +67,12 @@ public:
void startRecording()
{
isRecording = true;
needsToSendTimestampMessage = true;
}
void stopRecording()
{
isRecording = false;
needsToSendTimestampMessage = false;
}
void setSourceNodeId(int id);
......@@ -79,7 +81,7 @@ public:
void addSourceProcessor(GenericProcessor* p);
void removeSourceProcessor(GenericProcessor* p);
int64 getTimestamp();
int64 getTimestamp(bool softwareTime = false);
private:
bool newEventAvailable;
......@@ -87,6 +89,7 @@ private:
int sourceNodeId;
GenericProcessor* timestampSource;
int64 msTime;
bool needsToSendTimestampMessage;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MessageCenter);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment