midi

package module
v2.0.0-alpha.1 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: 137

Documentation

Overview

package midi

Index

Constants

This section is empty.

Variables

View Source
var ChannelType = map[uint8]MessageType{
	0:  Channel0,
	1:  Channel1,
	2:  Channel2,
	3:  Channel3,
	4:  Channel4,
	5:  Channel5,
	6:  Channel6,
	7:  Channel7,
	8:  Channel8,
	9:  Channel9,
	10: Channel10,
	11: Channel11,
	12: Channel12,
	13: Channel13,
	14: Channel14,
	15: Channel15,
}
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 AFlatMaj

func AFlatMaj() []byte

AFlatMaj returns the MIDI key signature meta message for Ab Major

func AMaj

func AMaj() []byte

AMaj returns the MIDI key signature meta message for A Major

func AMin

func AMin() []byte

AMin returns the MIDI key signature meta message for A Minor

func BFlatMaj

func BFlatMaj() []byte

BFlatMaj returns the MIDI key signature meta message for Bb Major

func BFlatMin

func BFlatMin() []byte

BFlatMin returns the MIDI key signature meta message for Bb Minor

func BMaj

func BMaj() []byte

BMaj returns the MIDI key signature meta message for B Major

func BMin

func BMin() []byte

BMin returns the MIDI key signature meta message for B Minor

func CMaj

func CMaj() []byte

CMaj returns the MIDI key signature meta message for C Major

func CMin

func CMin() []byte

CMin returns the MIDI key signature meta message for C Minor

func CSharpMin

func CSharpMin() []byte

CSharpMin returns the MIDI key signature meta message for C# Minor

func DFlatMaj

func DFlatMaj() []byte

DFlatMaj returns the MIDI key signature meta message for Db Major

func DMaj

func DMaj() []byte

DMaj returns the MIDI key signature meta message for D Major

func DMin

func DMin() []byte

DMin returns the MIDI key signature meta message for D Minor

func DSharpMin

func DSharpMin() []byte

DSharpMin returns the MIDI key signature meta message for D# Minor

func EFlatMaj

func EFlatMaj() []byte

EFlatMaj returns the MIDI key signature meta message for Eb Major

func EFlatMin

func EFlatMin() []byte

EFlatMin returns the MIDI key signature meta message for Eb Minor

func EMaj

func EMaj() []byte

EMaj returns the MIDI key signature meta message for E Major

func EMin

func EMin() []byte

EMin returns the MIDI key signature meta message for E Minor

func FMaj

func FMaj() []byte

FMaj returns the MIDI key signature meta message for F Major

func FMin

func FMin() []byte

FMin returns the MIDI key signature meta message for F Minor

func FSharpMaj

func FSharpMaj() []byte

FSharpMaj returns the MIDI key signature meta message for F# Major

func FSharpMin

func FSharpMin() []byte

FSharpMin returns the MIDI key signature meta message for F# Minor

func GFlatMaj

func GFlatMaj() []byte

GFlatMaj returns the MIDI key signature meta message for Gb Major

func GMaj

func GMaj() []byte

GMaj returns the MIDI key signature meta message for G Major

func GMin

func GMin() []byte

GMin returns the MIDI key signature meta message for G Minor

func GSharpMin

func GSharpMin() []byte

GSharpMin returns the MIDI key signature meta message for G# Minor

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 ParseStatus

func ParseStatus(b byte) (messageType uint8, messageChannel uint8)

ParseStatus parses the status byte and returns type and channel

This is a slightly modified variant of the readStatusByte function from Joe Wass. See the file midi_functions.go for the original.

func ReadByte

func ReadByte(rd io.Reader) (byte, error)

ReadByte reads a byte from the reader

func ReadMetaData

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

func ReadNBytes

func ReadNBytes(n int, rd io.Reader) ([]byte, error)

ReadNBytes reads n bytes from the reader

func ReadUint24

func ReadUint24(rd io.Reader) (uint32, error)

ReadUint24 parse a 3-byte 24 bit integer from a Reader. It returns the 32-bit value and an error. This is a slightly modified variant of the parseUint24 function from Joe Wass. See the file midi_functions.go for the original.

func SysEx

func SysEx(msg []byte) []byte

Types

type Channel

type Channel 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) 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 Filter

type Filter []MessageType

func (Filter) Receiver

func (f Filter) Receiver(rec Receiver) Receiver

func (Filter) Sender

func (f Filter) Sender(target Sender) Sender

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 {
	Type MessageType
	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 (msg 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 (msg 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 (msg Message) Controller() int8

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

func (Message) Is

func (m Message) Is(t MessageType) bool

func (Message) IsAllOf

func (m Message) IsAllOf(ts ...MessageType) bool

func (Message) IsNot

func (m Message) IsNot(t MessageType) bool

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

func (m Message) IsOneOf(ts ...MessageType) bool

func (Message) Key

func (msg 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 (msg Message) Pitch() (relative int16, absolute int16)

func (Message) Pressure

func (msg Message) Pressure() int8

func (Message) Program

func (msg Message) Program() int8

func (Message) String

func (m Message) String() string

func (Message) Text

func (msg 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 (msg 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 MessageType

type MessageType uint64
const (
	ChannelMsg MessageType = 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
	Channel0
	Channel1
	Channel2
	Channel3
	Channel4
	Channel5
	Channel6
	Channel7
	Channel8
	Channel9
	Channel10
	Channel11
	Channel12
	Channel13
	Channel14
	Channel15
)
const UnknownMsg MessageType = 0

func Clear

func Clear(b, flag MessageType) MessageType

func GetMessageType

func GetMessageType(msg []byte) (mType MessageType)

func GetMetaMessage

func GetMetaMessage(b byte) MessageType

func Set

func Set(b, flag MessageType) MessageType

func Toggle

func Toggle(b, flag MessageType) MessageType

func (MessageType) Is

func (b MessageType) Is(flag MessageType) bool

func (MessageType) IsAllOf

func (b MessageType) IsAllOf(flags ...MessageType) bool

func (MessageType) IsNot

func (b MessageType) IsNot(flag MessageType) bool

func (MessageType) IsOneOf

func (b MessageType) IsOneOf(flags ...MessageType) bool

func (MessageType) String

func (m MessageType) String() string

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(m Message, deltamicrosec int64)
}

Receiver receives MIDI messages.

type Sender

type Sender interface {
	// Send sends the given MIDI message and returns any error.
	Send(Message) error
}

Sender sends MIDI messages.

type SenderTo

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

SenderTo sends MIDI messages.

Directories

Path Synopsis
drivers
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