diff --git a/Source/EnumFloatParameter.cpp b/Source/EnumFloatParameter.cpp new file mode 100644 index 0000000..b8dab6a --- /dev/null +++ b/Source/EnumFloatParameter.cpp @@ -0,0 +1,26 @@ +#include "EnumFloatParameter.h" + + +EnumFloatParameter::EnumFloatParameter(String name, StringArray values) +:FloatParameter(name) +{ + this->values = values; +} + + +EnumFloatParameter::~EnumFloatParameter(void) +{ +} + +int EnumFloatParameter::getParameterIndex(void) +{ + int i = (int)(this->value * values.size()); + if (i >= values.size()) + i = values.size() - 1; + return i; +} + +String EnumFloatParameter::getParameterText(void) +{ + return values[this->getParameterIndex()]; +} diff --git a/Source/EnumFloatParameter.h b/Source/EnumFloatParameter.h new file mode 100644 index 0000000..d45d53e --- /dev/null +++ b/Source/EnumFloatParameter.h @@ -0,0 +1,14 @@ +#pragma once +#include "c:\code\game\fm\juceoplvsti\source\floatparameter.h" +class EnumFloatParameter : + public FloatParameter +{ +public: + EnumFloatParameter(String name, StringArray values); + ~EnumFloatParameter(void); + String getParameterText(void); + int getParameterIndex(void); +private: + StringArray values; +}; + diff --git a/Source/FloatParameter.cpp b/Source/FloatParameter.cpp new file mode 100644 index 0000000..02ae6ad --- /dev/null +++ b/Source/FloatParameter.cpp @@ -0,0 +1,27 @@ +#include "FloatParameter.h" + + +FloatParameter::FloatParameter(String name) +{ + this->name = name; + this->value = 0.0f; +} + +FloatParameter::~FloatParameter(void) +{ +} + +float FloatParameter::getParameter(void) +{ + return value; +} + +void FloatParameter::setParameter(float value) +{ + this->value = value; +} + +String FloatParameter::getName(void) +{ + return name; +} diff --git a/Source/FloatParameter.h b/Source/FloatParameter.h new file mode 100644 index 0000000..944459e --- /dev/null +++ b/Source/FloatParameter.h @@ -0,0 +1,17 @@ +#pragma once +#include "../JuceLibraryCode/JuceHeader.h" + +class FloatParameter +{ +public: + FloatParameter(String name); + virtual ~FloatParameter(void); + float getParameter(void); + void setParameter(float value); + String getName(void); + virtual String getParameterText(void) = 0; +protected: + float value; +private: + String name; +}; diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 62c7a12..89fc782 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -10,20 +10,19 @@ #include "PluginProcessor.h" #include "PluginEditor.h" - -enum -{ - // Parameters Tags - pOsc1Wave = 0, - pOsc2Wave, - - pNumParams -}; +#include "EnumFloatParameter.h" //============================================================================== JuceOplvstiAudioProcessor::JuceOplvstiAudioProcessor() { Opl = new Hiopl(44100); // 1 second at 44100 + const String waveforms[] = {"Sine", "Half Sine", "Abs Sine", "Quarter Sine"}; + params.push_back(new EnumFloatParameter("Carrier Wave", + StringArray(waveforms, sizeof(waveforms)/sizeof(String))) + ); + params.push_back(new EnumFloatParameter("Modulator Wave", + StringArray(waveforms, sizeof(waveforms)/sizeof(String))) + ); } JuceOplvstiAudioProcessor::~JuceOplvstiAudioProcessor() @@ -38,38 +37,27 @@ const String JuceOplvstiAudioProcessor::getName() const int JuceOplvstiAudioProcessor::getNumParameters() { - return pNumParams; + return params.size(); } float JuceOplvstiAudioProcessor::getParameter (int index) { - return 0.0f; + return params[index]->getParameter(); } void JuceOplvstiAudioProcessor::setParameter (int index, float newValue) { - switch (index) { - case pOsc1Wave: - break; - case pOsc2Wave: - break; - } + params[index]->setParameter(newValue); } const String JuceOplvstiAudioProcessor::getParameterName (int index) { - switch (index) { - case pOsc1Wave: - return "Carrier waveform"; - case pOsc2Wave: - return "Modulator waveform"; - } - return String::empty; + return params[index]->getName(); } const String JuceOplvstiAudioProcessor::getParameterText (int index) { - return String::empty; + return params[index]->getParameterText(); } const String JuceOplvstiAudioProcessor::getInputChannelName (int channelIndex) const @@ -167,8 +155,8 @@ void JuceOplvstiAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuf while (midi_buffer_iterator.getNextEvent(midi_message,sample_number)) { if (midi_message.isNoteOn()) { //note on at sample_number samples after - //the begining of the current buffer - float noteHz = MidiMessage::getMidiNoteInHertz(midi_message.getNoteNumber()); + //the beginning of the current buffer + float noteHz = (float)MidiMessage::getMidiNoteInHertz(midi_message.getNoteNumber()); Opl->KeyOn(0, noteHz); } else if (midi_message.isNoteOff()) { @@ -181,7 +169,7 @@ void JuceOplvstiAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuf //============================================================================== bool JuceOplvstiAudioProcessor::hasEditor() const { - return true; // (change this to false if you choose to not supply an editor) + return false; // (change this to false if you choose to not supply an editor) } AudioProcessorEditor* JuceOplvstiAudioProcessor::createEditor() diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 56b2e51..4319922 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -13,6 +13,7 @@ #include "../JuceLibraryCode/JuceHeader.h" #include "hiopl.h" +#include "FloatParameter.h" //============================================================================== @@ -69,6 +70,7 @@ public: private: Hiopl *Opl; + std::vector params; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JuceOplvstiAudioProcessor)