Ejemplo n.º 1
0
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)
	}
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
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")
}
Ejemplo n.º 4
0
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)
}
Ejemplo n.º 5
0
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
}
Ejemplo n.º 6
0
// 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
}
Ejemplo n.º 7
0
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
}