Browse Source

CV to MIDI: Generate Note Off message for active notes when number of channels is decreased.

tags/v2.6.5
Andrew Belt 5 months ago
parent
commit
de8fa6197b
2 changed files with 17 additions and 1 deletions
  1. +12
    -0
      include/dsp/midi.hpp
  2. +5
    -1
      src/core/CV_MIDI.cpp

+ 12
- 0
include/dsp/midi.hpp View File

@@ -16,6 +16,7 @@ CHANNELS is the number of polyphony channels. Use 1 for monophonic.
*/ */
template <int CHANNELS> template <int CHANNELS>
struct MidiGenerator { struct MidiGenerator {
uint8_t channels;
int8_t vels[CHANNELS]; int8_t vels[CHANNELS];
int8_t notes[CHANNELS]; int8_t notes[CHANNELS];
bool gates[CHANNELS]; bool gates[CHANNELS];
@@ -34,6 +35,7 @@ struct MidiGenerator {
} }


void reset() { void reset() {
channels = CHANNELS;
for (int c = 0; c < CHANNELS; c++) { for (int c = 0; c < CHANNELS; c++) {
vels[c] = 100; vels[c] = 100;
notes[c] = 60; notes[c] = 60;
@@ -65,6 +67,16 @@ struct MidiGenerator {
} }
} }


void setChannels(uint8_t channels) {
if (this->channels == channels)
return;
// Disable notes when channels decreases
for (uint8_t c = channels; c < this->channels; c++) {
setNoteGate(notes[c], false, c);
}
this->channels = channels;
}

/** Must be called before setNoteGate(). */ /** Must be called before setNoteGate(). */
void setVelocity(int8_t vel, int c) { void setVelocity(int8_t vel, int c) {
vels[c] = vel; vels[c] = vel;


+ 5
- 1
src/core/CV_MIDI.cpp View File

@@ -7,6 +7,7 @@ namespace core {


struct MidiOutput : dsp::MidiGenerator<PORT_MAX_CHANNELS>, midi::Output { struct MidiOutput : dsp::MidiGenerator<PORT_MAX_CHANNELS>, midi::Output {
void onMessage(const midi::Message& message) override { void onMessage(const midi::Message& message) override {
// DEBUG("MIDI: %ld %s", message.getFrame(), message.toString().c_str());
Output::sendMessage(message); Output::sendMessage(message);
} }


@@ -78,7 +79,10 @@ struct CV_MIDI : Module {


midiOutput.setFrame(args.frame); midiOutput.setFrame(args.frame);


for (int c = 0; c < inputs[PITCH_INPUT].getChannels(); c++) {
uint8_t channels = inputs[PITCH_INPUT].getChannels();
midiOutput.setChannels(channels);

for (int c = 0; c < channels; c++) {
int vel = (int) std::round(inputs[VEL_INPUT].getNormalPolyVoltage(10.f * 100 / 127, c) / 10.f * 127); int vel = (int) std::round(inputs[VEL_INPUT].getNormalPolyVoltage(10.f * 100 / 127, c) / 10.f * 127);
vel = clamp(vel, 0, 127); vel = clamp(vel, 0, 127);
midiOutput.setVelocity(vel, c); midiOutput.setVelocity(vel, c);


Loading…
Cancel
Save