Documentation ¶
Overview ¶
Package reader provides an easy abstraction for reading of cable MIDI and SMF (Standard MIDI File) data.
First create new Reader with callbacks. To read a SMF file use ReadSMFFile. To read cable MIDI, use the ListenTo method with an input port.
See the examples in the top level examples folder.
To connect with the MIDI ports of your computer use it with the adapter package for rtmidi (gitlab.com/gomidi/rtmididrv) or portmidi (gitlab.com/gomidi/portmididrv).
Index ¶
- Constants
- func Aftertouch(cb func(p *Position, channel, pressure uint8)) func(r *Reader)
- func ControlChange(cb func(p *Position, channel, controller, value uint8)) func(r *Reader)
- func Copyright(cb func(p Position, text string)) func(r *Reader)
- func Cuepoint(cb func(p Position, text string)) func(r *Reader)
- func DeprecatedChannel(cb func(p Position, channel uint8)) func(r *Reader)
- func DeprecatedPort(cb func(p Position, port uint8)) func(r *Reader)
- func Device(cb func(p Position, name string)) func(r *Reader)
- func Duration(r *Reader, deltaticks uint32) time.Duration
- func Each(cb func(*Position, midi.Message)) func(r *Reader)
- func EndOfTrack(cb func(p Position)) func(r *Reader)
- func IgnoreMIDIClock() func(*Reader)
- func Instrument(cb func(p Position, name string)) func(r *Reader)
- func Key(cb func(p Position, key uint8, ismajor bool, num_accidentals uint8, ...)) func(r *Reader)
- func Lyric(cb func(p Position, text string)) func(r *Reader)
- func MTC(cb func(frame uint8)) func(r *Reader)
- func Marker(cb func(p Position, text string)) func(r *Reader)
- func NoLogger() func(*Reader)
- func NoteOff(cb func(p *Position, channel, key, velocity uint8)) func(r *Reader)
- func NoteOn(cb func(p *Position, channel, key, velocity uint8)) func(r *Reader)
- func NrpnDecrement(cb func(p *Position, channel, typ1, typ2 uint8)) func(r *Reader)
- func NrpnIncrement(cb func(p *Position, channel, typ1, typ2 uint8)) func(r *Reader)
- func NrpnLSB(cb func(p *Position, channel uint8, typ1, typ2, msbVal uint8)) func(r *Reader)
- func NrpnMSB(cb func(p *Position, channel uint8, typ1, typ2, msbVal uint8)) func(r *Reader)
- func NrpnReset(cb func(p *Position, channel uint8)) func(r *Reader)
- func Pitchbend(cb func(p *Position, channel uint8, value int16)) func(r *Reader)
- func PolyAftertouch(cb func(p *Position, channel, key, pressure uint8)) func(r *Reader)
- func Program(cb func(p Position, text string)) func(r *Reader)
- func ProgramChange(cb func(p *Position, channel, program uint8)) func(r *Reader)
- func RTActivesense(cb func()) func(r *Reader)
- func RTClock(cb func()) func(r *Reader)
- func RTContinue(cb func()) func(r *Reader)
- func RTReset(cb func()) func(r *Reader)
- func RTStart(cb func()) func(r *Reader)
- func RTStop(cb func()) func(r *Reader)
- func RTTick(cb func()) func(r *Reader)
- func ReadAll(r *Reader) error
- func ReadAllFrom(r *Reader, src io.Reader) (err error)
- func ReadFrom(r *Reader, rd midi.Reader)
- func ReadSMF(r *Reader, src io.Reader, options ...smfreader.Option) error
- func ReadSMFFile(r *Reader, file string, options ...smfreader.Option) error
- func ReadSMFFileHeader(file string, options ...smfreader.Option) (smf.Header, error)
- func ReadSMFFrom(r *Reader, rd smf.Reader) error
- func ReadSMFHeader(in io.Reader, options ...smfreader.Option) (smf.Header, error)
- func Resolution(r *Reader) uint32
- func RpnDecrement(cb func(p *Position, channel, typ1, typ2 uint8)) func(r *Reader)
- func RpnIncrement(cb func(p *Position, channel, typ1, typ2 uint8)) func(r *Reader)
- func RpnLSB(cb func(p *Position, channel, typ1, typ2, lsbVal uint8)) func(r *Reader)
- func RpnMSB(cb func(p *Position, channel, typ1, typ2, msbVal uint8)) func(r *Reader)
- func RpnReset(cb func(p *Position, channel uint8)) func(r *Reader)
- func SMFHeader(cb func(smf.Header)) func(r *Reader)
- func SMPTE(cb func(p Position, hour, minute, second, frame, fractionalFrame byte)) func(r *Reader)
- func SPP(cb func(pos uint16)) func(r *Reader)
- func SequenceNo(cb func(p Position, number uint16)) func(r *Reader)
- func SequencerData(cb func(p Position, data []byte)) func(r *Reader)
- func SetLogger(l Logger) func(*Reader)
- func SongSelect(cb func(num uint8)) func(r *Reader)
- func SysEx(cb func(p *Position, data []byte)) func(r *Reader)
- func SysExContinue(cb func(p *Position, data []byte)) func(r *Reader)
- func SysExEnd(cb func(p *Position, data []byte)) func(r *Reader)
- func SysExEscape(cb func(p *Position, data []byte)) func(r *Reader)
- func SysExStart(cb func(p *Position, data []byte)) func(r *Reader)
- func TempoBPM(cb func(p Position, bpm float64)) func(r *Reader)
- func Text(cb func(p Position, text string)) func(r *Reader)
- func Ticks(r *Reader, d time.Duration) uint32
- func TimeAt(r *Reader, absTicks uint64) *time.Duration
- func TimeSig(cb func(p Position, num, denom uint8)) func(r *Reader)
- func TrackSequenceName(cb func(p Position, name string)) func(r *Reader)
- func Tune(cb func()) func(r *Reader)
- func Undefined(cb func(p Position, typ byte, data []byte)) func(r *Reader)
- func Unknown(cb func(p *Position, msg midi.Message)) func(r *Reader)
- type Logger
- type Position
- type Reader
- func (r *Reader) Callback(cb func(*Reader))
- func (r *Reader) Delta() uint32
- func (r *Reader) Header() smf.Header
- func (r *Reader) ListenTo(in midi.In) error
- func (r *Reader) Read() (m midi.Message, err error)
- func (r *Reader) ReadHeader() error
- func (r *Reader) TempoBPM() float64
- func (r *Reader) Track() int16
Constants ¶
const LiveResolution = smf.MetricTicks(1920)
LiveResolution is the resolution used for live over the wire reading with Reader.ReadFrom
Variables ¶
This section is empty.
Functions ¶
func Aftertouch ¶
Aftertouch is called for aftertouch messages (aka "channel pressure")
func ControlChange ¶
Each is called for every control change message If RPN or NRPN callbacks are defined, the corresponding control change messages will not be passed to each and the corrsponding RPN/NRPN callback are called.
func DeprecatedChannel ¶
Channel is called for the deprecated MIDI channel message
func DeprecatedPort ¶
Port is called for the deprecated MIDI port message
func Duration ¶
Duration returns the duration for the given delta ticks, respecting the current tempo
func EndOfTrack ¶
EndOfTrack is called for the end of a track message
func IgnoreMIDIClock ¶
func IgnoreMIDIClock() func(*Reader)
IgnoreMIDIClock lets the reader not use MIDI clock to calculate the tempo
func Instrument ¶
Instrument is called for the instrument (name) message
func Key ¶
func Key(cb func(p Position, key uint8, ismajor bool, num_accidentals uint8, accidentals_are_flat bool)) func(r *Reader)
Key is called for the key signature (change) message
func NoLogger ¶
func NoLogger() func(*Reader)
NoLogger is an option to disable the defaut logging of a Reader
func NoteOff ¶
NoteOff is called for noteoff messages (then the given velocity is passed) and for noteon messages of velocity 0 (then velocity is 0).
func NoteOn ¶
NoteOn is just called for noteon messages with a velocity > 0. Noteon messages with velocity == 0 will trigger NoteOff with a velocity of 0.
func NrpnDecrement ¶
Decrement is called, when the decrement of a NRPN arrives
func NrpnIncrement ¶
Increment is called, when the increment of a NRPN arrives
func PolyAftertouch ¶
PolyAftertouch is called for polyphonic aftertouch messages (aka "key pressure").
func ProgramChange ¶
ProgramChange is called for program change messages. Program numbers start with 0.
func RTActivesense ¶
func RTActivesense(cb func()) func(r *Reader)
Activesense is called for a active sense message
func RTContinue ¶
func RTContinue(cb func()) func(r *Reader)
Continue is called for a continue message
func ReadAllFrom ¶
ReadAllFrom reads midi messages from src until an error happens (for "live" MIDI data "over the wire"). io.EOF is the expected error that is returned when reading should stop.
ReadAllFrom does not close the src.
The messages are dispatched to the corresponding attached functions of the Reader.
They must be attached before Reader.ReadAllFrom is called and they must not be unset or replaced until Read returns. For more infomation about dealing with the MIDI messages, see Reader.
func ReadSMF ¶
ReadAllSMF reads midi messages from src (which is supposed to be the content of a standard midi file (SMF)) until an error or io.EOF happens.
ReadAllSMF does not close the src.
If the read content was a valid midi file, nil is returned.
The messages are dispatched to the corresponding attached functions of the Reader.
They must be attached before Reader.ReadSMF is called and they must not be unset or replaced until ReadSMF returns. For more infomation about dealing with the SMF midi messages, see Reader and SMFPosition.
func ReadSMFFile ¶
ReadSMFFile open, reads and closes a complete SMF file. If the read content was a valid midi file, nil is returned.
The messages are dispatched to the corresponding attached functions of the handler.
They must be attached before Reader.ReadSMF is called and they must not be unset or replaced until ReadSMF returns. For more infomation about dealing with the SMF midi messages, see Reader and SMFPosition.
func ReadSMFFileHeader ¶
ReadSMFFileHeader reads just the header of a SMF file
func ReadSMFHeader ¶ added in v1.20.2
ReadSMFHeader reads just the header of a SMF
func Resolution ¶
Resolution returns the ticks of a quarternote If it can't be determined, 0 is returned
func RpnDecrement ¶
Decrement is called, when the decrement of a RPN arrives
func RpnIncrement ¶
Increment is called, when the increment of a RPN arrives
func SequenceNo ¶
SequenceNo is called for the sequence number message
func SequencerData ¶
SequencerData is called for the sequencer specific message
func SongSelect ¶
SongSelect is called for a song select message
func SysExContinue ¶
Continue is called for a continuing system exclusive message
func SysExEscape ¶
Escape is called for an escaping system exclusive message
func SysExStart ¶
Start is called for a starting system exclusive message
func Ticks ¶
Ticks returns the ticks that correspond to a duration while respecting the current tempo If it can't be determined, 0 is returned
func TimeAt ¶
TimeAt returns the time.Duration at the given absolute position counted from the beginning of the file, respecting all the tempo changes in between. If the time format is not of type smf.MetricTicks, nil is returned.
func TrackSequenceName ¶
TrackSequenceName is called for the sequence / track name message If in a format 0 track, or the first track in a format 1 file, the name of the sequence. Otherwise, the name of the track.
Types ¶
type Logger ¶
type Logger interface {
Printf(format string, vals ...interface{})
}
Logger is the inferface used by Reader for logging incoming messages.
type Position ¶
type Position struct { // Track is the number of the track, starting with 0 Track int16 // DeltaTicks is number of ticks that passed since the previous message in the same track DeltaTicks uint32 // AbsoluteTicks is the number of ticks that passed since the beginning of the track AbsoluteTicks uint64 }
Position is the position of the event inside a standard midi file (SMF) or since start listening on a connection.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader allows the reading of either "over the wire" MIDI data (via Read) or SMF MIDI data (via ReadSMF or ReadSMFFile).
Before any of the Read* methods are called, callbacks for the MIDI messages of interest need to be attached to the Reader. These callbacks are then invoked when the corresponding MIDI message arrives. They must not be changed while any of the Read* methods is running.
It is possible to share the same Reader for reading of the wire MIDI ("live") and SMF Midi data as long as not more than one Read* method is running at a point in time. However, only channel messages and system exclusive message may be used in both cases. To enable this, the corresponding callbacks receive a pointer to the Position of the MIDI message. This pointer is always nil for "live" MIDI data and never nil when reading from a SMF.
The SMF header callback and the meta message callbacks are only called, when reading data from an SMF. Therefore the Position is passed directly and can't be nil.
System common and realtime message callbacks will only be called when reading "live" MIDI, so they get no Position.
func (*Reader) ListenTo ¶
ListenTo connects the reader to the given MIDI in connection and listens for incoming messages.