diff --git a/src/mezz/sys-ports.reb b/src/mezz/sys-ports.reb index dad6c182dc..1fedb5a27c 100644 --- a/src/mezz/sys-ports.reb +++ b/src/mezz/sys-ports.reb @@ -491,8 +491,8 @@ init-schemes: func [ parse spec/ref [ thru #":" 0 2 slash opt "device:" - copy inp *parse-url/digits - opt [#"/" copy out *parse-url/digits] + copy inp url-parser/digit + opt [#"/" copy out url-parser/digit] end ] if inp [ spec/device-in: to integer! inp] diff --git a/src/os/win32/dev-midi.c b/src/os/win32/dev-midi.c index 11eca3b203..b98bf0a428 100644 --- a/src/os/win32/dev-midi.c +++ b/src/os/win32/dev-midi.c @@ -46,6 +46,7 @@ #endif #ifdef INCLUDE_MIDI_DEVICE +//#define DEBUG_MIDI // NOTE: this will be useful for higher level launchpad schemes: // https://github.com/FMMT666/launchpad.py/blob/master/launchpad_py/launchpad.py diff --git a/src/tests/test-midi.r3 b/src/tests/test-midi.r3 new file mode 100644 index 0000000000..02b11a8f0b --- /dev/null +++ b/src/tests/test-midi.r3 @@ -0,0 +1,99 @@ +Rebol [ + Title: "Test MIDI port" + Date: 5-Jun-2023 + Author: "Oldes" + File: %test-midi.r3 + Version: 1.0.0 + Requires: 3.11.0 +] + +midi: query midi:// +unless object? midi [ print as-purple "No MIDI available!" quit] + +print [as-yellow "Input devices: " length? midi/devices-in] +foreach dev midi/devices-in [ print [tab mold dev] ] +print [as-yellow "Output devices:" length? midi/devices-out] +foreach dev midi/devices-out [ print [tab mold dev] ] + + +*MIDI_message: enum [ + note-off: 2#{0000 1000} + note-on: 2#{0000 1001} + poly-aftertouch: 2#{0000 1010} + control-change: 2#{0000 1011} + program-change: 2#{0000 1100} + channel-preasure: 2#{0000 1101} + pitch_bend-change: 2#{0000 1110} +] "MIDI Voice message" + +*MIDI_message_short: enum [ + Off: 2#{0000 1000} + On: 2#{0000 1001} + PoPr: 2#{0000 1010} + Par: 2#{0000 1011} + PrCh: 2#{0000 1100} + ChPr: 2#{0000 1101} + Pb: 2#{0000 1110} +] "MIDI Voice message (short variant)" + + +process-midi: function [data [binary!]][ + bin: binary data + while [(length? bin/buffer) >= 8][ + binary/read bin [ + status: UB 4 + channel: UB 4 + byte-1: SI8 + byte-2: SI8 + byte-3: SI8 + time: UI32LE + ] + either all [ + byte-3 = 0 + ][ + op: *MIDI_message_short/name status + prin ajoin [time #" " op " ch=" channel #" "] + print ajoin switch/default op [ + Par [["c=" byte-1 " v=" byte-2]] + Pb ChPr [reduce ["v=" byte-1 + (byte-2 << 7)]] + PrCh [["p=" byte-1]] + ][ + ["n=" byte-1 " v=" byte-2] + ] + ][ print "should not happen!" ] + ] +] + +close-midi: does [ + try [close midi-out] + try [close midi-inp] + wait 0 +] + +midi-inp: open midi:1 +midi-out: open [scheme: 'midi device-out: 1] + +midi-out/awake: +midi-inp/awake: function [event [event!]][ + switch event/type [ + read [ process-midi read event/port ] + open [ print ["MIDI port opened!" event/port/spec/ref] ] + close [ print ["MIDI port closed!" event/port/spec/ref] ] + ] + true +] + +;; Play some random modern piano music ;-) +;; MIDI input should be printed in the console. +loop 50 [ + write midi-out rejoin [ + #{90} random 127 50 + random 77 0 + #{90} random 127 50 + random 77 0 + #{90} random 127 50 + random 77 0 + ] + wait 0.5 + random 0.5 +] + +close-midi + +if system/options/script [ask "DONE"] \ No newline at end of file