Add xtouch library for reading X-Touch Extender input events
This commit is contained in:
52
main.go
52
main.go
@@ -3,35 +3,45 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"gitlab.com/gomidi/midi/v2"
|
||||
_ "gitlab.com/gomidi/midi/v2/drivers/rtmididrv"
|
||||
|
||||
"qrun/xtouch"
|
||||
)
|
||||
|
||||
func main() {
|
||||
defer midi.CloseDriver()
|
||||
|
||||
inPorts := midi.GetInPorts()
|
||||
outPorts := midi.GetOutPorts()
|
||||
|
||||
fmt.Println("MIDI Input Ports:")
|
||||
if len(inPorts) == 0 {
|
||||
fmt.Println(" (none)")
|
||||
}
|
||||
for i, port := range inPorts {
|
||||
fmt.Printf(" [%d] %s\n", i, port)
|
||||
}
|
||||
|
||||
fmt.Println("\nMIDI Output Ports:")
|
||||
if len(outPorts) == 0 {
|
||||
fmt.Println(" (none)")
|
||||
}
|
||||
for i, port := range outPorts {
|
||||
fmt.Printf(" [%d] %s\n", i, port)
|
||||
}
|
||||
|
||||
if len(inPorts) == 0 && len(outPorts) == 0 {
|
||||
fmt.Println("\nNo MIDI devices found.")
|
||||
port, err := xtouch.FindInPort("x-touch")
|
||||
if err != nil {
|
||||
fmt.Println("Available MIDI input ports:")
|
||||
for _, p := range midi.GetInPorts() {
|
||||
fmt.Printf(" %s\n", p)
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "\nError: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
dec := &xtouch.Decoder{EncoderMode: xtouch.EncoderRelative}
|
||||
|
||||
fmt.Printf("Listening on: %s\n", port)
|
||||
|
||||
stop, err := midi.ListenTo(port, func(msg midi.Message, timestampms int32) {
|
||||
if event := dec.Decode(msg); event != nil {
|
||||
fmt.Println(event)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error listening: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer stop()
|
||||
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-sig
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user