func listDevices() { n := portmidi.CountDevices() for i := 0; i < n; i++ { info := portmidi.GetDeviceInfo(portmidi.DeviceId(i)) fmt.Printf("Device %d: %v\n", i, info) } }
func newDevices() (devs devices) { portmidi.Initialize() devs = devices{ info: map[portmidi.DeviceId]*portmidi.DeviceInfo{}, } for id := 0; id < portmidi.CountDevices(); id++ { devID := deviceID(id) devs.info[devID] = portmidi.GetDeviceInfo(devID) } return }
func getDeviceId() (portmidi.DeviceId, error) { total := portmidi.CountDevices() for id := 0; id < total; id++ { id := portmidi.DeviceId(id) info := portmidi.GetDeviceInfo(id) if info.Name == "MicroBrute" && info.IsOutputAvailable { return id, nil } } return -1, fmt.Errorf("MicroBrute not found") }
func findMidiInputDevice(name string) portmidi.DeviceId { devcount := portmidi.CountDevices() for i := 0; i < devcount; i++ { id := portmidi.DeviceId(i) info := portmidi.GetDeviceInfo(id) if info.IsInputAvailable { if info.Name == name { return id } } } return portmidi.DeviceId(-1) }
func findMidiOutputDevice(name string) (portmidi.DeviceId, string) { devcount := portmidi.CountDevices() for i := 0; i < devcount; i++ { id := portmidi.DeviceId(i) info := portmidi.GetDeviceInfo(id) if info.IsOutputAvailable { if info.Name == name { return id, info.Name } } } id := portmidi.GetDefaultOutputDeviceId() info := portmidi.GetDeviceInfo(id) return id, info.Name }
// discovers the currently connected Launchpad device // as a MIDI device. func discover() (input portmidi.DeviceID, output portmidi.DeviceID, err error) { in := -1 out := -1 for i := 0; i < portmidi.CountDevices(); i++ { info := portmidi.Info(portmidi.DeviceID(i)) if strings.Contains(info.Name, "Launchpad") { if info.IsInputAvailable { in = i } if info.IsOutputAvailable { out = i } } } if in == -1 || out == -1 { err = errors.New("launchpad: no launchpad is connected") } else { input = portmidi.DeviceID(in) output = portmidi.DeviceID(out) } return }
func initPortMidi() *portmidi.Stream { portmidi.Initialize() deviceCount := portmidi.CountDevices() fmt.Println("Number of MIDI devices: ", deviceCount) dev := portmidi.DeviceId(3 - 1) for i := 0; i < deviceCount; i++ { id := portmidi.DeviceId(i) fmt.Println("Index ", i, "Id", id, " Device ", *portmidi.GetDeviceInfo(id)) } out, err := portmidi.NewOutputStream(dev, 0, 0) if err == nil { fmt.Println("used device info: ", *portmidi.GetDeviceInfo(dev)) } else { fmt.Println("Error: ", err) os.Exit(2) } return out }