Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
C# audioaudio-unitavaloniacpp20cross-platformdawdigital-audio-workstationdspjucelinux-audiomcp-servermidimusicmusic-productionpiano-rollplugin-hostsequencersynthesizervstvst3
(fix) Articulation keyswitches reach a plug-in behind a rack chain's MIDI effects (#600)
Egor Khindikaynen12804126e480
diff --git a/src/native/nota.engine/src/devices/Instrument.h b/src/native/nota.engine/src/devices/Instrument.hindex 7e31cd0a..682ad24d 100644--- a/src/native/nota.engine/src/devices/Instrument.h+++ b/src/native/nota.engine/src/devices/Instrument.h@@ -63,6 +63,11 @@ class Instrument {// instrument (specs/085, FR-024). A built-in would play a keyswitch as a note, so it says no// and the engine sends it nothing; a hosted plug-in, or a rack holding one, says yes.virtual bool takesArticulations() const { return false; }+ // An articulation's keyswitch note (specs/085), at eventOffset on eventChannel. A plain+ // instrument takes it as a note; a rack hands it straight to the chains that take+ // articulations, past its zones, mono and chain MIDI effects — a switch is not a note to play.+ virtual void keyswitchOn(int32_t pitch, float velocity) { noteOn(pitch, velocity); }+ virtual void keyswitchOff(int32_t pitch) { noteOff(pitch); }// Note events (applied at segment boundaries by the engine for sample accuracy, or at// eventOffset — see takesTimedEvents).diff --git a/src/native/nota.engine/src/devices/racks/RackInstrument.cpp b/src/native/nota.engine/src/devices/racks/RackInstrument.cppindex bc1285a2..9959b138 100644--- a/src/native/nota.engine/src/devices/racks/RackInstrument.cpp+++ b/src/native/nota.engine/src/devices/racks/RackInstrument.cpp@@ -353,6 +353,28 @@ void RackInstrument::programChange(int32_t program) {}}+void RackInstrument::keyswitchOn(int32_t pitch, float velocity) {+ RackState* st = live();+ if (!st) return;+ for (auto& c : st->chains)+ if (c.instrument && c.instrument->takesArticulations()) {+ c.instrument->eventChannel = eventChannel;+ c.instrument->keyswitchOn(pitch, velocity);+ c.instrument->eventChannel = 0;+ }+}++void RackInstrument::keyswitchOff(int32_t pitch) {+ RackState* st = live();+ if (!st) return;+ for (auto& c : st->chains)+ if (c.instrument && c.instrument->takesArticulations()) {+ c.instrument->eventChannel = eventChannel;+ c.instrument->keyswitchOff(pitch);+ c.instrument->eventChannel = 0;+ }+}+bool RackInstrument::takesArticulations() const {RackState* st = live();if (!st) return false;diff --git a/src/native/nota.engine/src/devices/racks/RackInstrument.h b/src/native/nota.engine/src/devices/racks/RackInstrument.hindex 302fb5a4..f4a836a5 100644--- a/src/native/nota.engine/src/devices/racks/RackInstrument.h+++ b/src/native/nota.engine/src/devices/racks/RackInstrument.h@@ -57,6 +57,11 @@ class RackInstrument : public Instrument, public RackCore {void controller(int32_t ctl, float value) override;// An articulation's program change (specs/085) reaches every chain, on its channel.void programChange(int32_t program) override;+ // An articulation's keyswitch (specs/085) goes straight to every chain whose instrument takes+ // articulations, on its channel: past the zones and mono, and past a chain's MIDI effects —+ // which only see the block's notes (blockMidi) and would drop or rework it.+ void keyswitchOn(int32_t pitch, float velocity) override;+ void keyswitchOff(int32_t pitch) override;// True when a chain holds an instrument that takes articulation MIDI (a hosted plug-in).bool takesArticulations() const override;bool supportsMpe() const override;diff --git a/src/native/nota.engine/src/engine/Engine_Render.cpp b/src/native/nota.engine/src/engine/Engine_Render.cppindex f7dc0297..61a97885 100644--- a/src/native/nota.engine/src/engine/Engine_Render.cpp+++ b/src/native/nota.engine/src/engine/Engine_Render.cpp@@ -185,8 +185,8 @@ inline void deliverExpr(Instrument& inst, int32_t pitch, int32_t dim, float valuinline void deliverArt(Instrument& inst, const ArtEv& e) {inst.eventChannel = e.channel;switch (e.kind) {- case ArtEvKind::KeyOn: inst.noteOn(e.data1, static_cast<float>(std::max<int>(1, e.data2)) / 127.0f); break;- case ArtEvKind::KeyOff: inst.noteOff(e.data1); break;+ case ArtEvKind::KeyOn: inst.keyswitchOn(e.data1, static_cast<float>(std::max<int>(1, e.data2)) / 127.0f); break;+ case ArtEvKind::KeyOff: inst.keyswitchOff(e.data1); break;case ArtEvKind::Control: inst.controller(e.data1, static_cast<float>(e.data2) / 127.0f); break;case ArtEvKind::Program: inst.programChange(e.data1); break;}@@ -4136,6 +4136,36 @@ int32_t Engine::articulationSelfTest() {std::count(capture->events.begin(), capture->events.end(), E5{1, 24, 100, 357, 0}) != 1 ||std::any_of(capture->events.begin(), capture->events.end(), [](const E5& e) { return e[0] == 0 && e[1] == 24; })) return 38;}+ // 39: a rack hands a keyswitch to its plug-in chains even behind a chain MIDI effect, on its+ // channel and ahead of the note; a built-in chain gets none.+ {+ auto rack = std::make_shared<RackInstrument>();+ rack->setSampleRate(sr);+ auto plug = std::make_shared<Probe>();+ plug->articulations = true;+ auto builtin = std::make_shared<Probe>();+ const int32_t pc = rack->addChainInstrument(plug);+ rack->addChainInstrument(builtin);+ if (rack->addChainMidiDevice(pc, 4) < 0) return 39; // Velocity: a pass-through MIDI effect+ if (!rack->takesBlockMidi() || !rack->takesArticulations()) return 39;+ const MidiEv on[] = {{100, true, 60, 0.5f}};+ const ArtEv ks[] = {{100, 0, ArtEvKind::KeyOn, 2, 24, 100}};+ playEvents(*rack, dst, B, on, 1, nullptr, 0, ks, 1, 0.0, spb, true, [] {});+ const auto plugOn = [&](int32_t pitch) {+ return std::find_if(plug->events.begin(), plug->events.end(),+ [&](const E5& e) { return e[0] == 1 && e[1] == pitch; }) - plug->events.begin();+ };+ const auto ksAt = plugOn(24), noteAt = plugOn(60);+ if (ksAt >= (std::ptrdiff_t)plug->events.size() || plug->events[ksAt][4] != 2) return 39;+ if (noteAt >= (std::ptrdiff_t)plug->events.size() || noteAt < ksAt) return 39;+ if (std::any_of(builtin->events.begin(), builtin->events.end(), [](const E5& e) { return e[1] == 24; })) return 39;+ if (plug->eventChannel != 0) return 39;+ // The keyswitch's release reaches the plug-in too, and the note it selected plays on.+ const ArtEv ksOff[] = {{10, 0, ArtEvKind::KeyOff, 2, 24, 0}};+ plug->events.clear();+ playEvents(*rack, dst, B, nullptr, 0, nullptr, 0, ksOff, 1, 0.0, spb, true, [] {});+ if (plug->events != std::vector<E5>{{0, 24, 0, 0, 2}}) return 39;+ }return 0;}