-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from schollz/rtmidi
Rtmidi
- Loading branch information
Showing
7 changed files
with
141 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package rtmidi | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/schollz/miti/src/log" | ||
driver "gitlab.com/gomidi/rtmididrv" | ||
) | ||
|
||
type Event struct { | ||
MIDI int | ||
On bool | ||
Instrument string | ||
Timestamp time.Time | ||
} | ||
|
||
func ReadAll(finished chan bool) (events chan Event, err error) { | ||
events = make(chan Event, 100) | ||
if !inited { | ||
drv, err = driver.New() | ||
if err != nil { | ||
return | ||
} | ||
inited = true | ||
} | ||
|
||
ins, err := drv.Ins() | ||
if err != nil { | ||
return | ||
} | ||
|
||
for i := range ins { | ||
err = ins[i].Open() | ||
if err != nil { | ||
log.Error(err) | ||
continue | ||
} | ||
func(j int) { | ||
name := ins[j].String() | ||
log.Tracef("setting up %s", name) | ||
ins[j].SetListener(func(data []byte, deltaMicroseconds int64) { | ||
if len(data) == 3 { | ||
log.Tracef("[%s] %+v", name, data) | ||
events <- Event{int(data[1]), data[0] == 144, name, time.Now()} | ||
} | ||
}) | ||
}(i) | ||
|
||
} | ||
go func() { | ||
<-finished | ||
for i := range ins { | ||
log.Debugf("[%s] closing midi input", ins[i].String()) | ||
ins[i].StopListening() | ||
ins[i].Close() | ||
} | ||
}() | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters