Reuse MIDI conversion function for CLAP events
This commit is contained in:
parent
b7633730e6
commit
56a12db1e6
|
@ -1212,35 +1212,17 @@ impl<P: ClapPlugin> Wrapper<P> {
|
||||||
|
|
||||||
clap_call! { out=>try_push(out, &event.header) }
|
clap_call! { out=>try_push(out, &event.header) }
|
||||||
}
|
}
|
||||||
NoteEvent::MidiChannelPressure {
|
midi_event @ (NoteEvent::MidiChannelPressure { .. }
|
||||||
timing: _,
|
| NoteEvent::MidiPitchBend { .. }
|
||||||
channel,
|
| NoteEvent::MidiCC { .. }
|
||||||
pressure,
|
| NoteEvent::MidiProgramChange { .. })
|
||||||
} if P::MIDI_OUTPUT >= MidiConfig::MidiCCs => {
|
if P::MIDI_OUTPUT >= MidiConfig::MidiCCs =>
|
||||||
let event = clap_event_midi {
|
{
|
||||||
header: clap_event_header {
|
// NIH-plug already includes MIDI conversion functions, so we'll reuse those for
|
||||||
size: mem::size_of::<clap_event_midi>() as u32,
|
// the MIDI events
|
||||||
time,
|
let midi = midi_event
|
||||||
space_id: CLAP_CORE_EVENT_SPACE_ID,
|
.as_midi()
|
||||||
type_: CLAP_EVENT_MIDI,
|
.expect("Missing MIDI conversion for MIDI event");
|
||||||
flags: 0,
|
|
||||||
},
|
|
||||||
port_index: 0,
|
|
||||||
data: [
|
|
||||||
midi::CHANNEL_KEY_PRESSURE | channel as u8,
|
|
||||||
(pressure * 127.0).round() as u8,
|
|
||||||
0,
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
clap_call! { out=>try_push(out, &event.header) }
|
|
||||||
}
|
|
||||||
NoteEvent::MidiPitchBend {
|
|
||||||
timing: _,
|
|
||||||
channel,
|
|
||||||
value,
|
|
||||||
} if P::MIDI_OUTPUT >= MidiConfig::MidiCCs => {
|
|
||||||
let scaled = (value * ((1 << 14) - 1) as f32).round() as i32;
|
|
||||||
|
|
||||||
let event = clap_event_midi {
|
let event = clap_event_midi {
|
||||||
header: clap_event_header {
|
header: clap_event_header {
|
||||||
|
@ -1251,54 +1233,7 @@ impl<P: ClapPlugin> Wrapper<P> {
|
||||||
flags: 0,
|
flags: 0,
|
||||||
},
|
},
|
||||||
port_index: 0,
|
port_index: 0,
|
||||||
data: [
|
data: midi,
|
||||||
midi::PITCH_BEND_CHANGE | channel as u8,
|
|
||||||
(scaled & 0b01111111) as u8,
|
|
||||||
((scaled >> 7) & 0b01111111) as u8,
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
clap_call! { out=>try_push(out, &event.header) }
|
|
||||||
}
|
|
||||||
NoteEvent::MidiCC {
|
|
||||||
timing: _,
|
|
||||||
channel,
|
|
||||||
cc,
|
|
||||||
value,
|
|
||||||
} if P::MIDI_OUTPUT >= MidiConfig::MidiCCs => {
|
|
||||||
let event = clap_event_midi {
|
|
||||||
header: clap_event_header {
|
|
||||||
size: mem::size_of::<clap_event_midi>() as u32,
|
|
||||||
time,
|
|
||||||
space_id: CLAP_CORE_EVENT_SPACE_ID,
|
|
||||||
type_: CLAP_EVENT_MIDI,
|
|
||||||
flags: 0,
|
|
||||||
},
|
|
||||||
port_index: 0,
|
|
||||||
data: [
|
|
||||||
midi::CONTROL_CHANGE | channel as u8,
|
|
||||||
cc,
|
|
||||||
(value * 127.0).round() as u8,
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
clap_call! { out=>try_push(out, &event.header) }
|
|
||||||
}
|
|
||||||
NoteEvent::MidiProgramChange {
|
|
||||||
timing: _,
|
|
||||||
channel,
|
|
||||||
program,
|
|
||||||
} if P::MIDI_OUTPUT >= MidiConfig::MidiCCs => {
|
|
||||||
let event = clap_event_midi {
|
|
||||||
header: clap_event_header {
|
|
||||||
size: mem::size_of::<clap_event_midi>() as u32,
|
|
||||||
time,
|
|
||||||
space_id: CLAP_CORE_EVENT_SPACE_ID,
|
|
||||||
type_: CLAP_EVENT_MIDI,
|
|
||||||
flags: 0,
|
|
||||||
},
|
|
||||||
port_index: 0,
|
|
||||||
data: [midi::PROGRAM_CHANGE | channel as u8, program, 0],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
clap_call! { out=>try_push(out, &event.header) }
|
clap_call! { out=>try_push(out, &event.header) }
|
||||||
|
|
Loading…
Reference in a new issue