Documentation ¶
Overview ¶
Package portmidi provides PortMidi bindings.
Index ¶
- Variables
- func CountDevices() int
- func Initialize() error
- func Terminate() error
- type Channel
- type DeviceID
- type DeviceInfo
- type Event
- type Stream
- func (s *Stream) Abort() error
- func (s *Stream) Close() error
- func (s *Stream) Listen() <-chan Event
- func (s *Stream) Poll() (bool, error)
- func (s *Stream) Read(max int) (events []Event, err error)
- func (s *Stream) ReadSysExBytes(max int) ([]byte, error)
- func (s *Stream) SetChannelMask(mask int) error
- func (s *Stream) Write(events []Event) error
- func (s *Stream) WriteShort(status int64, data1 int64, data2 int64) error
- func (s *Stream) WriteSysEx(when Timestamp, msg string) error
- func (s *Stream) WriteSysExBytes(when Timestamp, msg []byte) error
- type Timestamp
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrMaxBuffer = errors.New("portmidi: max event buffer size is 1024") ErrMinBuffer = errors.New("portmidi: min event buffer size is 1") )
Functions ¶
func Initialize ¶
func Initialize() error
Initialize initializes the portmidi. Needs to be called before making any other call from the portmidi package. Once portmidi package is no longer required, Terminate should be called to free the underlying resources.
Types ¶
type DeviceID ¶
type DeviceID int
DeviceID is a MIDI device ID.
func DefaultInputDeviceID ¶
func DefaultInputDeviceID() DeviceID
DefaultInputDeviceID returns the default input device's ID.
func DefaultOutputDeviceID ¶
func DefaultOutputDeviceID() DeviceID
DefaultOutputDeviceID returns the default output device's ID.
type DeviceInfo ¶
type DeviceInfo struct { Interface string Name string IsInputAvailable bool IsOutputAvailable bool IsOpened bool }
DeviceInfo provides info about a MIDI device.
func Info ¶
func Info(deviceID DeviceID) *DeviceInfo
Info returns the device info for the device indentified with deviceID. If deviceID is out of range, Info returns nil.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream represents a portmidi stream.
func NewInputStream ¶
NewInputStream initializes a new input stream.
func NewOutputStream ¶
NewOutputStream initializes a new output stream.
func (*Stream) Poll ¶
Poll reports whether there is input available in the stream.
Example ¶
package main import ( "fmt" "log" "github.com/rakyll/portmidi" ) func main() { in, err := portmidi.NewInputStream(portmidi.DefaultInputDeviceID(), 1024) if err != nil { log.Fatal(err) } result, err := in.Poll() if err != nil { log.Fatal(err) } if result { fmt.Println("New messages in the queue!") } else { fmt.Println("No new messages in the queue :(") } }
Output:
func (*Stream) Read ¶
Reads from the input stream, the max number events to be read are determined by max.
func (*Stream) ReadSysExBytes ¶
ReadSysExBytes reads 4*max sysex bytes from the input stream.
Example ¶
package main import ( "fmt" "log" "github.com/rakyll/portmidi" ) func main() { in, err := portmidi.NewInputStream(portmidi.DefaultInputDeviceID(), 1024) if err != nil { log.Fatal(err) } msg, err := in.Read(1024) if err != nil { log.Fatal(err) } for i, b := range msg { fmt.Printf("SysEx message byte %d = %02x\n", i, b) } }
Output:
func (*Stream) SetChannelMask ¶
SetChannelMask filters incoming stream based on channel. In order to filter from more than a single channel, or multiple channels. s.SetChannelMask(Channel(1) | Channel(10)) will both filter input from channel 1 and 10.
func (*Stream) WriteShort ¶
WriteShort writes a MIDI event of three bytes immediately to the output stream.
func (*Stream) WriteSysEx ¶
WriteSysEx writes a system exclusive MIDI message given as a string of hexadecimal characters to the output stream. The string must only consist of hex digits (0-9A-F) and optional spaces. This function is case-insenstive.
Example ¶
package main import ( "log" "github.com/rakyll/portmidi" ) func main() { out, err := portmidi.NewOutputStream(portmidi.DefaultOutputDeviceID(), 1024, 0) if err != nil { log.Fatal(err) } if err = out.WriteSysEx(portmidi.Time(), "F0 0A 0A 1B 00 7F 30 F7"); err != nil { log.Fatal(err) } }
Output:
func (*Stream) WriteSysExBytes ¶
WriteSysExBytes writes a system exclusive MIDI message given as a []byte to the output stream.
Example ¶
package main import ( "log" "github.com/rakyll/portmidi" ) func main() { out, err := portmidi.NewOutputStream(portmidi.DefaultOutputDeviceID(), 1024, 0) if err != nil { log.Fatal(err) } if err = out.WriteSysExBytes(portmidi.Time(), []byte{0xF0, 0x0A, 0x0A, 0x1B, 0x00, 0x7F, 0x30, 0xF7}); err != nil { log.Fatal(err) } }
Output: