diff --git a/Source/EnumFloatParameter.h b/Source/EnumFloatParameter.h index d45d53e..bc880b8 100644 --- a/Source/EnumFloatParameter.h +++ b/Source/EnumFloatParameter.h @@ -1,5 +1,5 @@ #pragma once -#include "c:\code\game\fm\juceoplvsti\source\floatparameter.h" +#include "FloatParameter.h" class EnumFloatParameter : public FloatParameter { diff --git a/Source/IntFloatParameter.cpp b/Source/IntFloatParameter.cpp new file mode 100644 index 0000000..b84c3f0 --- /dev/null +++ b/Source/IntFloatParameter.cpp @@ -0,0 +1,27 @@ +#include "IntFloatParameter.h" + + +IntFloatParameter::IntFloatParameter(String name, int min, int max) +:FloatParameter(name) +{ + this->min = min; + this->max = max; +} + +IntFloatParameter::~IntFloatParameter(void) +{ +} + +int IntFloatParameter::getParameterValue(void) +{ + int range = max - min; + int i = (int)(this->value * range); + if (i > range) + i = range; + return i; +} + +String IntFloatParameter::getParameterText(void) +{ + return String(this->getParameterValue()); +} diff --git a/Source/IntFloatParameter.h b/Source/IntFloatParameter.h new file mode 100644 index 0000000..9d2c2f2 --- /dev/null +++ b/Source/IntFloatParameter.h @@ -0,0 +1,15 @@ +#pragma once +#include "FloatParameter.h" +class IntFloatParameter : + public FloatParameter +{ +public: + IntFloatParameter(String name, int min, int max); + ~IntFloatParameter(void); + String getParameterText(void); + int getParameterValue(void); +private: + int min; + int max; +}; + diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 304064f..7d1a0b9 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -1,6 +1,7 @@ #include "PluginProcessor.h" #include "PluginEditor.h" #include "EnumFloatParameter.h" +#include "IntFloatParameter.h" //============================================================================== JuceOplvstiAudioProcessor::JuceOplvstiAudioProcessor() @@ -29,6 +30,14 @@ JuceOplvstiAudioProcessor::JuceOplvstiAudioProcessor() params.push_back(new EnumFloatParameter("Modulator Frequency Multiplier", StringArray(frq_multipliers, sizeof(frq_multipliers)/sizeof(String))) ); + params.push_back(new IntFloatParameter("Carrier Attack", 0, 15)); + params.push_back(new IntFloatParameter("Carrier Sustain", 0, 15)); + params.push_back(new IntFloatParameter("Carrier Decay", 0, 15)); + params.push_back(new IntFloatParameter("Carrier Release", 0, 15)); + params.push_back(new IntFloatParameter("Modulator Attack", 0, 15)); + params.push_back(new IntFloatParameter("Modulator Sustain", 0, 15)); + params.push_back(new IntFloatParameter("Modulator Decay", 0, 15)); + params.push_back(new IntFloatParameter("Modulator Release", 0, 15)); } JuceOplvstiAudioProcessor::~JuceOplvstiAudioProcessor() @@ -56,18 +65,18 @@ void JuceOplvstiAudioProcessor::setParameter (int index, float newValue) FloatParameter* p = params[index]; p->setParameter(newValue); String name = p->getName(); - if (name == "Carrier Wave") { - Opl->SetWaveform(1, 1, (Waveform)((EnumFloatParameter*)p)->getParameterIndex()); - } else if (name == "Modulator Wave") { - Opl->SetWaveform(1, 2, (Waveform)((EnumFloatParameter*)p)->getParameterIndex()); - } else if (name == "Modulator Attenuation") { - Opl->SetAttenuation(1, 1, 0x1<<((EnumFloatParameter*)p)->getParameterIndex()); - } else if (name == "Carrier Attenuation") { - Opl->SetAttenuation(1, 2, 0x1<<((EnumFloatParameter*)p)->getParameterIndex()); - } else if (name == "Carrier Frequency Multiplier") { - Opl->SetFrequencyMultiple(1, 1, (FreqMultiple)((EnumFloatParameter*)p)->getParameterIndex()); - } else if (name == "Modulator Frequency Multiplier") { - Opl->SetFrequencyMultiple(1, 2, (FreqMultiple)((EnumFloatParameter*)p)->getParameterIndex()); + int osc = 1; // Carrier + if (name.startsWith("Modulator")) { + osc = 2; + } + if (name.endsWith("Wave")) { + Opl->SetWaveform(1, osc, (Waveform)((EnumFloatParameter*)p)->getParameterIndex()); + } else if (name.endsWith("Attenuation")) { + Opl->SetAttenuation(1, osc, 0x1<<((EnumFloatParameter*)p)->getParameterIndex()); + } else if (name.endsWith("Frequency Multiplier")) { + Opl->SetFrequencyMultiple(1, osc, (FreqMultiple)((EnumFloatParameter*)p)->getParameterIndex()); + } else if (name.endsWith("Attack")) { + Opl->SetEnvelopeAttack(1, osc, ((IntFloatParameter*)p)->getParameterValue()); } } diff --git a/Source/hiopl.cpp b/Source/hiopl.cpp index 80de66e..7c4e5d9 100644 --- a/Source/hiopl.cpp +++ b/Source/hiopl.cpp @@ -109,13 +109,31 @@ void Hiopl::SetFrequencyMultiple(int ch, int osc, FreqMultiple mult) { _WriteReg(0x20+offset, (Bit8u)mult);//, 0xf); } +void Hiopl::SetEnvelopeAttack(int ch, int osc, int t) { + int offset = this->_GetOffset(ch, osc); + _WriteReg(0x60+offset, (Bit8u)t<<4, 0xf0); +} + +void Hiopl::SetEnvelopeDecay(int ch, int osc, int t) { + int offset = this->_GetOffset(ch, osc); + _WriteReg(0x60+offset, (Bit8u)t, 0x0f); +} + +void Hiopl::SetEnvelopeSustain(int ch, int osc, int level) { + int offset = this->_GetOffset(ch, osc); + _WriteReg(0x80+offset, (Bit8u)level<<4, 0xf0); +} + +void Hiopl::SetEnvelopeRelease(int ch, int osc, int t) { + int offset = this->_GetOffset(ch, osc); + _WriteReg(0x80+offset, (Bit8u)t, 0x0f); +} + void Hiopl::KeyOn(int ch, float frqHz) { unsigned int fnum, block; _milliHertzToFnum((unsigned int)(frqHz * 1000.0), &fnum, &block); _WriteReg(0xa0, fnum % 0x100); _WriteReg(0xb0, 0x20|((block&0x7)<<2)|(0x3&(fnum/0x100))); - //_WriteReg(0xa0, 0x8b); - //_WriteReg(0xb0, 0x26); } void Hiopl::KeyOff(int ch) { diff --git a/Source/hiopl.h b/Source/hiopl.h index 3d939df..603da14 100644 --- a/Source/hiopl.h +++ b/Source/hiopl.h @@ -27,6 +27,10 @@ class Hiopl { Waveform GetWaveform(int ch, int osc); void SetAttenuation(int ch, int osc, int level); void SetFrequencyMultiple(int ch, int osc, FreqMultiple mult); + void SetEnvelopeAttack(int ch, int osc, int t); + void SetEnvelopeDecay(int ch, int osc, int t); + void SetEnvelopeSustain(int ch, int osc, int level); + void SetEnvelopeRelease(int ch, int osc, int t); void KeyOn(int ch, float frqHz); void KeyOff(int ch); void _WriteReg(Bit32u reg, Bit8u value, Bit8u mask=0x0);