Skip to content

Commit e73a00b

Browse files
committed
Split erl.go into multiple files.
Also changed internal name to match new repo.
1 parent 5e8d7f4 commit e73a00b

File tree

13 files changed

+188
-141
lines changed

13 files changed

+188
-141
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ Copyright © 2020-2021, Duncan McGreggor
2020

2121
[logo]: assets/images/logo-v1-x250.png
2222
[logo-large]: assets/images/logo-v1-x1000.png
23-
[github]: https://github.com/geomyidia/erl-midi-server
24-
[gh-actions-badge]: https://github.com/geomyidia/erl-midi-server/workflows/ci%2Fcd/badge.svg
25-
[gh-actions]: https://github.com/geomyidia/erl-midi-server/actions
23+
[github]: https://github.com/geomyidia/midiserver
24+
[gh-actions-badge]: https://github.com/geomyidia/midiserver/workflows/ci%2Fcd/badge.svg
25+
[gh-actions]: https://github.com/geomyidia/midiserver/actions
2626
[lfe]: https://github.com/rvirding/lfe
2727
[lfe badge]: https://img.shields.io/badge/lfe-2.0-blue.svg
2828
[erlang badge]: https://img.shields.io/badge/erlang-21%20to%2024-blue.svg
29-
[versions]: https://github.com/geomyidia/erl-midi-server/blob/master/.github/workflows/cicd.yml
29+
[versions]: https://github.com/geomyidia/midiserver/blob/master/.github/workflows/cicd.yml

cmd/midiserver/main.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55

66
log "github.com/sirupsen/logrus"
77

8-
"github.com/geomyidia/erl-midi-server/internal/app"
9-
"github.com/geomyidia/erl-midi-server/internal/cli"
10-
"github.com/geomyidia/erl-midi-server/pkg/server"
11-
"github.com/geomyidia/erl-midi-server/pkg/types"
12-
"github.com/geomyidia/erl-midi-server/pkg/version"
8+
"github.com/geomyidia/midiserver/internal/app"
9+
"github.com/geomyidia/midiserver/internal/cli"
10+
"github.com/geomyidia/midiserver/pkg/server"
11+
"github.com/geomyidia/midiserver/pkg/types"
12+
"github.com/geomyidia/midiserver/pkg/version"
1313
)
1414

1515
func main() {

go.mod

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
module github.com/geomyidia/erl-midi-server
1+
module "github.com/geomyidia/midiserver"
22

33
go 1.12
44

55
require (
6+
github.com/deadcheat/goblet v1.3.1 // indirect
67
github.com/geomyidia/zylog v0.1.5
8+
github.com/kyoh86/richgo v0.3.9 // indirect
9+
github.com/mattn/go-isatty v0.0.13 // indirect
710
github.com/okeuday/erlang_go/v2 v2.0.2
811
github.com/sirupsen/logrus v1.8.1
912
gitlab.com/gomidi/midi v1.23.7
1013
gitlab.com/gomidi/rtmididrv v0.14.0
14+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
1115
)

go.sum

+28
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,60 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
12
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
23
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/deadcheat/goblet v1.3.1/go.mod h1:IrMNyAwyrVgB30HsND2WgleTUM4wHTS9m40yNY6NJQg=
5+
github.com/deadcheat/gonch v0.0.0-20180528124129-c2ff7a019863/go.mod h1:/5mH3gAuXUxGN3maOBAxBfB8RXvP9tBIX5fx2x1k0V0=
36
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
47
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
58
github.com/geomyidia/zylog v0.1.5 h1:f3FaxDrkCWJDRwiHjsDyA6YMz/EqpUcHHJ55QPEOWc8=
69
github.com/geomyidia/zylog v0.1.5/go.mod h1:y1pEB+nPevEmbupvHIuT6Znt5gRxah/eJ7dsBgfgbpA=
10+
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
711
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
12+
github.com/kyoh86/richgo v0.3.9 h1:om0AqQ6LmNYvaL7pMK7s3gixTM6iWzH3ICkfS0qNs+k=
13+
github.com/kyoh86/richgo v0.3.9/go.mod h1:2C8POkF1H04iTOG2Tp1yyZhspCME9nN3cir3VXJ02II=
14+
github.com/kyoh86/xdg v1.2.0 h1:CERuT/ShdTDj+A2UaX3hQ3mOV369+Sj+wyn2nIRIIkI=
15+
github.com/kyoh86/xdg v1.2.0/go.mod h1:/mg8zwu1+qe76oTFUBnyS7rJzk7LLC0VGEzJyJ19DHs=
816
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
917
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
1018
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
1119
github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
1220
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
21+
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
22+
github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA=
23+
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
24+
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
25+
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
1326
github.com/okeuday/erlang_go/v2 v2.0.2 h1:FgdZ/xxEpYNMsoGwpYsy2AecKyMPadlfq0+epT9gpSk=
1427
github.com/okeuday/erlang_go/v2 v2.0.2/go.mod h1:bUnKKmkI110+DM1rV59zPPqbcXp4yv18Fp2ofRwBmk4=
1528
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1629
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
30+
github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc=
1731
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
1832
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
1933
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
34+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2035
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2136
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
2237
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
38+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
39+
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
40+
github.com/wacul/ptr v1.0.0 h1:FIKu08Wx0YUIf9MNsfF62OCmBSmz5A1Tk65zWhOIL/I=
41+
github.com/wacul/ptr v1.0.0/go.mod h1:BD0gjsZrCwtoR+yWDB9v2hQ8STlq9tT84qKfa+3txOc=
2342
gitlab.com/gomidi/midi v1.21.0/go.mod h1:3ohtNOhqoSakkuLG/Li1OI6I3J1c2LErnJF5o/VBq1c=
2443
gitlab.com/gomidi/midi v1.23.7 h1:I6qKoIk9s9dcX+pNf0jC+tziCzJFn82bMpuntRkLeik=
2544
gitlab.com/gomidi/midi v1.23.7/go.mod h1:3ohtNOhqoSakkuLG/Li1OI6I3J1c2LErnJF5o/VBq1c=
2645
gitlab.com/gomidi/rtmididrv v0.14.0 h1:IBkDsqXs1RuFoRWgQbyYEpwe0hoXZ17FLTZaJuyXWx0=
2746
gitlab.com/gomidi/rtmididrv v0.14.0/go.mod h1:p/6IL1LGgj7utcv3wXudsDWiD9spgAdn0O8LDsGIPG0=
2847
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
48+
golang.org/x/net v0.0.0-20180404174746-b3c676e531a6/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
2949
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
3050
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
3151
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
3252
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
53+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
54+
golang.org/x/sys v0.0.0-20210326220804-49726bf1d181/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
55+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
56+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
57+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
58+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
59+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
60+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

internal/cli/cli.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/geomyidia/erl-midi-server/pkg/types"
9-
"github.com/geomyidia/erl-midi-server/pkg/version"
8+
"github.com/geomyidia/midiserver/pkg/types"
9+
"github.com/geomyidia/midiserver/pkg/version"
1010
)
1111

1212
const (

pkg/erl/message.go

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package erl
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
7+
erlang "github.com/okeuday/erlang_go/v2/erlang"
8+
log "github.com/sirupsen/logrus"
9+
10+
"github.com/geomyidia/midiserver/pkg/types"
11+
)
12+
13+
type CommandMessage struct {
14+
command erlang.OtpErlangAtom
15+
args []interface{}
16+
}
17+
18+
type MessageProcessor struct {
19+
packet *Packet
20+
term interface{}
21+
cmdMsg *CommandMessage
22+
midiMsg interface{}
23+
}
24+
25+
func handleTuple(tuple erlang.OtpErlangTuple) (*CommandMessage, error) {
26+
log.Debug("handling command tuple ...")
27+
if len(tuple) != DRCTVARITY {
28+
return nil, fmt.Errorf("tuple of wrong size; expected 2, got %d", len(tuple))
29+
}
30+
_, ok := tuple[DRCTVKEYINDEX].(erlang.OtpErlangAtom)
31+
if !ok {
32+
return nil, errors.New("unexpected type for directive")
33+
}
34+
msg := &CommandMessage{}
35+
msg.command = tuple[DRCTVVALUEINDEX].(erlang.OtpErlangAtom)
36+
return msg, nil
37+
}
38+
39+
func handleTuples(tuples erlang.OtpErlangList) (*CommandMessage, error) {
40+
msg := &CommandMessage{}
41+
//msg.command = tuple[DRCTVVALUEINDEX].(erlang.OtpErlangAtom)
42+
//msg.args =
43+
return msg, nil
44+
}
45+
46+
func NewCommandMessage(t interface{}) (*CommandMessage, error) {
47+
tuple, ok := t.(erlang.OtpErlangTuple)
48+
if !ok {
49+
tuples, ok := t.(erlang.OtpErlangList)
50+
if !ok {
51+
return nil, errors.New("unexpected message format")
52+
}
53+
return handleTuples(tuples)
54+
}
55+
return handleTuple(tuple)
56+
}
57+
58+
func (m *CommandMessage) Command() erlang.OtpErlangAtom {
59+
return m.command
60+
}
61+
62+
func (m *CommandMessage) Args() []interface{} {
63+
return m.args
64+
}
65+
66+
func NewMessageProcessor(opts *Opts) (*MessageProcessor, error) {
67+
packet, err := ReadStdIOPacket(opts)
68+
if err != nil {
69+
return &MessageProcessor{}, err
70+
}
71+
t, err := packet.Term()
72+
if err != nil {
73+
return &MessageProcessor{}, err
74+
}
75+
log.Debugf("got Erlang Port term")
76+
log.Tracef("%#v", t)
77+
msg, err := NewCommandMessage(t)
78+
if err != nil {
79+
resp := NewResponse(types.Result(""), types.Err(err.Error()))
80+
resp.Send()
81+
return &MessageProcessor{}, err
82+
}
83+
return &MessageProcessor{
84+
packet: packet,
85+
term: t,
86+
cmdMsg: msg,
87+
}, nil
88+
}
89+
90+
func (mp *MessageProcessor) Continue() types.Result {
91+
return types.Result("continue")
92+
}
93+
94+
func (mp *MessageProcessor) Process() types.Result {
95+
if mp.cmdMsg != nil {
96+
return types.Result(mp.cmdMsg.Command())
97+
} else if mp.midiMsg != nil {
98+
// process MIDI message
99+
return mp.Continue()
100+
} else {
101+
log.Error("unexected message type")
102+
return mp.Continue()
103+
}
104+
}

pkg/erl/opts.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package erl
2+
3+
import (
4+
"github.com/geomyidia/midiserver/pkg/types"
5+
)
6+
7+
// Constants
8+
const (
9+
DELIMITER = '\n'
10+
DRCTVARITY = 2
11+
DRCTVKEYINDEX = 0
12+
DRCTVVALUEINDEX = 1
13+
)
14+
15+
func Continue() types.Result {
16+
return types.Result("continue")
17+
}
18+
19+
type Opts struct {
20+
IsHexEncoded bool
21+
}
22+
23+
func DefaultOpts() *Opts {
24+
return &Opts{
25+
IsHexEncoded: false,
26+
}
27+
}

pkg/erl/erl.go renamed to pkg/erl/packet.go

-117
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,8 @@ import (
99

1010
erlang "github.com/okeuday/erlang_go/v2/erlang"
1111
log "github.com/sirupsen/logrus"
12-
13-
"github.com/geomyidia/erl-midi-server/pkg/types"
14-
)
15-
16-
// Constants
17-
const (
18-
DELIMITER = '\n'
19-
DRCTVARITY = 2
20-
DRCTVKEYINDEX = 0
21-
DRCTVVALUEINDEX = 1
2212
)
2313

24-
func Continue() types.Result {
25-
return types.Result("continue")
26-
}
27-
28-
type Opts struct {
29-
IsHexEncoded bool
30-
}
31-
32-
func DefaultOpts() *Opts {
33-
return &Opts{
34-
IsHexEncoded: false,
35-
}
36-
}
37-
3814
type Packet struct {
3915
bytes []byte
4016
len int
@@ -120,96 +96,3 @@ func (p *Packet) Term() (interface{}, error) {
12096
}
12197
return term, nil
12298
}
123-
124-
type CommandMessage struct {
125-
command erlang.OtpErlangAtom
126-
args []interface{}
127-
}
128-
129-
func handleTuple(tuple erlang.OtpErlangTuple) (*CommandMessage, error) {
130-
log.Debug("handling command tuple ...")
131-
if len(tuple) != DRCTVARITY {
132-
return nil, fmt.Errorf("tuple of wrong size; expected 2, got %d", len(tuple))
133-
}
134-
_, ok := tuple[DRCTVKEYINDEX].(erlang.OtpErlangAtom)
135-
if !ok {
136-
return nil, errors.New("unexpected type for directive")
137-
}
138-
msg := &CommandMessage{}
139-
msg.command = tuple[DRCTVVALUEINDEX].(erlang.OtpErlangAtom)
140-
return msg, nil
141-
}
142-
143-
func handleTuples(tuples erlang.OtpErlangList) (*CommandMessage, error) {
144-
msg := &CommandMessage{}
145-
//msg.command = tuple[DRCTVVALUEINDEX].(erlang.OtpErlangAtom)
146-
//msg.args =
147-
return msg, nil
148-
}
149-
150-
func NewCommandMessage(t interface{}) (*CommandMessage, error) {
151-
tuple, ok := t.(erlang.OtpErlangTuple)
152-
if !ok {
153-
tuples, ok := t.(erlang.OtpErlangList)
154-
if !ok {
155-
return nil, errors.New("unexpected message format")
156-
}
157-
return handleTuples(tuples)
158-
}
159-
return handleTuple(tuple)
160-
}
161-
162-
func (m *CommandMessage) Command() erlang.OtpErlangAtom {
163-
return m.command
164-
}
165-
166-
func (m *CommandMessage) Args() []interface{} {
167-
return m.args
168-
}
169-
170-
type MessageProcessor struct {
171-
packet *Packet
172-
term interface{}
173-
cmdMsg *CommandMessage
174-
midiMsg interface{}
175-
}
176-
177-
func NewMessageProcessor(opts *Opts) (*MessageProcessor, error) {
178-
packet, err := ReadStdIOPacket(opts)
179-
if err != nil {
180-
return &MessageProcessor{}, err
181-
}
182-
t, err := packet.Term()
183-
if err != nil {
184-
return &MessageProcessor{}, err
185-
}
186-
log.Debugf("got Erlang Port term")
187-
log.Tracef("%#v", t)
188-
msg, err := NewCommandMessage(t)
189-
if err != nil {
190-
resp := NewResponse(types.Result(""), types.Err(err.Error()))
191-
resp.Send()
192-
return &MessageProcessor{}, err
193-
}
194-
return &MessageProcessor{
195-
packet: packet,
196-
term: t,
197-
cmdMsg: msg,
198-
}, nil
199-
}
200-
201-
func (mp *MessageProcessor) Continue() types.Result {
202-
return types.Result("continue")
203-
}
204-
205-
func (mp *MessageProcessor) Process() types.Result {
206-
if mp.cmdMsg != nil {
207-
return types.Result(mp.cmdMsg.Command())
208-
} else if mp.midiMsg != nil {
209-
// process MIDI message
210-
return mp.Continue()
211-
} else {
212-
log.Error("unexected message type")
213-
return mp.Continue()
214-
}
215-
}

pkg/erl/response.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
erlang "github.com/okeuday/erlang_go/v2/erlang"
77
log "github.com/sirupsen/logrus"
88

9-
"github.com/geomyidia/erl-midi-server/pkg/types"
9+
"github.com/geomyidia/midiserver/pkg/types"
1010
)
1111

1212
type Response struct {

0 commit comments

Comments
 (0)