예제 #1
0
파일: listmidi.go 프로젝트: scgolang/poly
// 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
}
예제 #2
0
파일: listen.go 프로젝트: scgolang/poly
// 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()
}