diff options
author | Richard <q@1bpm.net> | 2025-04-13 18:48:02 +0100 |
---|---|---|
committer | Richard <q@1bpm.net> | 2025-04-13 18:48:02 +0100 |
commit | 9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 (patch) | |
tree | 291bd79ce340e67affa755a8a6b4f6a83cce93ea /site/udo/midi.udo | |
download | apps.csound.1bpm.net-9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22.tar.gz apps.csound.1bpm.net-9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22.tar.bz2 apps.csound.1bpm.net-9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22.zip |
initial
Diffstat (limited to 'site/udo/midi.udo')
-rwxr-xr-x | site/udo/midi.udo | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/site/udo/midi.udo b/site/udo/midi.udo new file mode 100755 index 0000000..1e608b3 --- /dev/null +++ b/site/udo/midi.udo @@ -0,0 +1,65 @@ +#ifndef UDO_MIDI
+#define UDO_MIDI ##
+/*
+ MIDI control handler
+ Currently only handling one channel
+
+ This file is part of the SONICS UDO collection by Richard Knight 2022
+ License: GPL-2.0-or-later
+ http://1bpm.net
+*/
+
+
+gimidi_values = ftgen(0, 0, -128, -2, 0) ; scale 0 to 1 values with index correlating to MIDI CC number
+
+
+/*
+ Handle incoming MIDI messages and write to channel with scaling if defined in gSmidimap_channels and gkmidimap_values
+*/
+instr midi_handler
+ kstatus, kchan, kdata1, kdata2 midiin
+ if (kstatus == 176) then ;144 is note on 128 is note off ; 208 is aftertouch
+ tabw scale(kdata2, 1, 0, 127, 0), kdata1, gimidi_values
+#ifndef MIDI_NOTE_HANDLER_INSTRUMENT
+ endif
+#else
+ elseif (kstatus == 144) then
+ schedulek("_midi_note_handler", 0, 1, 1, kchan, kdata1, kdata2)
+ elseif (kstatus == 128) then
+ schedulek("_midi_note_handler", 0, 1, 0, kchan, kdata1, kdata2)
+ endif
+#end
+endin
+alwayson("midi_handler")
+
+
+instr _midi_note_handler
+ ionoff = p4
+ ichannel = p5
+ inote = p6
+ ivelocity = p7
+ instrnum = nstrnum("$MIDI_NOTE_HANDLER_INSTRUMENT") + (ichannel / 100) + (inote / 100000)
+ if (ionoff == 0) then
+ turnoff2 instrnum, 4, 1
+ else
+ schedule(instrnum, 0, -1, ichannel, inote, ivelocity)
+ endif
+ turnoff
+endin
+
+opcode midi_cc, k, i
+ icc xin
+ kval tab icc, gimidi_values
+ xout kval
+endop
+
+opcode midi_zeroall, 0, 0
+ index = 0
+ while (index < 128) do
+ outic 1, index, 0, 0, 1
+ tabw_i 0, index, gimidi_values
+ index += 1
+ od
+endop
+
+#end
|