Permalink
Browse files

Added sample number to event saving

  • Loading branch information...
1 parent cb54295 commit e2615d33e41d1f29fe270d763a7d3b4ff51091e5 jsiegle committed Nov 16, 2012
@@ -97,7 +97,7 @@ int FPGAThread::getNumChannels()
int FPGAThread::getNumEventChannels()
{
- return 8;
+ return 16; // 8 inputs, 8 outputs
}
float FPGAThread::getSampleRate()
@@ -323,7 +323,7 @@ bool FPGAThread::updateBuffer()
eventCode = pBuffer[j+6]; // TTL input
- ttl_out = pBuffer[j+7]; // TTL output
+ eventCode += (pBuffer[j+7] << 8); // TTL output
j += 8; //move cursor to 1st data byte
@@ -418,7 +418,7 @@ int GenericProcessor::checkForEvents(MidiBuffer& midiMessages)
uint8* dataptr = message.getRawData();
- handleEvent(*dataptr, message);
+ handleEvent(*dataptr, message, samplePosition);
}
@@ -189,7 +189,7 @@ class GenericProcessor : public AudioProcessor,
uint8 numBytes = 0,
uint8* data = 0);
- virtual void handleEvent(int eventType, MidiMessage& event) {}
+ virtual void handleEvent(int eventType, MidiMessage& event, int samplePosition = 0) {}
enum eventTypes
{
@@ -439,29 +439,35 @@ void RecordNode::writeContinuousBuffer(float* data, int nSamples, int channel)
// n must equal "count", otherwise there was an error
}
-void RecordNode::writeEventBuffer(MidiMessage& event) //, int node, int channel)
+void RecordNode::writeEventBuffer(MidiMessage& event, int samplePosition) //, int node, int channel)
{
// find file and write samples to disk
//std::cout << "Received event!" << std::endl;
uint8* dataptr = event.getRawData();
+ int16 samplePos = (int16) samplePosition;
// write timestamp (for buffer only, not the actual event timestamp!!!!!)
fwrite(&timestamp, // ptr
8, // size of each element
1, // count
eventChannel->file); // ptr to FILE object
+ fwrite(&samplePos, // ptr
+ 2, // size of each element
+ 1, // count
+ eventChannel->file); // ptr to FILE object
+
// write 1st four bytes of event (type, nodeId, eventId, eventChannel)
fwrite(dataptr, 1, 4, eventChannel->file);
}
-void RecordNode::handleEvent(int eventType, MidiMessage& event)
+void RecordNode::handleEvent(int eventType, MidiMessage& event, int samplePosition)
{
if (eventType == TTL)
{
- writeEventBuffer(event);
+ writeEventBuffer(event, samplePosition);
}
}
@@ -163,7 +163,7 @@ class RecordNode : public GenericProcessor,
String generateDateString();
/** Cycle through the event buffer, looking for data to save */
- void handleEvent(int eventType, MidiMessage& event);
+ void handleEvent(int eventType, MidiMessage& event, int samplePos);
/** Object for holding information about the events file */
Channel* eventChannel;
@@ -174,7 +174,7 @@ class RecordNode : public GenericProcessor,
/** Method for writing event buffers to disk.
*/
- void writeEventBuffer(MidiMessage& event);
+ void writeEventBuffer(MidiMessage& event, int samplePos);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RecordNode);

0 comments on commit e2615d3

Please sign in to comment.