diff --git a/Source/Audio/AudioComponent.cpp b/Source/Audio/AudioComponent.cpp index 93119a912623e550a9c05661d94aca078fa920c1..f393750c1427fb75da9c2a059cb032512126ec1f 100644 --- a/Source/Audio/AudioComponent.cpp +++ b/Source/Audio/AudioComponent.cpp @@ -68,7 +68,7 @@ AudioComponent::AudioComponent() : isPlaying(false) std::cout << "Audio device sample rate: " << sr << std::endl; std::cout << "Audio device buffer size: " << buffSize << std::endl << std::endl; - graphPlayer = new AudioProcessorPlayer(); + graphPlayer = new AudioProcessorPlayer(); } diff --git a/Source/MainWindow.cpp b/Source/MainWindow.cpp index 31ed94a0a7f75046c07f647f00b44b6b0bffe3c1..f741aa3d61105c921ff3859a65dbbe026d9f35a5 100644 --- a/Source/MainWindow.cpp +++ b/Source/MainWindow.cpp @@ -34,17 +34,19 @@ MainWindow::MainWindow() setResizable (true, // isResizable false); // useBottomCornerRisizer -- doesn't work very well - + // centreWithSize(500,400); + // Constraining the window's size doesn't seem to work: //setResizeLimits(500, 400, 10000, 10000); // Create ProcessorGraph and AudioComponent, and connect them. // Callbacks will be set by the play button in the control panel - processorGraph = new ProcessorGraph(); - audioComponent = new AudioComponent(); - audioComponent->connectToProcessorGraph(processorGraph); - setContentComponent (new UIComponent(this, processorGraph, audioComponent), true, true); + processorGraph = new ProcessorGraph(); + audioComponent = new AudioComponent(); + audioComponent->connectToProcessorGraph(processorGraph); + + setContentComponent (new UIComponent(this, processorGraph, audioComponent), true, true); // commandManager.registerAllCommandsForTarget (getContentComponent()); // commandManager.registerAllCommandsForTarget (JUCEApplication::getInstance()); @@ -61,16 +63,16 @@ MainWindow::MainWindow() MainWindow::~MainWindow() { - saveWindowBounds(); - processorGraph->saveState(); + saveWindowBounds(); + processorGraph->saveState(); - audioComponent->disconnectProcessorGraph(); + audioComponent->disconnectProcessorGraph(); - deleteAndZero(processorGraph); - deleteAndZero(audioComponent); + deleteAndZero(processorGraph); + deleteAndZero(audioComponent); - setContentComponent (0); - setMenuBar(0); + setContentComponent (0); + // setMenuBar(0); } diff --git a/Source/Processors/GenericProcessor.cpp b/Source/Processors/GenericProcessor.cpp index 03a3c7059be1c90f8d8a95b19544164b3334f62b..3969860a37ee153c8effed6720d0be232d14dff1 100644 --- a/Source/Processors/GenericProcessor.cpp +++ b/Source/Processors/GenericProcessor.cpp @@ -47,10 +47,24 @@ AudioProcessorEditor* GenericProcessor::createEditor() void GenericProcessor::setParameter (int parameterIndex, float newValue) { + if (currentChannel > 0) + { + parameters[parameterIndex]->setValue((double) newValue, currentChannel); + } +} +const String GenericProcessor::getParameterName (int parameterIndex) +{ + return parameters[parameterIndex]->getName(); } +const String GenericProcessor::getParameterText (int parameterIndex) +{ + return parameters[parameterIndex]->getDescription(); +} + + void GenericProcessor::prepareToPlay (double sampleRate_, int estimatedSamplesPerBlock) { // use the enable() function instead @@ -88,29 +102,29 @@ void GenericProcessor::resetConnections() wasConnected = false; } -void GenericProcessor::setNumSamples(MidiBuffer& midiMessages, int sampleIndex) { +void GenericProcessor::setNumSamples(MidiBuffer& events, int sampleIndex) { uint8 data[2]; data[0] = BUFFER_SIZE; // most-significant byte data[1] = nodeId; // least-significant byte - midiMessages.addEvent(data, // spike data - 2, // total bytes - sampleIndex); // sample index + events.addEvent(data, // spike data + 2, // total bytes + sampleIndex); // sample index } -int GenericProcessor::getNumSamples(MidiBuffer& midiMessages) { +int GenericProcessor::getNumSamples(MidiBuffer& events) { int numRead = 0; - if (midiMessages.getNumEvents() > 0) + if (events.getNumEvents() > 0) { - int m = midiMessages.getNumEvents(); + int m = events.getNumEvents(); - MidiBuffer::Iterator i (midiMessages); + MidiBuffer::Iterator i (events); MidiMessage message(0xf4); int samplePosition = -5; diff --git a/Source/Processors/GenericProcessor.h b/Source/Processors/GenericProcessor.h index d32ed3f96f95cee82313b5abd301ac64c80d6053..ff1e382e68e263eae1302f45a1f843e8bcdc39fd 100644 --- a/Source/Processors/GenericProcessor.h +++ b/Source/Processors/GenericProcessor.h @@ -27,7 +27,9 @@ #include "../../JuceLibraryCode/JuceHeader.h" #include "Editors/GenericEditor.h" +#include "Parameter.h" #include "../AccessClass.h" + #include <time.h> #include <stdio.h> @@ -49,6 +51,7 @@ class EditorViewport; class DataViewport; class UIComponent; class GenericEditor; +class Parameter; class GenericProcessor : public AudioProcessor, public AccessClass @@ -82,9 +85,9 @@ public: const String getInputChannelName (int channelIndex) const {return settings.inputChannelNames[channelIndex];} const String getOutputChannelName (int channelIndex) const {return settings.outputChannelNames[channelIndex];} - const String getParameterName (int parameterIndex) {return T(" ");} - const String getParameterText (int parameterIndex) {return T(" ");} - const String getProgramName (int index) {return T(" ");} + const String getParameterName (int parameterIndex); //{return parameters[parameterIndex]->getName();} + const String getParameterText (int parameterIndex); //{return parameters[parameterIndex]->getDescription();} + const String getProgramName (int index) {return "";} bool isInputChannelStereoPair (int index) const {return true;} bool isOutputChannelStereoPair (int index) const {return true;} @@ -94,7 +97,7 @@ public: bool isParameterAutomatable(int parameterIndex) {return false;} bool isMetaParameter(int parameterIndex) {return false;} - int getNumParameters() {return 0;} + int getNumParameters() {return parameters.size();} int getNumPrograms() {return 0;} int getCurrentProgram() {return 0;} @@ -226,6 +229,9 @@ public: int nodeId; + // parameters: + OwnedArray<Parameter> parameters; + private: void processBlock (AudioSampleBuffer &buffer, MidiBuffer &midiMessages); diff --git a/Source/Processors/Parameter.cpp b/Source/Processors/Parameter.cpp index 2003b48bb4cfa710e09a4032e00045be3b0eed3b..2df56830ef2c322b16d412fc1cb881a3dcabe17d 100644 --- a/Source/Processors/Parameter.cpp +++ b/Source/Processors/Parameter.cpp @@ -1,10 +1,125 @@ /* - ============================================================================== + ------------------------------------------------------------------ - Parameter.cpp - Created: 5 Apr 2012 11:39:25am - Author: jsiegle + This file is part of the Open Ephys GUI + Copyright (C) 2012 Open Ephys + + ------------------------------------------------------------------ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. - ============================================================================== */ +#include "Parameter.h" + +bool Parameter::setValue(var val, int chan) +{ + if (isBoolean()) + { + if (val.isBool()) { + values.set(chan, val); + + } else if (val.isInt()) { + + if (int(val) > 0) + values.set(chan, true); + else + values.set(chan, false); + + } else if (val.isDouble()) { + + if (double(val) > 0.0f) + values.set(chan, true); + else + values.set(chan, false); + + } else { + return false; + } + + } else if (isContinuous()) { + + if (val.isDouble()) + { + if (double(val) < double(possibleValues[0])) + { + values.set(chan, possibleValues[0]); + } else if (double(val) > double(possibleValues[1])) + { + values.set(chan, possibleValues[1]); + } else { + values.set(chan, val); + } + } else { + return false; + } + + } else if (isDiscrete()) { + + if (val.isInt()) + { + if (int(val) >= 0 && int(val) < possibleValues.size()) + { + values.set(chan, possibleValues[val]); + } else { + return false; + } + } else { + return false; + } + + } + + return true; + +} + +const var& Parameter::getValue(int chan) +{ + return values[chan]; +} + +const var& Parameter::operator[](int chan) +{ + return values[chan]; +} + +BooleanParameter::BooleanParameter(const String& name_, bool& defaultVal) : Parameter(name_) +{ + possibleValues.add(true); + possibleValues.add(false); + + defaultValue = defaultVal; +} + +ContinuousParameter::ContinuousParameter(const String& name_, + double low, double high, double& defaultVal) + : Parameter(name_) +{ + possibleValues.add(low); + possibleValues.add(high); + + defaultValue = defaultVal; + +} + +DiscreteParameter::DiscreteParameter(const String& name_, + Array<var> a, int defaultVal) + : Parameter(name_) +{ + possibleValues = a; + + defaultValue = possibleValues[defaultVal]; +} + diff --git a/Source/Processors/Parameter.h b/Source/Processors/Parameter.h index 1f391bc4693299165faec42ef0c35f8f618e6020..e069567f6ed32c01aaf1079c86aab567cb6c3a72 100644 --- a/Source/Processors/Parameter.h +++ b/Source/Processors/Parameter.h @@ -26,6 +26,7 @@ #include "../../JuceLibraryCode/JuceHeader.h" #include "Editors/GenericEditor.h" +#include "GenericProcessor.h" #include "../AccessClass.h" #include <stdio.h> @@ -38,53 +39,54 @@ */ -class Parameter : +class GenericProcessor; +class GenericEditor; + +class Parameter { public: - Parameter(const String name_); - ~Parameter(); + Parameter(const String& name_) : name(name_), description("") {} + ~Parameter() {} + + const String& getName() {return name;} + const String& getDescription() {return description;} - const String getName() {return name;} + void addDescription(const String& desc) {description = desc;} - virtual Array<var> getPossibleValues() {return possibleValues} - virtual void setValue(var val, int chan); + Array<var> getPossibleValues() {return possibleValues;} + var getDefaultValue() {return defaultValue;} - var getValue(int chan); - var operator[](int chan); + bool setValue(var val, int chan); + + const var& getValue(int chan); + const var& operator[](int chan); virtual bool isBoolean() {return false;} virtual bool isContinuous() {return false;} virtual bool isDiscrete() {return false;} - virtual bool isString() {return false;} protected: const String name; + String description; GenericProcessor* processor; GenericEditor* editor; - Array<Channel*> channels; + //Array<Channel*> channels; Array<var> possibleValues; Array<var> values; + var defaultValue; + }; class BooleanParameter : public Parameter { public: - BooleanParameter(const String name_); - ~BooleanParameter(); - - Array<var> getPossibleValues() - { - Array<var> possibleValues; - possibleValues.add(true); - possibleValues.add(false); - - return possibleValues; - } + BooleanParameter(const String& name_, bool& defaultVal); + ~BooleanParameter() {} bool isBoolean() {return true;} @@ -93,43 +95,21 @@ public: class ContinuousParameter : public Parameter { public: - ContinuousParameter(const String name_, double low, double high); - ~ContinuousParameter(); - - Array<var> getPossibleValues() - { - Array<var> possibleValues; - possibleValues.add(low); - possibleValues.add(high); - - return possibleValues; - } + ContinuousParameter(const String& name_, double low, double high, double& defaultVal); + ~ContinuousParameter() {} bool isContinuous() {return true;} -private: - double low, high; - }; class DiscreteParameter : public Parameter { public: - DiscreteParameter(const String name_, Array<var> possibleValues); - ~DiscreteParameter(); - - Array<var> getPossibleValues() - { - return possibleValues; - } - - bool isContinuous() {return true;} - -private: - - Array<var> possibleValues; + DiscreteParameter(const String& name_, Array<var> a, int defaultVal); + ~DiscreteParameter() {} + bool isDiscrete() {return true;} }; #endif // __PARAMETER_H_62922AE5__ diff --git a/Source/UI/UIComponent.cpp b/Source/UI/UIComponent.cpp index 25a7d09d34bea1b3541966c1e19e2e432b5f664a..48d126c1e4cd4bee80cbe2693df2560f1d768f93 100644 --- a/Source/UI/UIComponent.cpp +++ b/Source/UI/UIComponent.cpp @@ -139,6 +139,17 @@ void UIComponent::resized() if (messageCenter != 0) messageCenter->setBounds(6,h-35,w-241,30); + // for debugging purposes: + if (false) { + dataViewport->setVisible(false); + editorViewport->setVisible(false); + processorList->setVisible(false); + messageCenter->setVisible(false); + controlPanel->setVisible(false); + editorViewportButton->setVisible(false); + } + + } void UIComponent::disableCallbacks() @@ -251,8 +262,6 @@ void EditorViewportButton::drawName() font->FaceSize(23); font->Render("SIGNAL CHAIN"); - - } void EditorViewportButton::drawButton()