From ca933d746ba16ef326d9b4ba85d51940ab9e8add Mon Sep 17 00:00:00 2001 From: Terin Stock Date: Sun, 29 Jul 2018 19:37:27 +0000 Subject: feat: initial version of midifi software This CL introduces the initial version of the midifi software, via a simplified CLI interface "playsmf". Though it is far from complete, this version can be manually invoked with the locations of the MIDI communications port (the `-com` flag), and MIDI file. It will playback the MIDI file with the correct time. Software is currently tested with an integration test, that invokes the program with a known MIDI file and compares the output of the serial port, standard out, and standard error. Golden files can be updated by providing the `-test.update-golden` flag. Change-Id: I312bc721736e2edf385ece5141133ffa6bd20a72 Signed-off-by: Terin Stock --- pkg/ttymididrv/driver.go | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 pkg/ttymididrv/driver.go (limited to 'pkg/ttymididrv/driver.go') diff --git a/pkg/ttymididrv/driver.go b/pkg/ttymididrv/driver.go new file mode 100644 index 0000000..cc7b1fd --- /dev/null +++ b/pkg/ttymididrv/driver.go @@ -0,0 +1,73 @@ +package ttymididrv + +import ( + "sync" + + "gitlab.com/gomidi/midi/mid" +) + +type driver struct { + mu sync.RWMutex + outs []mid.Out + opened []mid.Port + closed bool +} + +func New(name string, baud int) mid.Driver { + d := &driver{} + d.outs = []mid.Out{ + &out{ + name: name, + baud: baud, + number: 0, + driver: d, + }, + } + + return d +} + +func (d *driver) String() string { + return "ttymididrv" +} + +func (d *driver) Close() (err error) { + d.mu.RLock() + if d.closed { + d.mu.RUnlock() + return mid.ErrClosed + } + d.mu.RUnlock() + + d.mu.Lock() + d.closed = true + d.mu.Unlock() + + for _, p := range d.opened { + err = p.Close() + } + + return +} + +func (d *driver) Ins() ([]mid.In, error) { + d.mu.Lock() + defer d.mu.Unlock() + + if d.closed { + return nil, mid.ErrClosed + } + + return nil, nil +} + +func (d *driver) Outs() ([]mid.Out, error) { + d.mu.Lock() + defer d.mu.Unlock() + + if d.closed { + return nil, mid.ErrClosed + } + + return d.outs, nil +} -- cgit v1.2.3