-
Notifications
You must be signed in to change notification settings - Fork 1
/
launchpad_s.go
53 lines (42 loc) · 992 Bytes
/
launchpad_s.go
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
51
52
53
package launchpad
import (
"errors"
"gitlab.com/gomidi/midi"
"gitlab.com/gomidi/midi/reader"
"strings"
"sync"
)
type LaunchpadS struct {
inputStream midi.In
outputStream midi.Out
isListening bool
listenerMutex sync.RWMutex
listener []func(pos *reader.Position, msg midi.Message)
}
func (l *LaunchpadS) Out() midi.Out {
return l.outputStream
}
func (l *LaunchpadS) In() midi.In {
return l.inputStream
}
func (l *LaunchpadS) Close() error {
errMessages := make([]string, 0, 3)
if err := l.inputStream.Close(); err != nil {
errMessages = append(errMessages, err.Error())
}
if err := l.outputStream.Close(); err != nil {
errMessages = append(errMessages, err.Error())
}
if len(errMessages) > 0 {
return errors.New(strings.Join(errMessages, ";"))
}
return nil
}
func (l *LaunchpadS) write(b []byte) (int, error) {
if !l.outputStream.IsOpen() {
if err := l.outputStream.Open(); err != nil {
return -1, err
}
}
return l.outputStream.Write(b)
}