-
Notifications
You must be signed in to change notification settings - Fork 0
/
midi_sustain
82 lines (70 loc) · 3.15 KB
/
midi_sustain
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
desc:MIDI sustain emulator
//tags: MIDI processing
//author: Tale
// Copyright (C) 2014-2017 Theo Niessink
// License: LGPL - http://www.gnu.org/licenses/lgpl.html
// This effect emulates the MIDI sustain pedal, i.e. it holds off Note Off
// messages until the pedal is released. This is useful for instruments that
// don't natively support sustain.
slider1:0<0,15,1{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}>MIDI Ch
slider2:64<0,119,1{00 Bank Select MSB,01 Mod Wheel MSB,02 Breath MSB,03,04 Foot Pedal MSB,05 Portamento MSB,06 Data Entry MSB,07 Volume MSB,08 Balance MSB,09,10 Pan Position MSB,11 Expression MSB,12 Control 1 MSB,13 Control 2 MSB,14,15,16 GP Slider 1,17 GP Slider 2,18 GP Slider 3,19 GP Slider 4,20,21,22,23,24,25,26,27,28,29,30,31,32 Bank Select LSB,33 Mod Wheel LSB,34 Breath LSB,35,36 Foot Pedal LSB,37 Portamento LSB,38 Data Entry LSB,39 Volume LSB,40 Balance LSB,41,42 Pan Position LSB,43 Expression LSB,44 Control 1 LSB,45 Control 2 LSB,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64 Hold Pedal (on/off),65 Portamento (on/off),66 Sostenuto (on/off),67 Soft Pedal (on/off),68 Legato Pedal (on/off),69 Hold 2 Pedal (on/off),70 Sound Variation,71 Timbre/Resonance,72 Sound Release,73 Sound Attack,74 Brightness/Cutoff Freq,75 Sound Control 6,76 Sound Control 7,77 Sound Control 8,78 Sound Control 9,79 Sound Control 10,80 GP Button 1 (on/off),81 GP Button 2 (on/off),82 GP Button 3 (on/off),83 GP Button 4 (on/off),84,85,86,87,88,89,90,91 Effects Level,92 Tremolo Level,93 Chorus Level,94 Celeste Level,95 Phaser Level,96 Data Button Inc,97 Data Button Dec,98 Non-Reg Parm LSB,99 Non-Reg Parm MSB,100 Reg Parm LSB,101 Reg Parm MSB,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119}>Controller
@slider
ch = max(0, min(15, slider1 |0));
cc = max(0, min(127, slider2 |0));
@block
while(midirecv(ofs, msg1, msg23) ? (
msg1 & 0x0F == ch ? (
status = msg1 & 0xF0;
msg2 = msg23 & 0x7F;
msg3 = msg23 >> 8;
// Note On
status == 0x90 && msg3 ? (
i = 0; note = msg2 + 1;
while(i < num_note && buf[i] & 0xFF != note ? i += 1 );
buf[i] = note;
i >= num_note ? (
num_note += 1;
) : (
midisend(ofs, 0x80 | ch, note | 0x4000);
);
) :
// Note Off
!(status & 0x60) ? (
i = 0; note = msg2 + 1;
while(i < num_note && buf[i] & 0xFF != note ? i += 1 );
sustain ? (
i >= num_note ? (
buf[i] = note;
num_note += 1;
);
buf[i] |= 0x100;
msg1 = 0;
) : (
buf[i] = 0;
n = num_note;
while((n -= 1) >= 0 && !buf[n]);
num_note = n + 1;
);
) :
// Sustain
status == 0xB0 && msg2 == cc ? (
sustain = msg3 >= 64;
!sustain ? (
i = 0;
n = -1;
loop(num_note,
buf[i] & 0x100 ? (
midisend(ofs, 0x80 | ch, (buf[i] - 1) | 0x4000);
buf[i] = 0;
) : buf[i] ? (
i > n ? n = i;
);
i += 1;
);
num_note = n + 1;
);
msg1 = 0;
);
);
msg1 ? midisend(ofs, msg1, msg23) : 1;
));