2
0
Fork 0

Begin creating and using general purpose wrappers for floating point VST parameters.

This commit is contained in:
bruce 2013-09-10 00:14:43 +08:00
parent c428892c56
commit 7fe1775859
6 changed files with 102 additions and 28 deletions

View file

@ -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()];
}

View file

@ -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;
};

27
Source/FloatParameter.cpp Normal file
View file

@ -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;
}

17
Source/FloatParameter.h Normal file
View file

@ -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;
};

View file

@ -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()

View file

@ -13,6 +13,7 @@
#include "../JuceLibraryCode/JuceHeader.h"
#include "hiopl.h"
#include "FloatParameter.h"
//==============================================================================
@ -69,6 +70,7 @@ public:
private:
Hiopl *Opl;
std::vector<FloatParameter*> params;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JuceOplvstiAudioProcessor)