示例#1
0
func getSystemDevices() (inputs, outputs []SystemDevice) {
	numDevices := int(C.Pm_CountDevices())
	for i := 0; i < numDevices; i++ {
		info := C.Pm_GetDeviceInfo(C.PmDeviceID(i))
		name := C.GoString(info.name)

		var isInputPort, isOutputPort, isOpen bool
		if info.output > 0 { // "output" means "output stream" in portmidi-speak.
			isInputPort = true // An OUTPUT stream is for an INPUT port.
		}
		if info.input > 0 { // "input" means "input stream" in portmidi-speak.
			isOutputPort = true // An INPUT stream is for an OUTPUT port.
		}
		if info.opened > 0 {
			isOpen = true
		}
		port := &SystemPort{isOpen: isOpen, id: i, IsInputPort: isInputPort}
		device := SystemDevice{Name: name}

		if isInputPort {
			device.inPort = port
			device.outPort = &SystemPort{isOpen: false, id: -1}
			inputs = append(inputs, device)
		} else if isOutputPort {
			device.outPort = port
			device.inPort = &SystemPort{isOpen: false, id: -1}
			outputs = append(outputs, device)
		}
	}
	return inputs, outputs
}
示例#2
0
// Returns the device info for the device indentified with deviceId.
func GetDeviceInfo(deviceId DeviceID) *DeviceInfo {
	info := C.Pm_GetDeviceInfo(C.PmDeviceID(deviceId))
	return &DeviceInfo{
		Interface:         C.GoString(info.interf),
		Name:              C.GoString(info.name),
		IsInputAvailable:  info.input > 0,
		IsOutputAvailable: info.output > 0,
		IsOpened:          info.opened > 0,
	}
}