Skip to content
Snippets Groups Projects
Commit 86c3646f authored by jsiegle's avatar jsiegle
Browse files

Restructure LfpDisplayCanvas code

parent 3a3188f1
Branches
Tags
No related merge requests found
......@@ -25,12 +25,9 @@
#include <math.h>
LfpDisplayCanvas::LfpDisplayCanvas(LfpDisplayNode* n) :
xBuffer(105), yBuffer(2),
timebase(1.0f), displayGain(2.f), timeOffset(0.0f), processor(n),
screenBufferIndex(0), displayBufferIndex(0),
plotHeight(180), headerHeight(40), footerHeight(0),
interplotDistance(70), plotOverlap(200), selectedChan(-1)
LfpDisplayCanvas::LfpDisplayCanvas(LfpDisplayNode* processor_) :
timebase(1.0f), displayGain(2.f), timeOffset(0.0f), processor(processor_),
screenBufferIndex(0), displayBufferIndex(0)
{
nChans = processor->getNumInputs();
......@@ -41,10 +38,6 @@ LfpDisplayCanvas::LfpDisplayCanvas(LfpDisplayNode* n) :
displayBufferSize = displayBuffer->getNumSamples();
std::cout << "Setting displayBufferSize on LfpDisplayCanvas to " << displayBufferSize << std::endl;
totalHeight = nChans*(interplotDistance) + plotHeight/2 + headerHeight;
//refreshMs = 100; // override 5 s refresh rate
}
LfpDisplayCanvas::~LfpDisplayCanvas()
......@@ -59,13 +52,14 @@ void LfpDisplayCanvas::beginAnimation()
screenBufferIndex = 0;
//startCallbacks();
startCallbacks();
}
void LfpDisplayCanvas::endAnimation()
{
std::cout << "Ending animation." << std::endl;
//stopCallbacks();
stopCallbacks();
}
void LfpDisplayCanvas::update()
......@@ -79,7 +73,6 @@ void LfpDisplayCanvas::update()
repaint();
totalHeight = nChans*(interplotDistance) + plotHeight/2 + headerHeight;//(plotHeight+yBuffer)*nChans + yBuffer + headerHeight;
}
......@@ -93,7 +86,6 @@ void LfpDisplayCanvas::setParameter(int param, float val)
}
repaint();
}
void LfpDisplayCanvas::refreshState()
......@@ -102,8 +94,6 @@ void LfpDisplayCanvas::refreshState()
displayBufferIndex = processor->getDisplayBufferIndex();
screenBufferIndex = 0;
//resized();
}
void LfpDisplayCanvas::refreshScreenBuffer()
......@@ -120,8 +110,8 @@ void LfpDisplayCanvas::refreshScreenBuffer()
for (int n = 0; n < nChans; n++)
{
//waves[n][i*2] = x;
//waves[n][i*2+1] = 0.5f; // line in center of display
waves[n][i*2] = x;
waves[n][i*2+1] = 0.5f; // line in center of display
}
}
......@@ -160,13 +150,13 @@ void LfpDisplayCanvas::updateScreenBuffer()
for (int channel = 0; channel < nChans; channel++) {
gain = -1.0f / (processor->channels[channel]->bitVolts * float(0x7fff));
// waves[channel][screenBufferIndex*2+1] =
// *(displayBuffer->getSampleData(channel, displayBufferIndex))*invAlpha*gain*displayGain;
waves[channel][screenBufferIndex*2+1] =
*(displayBuffer->getSampleData(channel, displayBufferIndex))*invAlpha*gain*displayGain;
// waves[channel][screenBufferIndex*2+1] +=
// *(displayBuffer->getSampleData(channel, nextPos))*alpha*gain*displayGain;
waves[channel][screenBufferIndex*2+1] +=
*(displayBuffer->getSampleData(channel, nextPos))*alpha*gain*displayGain;
// waves[channel][screenBufferIndex*2+1] += 0.5f; // to center in viewport
waves[channel][screenBufferIndex*2+1] += 0.5f; // to center in viewport
}
......@@ -196,21 +186,9 @@ void LfpDisplayCanvas::updateScreenBuffer()
}
}
void LfpDisplayCanvas::canvasWasResized()
{
//std::cout << "Resized!" << std::endl;
refreshScreenBuffer();
}
void LfpDisplayCanvas::paint(Graphics& g)
{
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // clear buffers to preset values
//glClear(GL_COLOR_BUFFER_BIT); // clear buffers to preset values
//if (animationIsActive)
// updateScreenBuffer();
g.fillAll(Colours::magenta);
......@@ -218,444 +196,5 @@ void LfpDisplayCanvas::paint(Graphics& g)
g.drawLine(0,0, getWidth(), getHeight());
g.drawLine(0,getHeight(),getWidth(), 0);
// for (int i = 0; i < nChans; i++)
// {
// bool isSelected = false;
// if (selectedChan == i)
// isSelected = true;
// if (checkBounds(i)) {
// //setViewport(i);
// //drawBorder(isSelected);
// drawWaveform(g, i,isSelected);
// drawChannelInfo(g, i,isSelected);
// }
// }
// drawEvents(g);
// drawScrollBars(g);
// drawProgressBar(g);
// drawTimeline(g);
// glFlush();
//swapBuffers();
}
void LfpDisplayCanvas::drawEvents(Graphics& g)
{
//std::cout << waves[nChans][1] << std::endl;
// glViewport(xBuffer, 0, getWidth()-xBuffer, getHeight());
// glLineWidth(2.0f);
// // loop through events
// for (int n = 1; n < getWidth()*2; n += 2)
// {
// if (waves[nChans][n] > 0)
// {
// float x = (float(n-1)/2)/float(getWidth());
// int ttlState = int(waves[nChans][n]);
// //std::cout << x << std::endl;
// if ((ttlState & 0x100) >> 8) // channel 8
// {
// glColor4f(0.9, 0.9, 0.9, 0.4);
// glBegin(GL_LINE_STRIP);
// glVertex2f(x, 0);
// glVertex2f(x, 1);
// glEnd();
// }
// if ((ttlState & 0x80) >> 7) // channel 7
// {
// glColor4f(0.5, 0.3, 0.2, 0.1);
// glBegin(GL_LINE_STRIP);
// glVertex2f(x, 0);
// glVertex2f(x, 1);
// glEnd();
// }
// if ((ttlState & 0x40) >> 6) // channel 6
// {
// glColor4f(1.0, 0.3, 0.0, 0.1);
// glBegin(GL_LINE_STRIP);
// glVertex2f(x, 0);
// glVertex2f(x, 1);
// glEnd();
// }
// if ((ttlState & 0x20) >> 5) // channel 5
// {
// glColor4f(1.0, 0.0, 0.0, 0.1);
// glBegin(GL_LINE_STRIP);
// glVertex2f(x, 0);
// glVertex2f(x, 1);
// glEnd();
// }
// if ((ttlState & 0x10) >> 4) // channel 4
// {
// glColor4f(0.0, 1.0, 0.0, 0.1);
// glBegin(GL_LINE_STRIP);
// glVertex2f(x, 0);
// glVertex2f(x, 1);
// glEnd();
// }
// if ((ttlState & 0x8) >> 3) // channel 3
// {
// glColor4f(0.0, 0.0, 1.0, 0.1);
// glBegin(GL_LINE_STRIP);
// glVertex2f(x, 0);
// glVertex2f(x, 1);
// glEnd();
// }
// if ((ttlState & 0x4) >> 2) // channel 2
// {
// glColor4f(0.0, 1.0, 1.0, 0.1);
// glBegin(GL_LINE_STRIP);
// glVertex2f(x, 0);
// glVertex2f(x, 1);
// glEnd();
// }
// if ((ttlState & 0x2) >> 1) // channel 1
// {
// glColor4f(1.0, 1.0, 0.0, 0.1);
// glBegin(GL_LINE_STRIP);
// glVertex2f(x, 0);
// glVertex2f(x, 1);
// glEnd();
// }
// if ((ttlState & 0x1)) // channel 0
// {
// glColor4f(1.0, 1.0, 1.0, 0.1);
// glBegin(GL_LINE_STRIP);
// glVertex2f(x, 0);
// glVertex2f(x, 1);
// glEnd();
// }
// }
// }
}
void LfpDisplayCanvas::drawWaveform(Graphics& g, int chan, bool isSelected)
{
setViewport(g, chan);
int w = getWidth();
// draw zero line
// glColor4f(1.0, 1.0, 1.0, 0.2);
// glBegin(GL_LINE_STRIP);
// glVertex2f(0, 0.5);
// glVertex2f(1, 0.5);
// glEnd();
// // setWaveformColor(chan, isSelected);
// if (isSelected)
// glColor4f(1.0, 1.0, 1.0, 1.0);
// else
// glColor4f(1.0, 1.0, 1.0, 0.4);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer( 2, // number of coordinates per vertex (2, 3, or 4)
// GL_FLOAT, // data type
// 0, // byte offset between consecutive vertices
// waves[chan]); // pointer to the first coordinate of the first vertex
// glDrawArrays(GL_LINE_STRIP, // mode
// 0, // starting index
// w); // number of indices to be rendered
// glDisableClientState(GL_VERTEX_ARRAY);
}
void LfpDisplayCanvas::drawProgressBar(Graphics& g)
{
// glViewport(xBuffer,0,getWidth()-xBuffer,getHeight());
// int w = getWidth();
// // color of progress bar
// glColor4f(1.0, 1.0, 0.1, 1.0);
// glBegin(GL_LINE_STRIP);
// glVertex2f(float(screenBufferIndex)/w,0);
// glVertex2f(float(screenBufferIndex)/w,1);
// glEnd();
}
void LfpDisplayCanvas::drawTimeline(Graphics& g)
{
// glViewport(0,getHeight()-headerHeight,getWidth(),headerHeight);
// glColor4f(0.2f, 0.2f, 0.2f, 1.0f);
// glRectf(0,0,1,1);
// glColor4f(1.0f, 1.0f, 1.0f, 0.25f);
// String s = "TIME (s)";
// glRasterPos2f(5.0f/float(getWidth()), 0.7);
// getFont(cpmono_plain)->FaceSize(14);
// getFont(cpmono_plain)->Render(s);
// glViewport(xBuffer,getHeight()-headerHeight,getWidth()-xBuffer,headerHeight);
// float step;
// if (timebase < 1)
// {
// step = 0.1;
// } else if (timebase >= 1 && timebase < 2)
// {
// step = 0.2;
// } else if (timebase >= 2 && timebase < 5)
// {
// step = 0.5;
// } else {
// step = 1.0;
// }
// float currentPos = 0;
// glLineWidth(2.0);
// while (currentPos < timebase)
// {
// float xcoord = currentPos / timebase;
// glBegin(GL_LINE_STRIP);
// glVertex2f(xcoord,0);
// glVertex2f(xcoord,1);
// glEnd();
// String s = String(currentPos, 1);
// glRasterPos2f(xcoord + 5.0f/float(getWidth()), 0.4);
// getFont(cpmono_plain)->Render(s);
// currentPos += step;
// }
// glViewport(xBuffer, getHeight()-headerHeight, getWidth()-xBuffer, headerHeight/2);
// glColor4f(0.2f, 0.2f, 0.4f, 1.0f);
// glRectf(0,0,1,1);
// currentPos = 0;
// glColor4f(1.0f, 1.0f, 1.0f, 0.25f);
// while (currentPos < timebase)
// {
// float xcoord = currentPos/timebase + timeOffset / float(getWidth());
// glBegin(GL_LINE_STRIP);
// glVertex2f(xcoord,0);
// glVertex2f(xcoord,1);
// glEnd();
// String s = String(currentPos, 1);
// glRasterPos2f(xcoord+5.0f/float(getWidth()), 0.85);
// getFont(cpmono_plain)->Render(s);
// currentPos += step;
// }
}
bool LfpDisplayCanvas::checkBounds(int chan)
{
bool isVisible;
int lowerBound = (chan+1)*(interplotDistance)+plotHeight/2;//(chan+1)*(plotHeight+yBuffer);
int upperBound = chan*(interplotDistance)-plotHeight/2;
//if (getScrollAmount() < lowerBound && getScrollAmount() + getHeight() > upperBound)
// isVisible = true;
//else
// isVisible = false;
return isVisible;
}
void LfpDisplayCanvas::setViewport(Graphics& g, int chan)
{
// int y = (chan+1)*(interplotDistance); //interplotDistance - plotHeight/2);
// glViewport(xBuffer,
// getHeight()-y+getScrollAmount()- headerHeight - plotHeight/2,
// getWidth()-xBuffer,
// plotHeight);
}
void LfpDisplayCanvas::setInfoViewport(Graphics& g, int chan)
{
// int y = (chan+1)*(interplotDistance); //interplotDistance - plotHeight/2);
// glViewport(yBuffer,
// getHeight()-y+getScrollAmount()- headerHeight - interplotDistance/2 - yBuffer,
// xBuffer-yBuffer,
// interplotDistance - yBuffer*2);
}
void LfpDisplayCanvas::drawBorder(Graphics& g, bool isSelected)
{
// float alpha = 0.5f;
// if (isSelected)
// alpha = 1.0f;
// glColor4f(0.0f, 0.0f, 0.0f, alpha);
// glBegin(GL_LINE_STRIP);
// glVertex2f(0.0f, 0.0f);
// glVertex2f(1.0f, 0.0f);
// glVertex2f(1.0f, 1.0f);
// glVertex2f(0.0f, 1.0f);
// glVertex2f(0.0f, 0.0f);
// glEnd();
}
void LfpDisplayCanvas::drawChannelInfo(Graphics& g, int chan, bool isSelected)
{
// setInfoViewport(chan);
// drawBorder(isSelected);
// float alpha = 0.5f;
// if (isSelected)
// alpha = 1.0f;
// glColor4f(0.0f,0.0f,0.0f,alpha);
// glRasterPos2f(5.0f/getWidth(),0.6);
// String s = "";//String("Channel ");
// s += (chan+1);
// getFont(cpmono_bold)->FaceSize(35);
// getFont(cpmono_bold)->Render(s);
}
int LfpDisplayCanvas::getTotalHeight()
{
return totalHeight;
}
void LfpDisplayCanvas::mouseDownInCanvas(const MouseEvent& e)
{
// Point<int> pos = e.getPosition();
// int xcoord = pos.getX();
// int ycoord = pos.getY();
// if (xcoord < getWidth()-getScrollBarWidth() && ycoord > headerHeight)
// {
// int ycoord = e.getMouseDownY() - headerHeight - interplotDistance/2;// - interplotDistance/2;// - interplotDistance;
// int chan = (ycoord + getScrollAmount())/(yBuffer+interplotDistance);
// selectedChan = chan;
// repaint();
// }
}
void LfpDisplayCanvas::mouseDragInCanvas(const MouseEvent& e)
{
// int ypos = e.getMouseDownY();
// if (ypos <= headerHeight/2) {
// float scaleFactor = (float) e.getDistanceFromDragStartY();
// if (scaleFactor < 60.0 && scaleFactor > -200.0f)
// {
// timebase = pow(10.0f, -scaleFactor/200.0f);
// }
// repaint();
// } else if (ypos > headerHeight/2 && ypos < headerHeight) {
// float scaleFactor = (float) e.getDistanceFromDragStartX();
// timeOffset = scaleFactor;
// repaint();
// }
}
void LfpDisplayCanvas::mouseMoveInCanvas(const MouseEvent &e)
{
// int ypos = e.getMouseDownY();
// if (ypos <= headerHeight/2)
// {
// cursorType = MouseCursor::UpDownResizeCursor;
// } else if (ypos > headerHeight/2 && ypos < headerHeight) {
// cursorType = MouseCursor::LeftRightResizeCursor;
// } else {
// cursorType = MouseCursor::NormalCursor;
// }
}
// MouseCursor LfpDisplayCanvas::getMouseCursor()
// {
// // const MouseCursor c = MouseCursor(cursorType);
// // return c;
// }
......@@ -32,6 +32,10 @@
class LfpDisplayNode;
class LfpTimescale;
class LfpDisplay;
class LfpChannelDisplay;
/**
Displays multiple channels of continuous data.
......@@ -59,68 +63,54 @@ public:
void setParameter(int, float);
void setParameter(int, int, int, float){}
int getHeaderHeight() {return headerHeight;}
int getFooterHeight() {return footerHeight;}
//MouseCursor getMouseCursor();
void paint(Graphics& g);
private:
int xBuffer, yBuffer;
float sampleRate;
float timebase;
float displayGain;
float timeOffset;
static const int MAX_N_CHAN = 128;
static const int MAX_N_SAMP = 3000;
// GLfloat waves[MAX_N_SAMP][MAX_N_SAMP*2]; // we need an x and y point for each sample
static const int MAX_N_CHAN = 256; // maximum number of channels
static const int MAX_N_SAMP = 5000; // maximum display size in pixels
float waves[MAX_N_SAMP][MAX_N_SAMP*2]; // we need an x and y point for each sample
LfpDisplayNode* processor;
AudioSampleBuffer* displayBuffer;
MidiBuffer* eventBuffer;
void setViewport(Graphics& g, int chan);
void setInfoViewport(Graphics& g, int chan);
void drawBorder(Graphics& g, bool isSelected);
void drawChannelInfo(Graphics& g, int chan, bool isSelected);
void drawWaveform(Graphics& g, int chan, bool isSelected);
void drawEvents(Graphics& g);
void drawProgressBar(Graphics& g);
void drawTimeline(Graphics& g);
bool checkBounds(int chan);
void refreshScreenBuffer();
void updateScreenBuffer();
int screenBufferIndex;
int displayBufferIndex;
int displayBufferSize;
int nChans, plotHeight, totalHeight;
int headerHeight, footerHeight;
int interplotDistance;
int plotOverlap;
int selectedChan;
int nChans;
MouseCursor::StandardCursorType cursorType;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LfpDisplayCanvas);
};
class LfpTimescale : public Component
{
int getTotalHeight();
void canvasWasResized();
void mouseDownInCanvas(const MouseEvent& e);
void mouseDragInCanvas(const MouseEvent& e);
void mouseMoveInCanvas(const MouseEvent& e);
// void mouseUp(const MouseEvent& e);
// void mouseWheelMove(const MouseEvent&, float, float);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LfpDisplayCanvas);
};
class LfpDisplay : public Component
{
};
class LfpChannelDisplay : public Component
{
};
#endif // __LFPDISPLAYCANVAS_H_B711873A__
......@@ -37,11 +37,12 @@
*/
class Visualizer : public Component
class Visualizer : public Component,
public Timer
{
public:
Visualizer() {}
Visualizer() { refreshRate = 10; } // 10 Hz default refresh rate
~Visualizer() {}
/** Called when the component's tab becomes visible again.*/
......@@ -62,6 +63,18 @@ public:
/** Called by an editor to initiate a parameter change.*/
virtual void setParameter(int, int, int, float) = 0;
/** Starts the timer callbacks. */
void startCallbacks() { startTimer(1/refreshRate); }
/** Stops the timer callbacks. */
void stopCallbacks() { stopTimer(); }
/** Called whenever the timer is triggered. */
void timerCallback() { repaint(); }
/** Refresh rate in Hz. */
float refreshRate;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment