Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/open-ephys/GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Siegle committed Nov 20, 2012
2 parents 4ef389c + 3d4f97e commit d8e5beb
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 25 deletions.
10 changes: 9 additions & 1 deletion Source/Processors/Channel.cpp
Expand Up @@ -30,6 +30,7 @@ Channel::Channel(GenericProcessor* p, int n) :
sampleRate(44100.0f), bitVolts(1.0f), eventType(0)

{
nodeId = p->getNodeId();

createDefaultName();
}
Expand All @@ -45,9 +46,16 @@ Channel::Channel(const Channel& ch)
bitVolts = ch.bitVolts;
name = ch.name;
eventType = ch.eventType;
nodeId = ch.nodeId;

}

void Channel::setProcessor(GenericProcessor* p)
{
processor = p;
nodeId = p->getNodeId();
}

String Channel::getName()
{
return name;
Expand All @@ -66,5 +74,5 @@ void Channel::reset()
void Channel::createDefaultName()
{
name = String("CH");
name += num;
name += (num + 1);
}
5 changes: 5 additions & 0 deletions Source/Processors/Channel.h
Expand Up @@ -60,9 +60,14 @@ class Channel

void reset();

void setProcessor(GenericProcessor*);

// channel number:
int num;

// node id
int nodeId;

// event info:
int eventType;

Expand Down
6 changes: 3 additions & 3 deletions Source/Processors/FilterNode.cpp
Expand Up @@ -137,12 +137,12 @@ void FilterNode::updateSettings()
(1));

Parameter& p1 = parameters.getReference(0);
p1.setValue(600.0f, n);
p1.setValue(4.0f, n);

Parameter& p2 = parameters.getReference(1);
p2.setValue(6000.0f, n);
p2.setValue(12.0f, n);

setFilterParameters(600.0f, 3000.0f, n);
setFilterParameters(4.0f, 12.0f, n);
}

}
Expand Down
1 change: 1 addition & 0 deletions Source/Processors/GenericProcessor.cpp
Expand Up @@ -306,6 +306,7 @@ void GenericProcessor::update()
{
Channel* sourceChan = sourceNode->channels[i];
Channel* ch = new Channel(*sourceChan);
ch->setProcessor(this);
channels.add(ch);
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Processors/PhaseDetector.cpp
Expand Up @@ -88,10 +88,10 @@ void PhaseDetector::handleEvent(int eventType, MidiMessage& event, int sampleNum
// std::cout << "Received event from " << eventNodeId << ", channel "
// << eventChannel << ", with ID " << eventId << std::endl;

if (eventId == 1)
if (eventId == 1 && eventChannel == 5)
{
canBeTriggered = true;
} else {
} else if (eventId == 0 && eventChannel == 5) {
canBeTriggered = false;
}

Expand Down
59 changes: 42 additions & 17 deletions Source/Processors/RecordNode.cpp
Expand Up @@ -42,6 +42,13 @@ RecordNode::RecordNode()
eventChannel = new Channel(this, 0);
eventChannel->isEventChannel = true;

recordMarker = new char[10];
for (int i = 0; i < 9; i++)
{
recordMarker[i] = 0;
}
recordMarker[9] = 255;

// 128 inputs, 0 outputs
setPlayConfigDetails(getNumInputs(),getNumOutputs(),44100.0,128);

Expand Down Expand Up @@ -136,6 +143,8 @@ void RecordNode::addInputChannel(GenericProcessor* sourceNode, int chan)

channelPointers.add(sourceNode->channels[chan]);

// std::cout << channelIndex << std::endl;

updateFileName(channelPointers[channelIndex]);


Expand Down Expand Up @@ -174,7 +183,7 @@ void RecordNode::updateFileName(Channel* ch)

if (!ch->isEventChannel)
{
filename += ch->processor->getNodeId();
filename += ch->nodeId;
filename += "_";
filename += ch->name;
filename += ".continuous";
Expand All @@ -185,6 +194,8 @@ void RecordNode::updateFileName(Channel* ch)
ch->filename = filename;
ch->file = 0;

//std::cout << "Updating " << filename << std::endl;

}

void RecordNode::createNewDirectory()
Expand Down Expand Up @@ -445,27 +456,41 @@ void RecordNode::writeContinuousBuffer(float* data, int nSamples, int channel)

// find file and write samples to disk

AudioDataConverters::convertFloatToInt16BE(continuousDataFloatBuffer, continuousDataIntegerBuffer, nSamples);
//if (nSamples < 1000) // this is temporary, but there seems to be an error reading in the data if too many samples are written
// in the first few blocks
//{

int16 samps = (int16) nSamples;
AudioDataConverters::convertFloatToInt16BE(continuousDataFloatBuffer, continuousDataIntegerBuffer, nSamples);

//std::cout << samps << std::endl;
int16 samps = (int16) nSamples;

//std::cout << samps << std::endl;

fwrite(&timestamp, // ptr
8, // size of each element
1, // count
channelPointers[channel]->file); // ptr to FILE object

fwrite(&samps, // ptr
2, // size of each element
1, // count
channelPointers[channel]->file); // ptr to FILE object

int n = fwrite(continuousDataIntegerBuffer, // ptr
2, // size of each element
nSamples, // count
channelPointers[channel]->file); // ptr to FILE object
// n must equal "count", otherwise there was an error

// write a 10-byte marker indicating the end of a record
fwrite(recordMarker, // ptr
1, // size of each element
10, // count
channelPointers[channel]->file); // ptr to FILE object

fwrite(&timestamp, // ptr
8, // size of each element
1, // count
channelPointers[channel]->file); // ptr to FILE object

fwrite(&samps, // ptr
2, // size of each element
1, // count
channelPointers[channel]->file); // ptr to FILE object

int n = fwrite(continuousDataIntegerBuffer, // ptr
2, // size of each element
nSamples, // count
channelPointers[channel]->file); // ptr to FILE object
// n must equal "count", otherwise there was an error
//}
}

void RecordNode::writeEventBuffer(MidiMessage& event, int samplePosition) //, int node, int channel)
Expand Down
3 changes: 3 additions & 0 deletions Source/Processors/RecordNode.h
Expand Up @@ -179,6 +179,9 @@ class RecordNode : public GenericProcessor,
*/
void writeEventBuffer(MidiMessage& event, int samplePos);

/** Used to indicate the end of each record */
char* recordMarker;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RecordNode);

};
Expand Down
4 changes: 2 additions & 2 deletions Source/Processors/SourceNode.cpp
Expand Up @@ -307,8 +307,8 @@ void SourceNode::process(AudioSampleBuffer &buffer,
);
} else {

std::cout << "ON" << std::endl;
std::cout << c << std::endl;
// std::cout << "ON" << std::endl;
// std::cout << c << std::endl;

// signal channel state is ON
addEvent(events, // MidiBuffer
Expand Down

0 comments on commit d8e5beb

Please sign in to comment.