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 }