File tree 2 files changed +44
-17
lines changed
2 files changed +44
-17
lines changed Original file line number Diff line number Diff line change @@ -487,7 +487,7 @@ init-schemes: func [
487
487
spec: system/standard/port-spec-midi
488
488
init : func [ port /local spec inp out] [
489
489
spec: port/spec
490
- if url? spec/ref [
490
+ either url? spec/ref [
491
491
parse spec/ref [
492
492
thru #":" 0 2 slash
493
493
opt "device:"
@@ -497,12 +497,30 @@ init-schemes: func [
497
497
]
498
498
if inp [ spec/device-in: to integer! inp]
499
499
if out [ spec/device-out: to integer! out]
500
+ ][
501
+ ;; Lookup device IDs using full names (or wildcards)
502
+ all [
503
+ any-string? inp: select spec 'device-in
504
+ spec/device-in: find inp query /mode midi:// 'devices-in
505
+ ]
506
+ all [
507
+ any-string? out: select spec 'device-out
508
+ spec/device-out: find out query /mode midi:// 'devices-out
509
+ ]
500
510
]
501
511
; make port/spec to be only with midi related keys
502
512
set port/spec: copy system/standard/port-spec-midi spec
503
513
;protect/words port/spec ; protect spec object keys of modification
504
514
true
505
515
]
516
+ find : func [ device [any-string! ] devices [block! ]] [
517
+ forall devices [
518
+ if lib/find/match/any devices/1 device [
519
+ return index? devices
520
+ ]
521
+ ]
522
+ none
523
+ ]
506
524
]
507
525
508
526
make-scheme [
Original file line number Diff line number Diff line change @@ -66,10 +66,32 @@ close-midi: does [
66
66
wait 0
67
67
]
68
68
69
- midi-inp: open midi:1
70
- midi-out: open [scheme: 'midi device-out: 1 ]
69
+ either port? midi-out: try [
70
+ open [
71
+ scheme: 'midi
72
+ device-out: "Microsoft GS Wavetable" ;; note that the name is not complete, but still accepted
73
+ ]
74
+ ][
75
+ ;; Play some random modern piano music ;-)
76
+ loop 50 [
77
+ write midi-out rejoin [
78
+ ;; NOTE VOLUME
79
+ #{ 90 } random 127 50 + random 77 0
80
+ #{ 90 } random 127 50 + random 77 0
81
+ #{ 90 } random 127 50 + random 77 0
82
+ ]
83
+ ;; Random time between notes :)
84
+ wait 0.5 + random 0.5
85
+ ]
86
+ try [close midi-out]
87
+ wait 0
88
+ ][
89
+ ;; No SW synth...
90
+ print as-purple "Not playing the great piano music, because no SW synth found!"
91
+ ]
71
92
72
- midi-out/awake:
93
+ print as-yellow "You have 10 seconds to try your (first) MIDI device input!"
94
+ midi-inp: open midi:1
73
95
midi-inp/awake: function [event [event! ]][
74
96
switch event/type [
75
97
read [ process-midi read event/port ]
@@ -78,21 +100,8 @@ midi-inp/awake: function [event [event!]][
78
100
]
79
101
true
80
102
]
81
-
82
103
wait 10
83
104
close-midi
84
- halt
85
- ;; Play some random modern piano music ;-)
86
- ;; MIDI input should be printed in the console.
87
- loop 50 [
88
- write midi-out rejoin [
89
- #{ 90 } random 127 50 + random 77 0
90
- #{ 90 } random 127 50 + random 77 0
91
- #{ 90 } random 127 50 + random 77 0
92
- ]
93
- wait 0.5 + random 0.5
94
- ]
95
105
96
- close-midi
97
106
98
107
if system/options/script [ask "DONE" ]
You can’t perform that action at this time.
0 commit comments