func ExampleReadSysExBytes() { in, err := portmidi.NewInputStream(portmidi.GetDefaultInputDeviceId(), 1024) if err != nil { log.Fatal(err) } msg, err := in.Read(1024) if err != nil { log.Fatal(err) } for i, b := range msg { fmt.Printf("SysEx message byte %d = %02x\n", i, b) } }
func initMidi() { device := portmidi.DeviceId(*midiDevice) if device == -1 { device = portmidi.GetDefaultInputDeviceId() } s, err := portmidi.NewInputStream(device, 1024) if err != nil { log.Println(err) return } if s == nil { log.Println("could not initialize MIDI input device") return } go midiLoop(s) }
func main() { var ( flagPort = flag.String("port", "", "MIDI port name (or prefix) to watch") flagList = flag.Bool("l", false, "List the found input ports") flagVerbose = flag.Bool("v", false, "Display unmapped MIDI events and be more verbose") err error port portmidi.DeviceId ) flag.Parse() if *flagVerbose { debug = true } devs := newDevices() if *flagList { for _, name := range devs.DeviceNames() { fmt.Println(name) } return } if *flagPort != "" { port, err = devs.Input(*flagPort) if err != nil { fmt.Println(err.Error()) os.Exit(1) return } } else { port = portmidi.GetDefaultInputDeviceId() } if debug { fmt.Printf("monitoring MIDI port: %s\n", devs.info[port].Name) } watcher := newWatcher(port) watcher.Run() }
See the License for the specific language governing permissions and limitations under the License. */ package audio import ( "flag" "log" "sync" "sync/atomic" "github.com/rakyll/portmidi" ) var midiDevice = flag.Int("midi_device", int(portmidi.GetDefaultInputDeviceId()), "MIDI Device ID") var initMidiOnce sync.Once func initMidi() { s, err := portmidi.NewInputStream(portmidi.DeviceId(*midiDevice), 1024) if err != nil { log.Println(err) return } go midiLoop(s) } var midiNote, midiGate int64 // atomic func midiLoop(s *portmidi.Stream) {