Skip to content

Commit

Permalink
Add lock thresholds button to SpikeViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
aacuevas committed Oct 18, 2013
1 parent 33629e8 commit 3626ee3
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 6 deletions.
129 changes: 124 additions & 5 deletions Source/Processors/Visualization/SpikeDisplayCanvas.cpp
Expand Up @@ -30,6 +30,8 @@ SpikeDisplayCanvas::SpikeDisplayCanvas(SpikeDisplayNode* n) :

viewport = new Viewport();
spikeDisplay = new SpikeDisplay(this, viewport);
thresholdCoordinator = new SpikeThresholdCoordinator();
spikeDisplay->registerThresholdCoordinator(thresholdCoordinator);

viewport->setViewedComponent(spikeDisplay, false);
viewport->setScrollBarsShown(true, false);
Expand All @@ -41,6 +43,12 @@ SpikeDisplayCanvas::SpikeDisplayCanvas(SpikeDisplayNode* n) :
clearButton->addListener(this);
addAndMakeVisible(clearButton);

lockThresholdsButton = new UtilityButton("Lock Thresholds", Font("Small Text", 13, Font::plain));
lockThresholdsButton->setRadius(3.0f);
lockThresholdsButton->addListener(this);
lockThresholdsButton->setClickingTogglesState(true);
addAndMakeVisible(lockThresholdsButton);

addAndMakeVisible(viewport);

setWantsKeyboardFocus(true);
Expand Down Expand Up @@ -103,6 +111,8 @@ void SpikeDisplayCanvas::resized()

clearButton->setBounds(10, getHeight()-40, 100,20);

lockThresholdsButton->setBounds(130, getHeight()-40, 130,20);

}

void SpikeDisplayCanvas::paint(Graphics& g)
Expand Down Expand Up @@ -151,14 +161,18 @@ void SpikeDisplayCanvas::buttonClicked(Button* button)
{
spikeDisplay->clear();
}
else if (button == lockThresholdsButton)
{
thresholdCoordinator->setLockThresholds(button->getToggleState());
}
}



// ----------------------------------------------------------------

SpikeDisplay::SpikeDisplay(SpikeDisplayCanvas* sdc, Viewport* v) :
canvas(sdc), viewport(v)
canvas(sdc), viewport(v), thresholdCoordinator(nullptr)
{

totalHeight = 1000;
Expand Down Expand Up @@ -197,6 +211,10 @@ SpikePlot* SpikeDisplay::addSpikePlot(int numChannels, int electrodeNum, String
SpikePlot* spikePlot = new SpikePlot(canvas, electrodeNum, 1000 + numChannels, name_);
spikePlots.add(spikePlot);
addAndMakeVisible(spikePlot);
if (thresholdCoordinator)
{
spikePlot->registerThresholdCoordinator(thresholdCoordinator);
}

return spikePlot;
}
Expand Down Expand Up @@ -322,12 +340,20 @@ void SpikeDisplay::plotSpike(const SpikeObject& spike, int electrodeNum)
spikePlots[electrodeNum]->processSpikeObject(spike);
}

void SpikeDisplay::registerThresholdCoordinator(SpikeThresholdCoordinator *stc)
{
thresholdCoordinator = stc;
for (int i=0; i < spikePlots.size(); i++)
{
spikePlots[i]->registerThresholdCoordinator(stc);
}
}

// ----------------------------------------------------------------

SpikePlot::SpikePlot(SpikeDisplayCanvas* sdc, int elecNum, int p, String name_) :
canvas(sdc), isSelected(false), electrodeNumber(elecNum), plotType(p),
limitsChanged(true), name(name_)
limitsChanged(true), name(name_), thresholdCoordinator(nullptr)

{

Expand Down Expand Up @@ -388,7 +414,10 @@ SpikePlot::SpikePlot(SpikeDisplayCanvas* sdc, int elecNum, int p, String name_)

SpikePlot::~SpikePlot()
{

if (thresholdCoordinator)
{
thresholdCoordinator->unregisterSpikePlot(this);
}
}

void SpikePlot::paint(Graphics& g)
Expand Down Expand Up @@ -615,6 +644,45 @@ void SpikePlot::setDetectorThresholdForChannel(int i, float t)
wAxes[i]->setDetectorThreshold(t);
}

void SpikePlot::registerThresholdCoordinator(SpikeThresholdCoordinator *stc)
{
thresholdCoordinator = stc;
stc->registerSpikePlot(this);
for (int i=0; i < wAxes.size(); i++)
{
wAxes[i]->registerThresholdCoordinator(stc);
}
}

void SpikePlot::setAllThresholds(float displayThreshold, float range)
{
String label;
for (int i=0; i< nWaveAx; i++)
{
ranges.set(i,range);
wAxes[i]->setDisplaythreshold(displayThreshold);
}

if (range == 100)
{
label = "100";
}
else if (range == 250)
{
label = "250";
}
else
{
label = "500";
}

for(int i=0; i < rangeButtons.size(); i++)
{
rangeButtons[i]->setLabel(label);
}

setLimitsOnAxes();
}

// --------------------------------------------------

Expand All @@ -628,7 +696,8 @@ WaveAxes::WaveAxes(int channel) : GenericAxes(channel),
bufferSize(5),
range(250.0f),
isOverThresholdSlider(false),
isDraggingThresholdSlider(false)
isDraggingThresholdSlider(false),
thresholdCoordinator(nullptr)

{

Expand Down Expand Up @@ -898,7 +967,12 @@ void WaveAxes::mouseDrag(const MouseEvent& event)

//std::cout << "Threshold = " << thresholdLevel << std::endl;

repaint();
if (thresholdCoordinator)
{
thresholdCoordinator->thresholdChanged(displayThresholdLevel,range);
}

repaint();
}
}

Expand Down Expand Up @@ -929,6 +1003,18 @@ void WaveAxes::setDetectorThreshold(float t)
detectorThresholdLevel = t;
}

void WaveAxes::registerThresholdCoordinator(SpikeThresholdCoordinator *stc)
{
thresholdCoordinator = stc;
}

void WaveAxes::setDisplaythreshold(float threshold)
{
displayThresholdLevel = threshold;

repaint();
}

// --------------------------------------------------

ProjectionAxes::ProjectionAxes(int projectionNum) : GenericAxes(projectionNum), imageDim(500),
Expand Down Expand Up @@ -1187,4 +1273,37 @@ double GenericAxes::ad16ToUv(int x, int gain)
{
int result = (double)(x * 20e6) / (double)(gain * pow(2.0,16));
return result;
}

SpikeThresholdCoordinator::SpikeThresholdCoordinator() : lockThresholds(false) {}

void SpikeThresholdCoordinator::registerSpikePlot(SpikePlot *sp)
{
registeredPlots.addIfNotAlreadyThere(sp);
}

void SpikeThresholdCoordinator::unregisterSpikePlot(SpikePlot *sp)
{
registeredPlots.removeAllInstancesOf(sp);
}

void SpikeThresholdCoordinator::setLockThresholds(bool en)
{
lockThresholds = en;
}

bool SpikeThresholdCoordinator::getLockThresholds()
{
return lockThresholds;
}

void SpikeThresholdCoordinator::thresholdChanged(float displayThreshold, float range)
{
if (lockThresholds)
{
for (int i = 0; i < registeredPlots.size(); i++)
{
registeredPlots[i]->setAllThresholds(displayThreshold,range);
}
}
}
37 changes: 36 additions & 1 deletion Source/Processors/Visualization/SpikeDisplayCanvas.h
Expand Up @@ -58,6 +58,7 @@ class ProjectionAxes;
class WaveAxes;
class SpikePlot;
class RecordNode;
class SpikeThresholdCoordinator;

/**
Expand Down Expand Up @@ -113,6 +114,9 @@ class SpikeDisplayCanvas : public Visualizer, public Button::Listener

int scrollBarThickness;

ScopedPointer<SpikeThresholdCoordinator> thresholdCoordinator;
ScopedPointer<UtilityButton> lockThresholdsButton;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SpikeDisplayCanvas);

};
Expand Down Expand Up @@ -140,6 +144,8 @@ class SpikeDisplay : public Component
return totalHeight;
}

void registerThresholdCoordinator(SpikeThresholdCoordinator *stc);

private:

//void computeColumnLayout();
Expand All @@ -158,6 +164,8 @@ class SpikeDisplay : public Component
// float tetrodePlotMinWidth, stereotrodePlotMinWidth, singleElectrodePlotMinWidth;
// float tetrodePlotRatio, stereotrodePlotRatio, singleElectrodePlotRatio;

SpikeThresholdCoordinator *thresholdCoordinator;

};

/**
Expand Down Expand Up @@ -203,6 +211,10 @@ class SpikePlot : public Component, Button::Listener
float getDisplayThresholdForChannel(int);
void setDetectorThresholdForChannel(int, float);

//For locking the tresholds
void registerThresholdCoordinator(SpikeThresholdCoordinator *stc);
void setAllThresholds(float displayThreshold, float range);

private:

int plotType;
Expand All @@ -226,7 +238,7 @@ class SpikePlot : public Component, Button::Listener

Font font;

SpikeThresholdCoordinator *thresholdCoordinator;

};

Expand Down Expand Up @@ -315,6 +327,10 @@ class WaveAxes : public GenericAxes

//MouseCursor getMouseCursor();

//For locking the thresholds
void registerThresholdCoordinator(SpikeThresholdCoordinator *stc);
void setDisplaythreshold(float threshold);

private:

Colour waveColour;
Expand Down Expand Up @@ -345,6 +361,7 @@ class WaveAxes : public GenericAxes
bool isDraggingThresholdSlider;

MouseCursor::StandardCursorType cursorType;
SpikeThresholdCoordinator *thresholdCoordinator;

};

Expand Down Expand Up @@ -396,6 +413,24 @@ class ProjectionAxes : public GenericAxes

};

class SpikeThresholdCoordinator
{
public:
SpikeThresholdCoordinator();
~SpikeThresholdCoordinator() {};

void registerSpikePlot(SpikePlot *sp);
void unregisterSpikePlot(SpikePlot *sp);
void setLockThresholds(bool en);
bool getLockThresholds();

void thresholdChanged(float displayThreshold, float range);

private:
bool lockThresholds;
Array<SpikePlot*> registeredPlots;

};


#endif // SPIKEDISPLAYCANVAS_H_

0 comments on commit 3626ee3

Please sign in to comment.