Example #1
0
// Initializes the portmidi.
func Initialize() error {
	if code := C.Pm_Initialize(); code != 0 {
		return convertToError(code)
	}
	C.Pt_Start(C.int(1), nil, nil)
	return nil
}
Example #2
0
func GetDevices() (SystemDevices, error) {
	inputs, outputs := getSystemDevices()
	devices := make(map[string]SystemDevice, len(inputs)+len(outputs))

	// Pair devices that have both an input and an output, add all to system.
	for _, inDev := range inputs {
		for _, outDev := range outputs {
			if inDev.Name == outDev.Name {
				inDev.outPort = outDev.outPort
				outDev.inPort = inDev.inPort
				break
			}
		}
		devices[inDev.Name] = inDev
	}
	for _, outDev := range outputs {
		if _, ok := devices[outDev.Name]; !ok {
			devices[outDev.Name] = outDev
		}
	}
	errNum := C.Pm_Initialize()
	return devices, makePortMidiError(errNum)
}