From 9f6525c918cf27974372c0ad932a4e419d95f542 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Thu, 5 Sep 2024 14:30:16 +0100 Subject: [PATCH] moved midi around --- plugin/chassis.cpp | 28 +++++++++++++++++----------- plugin/chassis.hpp | 3 ++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/plugin/chassis.cpp b/plugin/chassis.cpp index 125ecd8..29ce682 100644 --- a/plugin/chassis.cpp +++ b/plugin/chassis.cpp @@ -133,11 +133,23 @@ void Chassis::noteOff(uint8_t note) { } } -void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEvent *MidiEvents, uint32_t midiEventCount) { +void Chassis::doMidi(const MidiEvent *ev, uint32_t count, uint32_t timelimit ) { + + for (uint32_t i = 0; i < count; i++) { + if (ev[i].data[0] == 0x90) { + noteOn(ev[i].data[1]); + } + if (ev[i].data[0] == 0x80) { + noteOff(ev[i].data[1]); + } + } + +} + +void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) { // if (midiEventCount > 0) printf("\n--------------------\n"); - - if (s.framesLeft == 0) s.framesLeft = frames; + s.framesLeft = frames; while ( s.framesLeft != 0) { uint32_t sizeThisTime = (frames <= s.blockLeft)?frames:s.blockLeft; @@ -149,6 +161,8 @@ void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEv s.blockLeft -= sizeThisTime; if (s.blockLeft == 0) { s.blockLeft = 48000/238; + doMidi(midiEvents, midiEventCount, 201); + printf("compute params and reset block size\n"); } if (s.framesLeft <= s.blockLeft) { @@ -162,14 +176,6 @@ void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEv printf("and now run the rest of the process for %d frames\n\n", frames); - for (uint32_t i = 0; i < midiEventCount; i++) { - if (MidiEvents[i].data[0] == 0x90) { - noteOn(MidiEvents[i].data[1]); - } - if (MidiEvents[i].data[0] == 0x80) { - noteOff(MidiEvents[i].data[1]); - } - } // run each synth voice bzero(outputs[0], sizeof(float) * frames); diff --git a/plugin/chassis.hpp b/plugin/chassis.hpp index 961430c..b2932f1 100644 --- a/plugin/chassis.hpp +++ b/plugin/chassis.hpp @@ -60,12 +60,13 @@ class Chassis : public Plugin { // Processing void activate() override; void deactivate() override; - void run(const float **, float **outputs, uint32_t frames, const MidiEvent *MidiEvents, uint32_t midiEventCount) override; + void run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) override; void noteOn(uint8_t note); void noteOff(uint8_t note); private: + void doMidi(const MidiEvent *ev, uint32_t count, uint32_t timelimit ) ; double sampleRate; // Voice voice[NUM_VOICES]; uint8_t vPtr;