portmidi

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package portmidi provides PortMidi bindings.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMaxBuffer         = errors.New("portmidi: max event buffer size is 1024")
	ErrMinBuffer         = errors.New("portmidi: min event buffer size is 1")
	ErrInputUnavailable  = errors.New("portmidi: input is unavailable")
	ErrOutputUnavailable = errors.New("portmidi: output is unavailable")
)

Functions

func CountDevices

func CountDevices() int

CountDevices returns the number of MIDI devices.

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.

func Terminate

func Terminate() error

Terminate terminates and cleans up the midi streams.

Types

type Channel

type Channel int

Channel represent a MIDI channel. It should be between 1-16.

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 Event

type Event struct {
	Timestamp Timestamp
	Status    int64
	Data1     int64
	Data2     int64
}

Event represents a MIDI event.

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream represents a portmidi stream.

func NewInputStream

func NewInputStream(id DeviceID, bufferSize int64) (stream *Stream, err error)

NewInputStream initializes a new input stream.

func NewOutputStream

func NewOutputStream(id DeviceID, bufferSize int64, latency int64) (stream *Stream, err error)

NewOutputStream initializes a new output stream.

func (*Stream) Abort

func (s *Stream) Abort() error

Abort aborts the MIDI stream.

func (*Stream) Close

func (s *Stream) Close() error

Close closes the MIDI stream.

func (*Stream) Listen

func (s *Stream) Listen() <-chan Event

Listen input stream for MIDI events.

func (*Stream) Poll

func (s *Stream) Poll() (bool, error)

Poll reports whether there is input available in the stream.

func (*Stream) Read

func (s *Stream) Read(max int) (events []Event, err error)

Reads from the input stream, the max number events to be read are determined by max.

func (*Stream) ReadSysExBytes

func (s *Stream) ReadSysExBytes(max int) ([]byte, error)

ReadSysExBytes reads 4*max sysex bytes from the input stream.

func (*Stream) SetChannelMask

func (s *Stream) SetChannelMask(mask int) error

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) Write

func (s *Stream) Write(events []Event) error

Write writes a buffer of MIDI events to the output stream.

func (*Stream) WriteShort

func (s *Stream) WriteShort(status int64, data1 int64, data2 int64) error

WriteShort writes a MIDI event of three bytes immediately to the output stream.

func (*Stream) WriteShorts

func (s *Stream) WriteShorts(status int64, data1s []int64, data2s []int64) error

WriteShorts writes a bunch of MIDI events of three bytes immediately to the output stream.

func (*Stream) WriteSysEx

func (s *Stream) WriteSysEx(when Timestamp, msg string) error

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.

func (*Stream) WriteSysExBytes

func (s *Stream) WriteSysExBytes(when Timestamp, msg []byte) error

WriteSysExBytes writes a system exclusive MIDI message given as a []byte to the output stream.

type Timestamp

type Timestamp int64

func Time

func Time() Timestamp

Time returns the portmidi timer's current time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL