From cbae975760767a8ed2ab8a9a8a8b0537e22525a4 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Sat, 12 Oct 2024 00:15:00 +0100 Subject: [PATCH] global synth, envelope might even work --- plugin/ic29.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++ plugin/ic29.hpp | 50 ++++++++++++++++++++++++++++++++++++++-------- plugin/peacock.cpp | 3 +++ 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/plugin/ic29.cpp b/plugin/ic29.cpp index 4d0de5e..b93c461 100644 --- a/plugin/ic29.cpp +++ b/plugin/ic29.cpp @@ -20,6 +20,53 @@ #include "peacock.hpp" +Synth::Synth() { +} + +void Synth::run() { + printf("called synth::run()\n"); + printf("%d\n", voices[0].env.phase); +} + void Synth::voiceOn(uint8_t voice, uint8_t note) { // enable synth voice, start it all running } + +Envelope::Envelope() { + level = 0; + phase = ENV_IDLE; + printf("initialising envelope\n"); +} + +void Envelope::run() { + switch (phase) { + case ENV_ATK: + level += s.envAtk; + if (level > 0x3fff) { + level = 0x3fff; + phase = ENV_DCY; + } + break; + case ENV_DCY: + if (level > s.envStn) { + level -= s.envStn; + level *= s.envDcy; + level += s.envStn; + } else { + level = s.envStn; + } + break; + case ENV_RLS: + level *= s.envRls; + break; + case ENV_IDLE: + default: + break; + } +} + +void Envelope::gate(uint8_t gate) { +} + +Voice::Voice() { +} diff --git a/plugin/ic29.hpp b/plugin/ic29.hpp index 491f839..f62cd0e 100644 --- a/plugin/ic29.hpp +++ b/plugin/ic29.hpp @@ -20,23 +20,57 @@ #include "peacock.hpp" +class Envelope { + public: + Envelope(); + void run(); + void gate(uint8_t gate); + uint16_t level; + + //private: + enum { + ENV_ATK, + ENV_DCY, + ENV_RLS, + ENV_IDLE + } phase; +}; + +class Voice { + public: + Voice(); + void run(); + uint8_t note; + + //private: + Envelope env; // calculated envelope value + uint16_t pitch; // calculated pitch value with porta and master pitch etc + enum { V_DONE, + V_OFF, + V_ON } voiceState; +}; + class Synth { + friend Envelope; + friend Peacock; + public: Synth(); + void run(); void voiceOn(uint8_t voice, uint8_t note); void voiceOff(uint8_t voice); void sustainSwitch(uint8_t val); void pitchBend(int16_t bend); void modWheel(uint8_t wheel); uint16_t masterPitch; // sum of bend and LFO, plus any other pitch-setting value + protected: + uint16_t envAtk, envDcy, envStn, envRls; + private: + Voice voices[NUM_VOICES]; + void runLfo(); + void runEnvelope(Voice voice); }; -class Voice { - public: - Voice(); - void run(); - private: - - -}; +// global +extern Synth s; diff --git a/plugin/peacock.cpp b/plugin/peacock.cpp index 7a86bcf..bc46825 100644 --- a/plugin/peacock.cpp +++ b/plugin/peacock.cpp @@ -18,12 +18,15 @@ #include "peacock.hpp" #include "ic1.hpp" +#include "ic29.hpp" START_NAMESPACE_DISTRHO Assigner ic1; +Synth s; Peacock::Peacock() : Plugin(paramCount, 0, 0), sampleRate(getSampleRate()) { + s.run(); } void Peacock::run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) {