midi

package module
v2.0.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 7 Imported by: 136

Documentation

Overview

package midi

Index

Constants

This section is empty.

Variables

View Source
var EOT = MetaMessage(byteEndOfTrack, nil)

EndOfTrack you should not use this. Use the smf package instead.

View Source
var ErrPortClosed = fmt.Errorf("ERROR: port is closed")

ErrPortClosed should be returned from a driver when trying to write to a closed port.

Functions

func MetaChannel

func MetaChannel(ch uint8) []byte

func MetaCopyright

func MetaCopyright(text string) []byte

func MetaCuepoint

func MetaCuepoint(text string) []byte

func MetaDevice

func MetaDevice(text string) []byte

func MetaInstrument

func MetaInstrument(text string) []byte

func MetaKey

func MetaKey(key uint8, isMajor bool, num uint8, isFlat bool) []byte

func MetaLyric

func MetaLyric(text string) []byte

func MetaMarker

func MetaMarker(text string) []byte

func MetaMessage

func MetaMessage(typ byte, data []byte) []byte

func MetaMeter

func MetaMeter(num, denom uint8) []byte

func MetaPort

func MetaPort(p uint8) []byte

func MetaProgram

func MetaProgram(text string) []byte

func MetaSMPTE

func MetaSMPTE(hour, minute, second, frame, fractionalFrame byte) []byte

func MetaSequenceNo

func MetaSequenceNo(no uint16) []byte

func MetaSequencerData

func MetaSequencerData(data []byte) []byte

func MetaTempo

func MetaTempo(bpm float64) []byte

func MetaText

func MetaText(text string) []byte

func MetaTimeSig

func MetaTimeSig(numerator, denominator, clocksPerClick, demiSemiQuaverPerQuarter uint8) []byte

Raw returns the raw MIDI data

func MetaTrackSequenceName

func MetaTrackSequenceName(text string) []byte

func MetaUndefined

func MetaUndefined(typ byte, data []byte) []byte

func ReadMetaData

func ReadMetaData(tp MsgType, rd io.Reader) (data []byte, err error)

func SysEx

func SysEx(msg []byte) []byte

Types

type Channel

type Channel uint8

func (Channel) Aftertouch

func (ch Channel) Aftertouch(pressure uint8) []byte

Aftertouch returns the bytes of an aftertouch message.

func (Channel) ControlChange

func (ch Channel) ControlChange(controller, value uint8) []byte

ControlChange returns the bytes of an control change message.

func (Channel) Index

func (ch Channel) Index() uint8

func (Channel) NoteOff

func (ch Channel) NoteOff(key uint8) []byte

func (Channel) NoteOffVelocity

func (ch Channel) NoteOffVelocity(key, velocity uint8) []byte

func (Channel) NoteOn

func (ch Channel) NoteOn(key, velocity uint8) []byte

func (Channel) Pitchbend

func (ch Channel) Pitchbend(value int16) []byte

Pitchbend returns the raw bytes for the message

func (Channel) PolyAftertouch

func (ch Channel) PolyAftertouch(key, pressure uint8) []byte

PolyAftertouch returns the raw bytes of the polyphonic aftertouch message.

func (Channel) ProgramChange

func (ch Channel) ProgramChange(program uint8) []byte

type Driver

type Driver interface {

	// Ins returns the available MIDI input ports.
	Ins() ([]In, error)

	// Outs returns the available MIDI output ports.
	Outs() ([]Out, error)

	// String returns the name of the driver.
	String() string

	// Close closes the driver. Must be called for cleanup at the end of a session.
	Close() error
}

Driver is a driver for MIDI connections.

type In

type In interface {
	Port
	SenderTo

	// StopListening stops the listening.
	// When closing a MIDI input port, StopListening must be called before (from the driver).
	StopListening() error
}

In is an interface for a MIDI input port

func OpenIn

func OpenIn(d Driver, number int, name string) (in In, err error)

OpenIn opens a MIDI input port with the help of the given driver. To find the port by port number, pass a number >= 0. To find the port by port name, pass a number < 0 and a non empty string.

type Message

type Message struct {
	MsgType
	Data []byte
}

func NewMessage

func NewMessage(data []byte) (m Message)

func ReadChannelMessage

func ReadChannelMessage(status byte, arg1 byte, rd io.Reader) (m Message, err error)

Read reads a channel message

func (Message) BPM

func (m Message) BPM() float64

func (Message) Change

func (m Message) Change() int8

Change returns the MIDI controllchange a number from 0 to 127 or -1, if it is no controller message

func (Message) Channel

func (m Message) Channel() int8

Channel returns the MIDI channel - a number from 0 to 15 or -1, if it is no channel message or an invalid channel number

func (Message) Controller

func (m Message) Controller() int8

Controller returns the MIDI controller - a number from 0 to 127 or -1, if it is no controller message

func (Message) IsNoteEnd

func (m Message) IsNoteEnd() bool

IsNoteEnd checks, if we have a de facto note end, i.e. a NoteoffMsg or a NoteOnMsg with velocity == 0

func (Message) IsNoteStart

func (m Message) IsNoteStart() bool

IsNoteStart checks, if we have a de facto note start, i.e. a NoteOnMsg with velocity > 0

func (Message) Key

func (m Message) Key() int8

Key returns the MIDI key - a number from 0 to 127 or -1, if it is no noteOn / noteOff / PolyAfterTouch message or an invalid key

func (Message) Meter

func (m Message) Meter() (num, denom uint8)

func (Message) Pitch

func (m Message) Pitch() (relative int16, absolute int16)

func (Message) Pressure

func (m Message) Pressure() int8

func (Message) Program

func (m Message) Program() int8

func (Message) String

func (m Message) String() string

func (Message) Text

func (m Message) Text() string

Text returns the text for the meta messages

Lyric Copyright Cuepoint Device Instrument Marker Program Text TrackSequenceName

func (Message) TimeSig

func (m Message) TimeSig() (numerator, denominator, clocksPerClick, demiSemiQuaverPerQuarter uint8)

func (Message) Velocity

func (m Message) Velocity() int8

Velocity returns the MIDI velocity - a number from 0 to 127 or -1, if it is no channel / noteOn / noteOff message or an invalid velocity

type MsgType

type MsgType uint64
const (
	ChannelMsg MsgType = 1 << iota
	MetaMsg
	RealTimeMsg
	SysCommonMsg
	SysExMsg
	NoteOnMsg
	NoteOffMsg
	ControlChangeMsg
	PitchBendMsg
	AfterTouchMsg
	PolyAfterTouchMsg
	ProgramChangeMsg
	MetaChannelMsg
	MetaCopyrightMsg
	MetaCuepointMsg
	MetaDeviceMsg
	MetaEndOfTrackMsg
	MetaInstrumentMsg
	MetaKeySigMsg
	MetaLyricMsg
	MetaTextMsg
	MetaMarkerMsg
	MetaPortMsg
	MetaSeqNumberMsg
	MetaSeqDataMsg
	MetaTempoMsg
	MetaTimeSigMsg
	MetaTrackNameMsg
	MetaSMPTEOffsetMsg
	MetaUndefinedMsg
	MetaProgramNameMsg
	TimingClockMsg
	TickMsg
	StartMsg
	ContinueMsg
	StopMsg
	ActiveSenseMsg
	ResetMsg
	SysExStartMsg
	SysExEndMsg
	SysExCompleteMsg
	SysExEscapeMsg
	SysExContinueMsg
	MTCMsg
	SongSelectMsg
	SPPMsg
	UndefinedMsg
	TuneMsg
	Channel0Msg
	Channel1Msg
	Channel2Msg
	Channel3Msg
	Channel4Msg
	Channel5Msg
	Channel6Msg
	Channel7Msg
	Channel8Msg
	Channel9Msg
	Channel10Msg
	Channel11Msg
	Channel12Msg
	Channel13Msg
	Channel14Msg
	Channel15Msg
)
const UnknownMsg MsgType = 0

func GetMetaMessage

func GetMetaMessage(b byte) MsgType

func GetMsgType

func GetMsgType(msg []byte) (mType MsgType)

func (MsgType) Clear

func (m MsgType) Clear(flag MsgType) MsgType

func (MsgType) Is

func (m MsgType) Is(flag MsgType) bool

func (MsgType) IsAllOf

func (m MsgType) IsAllOf(flags ...MsgType) bool

func (MsgType) IsNot

func (m MsgType) IsNot(flag MsgType) bool

func (MsgType) IsOneOf

func (m MsgType) IsOneOf(flags ...MsgType) bool

func (MsgType) Set

func (m MsgType) Set(flag MsgType) MsgType

func (MsgType) String

func (m MsgType) String() string

func (MsgType) Toggle

func (m MsgType) Toggle(flag MsgType) MsgType

type Out

type Out interface {
	Port
	Sender
}

Out is an interface for a MIDI output port.

func OpenOut

func OpenOut(d Driver, number int, name string) (out Out, err error)

OpenOut opens a MIDI output port with the help of the given driver. To find the port by port number, pass a number >= 0. To find the port by port name, pass a number < 0 and a non empty string.

type Port

type Port interface {

	// Open opens the MIDI port. An implementation should save the open state to make it
	// save to call open when the port is already open without getting an error.
	Open() error

	// Close closes the MIDI port. An implementation should save the open state to make it
	// save to call close when the port is already closed without getting an error.
	Close() error

	// IsOpen returns wether the MIDI port is open.
	IsOpen() bool

	// Number returns the number of the MIDI port. It is only guaranteed that the numbers are unique within
	// MIDI port groups i.e. within MIDI input ports and MIDI output ports. So there may be the same number
	// for a given MIDI input port and some MIDI output port. Or not - that depends on the underlying driver.
	Number() int

	// String represents the MIDI port by a string, aka name.
	String() string

	// Underlying returns the underlying driver to allow further adjustments.
	// When using the underlying driver, the user must take care of proper opening/closing etc.
	Underlying() interface{}
}

Port is an interface for a MIDI port.

type Receiver

type Receiver interface {
	// Receive receives a MIDI message. deltamicrosec is the delta to the previous note in microseconds (^-6)
	Receive(msg []byte, deltamicrosec int64)
}

Receiver receives MIDI messages.

func NewReceiver

func NewReceiver(otherMsgCallback func(msg Message, deltamicrosec int64), realtimeMsgCallback func(msg Message, deltamicrosec int64)) Receiver

type Sender

type Sender interface {
	// Send sends the given MIDI message and returns any error.
	Send(msg []byte) error
}

Sender sends MIDI messages.

type SenderTo

type SenderTo interface {
	// SendTo sends MIDI messages to the given receiver.
	SendTo(Receiver) error
}

SenderTo sends MIDI messages.

Directories

Path Synopsis
drivers
testdrv
Package testdrv provides a gomidi/midi.Driver for testing.
Package testdrv provides a gomidi/midi.Driver for testing.
midicatdrv Module
portmididrv Module
rtmididrv Module
webmididrv Module
listports Module
logger Module
simple Module
smf0player Module
smf0recorder Module
smfplayer Module
smfrecorder Module
internal
tools
midispy Module
smflyrics Module

Jump to

Keyboard shortcuts

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