From 1e449666b2c27f2a47e523d63e1fad7c485d8f31 Mon Sep 17 00:00:00 2001 From: jsiegle <jsiegle@mit.edu> Date: Wed, 18 Apr 2012 16:04:46 -0400 Subject: [PATCH] Updated interface for parameter selection --- Source/Processors/DataThreads/FPGAThread.cpp | 3 +- Source/Processors/Editors/ChannelSelector.cpp | 1 + Source/Processors/Editors/EventNodeEditor.cpp | 8 +- Source/Processors/Editors/FilterEditor.cpp | 12 +-- Source/Processors/Editors/GenericEditor.cpp | 25 ++---- Source/Processors/Editors/GenericEditor.h | 2 +- .../Processors/Editors/LfpDisplayEditor.cpp | 19 +---- Source/Processors/Editors/ParameterEditor.cpp | 82 +++++++++++++++---- Source/Processors/Editors/ParameterEditor.h | 24 +++++- .../Processors/Editors/VisualizerEditor.cpp | 2 +- Source/Processors/EventNode.cpp | 18 ++-- Source/Processors/EventNode.h | 2 +- Source/Processors/FilterNode.cpp | 65 +++++++++++++-- Source/Processors/GenericProcessor.cpp | 2 +- Source/Processors/LfpDisplayNode.cpp | 21 ++++- Source/Processors/Parameter.cpp | 22 ++--- Source/Processors/Parameter.h | 10 ++- Source/Processors/SignalGenerator.cpp | 5 +- 18 files changed, 215 insertions(+), 108 deletions(-) diff --git a/Source/Processors/DataThreads/FPGAThread.cpp b/Source/Processors/DataThreads/FPGAThread.cpp index 9a6b77667..f7f45df00 100644 --- a/Source/Processors/DataThreads/FPGAThread.cpp +++ b/Source/Processors/DataThreads/FPGAThread.cpp @@ -74,8 +74,7 @@ FPGAThread::~FPGAThread() { // probably not the best way to do this: deleteAndZero(dataBuffer); - delete dev; - dev = 0; + deleteAndZero(dev); } diff --git a/Source/Processors/Editors/ChannelSelector.cpp b/Source/Processors/Editors/ChannelSelector.cpp index 4f25d486e..98dc40623 100644 --- a/Source/Processors/Editors/ChannelSelector.cpp +++ b/Source/Processors/Editors/ChannelSelector.cpp @@ -100,6 +100,7 @@ void ChannelSelector::paint(Graphics& g) g.fillRect(0, 15, getWidth(), getHeight()-30); } + void ChannelSelector::setNumChannels(int numChans) { diff --git a/Source/Processors/Editors/EventNodeEditor.cpp b/Source/Processors/Editors/EventNodeEditor.cpp index 26baa7c82..fe9f9cab0 100644 --- a/Source/Processors/Editors/EventNodeEditor.cpp +++ b/Source/Processors/Editors/EventNodeEditor.cpp @@ -29,13 +29,9 @@ EventNodeEditor::EventNodeEditor (GenericProcessor* parentNode) : GenericEditor(parentNode) { - desiredWidth = 250; + desiredWidth = 200; - StringArray hzValues; - hzValues.add("0.25"); - hzValues.add("0.5"); - hzValues.add("1"); - hzValues.add("2"); + //createRadioButtons(35, 65, 160, hzValues, "Event frequency"); diff --git a/Source/Processors/Editors/FilterEditor.cpp b/Source/Processors/Editors/FilterEditor.cpp index a6c64763c..c54b9b0c9 100644 --- a/Source/Processors/Editors/FilterEditor.cpp +++ b/Source/Processors/Editors/FilterEditor.cpp @@ -32,17 +32,7 @@ FilterEditor::FilterEditor (GenericProcessor* parentNode) { desiredWidth = 250; - StringArray lowCutValues; - lowCutValues.add("1"); - lowCutValues.add("10"); - lowCutValues.add("100"); - lowCutValues.add("500"); - - StringArray highCutValues; - highCutValues.add("1K"); - highCutValues.add("3K"); - highCutValues.add("6K"); - highCutValues.add("9K"); + //createRadioButtons(35, 50, 160, lowCutValues, "Low Cutoff"); //createRadioButtons(35, 90, 160, highCutValues, "High Cutoff"); diff --git a/Source/Processors/Editors/GenericEditor.cpp b/Source/Processors/Editors/GenericEditor.cpp index fac0c8590..4634d80c5 100644 --- a/Source/Processors/Editors/GenericEditor.cpp +++ b/Source/Processors/Editors/GenericEditor.cpp @@ -92,8 +92,9 @@ void GenericEditor::addParameterEditors() for (int i = 0; i < getProcessor()->getNumParameters(); i++) { - ParameterEditor* p = new ParameterEditor(getProcessor()->getParameterReference(i), titleFont); + ParameterEditor* p = new ParameterEditor(getProcessor(), getProcessor()->getParameterReference(i), titleFont); + p->setChannelSelector(channelSelector); int dWidth = p->desiredWidth; int dHeight = p->desiredHeight; @@ -285,8 +286,6 @@ void GenericEditor::buttonClicked(Button* button) { std::cout << "Button clicked." << std::endl; - - checkParameterButtons(button); checkDrawerButton(button); @@ -294,20 +293,6 @@ void GenericEditor::buttonClicked(Button* button) // button event } -void GenericEditor::sliderValueChanged(Slider* slider) -{ - std::cout << "Slider name: " << slider->getName() << std::endl; - std::cout << "Slider value: " << slider->getValue() << std::endl; - - sliderEvent(slider); - -} - -bool GenericEditor::checkParameterButtons(Button* button) -{ - std::cout << "Button name: " << button->getName() << std::endl; - std::cout << "Button value: " << button->getButtonText() << std::endl; -} bool GenericEditor::checkDrawerButton(Button* button) { @@ -338,6 +323,12 @@ bool GenericEditor::checkDrawerButton(Button* button) } +void GenericEditor::sliderValueChanged(Slider* slider) +{ + + sliderEvent(slider); +} + void GenericEditor::update() { diff --git a/Source/Processors/Editors/GenericEditor.h b/Source/Processors/Editors/GenericEditor.h index a1f668993..d7b187ab8 100644 --- a/Source/Processors/Editors/GenericEditor.h +++ b/Source/Processors/Editors/GenericEditor.h @@ -99,7 +99,7 @@ public: virtual void sliderEvent(Slider* slider) {} bool checkDrawerButton(Button* button); - bool checkParameterButtons(Button* button); +// bool checkParameterButtons(Button* button); bool getRecordStatus(int chan); diff --git a/Source/Processors/Editors/LfpDisplayEditor.cpp b/Source/Processors/Editors/LfpDisplayEditor.cpp index 7ef2a4a05..0fe61a9b8 100644 --- a/Source/Processors/Editors/LfpDisplayEditor.cpp +++ b/Source/Processors/Editors/LfpDisplayEditor.cpp @@ -31,24 +31,7 @@ LfpDisplayEditor::LfpDisplayEditor (GenericProcessor* parentNode) tabText = "LFP"; - desiredWidth = 250; - - StringArray timeBaseValues; - timeBaseValues.add("1"); - timeBaseValues.add("2"); - timeBaseValues.add("5"); - timeBaseValues.add("10"); - - //createRadioButtons(35, 50, 160, timeBaseValues, "Display width (s)"); - - StringArray displayGainValues; - displayGainValues.add("1"); - displayGainValues.add("2"); - displayGainValues.add("4"); - displayGainValues.add("8"); - - //createRadioButtons(35, 90, 160, displayGainValues, "Display Gain"); - + desiredWidth = 180; } diff --git a/Source/Processors/Editors/ParameterEditor.cpp b/Source/Processors/Editors/ParameterEditor.cpp index db6a162e1..79908223a 100644 --- a/Source/Processors/Editors/ParameterEditor.cpp +++ b/Source/Processors/Editors/ParameterEditor.cpp @@ -23,9 +23,11 @@ #include "ParameterEditor.h" -ParameterEditor::ParameterEditor(Parameter& p, Font labelFont) +ParameterEditor::ParameterEditor(GenericProcessor* proc, Parameter& p, Font labelFont) { + processor = proc; + if (p.isBoolean()) { std::cout << "Boolean parameter. Creating checkbox." << std::endl; @@ -34,8 +36,10 @@ ParameterEditor::ParameterEditor(Parameter& p, Font labelFont) ParameterCheckbox* pc = new ParameterCheckbox((bool) p.getDefaultValue()); addAndMakeVisible(pc); pc->setBounds(0,0,12, 12); - pc->setName(p.getName()); + pc->setName(String(p.getID())); buttonArray.add(pc); + //buttonIdArray.add(p.getID()); + pc->addListener(this); Label* label = new Label(p.getName(), p.getName()); labelFont.setHeight(10); @@ -58,9 +62,11 @@ ParameterEditor::ParameterEditor(Parameter& p, Font labelFont) labelFont); ps->setBounds(0,0, 40, 40); - ps->setName(p.getName()); + ps->setName(String(p.getID())); addAndMakeVisible(ps); sliderArray.add(ps); + //sliderIdArray.add(p.getID()); + ps->addListener(this); Label* label = new Label(p.getName(), p.getName()); labelFont.setHeight(10); @@ -92,7 +98,9 @@ ParameterEditor::ParameterEditor(Parameter& p, Font labelFont) std::cout << "Default value: " << (int) p.getDefaultValue() << std::endl; - for (int i = 0; i < possibleValues.size(); i++) + int i; + + for (i = 0; i < possibleValues.size(); i++) { std::cout << "Creating button " << i << std::endl; int buttonType = MIDDLE; @@ -103,8 +111,10 @@ ParameterEditor::ParameterEditor(Parameter& p, Font labelFont) ParameterButton* pb = new ParameterButton(possibleValues[i], buttonType, labelFont); pb->setBounds(buttonWidth*i, 12, buttonWidth, 18); - pb->setName(p.getName()); + pb->setName(String(p.getID())); buttonArray.add(pb); + //buttonIdArray.add(p.getID()); + pb->addListener(this); if (i == (int) p.getDefaultValue()) pb->setToggleState(true, false); @@ -113,7 +123,7 @@ ParameterEditor::ParameterEditor(Parameter& p, Font labelFont) } - desiredWidth = 120; + desiredWidth = buttonWidth*i; desiredHeight = 30; } } @@ -125,25 +135,69 @@ ParameterEditor::~ParameterEditor() void ParameterEditor::parentHierarchyChanged() { - std::cout << "Parent hierarchy changed." << std::endl; + // std::cout << "Parent hierarchy changed." << std::endl; - // register all children with parent --> not currently working - if (getParentComponent() != 0) { + // // register all children with parent --> not currently working + // if (getParentComponent() != 0) { - for (int i = 0; i < sliderArray.size(); i++) + // for (int i = 0; i < sliderArray.size(); i++) + // { + // sliderArray[i]->addListener((Slider::Listener*) getParentComponent()); + // } + + // for (int i = 0; i < buttonArray.size(); i++) + // { + // buttonArray[i]->addListener((Button::Listener*) getParentComponent()); + // } + // } + +} + +void ParameterEditor::buttonClicked(Button* button) +{ + //std::cout << "Button name: " << button->getName() << std::endl; + //std::cout << "Button value: " << button->getButtonText() << std::endl; + + Array<int> a = channelSelector->getActiveChannels(); + { + for (int i = 0; i < a.size(); i++) { - sliderArray[i]->addListener((Slider::Listener*) getParentComponent()); + //std::cout << a[i] << " "; + processor->setCurrentChannel(a[i]); + processor->setParameter(button->getName().getIntValue(), + button->getButtonText().getFloatValue()); + //processor-> } + //std::cout << std::endl; + } - for (int i = 0; i < buttonArray.size(); i++) + //processor->sliderValueChanged(slider); + +} + +void ParameterEditor::sliderValueChanged(Slider* slider) +{ + + + //std::cout << "Slider name: " << slider->getName() << std::endl; + //std::cout << "Slider value: " << slider->getValue() << std::endl; + + Array<int> a = channelSelector->getActiveChannels(); + { + for (int i = 0; i < a.size(); i++) { - buttonArray[i]->addListener((Button::Listener*) getParentComponent()); + //std::cout << a[i] << " "; + processor->setCurrentChannel(a[i]); + processor->setParameter(slider->getName().getIntValue(), + slider->getValue()); + //processor-> } + //std::cout << std::endl; } - } + /// ============= PARAMETER BUTTON ================== ParameterButton::ParameterButton(var value, int buttonType, Font labelFont) : diff --git a/Source/Processors/Editors/ParameterEditor.h b/Source/Processors/Editors/ParameterEditor.h index c3d592acd..b33628a15 100644 --- a/Source/Processors/Editors/ParameterEditor.h +++ b/Source/Processors/Editors/ParameterEditor.h @@ -25,7 +25,8 @@ #define __PARAMETEREDITOR_H_44537DA9__ #include "../../../JuceLibraryCode/JuceHeader.h" -#include "GenericEditor.h" +#include "../GenericProcessor.h" +#include "ChannelSelector.h" #include "../Parameter.h" #include <stdio.h> @@ -34,15 +35,17 @@ Automatically creates an interactive editor for a particular parameter. - @see GenericEditor, Parameter + @see GenericEditor, GenericProcessor, Parameter */ -class ParameterEditor : public Component +class ParameterEditor : public Component, + public Button::Listener, + public Slider::Listener { public: - ParameterEditor(Parameter& p, Font labelFont); + ParameterEditor(GenericProcessor* proc, Parameter& p, Font labelFont); ~ParameterEditor(); @@ -51,10 +54,23 @@ public: void parentHierarchyChanged(); + void buttonClicked(Button* button); + void sliderValueChanged(Slider* slider); + + void setChannelSelector(ChannelSelector* ch) + { + channelSelector = ch; + } + private: Array<Slider*> sliderArray; Array<Button*> buttonArray; + Array<int> buttonIdArray; + Array<int> sliderIdArray; + + GenericProcessor* processor; + ChannelSelector* channelSelector; enum { LEFT, diff --git a/Source/Processors/Editors/VisualizerEditor.cpp b/Source/Processors/Editors/VisualizerEditor.cpp index db474bbb2..ead969534 100644 --- a/Source/Processors/Editors/VisualizerEditor.cpp +++ b/Source/Processors/Editors/VisualizerEditor.cpp @@ -84,7 +84,7 @@ VisualizerEditor::VisualizerEditor (GenericProcessor* parentNode) { - desiredWidth = 250; + desiredWidth = 180; initializeSelectors(); diff --git a/Source/Processors/EventNode.cpp b/Source/Processors/EventNode.cpp index b36be29e7..e3c18aa68 100644 --- a/Source/Processors/EventNode.cpp +++ b/Source/Processors/EventNode.cpp @@ -28,6 +28,14 @@ EventNode::EventNode() : GenericProcessor("Event Generator"), Hz(1), accumulator(0) { + Array<var> hzValues; + hzValues.add(0.25f); + hzValues.add(0.5f); + hzValues.add(1.0f); + hzValues.add(2.0f); + + parameters.add(Parameter("Frequency",hzValues, 0, 0)); + } EventNode::~EventNode() @@ -49,11 +57,11 @@ void EventNode::updateSettings() } -void EventNode::setParameter (int parameterIndex, float newValue) -{ - std::cout << "Setting frequency to " << newValue << " Hz." << std::endl; - Hz = newValue; -} +// void EventNode::setParameter (int parameterIndex, float newValue) +// { +// std::cout << "Setting frequency to " << newValue << " Hz." << std::endl; +// Hz = newValue; +// } void EventNode::process(AudioSampleBuffer &buffer, diff --git a/Source/Processors/EventNode.h b/Source/Processors/EventNode.h index f0664849d..788544916 100644 --- a/Source/Processors/EventNode.h +++ b/Source/Processors/EventNode.h @@ -45,7 +45,7 @@ public: ~EventNode(); void process(AudioSampleBuffer &buffer, MidiBuffer &midiMessages, int& nSamples); - void setParameter (int parameterIndex, float newValue); + //void setParameter (int parameterIndex, float newValue); bool isSource() {return true;} diff --git a/Source/Processors/FilterNode.cpp b/Source/Processors/FilterNode.cpp index e381b58ea..29ac76598 100644 --- a/Source/Processors/FilterNode.cpp +++ b/Source/Processors/FilterNode.cpp @@ -30,6 +30,22 @@ FilterNode::FilterNode() { + Array<var> lowCutValues; + lowCutValues.add(1.0f); + lowCutValues.add(10.0f); + lowCutValues.add(100.0f); + lowCutValues.add(500.0f); + + parameters.add(Parameter("low cut",lowCutValues, 0, 0)); + + Array<var> highCutValues; + highCutValues.add(1000.0f); + highCutValues.add(3000.0f); + highCutValues.add(6000.0f); + highCutValues.add(9000.0f); + + parameters.add(Parameter("high cut",highCutValues, 0, 1)); + } FilterNode::~FilterNode() @@ -85,8 +101,8 @@ void FilterNode::updateSettings() { filters.clear(); - lowCuts.clear(); - highCuts.clear(); +// lowCuts.clear(); + //highCuts.clear(); if (getNumInputs() < 100) { @@ -101,8 +117,11 @@ void FilterNode::updateSettings() Dsp::DirectFormII> // realization (1024)); - lowCuts.add(1.0f); - highCuts.add(1000.0f); + Parameter& p1 = parameters.getReference(0); + p1.setValue(1.0f, n); + + Parameter& p2 = parameters.getReference(1); + p2.setValue(1000.0f, n); setFilterParameters(1.0f, 1000.0f, n); } @@ -128,14 +147,42 @@ void FilterNode::setFilterParameters(double lowCut, double highCut, int chan) void FilterNode::setParameter (int parameterIndex, float newValue) { - if (parameterIndex == 0) { - lowCuts.set(currentChannel, newValue); - setFilterParameters(newValue, highCuts[currentChannel], currentChannel); + std::cout << "Setting channel " << currentChannel;// << std::endl; + + if (parameterIndex == 0) + { + std::cout << " low cut to "; } else { - highCuts.set(currentChannel, newValue); - setFilterParameters(lowCuts[currentChannel], newValue, currentChannel); + std::cout << " high cut to "; } + std::cout << newValue << std::endl; + + //if (parameterIndex) +// + Parameter& p = parameters.getReference(parameterIndex); + + p.setValue(newValue, currentChannel); + + + Parameter& p1 = parameters.getReference(0); + Parameter& p2 = parameters.getReference(1); + + std::cout << float(p1[currentChannel]) << " "; + std::cout << float(p2[currentChannel]) << std::endl; + + setFilterParameters(float(p1[currentChannel]), + float(p2[currentChannel]), + currentChannel); + + // if (parameterIndex == 0) { + // parameters[0].setValue(newValue, currentChannel); + // setFilterParameters(newValue, parameters[0][currentChannel], currentChannel); + // } else { + // parameters[1].setValue(newValue, currentChannel); + // setFilterParameters(lowCuts[currentChannel], newValue, currentChannel); + // } + } void FilterNode::process(AudioSampleBuffer &buffer, diff --git a/Source/Processors/GenericProcessor.cpp b/Source/Processors/GenericProcessor.cpp index 8df1cb70c..a24af8954 100644 --- a/Source/Processors/GenericProcessor.cpp +++ b/Source/Processors/GenericProcessor.cpp @@ -30,7 +30,7 @@ GenericProcessor::GenericProcessor(const String& name_) : isEnabled(true), saveOrder(-1), loadOrder(-1), nextAvailableChannel(0), currentChannel(-1), - wasConnected(false), nullParam("VOID", false) + wasConnected(false), nullParam("VOID", false, -1) { } diff --git a/Source/Processors/LfpDisplayNode.cpp b/Source/Processors/LfpDisplayNode.cpp index c444d776a..674543062 100644 --- a/Source/Processors/LfpDisplayNode.cpp +++ b/Source/Processors/LfpDisplayNode.cpp @@ -22,6 +22,7 @@ */ #include "LfpDisplayNode.h" +#include "Visualization/LfpDisplayCanvas.h" #include <stdio.h> LfpDisplayNode::LfpDisplayNode() @@ -32,6 +33,23 @@ LfpDisplayNode::LfpDisplayNode() { displayBuffer = new AudioSampleBuffer(8, 100); eventBuffer = new MidiBuffer(); + + Array<var> timeBaseValues; + timeBaseValues.add(1); + timeBaseValues.add(2); + timeBaseValues.add(5); + timeBaseValues.add(10); + + parameters.add(Parameter("timebase",timeBaseValues, 0, 0));//true);//a,0); + + Array<var> displayGainValues; + displayGainValues.add(1); + displayGainValues.add(2); + displayGainValues.add(4); + displayGainValues.add(8); + + parameters.add(Parameter("display gain",displayGainValues, 0, 1));//true);//a,0); + } LfpDisplayNode::~LfpDisplayNode() @@ -94,7 +112,8 @@ bool LfpDisplayNode::disable() void LfpDisplayNode::setParameter (int parameterIndex, float newValue) { - + LfpDisplayEditor* ed = (LfpDisplayEditor*) getEditor(); + ed->canvas->setParameter(parameterIndex, newValue); } void LfpDisplayNode::process(AudioSampleBuffer &buffer, MidiBuffer &midiMessages, int& nSamples) diff --git a/Source/Processors/Parameter.cpp b/Source/Processors/Parameter.cpp index 349506160..c123ff84d 100644 --- a/Source/Processors/Parameter.cpp +++ b/Source/Processors/Parameter.cpp @@ -24,8 +24,8 @@ #include "Parameter.h" -Parameter::Parameter(const String& name_, bool defaultVal) - : name(name_), description("") +Parameter::Parameter(const String& name_, bool defaultVal, int ID) + : name(name_), description(""), parameterId(ID) { defaultValue = defaultVal; @@ -39,8 +39,8 @@ Parameter::Parameter(const String& name_, bool defaultVal) } -Parameter::Parameter(const String& name_, float low, float high, float defaultVal) - : name(name_), description("") +Parameter::Parameter(const String& name_, float low, float high, float defaultVal, int ID) + : name(name_), description(""), parameterId(ID) { defaultValue = defaultVal; @@ -53,8 +53,8 @@ Parameter::Parameter(const String& name_, float low, float high, float defaultVa } -Parameter::Parameter(const String& name_, Array<var> a, int defaultVal) - : name(name_), description("") +Parameter::Parameter(const String& name_, Array<var> a, int defaultVal, int ID) + : name(name_), description(""), parameterId(ID) { possibleValues = a; defaultValue = defaultVal; //possibleValues[defaultVal]; @@ -87,12 +87,12 @@ void Parameter::setValue(float val, int chan) } } else { - int index = (int) val; + //int index = (int) val; - if (index >= 0 && index < possibleValues.size()) - { - values.set(chan, possibleValues[index]); - } + //if (index >= 0 && index < possibleValues.size()) + //{ + values.set(chan, val); + //} } diff --git a/Source/Processors/Parameter.h b/Source/Processors/Parameter.h index 89f78dc2c..20d357f87 100644 --- a/Source/Processors/Parameter.h +++ b/Source/Processors/Parameter.h @@ -43,9 +43,9 @@ class Parameter { public: - Parameter(const String& name_, bool defaultVal); - Parameter(const String& name_, float low, float high, float defaultVal); - Parameter(const String& name_, Array<var> a, int defaultVal); + Parameter(const String& name_, bool defaultVal, int ID); + Parameter(const String& name_, float low, float high, float defaultVal, int ID); + Parameter(const String& name_, Array<var> a, int defaultVal, int ID); ~Parameter() {} @@ -55,6 +55,8 @@ public: var getDefaultValue() {return defaultValue;} + int getID() {return parameterId;} + Array<var> getPossibleValues() {return possibleValues;} void setValue(float val, int chan); @@ -71,6 +73,8 @@ private: const String name; String description; + int parameterId; + bool isBool, isCont, isDisc; var defaultValue; diff --git a/Source/Processors/SignalGenerator.cpp b/Source/Processors/SignalGenerator.cpp index 43e59ced0..4db3bc7d6 100644 --- a/Source/Processors/SignalGenerator.cpp +++ b/Source/Processors/SignalGenerator.cpp @@ -42,10 +42,9 @@ SignalGenerator::SignalGenerator() a.add(2); a.add(3); + parameters.add(Parameter("Param 1",a, 0, 0));//true);//a,0); - parameters.add(Parameter("Param 1",a, 0));//true);//a,0); - - parameters.add(Parameter("PARAM",0.0f, 100.0f, 50.0f)); + parameters.add(Parameter("PARAM",0.0f, 100.0f, 50.0f, 1)); //parameters.add(Parameter("Param 1",a, 0));//true);//a,0); -- GitLab