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

Changes to prevent crashes during acquisition when activating new editors

parent 82329af5
Branches
Tags
No related merge requests found
......@@ -31,7 +31,7 @@ FileReaderThread::FileReaderThread(SourceNode* sn) : DataThread(sn)
//input = file.createInputStream();
bufferSize = 1600;
input = fopen("./data_stream_16ch", "r");
input = fopen("./data_stream_16ch_2", "r");
fseek(input, 0, SEEK_END);
lengthOfInputFile = ftell(input);
......@@ -68,7 +68,7 @@ float FileReaderThread::getSampleRate()
float FileReaderThread::getBitVolts()
{
return 1.0f;
return 0.0305f;
}
bool FileReaderThread::startAcquisition()
......@@ -109,7 +109,7 @@ bool FileReaderThread::updateBuffer()
for (int n = 0; n < bufferSize; n++)
{
thisSample[chan] = float(readBuffer[n])/80000.0f;
thisSample[chan] = float(-readBuffer[n])*0.0305f;
if (chan == 15)
{
......
......@@ -249,7 +249,7 @@ void SpikeDetectorEditor::buttonEvent(Button* button)
drawElectrodeButtons(electrodeList->getNumItems()-1);
getEditorViewport()->makeEditorVisible(this);
getEditorViewport()->makeEditorVisibleAndUpdateSettings(this);
return;
} else if (button == electrodeEditorButtons[0]) // EDIT
......@@ -293,7 +293,7 @@ void SpikeDetectorEditor::buttonEvent(Button* button)
removeElectrode(electrodeList->getSelectedItemIndex());
getEditorViewport()->makeEditorVisible(this);
getEditorViewport()->makeEditorVisibleAndUpdateSettings(this);
return;
}
......@@ -517,7 +517,7 @@ ThresholdSlider::ThresholdSlider(Font f) : Slider("name"), font(f)
{
setSliderStyle(Slider::Rotary);
setRange(25.0f,200.0f,1.0f);
setRange(25.0f,400.0f,25.0f);
setValue(75.0f);
setTextBoxStyle(Slider::NoTextBox, false, 40, 20);
......
......@@ -152,7 +152,7 @@ bool SpikeDetector::addElectrode(int nChans)
float SpikeDetector::getDefaultThreshold()
{
return 75.0f;
return 250.0f;
}
StringArray SpikeDetector::getElectrodeNames()
......@@ -398,11 +398,21 @@ float SpikeDetector::getNextSample(int& chan)
if (sampleIndex < 0)
{
// std::cout << " sample index " << sampleIndex << "from overflowBuffer" << std::endl;
return *overflowBuffer.getSampleData(chan, overflowBufferSize + sampleIndex);
int ind = overflowBufferSize + sampleIndex;
if (ind < overflowBuffer.getNumChannels())
return *overflowBuffer.getSampleData(chan, ind);
else
return 0;
} else {
// useOverflowBuffer = false;
// std::cout << " sample index " << sampleIndex << "from regular buffer" << std::endl;
return *dataBuffer.getSampleData(chan, sampleIndex);
if (sampleIndex < dataBuffer.getNumChannels())
return *dataBuffer.getSampleData(chan, sampleIndex);
else
return 0;
}
//} else {
// std::cout << " sample index " << sampleIndex << "from regular buffer" << std::endl;
......
......@@ -249,7 +249,8 @@ void LfpDisplayCanvas::drawWaveform(int chan, bool isSelected)
for (float i = 0; i < float(getWidth()); i++)
{
glVertex2f(i/w,*screenBuffer->getSampleData(chan, int(i))+0.5);
if ((int) i < screenBuffer->getNumSamples()) // check to avoid triggering assertion at juce_AudioSampleBuffer.h: 126
glVertex2f(i/w,*screenBuffer->getSampleData(chan, int(i))+0.5);
}
glEnd();
......
......@@ -249,6 +249,20 @@ void EditorViewport::makeEditorVisible(GenericEditor* editor)
}
void EditorViewport::makeEditorVisibleAndUpdateSettings(GenericEditor* editor)
{
if (editor == 0)
return;
signalChainManager->updateVisibleEditors(editor, 0, 0, UPDATE);
refreshEditors();
editor->highlight();
}
void EditorViewport::deleteNode (GenericEditor* editor) {
if (canEdit) {
......
......@@ -67,6 +67,7 @@ public:
void selectEditor(GenericEditor* e);
void makeEditorVisible(GenericEditor* e);
void makeEditorVisibleAndUpdateSettings(GenericEditor* e);
void refreshEditors();
void signalChainCanBeEdited(bool t);
......@@ -131,7 +132,7 @@ private:
int currentTab;
enum actions {ADD, MOVE, REMOVE, ACTIVATE};
enum actions {ADD, MOVE, REMOVE, ACTIVATE, UPDATE};
enum directions1 {LEFT, RIGHT};
enum directions2 {UP, DOWN};
......
......@@ -151,7 +151,7 @@ void SignalChainManager::updateVisibleEditors(GenericEditor* activeEditor,
{
enum actions {ADD, MOVE, REMOVE, ACTIVATE };
enum actions {ADD, MOVE, REMOVE, ACTIVATE, UPDATE};
// Step 1: update the editor array
if (action == ADD) /// add
......@@ -237,7 +237,7 @@ void SignalChainManager::updateVisibleEditors(GenericEditor* activeEditor,
}
// Step 2: update connections
if (action != ACTIVATE && editorArray.size() > 0) {
if (action != ACTIVATE && action != UPDATE && editorArray.size() > 0) {
std::cout << "Updating connections." << std::endl;
......@@ -260,7 +260,7 @@ void SignalChainManager::updateVisibleEditors(GenericEditor* activeEditor,
}
// Step 3: check for new tabs
if (action != ACTIVATE) {
if (action != ACTIVATE && action != UPDATE) {
std::cout << "Checking for new tabs." << std::endl;
......@@ -365,7 +365,7 @@ void SignalChainManager::updateVisibleEditors(GenericEditor* activeEditor,
}
// Step 5: check the validity of the signal chain
if (true) {
if (action != ACTIVATE) {
bool enable = true;
if (editorArray.size() == 1) {
......@@ -414,7 +414,7 @@ void SignalChainManager::updateVisibleEditors(GenericEditor* activeEditor,
}
// Step 7: update all settings
if (true) {//action != ACTIVATE) {
if (action != ACTIVATE) {
std::cout << "Updating settings." << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment