From cb7445434ca34b11762b0504276bb619d73ba027 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Tue, 3 Sep 2024 23:30:08 +0100 Subject: [PATCH] synth class --- plugin/chassis.cpp | 35 ++++++++++++++++++++++++----------- plugin/chassis.hpp | 9 ++++++--- plugin/voice.hpp | 15 ++++++++++++--- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/plugin/chassis.cpp b/plugin/chassis.cpp index eeef3cd..1a286dc 100644 --- a/plugin/chassis.cpp +++ b/plugin/chassis.cpp @@ -25,13 +25,26 @@ Chassis::Chassis() : Plugin(kParameterCount, 0, 0) { // one parameter, no progr // Initialisation functions -// void Chassis::initParameter(uint32_t index, Parameter ¶meter) { -// } - -/* -void Chassis::setParameterValue(uint32_t index, float value) { +void Chassis::initParameter(uint32_t index, Parameter ¶meter) { + switch (index) { + case k_saw: + parameter.hints = kParameterIsAutomatable | kParameterIsBoolean; + parameter.name = "Saw"; + parameter.symbol = "saw"; + parameter.ranges.min = 0.0f; + parameter.ranges.max = 127.0f; + parameter.ranges.def = 127.0f; + } } +void Chassis::setParameterValue(uint32_t index, float value) { + switch (index) { + case k_saw: + s.p.saw = value / 127.0f; + } +} + +/* float Chassis::getParameterValue(uint32_t index) const { return 0; } @@ -71,23 +84,23 @@ void Chassis::noteOn(uint8_t note) { for (i = 0; i < NUM_VOICES; i++) { vPtr++; if (vPtr == NUM_VOICES) vPtr = 0; - if (voice[vPtr].isFree()) { + if (s.voice[vPtr].isFree()) { // if it's an existing note don't reset - voice[vPtr].on(note, voice[i].note != note); + s.voice[vPtr].on(note, s.voice[i].note != note); break; } } if (i == NUM_VOICES) { // didn't find a free voice vPtr++; if (vPtr == NUM_VOICES) vPtr = 0; - voice[vPtr].on(note, true); + s.voice[vPtr].on(note, true); } } void Chassis::noteOff(uint8_t note) { for (uint32_t i = 0; i < NUM_VOICES; i++) { - if (voice[i].note == note && !voice[i].isFree()) { - voice[i].off(); + if (s.voice[i].note == note && !s.voice[i].isFree()) { + s.voice[i].off(); break; } } @@ -108,7 +121,7 @@ void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEv // run each synth voice bzero(outputs[0], sizeof(float) * frames); for (uint8_t i = 0; i < NUM_VOICES; i++) { - voice[i].run(outputs[0], frames); + s.voice[i].run(outputs[0], frames); } // copy left to right memmove(outputs[1], outputs[0], sizeof(float) * frames); diff --git a/plugin/chassis.hpp b/plugin/chassis.hpp index c415504..4ab8302 100644 --- a/plugin/chassis.hpp +++ b/plugin/chassis.hpp @@ -29,6 +29,7 @@ START_NAMESPACE_DISTRHO class Chassis : public Plugin { public: enum Parameters { + k_saw, kParameterCount }; @@ -46,9 +47,9 @@ class Chassis : public Plugin { // Initialisation void initAudioPort(bool input, uint32_t index, AudioPort &port) override; - // void initParameter(uint32_t index, Parameter ¶meter) override; + void initParameter(uint32_t index, Parameter ¶meter) override; - // void setParameterValue(uint32_t index, float value) override; + void setParameterValue(uint32_t index, float value) override; // float getParameterValue(uint32_t index) const override; // void initProgramName(uint32_t index, String &programName) override; @@ -63,9 +64,11 @@ class Chassis : public Plugin { void noteOff(uint8_t note); private: - Voice voice[NUM_VOICES]; + // Voice voice[NUM_VOICES]; uint8_t vPtr; + Synth s; + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Chassis); }; diff --git a/plugin/voice.hpp b/plugin/voice.hpp index b4114a2..6f0ac0e 100644 --- a/plugin/voice.hpp +++ b/plugin/voice.hpp @@ -16,11 +16,16 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef _VOICE_HPP -#define _VOICE_HPP +#pragma once #include +class Patch { + public: + float saw,sqr; + +}; + class Voice { public: uint8_t note; @@ -45,4 +50,8 @@ class Voice { float env, target; }; -#endif // _VOICE_HPP \ No newline at end of file +class Synth { + public: + Patch p; + Voice voice[8]; +};