-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirt.sml
51 lines (46 loc) · 1.26 KB
/
virt.sml
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
(* named virtual port *)
use "./portmidi.sml";
open Portmidi;
(* use with
virtual-portmidi diato &
fluidsynth Gaillard.sf2 -m alsa_seq -p diato
*)
(*
fun clean (diatout,diatin) =
(deleteVirtualDevice diatout;
deleteVirtualDevice diatin;
terminate())
*)
fun testExists id =
if id >= 0 then (* good id *)
let val infos = getDeviceInfo id
val name = #name infos
val isOutput = #output infos
val isInput = #input infos
val direction = if isOutput then " output" else if isInput then " input" else "inconnu"
in print ("Virtual Portmidi : " ^ name ^ direction ^ " created\n")
end
else (* error *)
print (getErrorText id ^ "\n")
fun main () =
let val dum1 = initialize()
val dum = ptStart 1
val args = CommandLine.arguments()
val name = List.hd args
val diatout = createVirtualOutput name
val dum = testExists diatout (* print result *)
val diatin = createVirtualInput name
val dum = testExists diatin (* print result *)
val err_in = openInput diatin 100
val err_out = openOutput diatout 100 2
val buf1 = ref (0,0,0,0,0) (* one event storage *)
in
while (true) do (
ptSleep 1; (* reduce cpu usage *)
if (poll diatin ) then (
read1 diatin buf1 ;
write1 diatout (!buf1)
)
else 1
)
end