Skip to content

Commit f9a98b6

Browse files
committed
Converted to new message format (with id).
1 parent 90f611d commit f9a98b6

File tree

7 files changed

+124
-70
lines changed

7 files changed

+124
-70
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.12
55
require (
66
github.com/fatih/color v1.9.0 // indirect
77
github.com/geomyidia/zylog v0.1.5
8+
github.com/google/uuid v1.3.0
89
github.com/kr/pretty v0.1.0 // indirect
910
github.com/mattn/go-isatty v0.0.13 // indirect
1011
github.com/okeuday/erlang_go/v2 v2.0.2

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
66
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
77
github.com/geomyidia/zylog v0.1.5 h1:f3FaxDrkCWJDRwiHjsDyA6YMz/EqpUcHHJ55QPEOWc8=
88
github.com/geomyidia/zylog v0.1.5/go.mod h1:y1pEB+nPevEmbupvHIuT6Znt5gRxah/eJ7dsBgfgbpA=
9+
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
10+
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
911
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
1012
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
1113
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=

pkg/erl/messages/midi.go

+68-39
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,51 @@
11
package messages
22

33
import (
4+
"errors"
45
"fmt"
56

7+
"github.com/google/uuid"
68
erlang "github.com/okeuday/erlang_go/v2/erlang"
79
log "github.com/sirupsen/logrus"
810

911
"github.com/geomyidia/midiserver/pkg/erl/datatypes"
1012
"github.com/geomyidia/midiserver/pkg/types"
1113
)
1214

13-
type MidiCalls struct {
15+
type MidiCallGroup struct {
16+
id string
1417
calls []types.MidiCall
1518
}
1619

17-
func NewMidiCalls(t interface{}) (*MidiCalls, error) {
18-
calls, err := Convert(t)
20+
func NewMidiCalls(t interface{}) (*MidiCallGroup, error) {
21+
id, calls, err := Convert(t)
1922
if err != nil {
2023
log.Error(err)
2124
return nil, err
2225
}
23-
return &MidiCalls{calls: calls}, nil
26+
return &MidiCallGroup{id: id, calls: calls}, nil
2427
}
2528

26-
func (mc *MidiCalls) Length() int {
27-
return len(mc.calls)
29+
func (mcg *MidiCallGroup) Id() string {
30+
return mcg.id
2831
}
2932

30-
func (mc *MidiCalls) Calls() []types.MidiCall {
31-
return mc.calls
33+
func (mcg *MidiCallGroup) Length() int {
34+
return len(mcg.calls)
35+
}
36+
37+
func (mcg *MidiCallGroup) Calls() []types.MidiCall {
38+
return mcg.calls
3239
}
3340

3441
func ConvertArg(k string, v interface{}) (*types.MidiArgs, error) {
3542
args := &types.MidiArgs{}
3643
switch k {
37-
case "device":
44+
case types.MidiDeviceKey:
3845
args.Device = v.(uint8)
39-
case "tempo_bpm":
40-
args.Tempo = v.(uint8)
41-
case "note_off":
46+
case types.MidiNoteOffKey:
4247
args.NoteOff = v.(uint8)
43-
case "meter":
44-
list := v.(erlang.OtpErlangList)
45-
meter, err := datatypes.PropListToMap(list)
46-
if err != nil {
47-
log.Error(err)
48-
return nil, err
49-
}
50-
args.Meter = types.MidiMeter{
51-
Numerator: meter["numerator"].(uint8),
52-
Denominator: meter["denominator"].(uint8),
53-
}
54-
case "note_on":
48+
case types.MidiNoteOnKey:
5549
list := v.(erlang.OtpErlangList)
5650
noteOn, err := datatypes.PropListToMap(list)
5751
if err != nil {
@@ -66,56 +60,91 @@ func ConvertArg(k string, v interface{}) (*types.MidiArgs, error) {
6660
return args, nil
6761
}
6862

69-
func Convert(term interface{}) ([]types.MidiCall, error) {
70-
emptyCalls := []types.MidiCall{}
63+
func Convert(term interface{}) (string, []types.MidiCall, error) {
64+
var id string
7165
calls := []types.MidiCall{}
7266
switch t := term.(type) {
7367
default:
74-
return emptyCalls, fmt.Errorf("could not convert %T", t)
68+
return "", nil, fmt.Errorf("could not convert %T", t)
7569
case erlang.OtpErlangList:
7670
ops, ok := term.(erlang.OtpErlangList)
7771
fmt.Printf("%+v\n", ops)
7872
if !ok {
79-
return emptyCalls, fmt.Errorf("could not convert %T", t)
73+
return "", nil, fmt.Errorf("could not convert %T", t)
8074
}
81-
for _, op := range ops.Value {
82-
call, err := Convert(op)
75+
for idx, op := range ops.Value {
76+
_, call, err := Convert(op)
8377
if err != nil {
8478
log.Error(err)
85-
return emptyCalls, err
79+
return "", nil, err
8680
}
87-
calls = append(calls, call...)
81+
var updatedCall []types.MidiCall
82+
for _, op := range call {
83+
op.Id = idx + 1
84+
updatedCall = append(updatedCall, op)
85+
}
86+
calls = append(calls, updatedCall...)
8887
}
89-
return calls, nil
88+
return "", calls, nil
9089
case erlang.OtpErlangTuple:
9190
key, val, err := datatypes.Tuple(t)
9291
if err != nil {
9392
log.Error(err)
94-
return emptyCalls, err
93+
return "", nil, err
9594
}
9695
if key == types.MidiKey {
9796
key, val, err = datatypes.Tuple(val)
9897
}
9998
if err != nil {
10099
log.Error(err)
101-
return emptyCalls, err
100+
return "", nil, err
102101
}
103102
if key == types.MidiBatchKey {
104-
batchCalls, err := Convert(val)
103+
var batchCalls []types.MidiCall
104+
id, batchCalls, err = ConvertBatch(val)
105105
if err != nil {
106106
log.Error(err)
107-
return emptyCalls, err
107+
return "", nil, err
108108
}
109109
calls = append(calls, batchCalls...)
110110
} else {
111111
args, err := ConvertArg(key, val)
112112
if err != nil {
113113
log.Error(err)
114-
return emptyCalls, err
114+
return "", nil, err
115115
}
116116
call := types.MidiCall{Op: types.MidiOpType(key), Args: args}
117117
calls = append(calls, call)
118118
}
119-
return calls, nil
119+
return id, calls, nil
120+
}
121+
}
122+
123+
func ConvertBatch(term interface{}) (string, []types.MidiCall, error) {
124+
var id string
125+
list, ok := term.(erlang.OtpErlangList)
126+
if !ok {
127+
return "", nil, errors.New("couldn't convert batch")
128+
}
129+
batchMap, err := datatypes.PropListToMap(list)
130+
if err != nil {
131+
return "", nil, err
132+
}
133+
// Process the Batch ID
134+
rawId := batchMap[types.MidiIdKey]
135+
binId, ok := rawId.(erlang.OtpErlangBinary)
136+
if !ok {
137+
return "", nil, errors.New("couldn't convert batch id")
138+
}
139+
uuid4, err := uuid.FromBytes(binId.Value)
140+
if err != nil {
141+
return "", nil, err
142+
}
143+
id = uuid4.String()
144+
// Process the Batch Messages
145+
_, batch, err := Convert(batchMap[types.MidiMessagesKey])
146+
if err != nil {
147+
return "", nil, err
120148
}
149+
return id, batch, nil
121150
}

pkg/erl/messages/processor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type MessageProcessor struct {
1313
packet *packets.Packet
1414
term interface{}
1515
cmdMsg *CommandMessage
16-
midiCalls *MidiCalls
16+
midiCalls *MidiCallGroup
1717
IsMidi bool
1818
IsCommand bool
1919
}

pkg/midi/midi.go

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func (s *System) CallMidi(call types.MidiCall) error {
132132
}
133133
return nil
134134
default:
135+
log.Errorf("no handler for operation '%s'", call.Op)
135136
return nil
136137
}
137138
}

pkg/types/types.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ package types
33
import "context"
44

55
const (
6-
ArgsKey string = "args"
7-
CommandKey string = "command"
8-
MidiKey string = "midi"
9-
MidiBatchKey string = "batch"
6+
ArgsKey string = "args"
7+
CommandKey string = "command"
8+
MidiKey string = "midi"
9+
MidiBatchKey string = "batch"
10+
MidiIdKey string = "id"
11+
MidiMessagesKey string = "messages"
12+
MidiDeviceKey string = "device"
13+
MidiNoteOffKey string = "note_off"
14+
MidiNoteOnKey string = "note_on"
1015
)
1116

1217
// CLI Flag types
@@ -56,6 +61,7 @@ type MidiArgs struct {
5661
}
5762

5863
type MidiCall struct {
64+
Id int
5965
Op MidiOpType
6066
Args *MidiArgs
6167
}

test/erl/messages_midi_test.go

+41-26
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,68 @@ import (
1212
"github.com/geomyidia/midiserver/pkg/types"
1313
)
1414

15+
const (
16+
Bb uint8 = 34
17+
Volume uint8 = 40
18+
)
19+
1520
type MidiMessageTestSuite struct {
1621
suite.Suite
17-
batch interface{}
18-
meter interface{}
19-
tempo interface{}
22+
batch interface{}
23+
device interface{}
24+
noteOn interface{}
2025
}
2126

2227
func (suite *MidiMessageTestSuite) SetupTest() {
23-
batchBytes := []byte{0x38, 0x33, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x34, 0x36, 0x44, 0x36, 0x39, 0x36, 0x34, 0x36, 0x39, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x35, 0x36, 0x32, 0x36, 0x31, 0x37, 0x34, 0x36, 0x33, 0x36, 0x38, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x33, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x36, 0x36, 0x34, 0x36, 0x35, 0x37, 0x36, 0x36, 0x39, 0x36, 0x33, 0x36, 0x35, 0x36, 0x31, 0x30, 0x30, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x35, 0x36, 0x44, 0x36, 0x35, 0x37, 0x34, 0x36, 0x35, 0x37, 0x32, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x39, 0x36, 0x45, 0x37, 0x35, 0x36, 0x44, 0x36, 0x35, 0x37, 0x32, 0x36, 0x31, 0x37, 0x34, 0x36, 0x46, 0x37, 0x32, 0x36, 0x31, 0x30, 0x34, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x42, 0x36, 0x34, 0x36, 0x35, 0x36, 0x45, 0x36, 0x46, 0x36, 0x44, 0x36, 0x39, 0x36, 0x45, 0x36, 0x31, 0x37, 0x34, 0x36, 0x46, 0x37, 0x32, 0x36, 0x31, 0x30, 0x34, 0x36, 0x41, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x39, 0x37, 0x34, 0x36, 0x35, 0x36, 0x44, 0x37, 0x30, 0x36, 0x46, 0x35, 0x46, 0x36, 0x32, 0x37, 0x30, 0x36, 0x44, 0x36, 0x31, 0x34, 0x34, 0x36, 0x41, 0xa}
24-
meterBytes := []byte{0x38, 0x33, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x34, 0x36, 0x44, 0x36, 0x39, 0x36, 0x34, 0x36, 0x39, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x35, 0x36, 0x44, 0x36, 0x35, 0x37, 0x34, 0x36, 0x35, 0x37, 0x32, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x39, 0x36, 0x45, 0x37, 0x35, 0x36, 0x44, 0x36, 0x35, 0x37, 0x32, 0x36, 0x31, 0x37, 0x34, 0x36, 0x46, 0x37, 0x32, 0x36, 0x31, 0x30, 0x36, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x42, 0x36, 0x34, 0x36, 0x35, 0x36, 0x45, 0x36, 0x46, 0x36, 0x44, 0x36, 0x39, 0x36, 0x45, 0x36, 0x31, 0x37, 0x34, 0x36, 0x46, 0x37, 0x32, 0x36, 0x31, 0x30, 0x38, 0x36, 0x41, 0xa}
25-
tempoBytes := []byte{0x38, 0x33, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x34, 0x36, 0x44, 0x36, 0x39, 0x36, 0x34, 0x36, 0x39, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x39, 0x37, 0x34, 0x36, 0x35, 0x36, 0x44, 0x37, 0x30, 0x36, 0x46, 0x35, 0x46, 0x36, 0x32, 0x37, 0x30, 0x36, 0x44, 0x36, 0x31, 0x34, 0x34, 0xa}
28+
batchBytes := []byte{0x38, 0x33, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x34, 0x36, 0x44, 0x36, 0x39, 0x36, 0x34, 0x36, 0x39, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x35, 0x36, 0x32, 0x36, 0x31, 0x37, 0x34, 0x36, 0x33, 0x36, 0x38, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x32, 0x36, 0x39, 0x36, 0x34, 0x36, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x33, 0x30, 0x39, 0x36, 0x39, 0x35, 0x37, 0x39, 0x43, 0x41, 0x35, 0x33, 0x34, 0x42, 0x41, 0x30, 0x42, 0x34, 0x41, 0x46, 0x41, 0x43, 0x46, 0x43, 0x45, 0x44, 0x37, 0x30, 0x39, 0x38, 0x36, 0x34, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x38, 0x36, 0x44, 0x36, 0x35, 0x37, 0x33, 0x37, 0x33, 0x36, 0x31, 0x36, 0x37, 0x36, 0x35, 0x37, 0x33, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x36, 0x36, 0x34, 0x36, 0x35, 0x37, 0x36, 0x36, 0x39, 0x36, 0x33, 0x36, 0x35, 0x36, 0x31, 0x30, 0x30, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x37, 0x36, 0x33, 0x36, 0x38, 0x36, 0x31, 0x36, 0x45, 0x36, 0x45, 0x36, 0x35, 0x36, 0x43, 0x36, 0x31, 0x30, 0x30, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x37, 0x36, 0x45, 0x36, 0x46, 0x37, 0x34, 0x36, 0x35, 0x35, 0x46, 0x36, 0x46, 0x36, 0x45, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x35, 0x37, 0x30, 0x36, 0x39, 0x37, 0x34, 0x36, 0x33, 0x36, 0x38, 0x36, 0x31, 0x32, 0x32, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x38, 0x37, 0x36, 0x36, 0x35, 0x36, 0x43, 0x36, 0x46, 0x36, 0x33, 0x36, 0x39, 0x37, 0x34, 0x37, 0x39, 0x36, 0x31, 0x32, 0x38, 0x36, 0x41, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x38, 0x36, 0x45, 0x36, 0x46, 0x37, 0x34, 0x36, 0x35, 0x35, 0x46, 0x36, 0x46, 0x36, 0x36, 0x36, 0x36, 0x36, 0x31, 0x32, 0x32, 0x36, 0x41, 0x36, 0x41, 0xa}
29+
deviceBytes := []byte{0x38, 0x33, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x34, 0x36, 0x44, 0x36, 0x39, 0x36, 0x34, 0x36, 0x39, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x35, 0x36, 0x32, 0x36, 0x31, 0x37, 0x34, 0x36, 0x33, 0x36, 0x38, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x32, 0x36, 0x39, 0x36, 0x34, 0x36, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x31, 0x31, 0x46, 0x46, 0x31, 0x33, 0x35, 0x43, 0x37, 0x38, 0x44, 0x35, 0x34, 0x31, 0x35, 0x43, 0x38, 0x38, 0x31, 0x38, 0x43, 0x44, 0x45, 0x37, 0x32, 0x32, 0x35, 0x32, 0x46, 0x46, 0x30, 0x32, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x38, 0x36, 0x44, 0x36, 0x35, 0x37, 0x33, 0x37, 0x33, 0x36, 0x31, 0x36, 0x37, 0x36, 0x35, 0x37, 0x33, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x36, 0x36, 0x34, 0x36, 0x35, 0x37, 0x36, 0x36, 0x39, 0x36, 0x33, 0x36, 0x35, 0x36, 0x31, 0x30, 0x30, 0x36, 0x41, 0x36, 0x41, 0xa}
30+
noteOnBytes := []byte{0x38, 0x33, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x34, 0x36, 0x44, 0x36, 0x39, 0x36, 0x34, 0x36, 0x39, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x35, 0x36, 0x32, 0x36, 0x31, 0x37, 0x34, 0x36, 0x33, 0x36, 0x38, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x32, 0x36, 0x39, 0x36, 0x34, 0x36, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x44, 0x45, 0x39, 0x35, 0x30, 0x37, 0x37, 0x39, 0x45, 0x36, 0x30, 0x41, 0x34, 0x33, 0x39, 0x41, 0x42, 0x43, 0x38, 0x33, 0x33, 0x32, 0x37, 0x41, 0x44, 0x46, 0x37, 0x30, 0x44, 0x39, 0x36, 0x31, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x38, 0x36, 0x44, 0x36, 0x35, 0x37, 0x33, 0x37, 0x33, 0x36, 0x31, 0x36, 0x37, 0x36, 0x35, 0x37, 0x33, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x37, 0x36, 0x45, 0x36, 0x46, 0x37, 0x34, 0x36, 0x35, 0x35, 0x46, 0x36, 0x46, 0x36, 0x45, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x35, 0x37, 0x30, 0x36, 0x39, 0x37, 0x34, 0x36, 0x33, 0x36, 0x38, 0x36, 0x31, 0x32, 0x32, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x38, 0x37, 0x36, 0x36, 0x35, 0x36, 0x43, 0x36, 0x46, 0x36, 0x33, 0x36, 0x39, 0x37, 0x34, 0x37, 0x39, 0x36, 0x31, 0x32, 0x38, 0x36, 0x41, 0x36, 0x41, 0x36, 0x41, 0xa}
31+
2632
opts := &erl.Opts{IsHexEncoded: true}
2733
bPkt, _ := packets.NewPacket(batchBytes, opts)
2834
suite.batch, _ = bPkt.Term()
29-
mPkt, _ := packets.NewPacket(meterBytes, opts)
30-
suite.meter, _ = mPkt.Term()
31-
tPkt, _ := packets.NewPacket(tempoBytes, opts)
32-
suite.tempo, _ = tPkt.Term()
35+
dPkt, _ := packets.NewPacket(deviceBytes, opts)
36+
suite.device, _ = dPkt.Term()
37+
nPkt, _ := packets.NewPacket(noteOnBytes, opts)
38+
suite.noteOn, _ = nPkt.Term()
3339

3440
}
3541

36-
func (suite *MidiMessageTestSuite) TestConvertTempo() {
37-
converted, err := messages.Convert(suite.tempo)
42+
func (suite *MidiMessageTestSuite) TestConvertDevice() {
43+
id, converted, err := messages.Convert(suite.device)
3844
suite.NoError(err)
39-
suite.Equal(types.MidiTempoType(), converted[0].Op)
40-
suite.Equal(uint8(68), converted[0].Args.Tempo)
45+
suite.Equal("11ff135c-78d5-415c-8818-cde72252ff02", id)
46+
suite.Equal(types.MidiDeviceType(), converted[0].Op)
47+
suite.Equal(uint8(0), converted[0].Args.Device)
4148
}
4249

43-
func (suite *MidiMessageTestSuite) TestConvertMeter() {
44-
converted, err := messages.Convert(suite.meter)
50+
func (suite *MidiMessageTestSuite) TestConvertNoteOn() {
51+
id, converted, err := messages.Convert(suite.noteOn)
4552
suite.NoError(err)
46-
suite.Equal(types.MidiMeterType(), converted[0].Op)
47-
suite.Equal(uint8(6), converted[0].Args.Meter.Numerator)
48-
suite.Equal(uint8(8), converted[0].Args.Meter.Denominator)
53+
suite.Equal("de950779-e60a-439a-bc83-327adf70d961", id)
54+
suite.Equal(types.MidiNoteOnType(), converted[0].Op)
55+
suite.Equal(Bb, converted[0].Args.NoteOn.Pitch)
56+
suite.Equal(Volume, converted[0].Args.NoteOn.Velocity)
4957
}
5058

5159
func (suite *MidiMessageTestSuite) TestConvertBatch() {
52-
converted, err := messages.Convert(suite.batch)
60+
id, converted, err := messages.Convert(suite.batch)
5361
suite.NoError(err)
54-
suite.Equal(3, len(converted))
62+
suite.Equal("30969579-ca53-4ba0-b4af-acfced709864", id)
63+
suite.Equal(4, len(converted))
64+
suite.Equal(1, converted[0].Id)
5565
suite.Equal(types.MidiDeviceType(), converted[0].Op)
5666
suite.Equal(uint8(0), converted[0].Args.Device)
57-
suite.Equal(types.MidiMeterType(), converted[1].Op)
58-
suite.Equal(uint8(4), converted[1].Args.Meter.Numerator)
59-
suite.Equal(uint8(4), converted[1].Args.Meter.Denominator)
60-
suite.Equal(types.MidiTempoType(), converted[2].Op)
61-
suite.Equal(uint8(68), converted[2].Args.Tempo)
67+
suite.Equal(2, converted[1].Id)
68+
suite.Equal(types.MidiChannelType(), converted[1].Op)
69+
suite.Equal(uint8(0), converted[1].Args.Channel)
70+
suite.Equal(3, converted[2].Id)
71+
suite.Equal(types.MidiNoteOnType(), converted[2].Op)
72+
suite.Equal(Bb, converted[2].Args.NoteOn.Pitch)
73+
suite.Equal(Volume, converted[2].Args.NoteOn.Velocity)
74+
suite.Equal(4, converted[3].Id)
75+
suite.Equal(types.MidiNoteOffType(), converted[3].Op)
76+
suite.Equal(Bb, converted[3].Args.NoteOff)
6277
}
6378

6479
// In order for 'go test' to run this suite, we need to create

0 commit comments

Comments
 (0)