ref: b7eeb823e45f4465f5b19297ac1faed22b81ac13
parent: ed9c9803ab5f8c465776875925cec5fa98751f18
author: cancel <cancel@cancel.fm>
date: Sun Jan 19 10:52:08 EST 2020
Change MIDI velocity behavior to match newer Orca JS
--- a/sim.c
+++ b/sim.c
@@ -129,22 +129,6 @@
}
}
-static ORCA_FORCE_NO_INLINE U8 midi_velocity_of(Glyph g) {
- Usz n = index_of(g);
- // scale [0,9] to [0,127]
- if (n < 10)
- return (U8)(n * 14 + 1);
- n -= 10;
- // scale [0,25] to [0,127]
- // js seems to send 1 when original n is < 10, and 0 when n is 11. Is that
- // the intended behavior?
- if (n == 0)
- return UINT8_C(0);
- if (n >= 26)
- return UINT8_C(127);
- return (U8)(n * 5 - 3);
-}
-
typedef struct {
Glyph *vars_slots;
Oevent_list *oevent_list;
@@ -342,6 +326,15 @@
Usz channel_num = index_of(channel_g);
if (channel_num > 15)
channel_num = 15;
+ Usz vel_num = index_of(velocity_g);
+ // MIDI notes with velocity zero are actually note-offs. (MIDI has two ways
+ // to send note offs. Zero-velocity is the alternate way.) If there is a zero
+ // velocity, we'll just not do anything.
+ if (vel_num == 0)
+ return;
+ vel_num = vel_num * 8 - 1; // 1~16 -> 7~127
+ if (vel_num > 127)
+ vel_num = 127;
Oevent_midi *oe =
(Oevent_midi *)oevent_list_alloc_item(extra_params->oevent_list);
oe->oevent_type = (U8)Oevent_type_midi;
@@ -348,7 +341,7 @@
oe->channel = (U8)channel_num;
oe->octave = octave_num;
oe->note = note_num;
- oe->velocity = midi_velocity_of(velocity_g);
+ oe->velocity = (U8)vel_num;
oe->bar_divisor = (U8)(index_of(length_g) + 1);
END_OPERATOR