Permalink
Browse files

Updated event handling

  • Loading branch information...
1 parent 9bbf072 commit e6331afe20e37f79717c87e4bed510167194de35 Josh Siegle committed Nov 17, 2012
@@ -42,7 +42,7 @@ AudioProcessorEditor* ArduinoOutput::createEditor()
return editor;
}
-void ArduinoOutput::handleEvent(int eventType, MidiMessage& event)
+void ArduinoOutput::handleEvent(int eventType, MidiMessage& event, int sampleNum)
{
if (eventType == TTL)
{
@@ -57,7 +57,7 @@ class ArduinoOutput : public GenericProcessor
void setParameter (int parameterIndex, float newValue);
- void handleEvent(int eventType, MidiMessage& event);
+ void handleEvent(int eventType, MidiMessage& event, int sampleNum);
bool enable();
bool disable();
@@ -323,7 +323,10 @@ bool FPGAThread::updateBuffer()
eventCode = pBuffer[j+6]; // TTL input
- eventCode += (pBuffer[j+7] << 3); // TTL output
+ ttl_out = pBuffer[j+7];
+
+ if (ttl_out > 0)
+ eventCode |= 8; // TTL output
j += 8; //move cursor to 1st data byte
@@ -60,7 +60,7 @@ AudioProcessorEditor* FPGAOutput::createEditor()
return editor;
}
-void FPGAOutput::handleEvent(int eventType, MidiMessage& event)
+void FPGAOutput::handleEvent(int eventType, MidiMessage& event, int sampleNum)
{
if (eventType == TTL && isEnabled)
{
@@ -56,7 +56,7 @@ class FPGAOutput : public GenericProcessor,
void process(AudioSampleBuffer &buffer, MidiBuffer &midiMessages, int& nSamples);
void setParameter (int parameterIndex, float newValue);
- void handleEvent(int eventType, MidiMessage& event);
+ void handleEvent(int eventType, MidiMessage& event, int sampleNum);
AudioProcessorEditor* createEditor();
@@ -448,8 +448,8 @@ void GenericProcessor::addEvent(MidiBuffer& eventBuffer,
sizeof(data), // total bytes
sampleNum); // sample index
- if (type == TTL)
- std::cout << "Adding event for channel " << (int) eventChannel << " with ID " << (int) eventId << std::endl;
+ //if (type == TTL)
+ // std::cout << "Adding event for channel " << (int) eventChannel << " with ID " << (int) eventId << std::endl;
delete data;
}
@@ -124,7 +124,7 @@ void LfpDisplayNode::setParameter (int parameterIndex, float newValue)
ed->canvas->setParameter(parameterIndex, newValue);
}
-void LfpDisplayNode::handleEvent(int eventType, MidiMessage& event)
+void LfpDisplayNode::handleEvent(int eventType, MidiMessage& event, int sampleNum)
{
if (eventType == TTL)
{
@@ -138,9 +138,9 @@ void LfpDisplayNode::handleEvent(int eventType, MidiMessage& event)
int samplesLeft = totalSamples - eventTime;
- std::cout << "Received event from " << eventNodeId << ", channel "
- << eventChannel << ", with ID " << eventId << std::endl;
-
+ // std::cout << "Received event from " << eventNodeId << ", channel "
+ // << eventChannel << ", with ID " << eventId << std::endl;
+//
int bufferIndex = (displayBufferIndex + eventTime);// % displayBuffer->getNumSamples();
if (eventId == 1)
@@ -64,7 +64,7 @@ class LfpDisplayNode : public GenericProcessor
bool enable();
bool disable();
- void handleEvent(int, MidiMessage&);
+ void handleEvent(int, MidiMessage&, int);
AudioSampleBuffer* getDisplayBufferAddress() {return displayBuffer;}
int getDisplayBufferIndex() {return displayBufferIndex;}
@@ -71,10 +71,10 @@ bool PhaseDetector::enable()
return true;
}
-void PhaseDetector::handleEvent(int eventType, MidiMessage& event)
+void PhaseDetector::handleEvent(int eventType, MidiMessage& event, int sampleNum)
{
- std::cout << "GOT EVENT." << std::endl;
+ //std::cout << "GOT EVENT." << std::endl;
if (eventType == TTL)
{
@@ -85,8 +85,8 @@ void PhaseDetector::handleEvent(int eventType, MidiMessage& event)
int eventChannel = *(dataptr+3);
//int eventTime = event.getTimeStamp();
- std::cout << "Received event from " << eventNodeId << ", channel "
- << eventChannel << ", with ID " << eventId << std::endl;
+ // std::cout << "Received event from " << eventNodeId << ", channel "
+ // << eventChannel << ", with ID " << eventId << std::endl;
if (eventId == 1)
{
@@ -71,7 +71,7 @@ class PhaseDetector : public GenericProcessor
bool canBeTriggered;
- void handleEvent(int eventType, MidiMessage& event);
+ void handleEvent(int eventType, MidiMessage& event, int sampleNum);
float estimatedFrequency;
@@ -119,9 +119,7 @@ void RecordNode::filenameComponentChanged(FilenameComponent* fnc)
createNewDirectory();
- String filename = rootFolder.getFullPathName();
- filename += "/all_channels.events";
- eventChannel->filename = filename;
+
}
@@ -138,15 +136,9 @@ void RecordNode::addInputChannel(GenericProcessor* sourceNode, int chan)
channelPointers.add(sourceNode->channels[chan]);
- String filename = rootFolder.getFullPathName();
- filename += "/";
- filename += sourceNode->getNodeId();
- filename += "_";
- filename += channelPointers[channelIndex]->name;
- filename += ".continuous";
+ updateFileName(channelPointers[channelIndex]);
- channelPointers[channelIndex]->filename = filename;
- channelPointers[channelIndex]->file = 0;
+
//if (channelPointers[channelIndex]->isRecording)
// std::cout << " This channel will be recorded." << std::endl;
@@ -175,12 +167,39 @@ void RecordNode::addInputChannel(GenericProcessor* sourceNode, int chan)
}
+void RecordNode::updateFileName(Channel* ch)
+{
+ String filename = rootFolder.getFullPathName();
+ filename += rootFolder.separatorString;
+
+ if (!ch->isEventChannel)
+ {
+ filename += ch->processor->getNodeId();
+ filename += "_";
+ filename += ch->name;
+ filename += ".continuous";
+ } else {
+ filename += "all_channels.events";
+ }
+
+ ch->filename = filename;
+ ch->file = 0;
+
+}
+
void RecordNode::createNewDirectory()
{
std::cout << "Creating new directory." << std::endl;
rootFolder = File(dataDirectory.getFullPathName() + File::separator + generateDirectoryName());
+ updateFileName(eventChannel);
+
+ for (int i = 0; i < channelPointers.size(); i++)
+ {
+ updateFileName(channelPointers[i]);
+ }
+
}
String RecordNode::generateDirectoryName()
@@ -252,6 +271,8 @@ void RecordNode::setParameter (int parameterIndex, float newValue)
if (!rootFolder.exists())
rootFolder.createDirectory();
+ openFile(eventChannel);
+
// create / open necessary files
for (int i = 0; i < channelPointers.size(); i++)
{
@@ -261,7 +282,7 @@ void RecordNode::setParameter (int parameterIndex, float newValue)
}
}
- openFile(eventChannel);
+
} else if (parameterIndex == 0) {
@@ -319,8 +340,11 @@ void RecordNode::openFile(Channel* ch)
if (!fileExists)
{
// create and write header
+ std::cout << "Writing header." << std::endl;
String header = generateHeader(ch);
fwrite(header.toUTF8(), 1, header.getNumBytesAsUTF8(), ch->file);
+ } else {
+ std::cout << "File already exists, just opening." << std::endl;
}
}
@@ -386,6 +410,9 @@ void RecordNode::closeAllFiles()
bool RecordNode::enable()
{
+
+ //updateFileName(eventChannel);
+
isProcessing = true;
return true;
}
@@ -162,6 +162,9 @@ class RecordNode : public GenericProcessor,
/** Generate a Matlab-compatible datestring */
String generateDateString();
+ /** Generate filename for a given channel */
+ void updateFileName(Channel* ch);
+
/** Cycle through the event buffer, looking for data to save */
void handleEvent(int eventType, MidiMessage& event, int samplePos);
@@ -40,7 +40,7 @@ AudioProcessorEditor* WiFiOutput::createEditor()
return editor;
}
-void WiFiOutput::handleEvent(int eventType, MidiMessage& event)
+void WiFiOutput::handleEvent(int eventType, MidiMessage& event, int sampleNum)
{
if (eventType == TTL)
{
@@ -60,7 +60,7 @@ class WiFiOutput : public GenericProcessor,
void process(AudioSampleBuffer &buffer, MidiBuffer &midiMessages, int& nSamples);
void setParameter (int parameterIndex, float newValue);
- void handleEvent(int eventType, MidiMessage& event);
+ void handleEvent(int eventType, MidiMessage& event, int sampleNum);
AudioProcessorEditor* createEditor();
@@ -525,7 +525,7 @@ void ControlPanel::buttonClicked(Button* button)
{
playButton->setToggleState(true,false);
- graph->getRecordNode()->setParameter(1,10.0f);
+ //graph->getRecordNode()->setParameter(1,10.0f);
masterClock->startRecording(); // turn on recording
@@ -572,6 +572,11 @@ void ControlPanel::buttonClicked(Button* button)
masterClock->start();
}
+ } else {
+
+ if (recordButton->getToggleState())
+ graph->getRecordNode()->setParameter(1,10.0f);
+
}
} else {

0 comments on commit e6331af

Please sign in to comment.