Skip to content

Commit

Permalink
Minor bug fixes in LfpDisplayNode
Browse files Browse the repository at this point in the history
The LfpDisplayNode/LfpDisplayCanvas are more stable now, although there's
still a bug in the DisplayNode causing small gaps to appear in the buffer.
  • Loading branch information
jsiegle committed Feb 21, 2012
1 parent 947a01f commit c5b644c
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 111 deletions.
29 changes: 21 additions & 8 deletions Source/Processors/Editors/LfpDisplayEditor.cpp
Expand Up @@ -58,8 +58,9 @@ LfpDisplayEditor::LfpDisplayEditor (GenericProcessor* parentNode,
DataViewport* dv)
: GenericEditor(parentNode, vp), dataViewport(dv),
tabIndex(-1), dataWindow(0),
streamBuffer(0), eventBuffer(0), canvas(0),
isPlaying(false)
//streamBuffer(0), eventBuffer(0), canvas(0),
isPlaying(false),
canvas(0)

{

Expand Down Expand Up @@ -116,6 +117,8 @@ LfpDisplayEditor::LfpDisplayEditor (GenericProcessor* parentNode,
addAndMakeVisible(tabSelector);
tabSelector->setToggleState(false,false);

//canvas = new LfpDisplayCanvas((LfpDisplayNode*) getProcessor());


}

Expand All @@ -133,6 +136,7 @@ LfpDisplayEditor::~LfpDisplayEditor()

void LfpDisplayEditor::enable()
{
std::cout << " Enabling LfpDisplayEditor" << std::endl;
if (canvas != 0)
canvas->beginAnimation();

Expand All @@ -149,6 +153,7 @@ void LfpDisplayEditor::disable()

void LfpDisplayEditor::updateNumInputs(int n)
{
std::cout << "Setting num inputs on LfpDisplayEditor to " << n << std::endl;
if (canvas != 0)
canvas->updateNumInputs(n);
}
Expand All @@ -161,12 +166,12 @@ void LfpDisplayEditor::updateSampleRate(float r)

void LfpDisplayEditor::setBuffers(AudioSampleBuffer* asb, MidiBuffer* mb)
{
std::cout << "Buffers are set!" << std::endl;
streamBuffer = asb;
eventBuffer = mb;
std::cout << "LfpDisplayEditor buffers are set!" << std::endl;
//streamBuffer = asb;
//eventBuffer = mb;

std::cout << streamBuffer << std::endl;
std::cout << eventBuffer << std::endl;
//std::cout << streamBuffer << std::endl;
//std::cout << eventBuffer << std::endl;
}

void LfpDisplayEditor::buttonClicked(Button* button)
Expand All @@ -183,7 +188,10 @@ void LfpDisplayEditor::buttonClicked(Button* button)
} else {

if (canvas == 0) {
canvas = new LfpDisplayCanvas((LfpDisplayNode*) getProcessor());

LfpDisplayNode* processor = (LfpDisplayNode*) getProcessor();
canvas = new LfpDisplayCanvas(processor);

if (isPlaying)
canvas->beginAnimation();
}
Expand Down Expand Up @@ -249,6 +257,11 @@ void LfpDisplayEditor::buttonClicked(Button* button)

//LfpDisplayNode* p = (LfpDisplayNode*) getProcessor();
tabIndex = dataViewport->addTabToDataViewport("LFP",canvas);
//if (isPlaying)
///{
// canvas->beginAnimation();
//}

//p->isVisible = true;

} else if (!tabSelector->getToggleState() && tabIndex > -1)
Expand Down
4 changes: 2 additions & 2 deletions Source/Processors/Editors/LfpDisplayEditor.h
Expand Up @@ -78,8 +78,8 @@ class LfpDisplayEditor : public GenericEditor,

ScopedPointer <LfpDisplayCanvas> canvas;

AudioSampleBuffer* streamBuffer;
MidiBuffer* eventBuffer;
//AudioSampleBuffer* streamBuffer;
//MidiBuffer* eventBuffer;
UIComponent* UI;
DataViewport* dataViewport;

Expand Down
103 changes: 33 additions & 70 deletions Source/Processors/LfpDisplayNode.cpp
Expand Up @@ -26,70 +26,52 @@

LfpDisplayNode::LfpDisplayNode()
: GenericProcessor("LFP Viewer"),
timebase(1000), displayGain(1), parameterChanged(true), isVisible(false),
xBuffer(10), yBuffer(10),
plotHeight(60), selectedChan(-1),
displayBufferIndex(0),// screenBufferIndex(0),
repaintInterval(10), repaintCounter(0)
bufferLength(5.0f), displayGain(1),
displayBufferIndex(0)

{

numInputs = 2;
numOutputs = 0;
sampleRate = 44100.0;

lock = new ReadWriteLock();

displayBuffer = 0;
//screenBuffer = 0; //new AudioSampleBuffer(16, 10000);

//setNumInputs(16);
//setSampleRate(10000.0);
setPlayConfigDetails(16,0,44100.0,128);
setPlayConfigDetails(2,0,44100.0,128);

displayBuffer = new AudioSampleBuffer (8, 100);
eventBuffer = new MidiBuffer();
}

LfpDisplayNode::~LfpDisplayNode()
{
if (displayBuffer != 0)
deleteAndZero(displayBuffer);

//if (screenBuffer != 0)
// deleteAndZero(screenBuffer);

deleteAndZero(displayBuffer);
deleteAndZero(eventBuffer);
deleteAndZero(lock);
}

AudioProcessorEditor* LfpDisplayNode::createEditor()
{

std::cout << "Processor data viewport: " << getDataViewport() << std::endl;

LfpDisplayEditor* editor = new LfpDisplayEditor(this, viewport, getDataViewport());

editor->setBuffers(displayBuffer,eventBuffer);
editor->setUIComponent(getUIComponent());
editor->setConfiguration(config);
//editor->setBuffers (displayBuffer, eventBuffer);
editor->setUIComponent (getUIComponent());
editor->setConfiguration (config);
//editor->updateNumInputs(getNumInputs());
//editor->updateSampleRate(sampleRate);

setEditor(editor);

std::cout << "Creating LFP Display Editor." << std::endl;
return editor;

}

void LfpDisplayNode::setNumInputs(int inputs)
{
std::cout << "Setting num inputs on LfpDisplayNode to " << inputs << std::endl;
numInputs = inputs;
setNumOutputs(0);

int nSamples = (int) sampleRate*10.0f;
int nInputs = getNumInputs();
std::cout << "Setting inputs. Samples: " << nSamples << ", Inputs: " << nInputs << std::endl;

setPlayConfigDetails(getNumInputs(), 0, 44100.0, 128);

if (nSamples > 0 && nInputs > 0)
resizeBuffer();
setPlayConfigDetails(getNumInputs(),0,44100.0,128);

LfpDisplayEditor* editor = (LfpDisplayEditor*) getEditor();
editor->updateNumInputs(inputs);
Expand All @@ -98,47 +80,41 @@ void LfpDisplayNode::setNumInputs(int inputs)
void LfpDisplayNode::setSampleRate(float r)
{
sampleRate = r;
int nSamples = (int) sampleRate*10.0f;
int nInputs = getNumInputs();
std::cout << "Setting sample rate. Samples: " << nSamples << ", Inputs: " << nInputs << std::endl;

resizeBuffer();

LfpDisplayEditor* editor = (LfpDisplayEditor*) getEditor();
editor->updateSampleRate(r);
}

void LfpDisplayNode::resizeBuffer()
bool LfpDisplayNode::resizeBuffer()
{
int nSamples = (int) sampleRate*10.0f;
int nSamples = (int) sampleRate*bufferLength;
int nInputs = getNumInputs();

std::cout << "Resizing buffer. Samples: " << nSamples << ", Inputs: " << nInputs << std::endl;

if (displayBuffer != 0)
deleteAndZero(displayBuffer);

//if (screenBuffer != 0)
//deleteAndZero(screenBuffer);

displayBuffer = new AudioSampleBuffer(nInputs, nSamples);
//screenBuffer = new AudioSampleBuffer(nInputs, 10000);
if (nSamples > 0 && nInputs > 0)
{
displayBuffer->setSize(nInputs, nSamples);
return true;
} else {
return false;
}

}

bool LfpDisplayNode::enable()
{

if (displayBuffer == 0)
displayBuffer = new AudioSampleBuffer(16, 100000);

if (isEnabled) {
LfpDisplayEditor* editor = (LfpDisplayEditor*) getEditor();
editor->enable();
return true;
if (resizeBuffer())
{
LfpDisplayEditor* editor = (LfpDisplayEditor*) getEditor();
editor->enable();
return true;
} else {
return false;
}

}

bool LfpDisplayNode::disable()
Expand All @@ -150,19 +126,6 @@ bool LfpDisplayNode::disable()

void LfpDisplayNode::setParameter (int parameterIndex, float newValue)
{
//std::cout << "Message received." << std::endl;

// if (parameterIndex == 0) {
// timebase = newValue;
// //screenBuffer->clear();
// //screenBufferIndex = 0;
// } else {
// displayGain = newValue;
// screenBuffer->clear();
// screenBufferIndex = 0;
// }

// parameterChanged = true;

}

Expand All @@ -186,7 +149,7 @@ void LfpDisplayNode::process(AudioSampleBuffer &buffer, MidiBuffer &midiMessages
nSamples); // numSamples

}
displayBufferIndex += nSamples;
displayBufferIndex += (nSamples);

} else {

Expand All @@ -209,7 +172,7 @@ void LfpDisplayNode::process(AudioSampleBuffer &buffer, MidiBuffer &midiMessages
extraSamples);
}

displayBufferIndex = extraSamples;
displayBufferIndex = extraSamples+1;
}

//lock->exitWrite();
Expand Down
21 changes: 2 additions & 19 deletions Source/Processors/LfpDisplayNode.h
Expand Up @@ -42,7 +42,6 @@ class DataViewport;

class LfpDisplayNode : public GenericProcessor


{
public:

Expand All @@ -65,36 +64,20 @@ class LfpDisplayNode : public GenericProcessor

AudioSampleBuffer* getDisplayBufferAddress() {return displayBuffer;}
int getDisplayBufferIndex() {return displayBufferIndex;}
ReadWriteLock* getLock() {return lock;}

bool isVisible;

ReadWriteLock* lock;

private:

DataViewport* dataViewport;

AudioSampleBuffer* displayBuffer;

MidiBuffer* eventBuffer;

int displayBufferIndex;

int repaintInterval, repaintCounter;

int selectedChan;

float timebase; // ms
float displayGain; //
float bufferLength; // s

int xBuffer, yBuffer, plotHeight, totalHeight;

bool parameterChanged;

void resizeBuffer();

void resized();
bool resizeBuffer();

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LfpDisplayNode);

Expand Down
23 changes: 13 additions & 10 deletions Source/Processors/Visualization/LfpDisplayCanvas.cpp
Expand Up @@ -31,19 +31,19 @@ LfpDisplayCanvas::LfpDisplayCanvas(LfpDisplayNode* n) : processor(n),

//GenericProcessor* gp = (GenericProcessor*) editor->getProcessor();


nChans = processor->getNumInputs();
sampleRate = processor->getSampleRate();
std::cout << "Setting num inputs on LfpDisplayCanvas to " << nChans << std::endl;

displayBuffer = processor->getDisplayBufferAddress();
displayBufferSize = displayBuffer->getNumSamples();
std::cout << "Setting displayBufferSize on LfpDisplayCanvas to " << displayBufferSize << std::endl;

lock = processor->getLock();

//screenBuffer = new AudioSampleBuffer(nChans, 10000);

//setBounds(0,0,700,400);

totalHeight = (plotHeight+yBuffer)*nChans + yBuffer;

screenBuffer = new AudioSampleBuffer(nChans, 10000);

}

Expand All @@ -61,7 +61,6 @@ void LfpDisplayCanvas::newOpenGLContextCreated()
glClearColor (0.667, 0.698, 0.718, 1.0);
resized();

screenBuffer = new AudioSampleBuffer(nChans, 10000);

//startTimer(50);

Expand All @@ -71,7 +70,11 @@ void LfpDisplayCanvas::beginAnimation()
{
std::cout << "Beginning animation." << std::endl;

displayBufferIndex = 0;
displayBufferSize = displayBuffer->getNumSamples();

screenBuffer->clear();

//displayBufferIndex = 0;
screenBufferIndex = 0;

startCallbacks();
Expand All @@ -85,7 +88,10 @@ void LfpDisplayCanvas::endAnimation()

void LfpDisplayCanvas::updateNumInputs(int n)
{
std::cout << "Setting num inputs on LfpDisplayCanvas to " << n << std::endl;
nChans = n;
if (n < 200)
screenBuffer->setSize(nChans, 10000);
//sampleRate = processor->getSampleRate();
}

Expand Down Expand Up @@ -157,9 +163,6 @@ void LfpDisplayCanvas::updateScreenBuffer()
if (overflow > 0)
screenBuffer->clear(0, overflow);




for (int i = 0; i < valuesNeeded; i++)
{
float gain = 1.0;
Expand Down

0 comments on commit c5b644c

Please sign in to comment.