// Run runs the command from command-line arguments. func (list *ListMIDI) Run(args []string) error { fmt.Println(h1) fmt.Println(h2) for i := 0; i < portmidi.CountDevices(); i++ { info := portmidi.GetDeviceInfo(portmidi.DeviceId(i)) fmt.Printf(row, i, info.Interface, info.Name, info.IsInputAvailable, info.IsOutputAvailable) } return nil }
// ListenMIDI listens for MIDI events. func (poly *Poly) ListenMIDI() error { did := portmidi.DeviceId(poly.midi) midiInput, err := portmidi.NewInputStream(did, midiBufferSize) if err != nil { return err } for events, err := midiInput.Read(1024); err == nil; events, err = midiInput.Read(1024) { for _, event := range events { if err := poly.HandleMIDI(event); err != nil { _ = midiInput.Close() // Best effort. return err } } } return midiInput.Close() }