5
5
"io"
6
6
"time"
7
7
8
+ log "github.com/sirupsen/logrus"
9
+ driver "gitlab.com/gomidi/rtmididrv"
8
10
"gitlab.com/gomidi/midi/reader"
9
11
"gitlab.com/gomidi/midi/writer"
10
12
)
@@ -23,6 +25,44 @@ func Example() {
23
25
24
26
var p printer
25
27
28
+ drv , err := driver .New ()
29
+ if err != nil {
30
+ log .Panic (err )
31
+ }
32
+ defer drv .Close ()
33
+
34
+ ins , err := drv .Ins ()
35
+ if err != nil {
36
+ log .Panic (err )
37
+ }
38
+
39
+ outs , err := drv .Outs ()
40
+ if err != nil {
41
+ log .Panic (err )
42
+ }
43
+
44
+ log .Debug ("MIDI IN Ports" )
45
+ for _ , port := range ins {
46
+ log .Debugf ("[%v] %s\n " , port .Number (), port .String ())
47
+ }
48
+
49
+ log .Debug ("MIDI OUT Ports" )
50
+ for _ , port := range outs {
51
+ log .Debugf ("[%v] %s\n " , port .Number (), port .String ())
52
+ }
53
+
54
+ in , out := ins [0 ], outs [0 ]
55
+
56
+ err = in .Open ()
57
+ if err != nil {
58
+ log .Panic (err )
59
+ }
60
+
61
+ err = out .Open ()
62
+ if err != nil {
63
+ log .Panic (err )
64
+ }
65
+
26
66
// to disable logging, pass mid.NoLogger() as option
27
67
rd := reader .New (reader .NoLogger (),
28
68
// set the callbacks for the messages you are interested in
@@ -35,11 +75,15 @@ func Example() {
35
75
piperd , pipewr := io .Pipe ()
36
76
37
77
go func () {
38
- wr := writer .New (pipewr )
39
- wr .SetChannel (1 ) // sets the channel for the next messages
40
- writer .NoteOn (wr , 120 , 100 )
78
+ // wr := writer.New(pipewr)
79
+ wr := writer .New (out )
80
+ wr .SetChannel (0 ) // sets the channel for the next messages
81
+ err := writer .NoteOn (wr , 60 , 100 )
82
+ if err != nil {
83
+ log .Panic (err )
84
+ }
41
85
time .Sleep (5 * time .Second )
42
- writer .NoteOff (wr , 120 ) // let the note ring for 5 sec
86
+ writer .NoteOff (wr , 60 ) // let the note ring for 5 sec
43
87
pipewr .Close () // finishes the writing
44
88
}()
45
89
0 commit comments