diff --git a/plugin/chassis.cpp b/plugin/chassis.cpp index 37032dd..779a71b 100644 --- a/plugin/chassis.cpp +++ b/plugin/chassis.cpp @@ -18,7 +18,6 @@ #include "chassis.hpp" - SVF::SVF(float cutoff = 0, float q = 0, float samplerate = 0) { z1 = z2 = 0; setFreq(cutoff, q, samplerate); @@ -51,14 +50,14 @@ inline float SVF::lpStep(float in) { START_NAMESPACE_DISTRHO Chassis::Chassis() : Plugin(kParameterCount, 0, 0) { // one parameter, no programs, no states - //lowpass = new float[getBufferSize()]; - //ram = new int16_t[16384]; + // lowpass = new float[getBufferSize()]; + // ram = new int16_t[16384]; - //bzero(lowpass, sizeof(float) * getBufferSize()); - //bzero(ram, sizeof(int16_t) * 16384); + // bzero(lowpass, sizeof(float) * getBufferSize()); + // bzero(ram, sizeof(int16_t) * 16384); - //f1.setFreq(5916, .6572, getSampleRate()); - // f2.setFreq(9458, 2.536, getSampleRate()); + // f1.setFreq(5916, .6572, getSampleRate()); + // f2.setFreq(9458, 2.536, getSampleRate()); } // Initialisation functions @@ -96,12 +95,9 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { } void Chassis::setParameterValue(uint32_t index, float value) { - - } float Chassis::getParameterValue(uint32_t index) const { - return 0; } @@ -127,17 +123,68 @@ void Chassis::loadProgram(uint32_t index) { void Chassis::activate() { // calculate filter coefficients printf("called activate()\n"); + for (uint32_t i = 0; i< NUM_VOICES; i++ ) { + assign[i] = 0x80 | i; + + } } void Chassis::deactivate() { // zero out the outputs, maybe printf("called deactivate()\n"); + printf("%02x", assign[1]); } +void Chassis::noteOn(uint8_t note) { + for (uint32_t i = 0; i < NUM_VOICES; i++) { + printf("note on, finding free voice in %02x for %d\n", assign[i], note); + if (assign[i] & 0x80) { // top bit is voice free flag + assign[i] &= 0x7f; // enable + printf("voice %d would be set to note %d\n", assign[i], note); + break; + } + + if (i == NUM_VOICES) { // didn't find a free voice + uint32_t v = assign[0]; + memmove(assign, assign + 1, NUM_VOICES - 1); // shunt all voices down by one + assign[NUM_VOICES - 1] = v; // oldest voice goes at the top of the queue + printf("no free voices, reused %d for note %d\n", v, note); + } + } + printf("note table is now "); + for (uint32_t i=0; i < NUM_VOICES; i++ ) { + printf("%02x = ", assign[i]); + } + printf("----------------------------\n"); + +} + +/* +void Chassis::noteOff(uint8_t note) { + + uint32_t v; + printf("note off called for %3d\n", note); + + for (uint32_t i = 0; i < NUM_VOICES; i++) { + v = assign[i]; + printf("trying voice %02x\n", v); + if (v < 0x80) { + printf("note %02x is playing\n", v); + + } + + } + +} +*/ void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEvent *MidiEvents, uint32_t midiEventCount) { - // actual effects here - - + if (midiEventCount > 0) printf("\n--------------------\n"); + for (uint32_t i = 0; i < midiEventCount; i++) { + printf("%4d %02x %02x\n", MidiEvents[i].frame, MidiEvents[i].data[0], MidiEvents[i].data[1]); + if (MidiEvents[i].data[0] == 0x90) { + noteOn(MidiEvents[i].data[1]); + } + } } // create the plugin diff --git a/plugin/chassis.hpp b/plugin/chassis.hpp index 3f8befd..e2a2adf 100644 --- a/plugin/chassis.hpp +++ b/plugin/chassis.hpp @@ -19,6 +19,8 @@ #ifndef BARRVERB_HPP #define BARRVERB_HPP +#define NUM_VOICES 8 + #include "DistrhoPlugin.hpp" class SVF { @@ -70,7 +72,13 @@ class Chassis : public Plugin { void deactivate() override; void run(const float **, float **outputs, uint32_t frames, const MidiEvent *MidiEvents, uint32_t midiEventCount) override; + +void noteOn(uint8_t note); + private: + uint8_t assign[NUM_VOICES]; // assigner table + + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Chassis); };