Documentation ¶
Overview ¶
Package writer provides an easy abstraction for writing of cable MIDI and SMF (Standard MIDI File) data.
Create a new Writer to write to a MIDI cable (an io.Writer). Use WriteSMF to write a complete SMF file.
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 ¶
- func Aftertouch(w ChannelWriter, pressure uint8) error
- func BackupTimeline(wr *SMF)
- func CcOff(w ChannelWriter, controller uint8) error
- func CcOn(w ChannelWriter, controller uint8) error
- func Channel(w ChannelWriter) channel.Channel
- func CoarseTuningRPN(w ChannelWriter, msbVal, lsbVal uint8) error
- func ControlChange(w ChannelWriter, controller, value uint8) error
- func Copyright(w *SMF, text string) error
- func Cuepoint(w *SMF, text string) error
- func DeprecatedChannel(w *SMF, ch uint8) error
- func DeprecatedPort(w *SMF, port uint8) error
- func Device(w *SMF, port string) error
- func EndOfTrack(w *SMF) error
- func FineTuningRPN(w ChannelWriter, msbVal, lsbVal uint8) error
- func FinishPlanned(w *SMF)
- func Forward(w *SMF, nbars, num, denom uint32)
- func GMReset(w ChannelWriter, prog uint8) error
- func Instrument(w *SMF, name string) error
- func Key(w *SMF, keysig meta.Key) error
- func KeySig(w *SMF, key uint8, ismajor bool, num uint8, isflat bool) error
- func Lyric(w *SMF, text string) error
- func MTC(w *Writer, code uint8) error
- func Marker(w *SMF, text string) error
- func Meter(w *SMF, numerator, denominator uint8) error
- func MsbLsb(w ChannelWriter, msbControl, lsbControl uint8, value uint16) error
- func NRPN(w ChannelWriter, val99, val98, msbVal, lsbVal uint8) error
- func NRPNDecrement(w ChannelWriter, val99, val98 uint8) error
- func NRPNIncrement(w ChannelWriter, val99, val98 uint8) error
- func NoteOff(w ChannelWriter, key uint8) error
- func NoteOffVelocity(w ChannelWriter, key, velocity uint8) error
- func NoteOn(w ChannelWriter, key, velocity uint8) error
- func PitchBendSensitivityRPN(w ChannelWriter, msbVal, lsbVal uint8) error
- func Pitchbend(w ChannelWriter, value int16) error
- func Plan(w *SMF, nbars, num, denom uint32, msg midi.Message)
- func PolyAftertouch(w ChannelWriter, key, pressure uint8) error
- func Program(w *SMF, text string) error
- func ProgramChange(w ChannelWriter, program uint8) error
- func RPN(w ChannelWriter, val101, val100, msbVal, lsbVal uint8) error
- func RPNDecrement(w ChannelWriter, val101, val100 uint8) error
- func RPNIncrement(w ChannelWriter, val101, val100 uint8) error
- func RTActivesense(w *Writer) error
- func RTClock(w *Writer) error
- func RTContinue(w *Writer) error
- func RTReset(w *Writer) error
- func RTStart(w *Writer) error
- func RTStop(w *Writer) error
- func RTTick(w *Writer) error
- func Reset(w ChannelWriter, bank uint8, prog uint8) error
- func ResetNRPN(w ChannelWriter) error
- func ResetRPN(w ChannelWriter) error
- func RestoreTimeline(wr *SMF)
- func SMPTE(w *SMF, hour, minute, second, frame, fractionalFrame byte) error
- func SPP(w *Writer, ptr uint16) error
- func SequenceNo(w *SMF, no uint16) error
- func SequencerData(w *SMF, data []byte) error
- func SongSelect(w *Writer, song uint8) error
- func SysEx(w ChannelWriter, data []byte) error
- func TempoBPM(w *SMF, bpm float64) error
- func Text(w *SMF, text string) error
- func TimeSig(w *SMF, numerator, denominator, clocksPerClick, demiSemiQuaverPerQuarter uint8) error
- func TrackSequenceName(w *SMF, name string) error
- func Tune(w *Writer) error
- func TuningBankSelectRPN(w ChannelWriter, msbVal, lsbVal uint8) error
- func TuningProgramSelectRPN(w ChannelWriter, msbVal, lsbVal uint8) error
- func Undefined(w *SMF, typ byte, bt []byte) error
- func WriteMessages(w ChannelWriter, msgs []midi.Message) error
- func WriteSMF(file string, numtracks uint16, writer func(*SMF) error, ...) error
- type ChannelWriter
- type SMF
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Aftertouch ¶
func Aftertouch(w ChannelWriter, pressure uint8) error
Aftertouch writes a channel pressure message for the current channel
func BackupTimeline ¶
func BackupTimeline(wr *SMF)
func CcOff ¶
func CcOff(w ChannelWriter, controller uint8) error
CcOff writes a control change message with a value of 0 (=off) for the current channel
func CcOn ¶
func CcOn(w ChannelWriter, controller uint8) error
CcOn writes a control change message with a value of 127 (=on) for the current channel
func Channel ¶
func Channel(w ChannelWriter) channel.Channel
func CoarseTuningRPN ¶
func CoarseTuningRPN(w ChannelWriter, msbVal, lsbVal uint8) error
CoarseTuningRPN
func ControlChange ¶
func ControlChange(w ChannelWriter, controller, value uint8) error
ControlChange writes a control change message for the current channel For more comfortable use, used it in conjunction with the gomidi/cc package
func DeprecatedChannel ¶
DeprecatedChannel writes the deprecated MIDI channel meta message
func DeprecatedPort ¶
DeprecatedPort writes the deprecated MIDI port meta message
func Forward ¶
Forward sets the cursor based on the given number of bars and ratio of whole notes. The cursor is the current position where the next event will be inserted. In the background it sets the delta to the next event. The cursor can only move forward.
Examples:
To move the cursor to the 2nd next bar (respecting time signature changes), use
Forward(2,0,0)
To move the cursor by 23 8ths (independent from time signatures), use
Forward(0,23,8)
To move the cursor to the 3rd 4th of the next bar (respecting time signature changes), use
Forward(1,3,4)
Important notes:
- Always put time signature changes at the beginning of a bar.
- Never forward more than once without setting a event in between.
func GMReset ¶
func GMReset(w ChannelWriter, prog uint8) error
GMReset resets the channel to some GM based standards (see Reset) and sets the given GM program.
func Instrument ¶
Instrument writes the instrument name meta message
func Key ¶
Key writes the given key signature meta message. It is supposed to be used with the gomidi/midi/midimessage/meta/key package
func KeySig ¶
KeySig writes the key signature meta message. A more comfortable way is to use the Key method in conjunction with the gomidi/midi/midimessage/meta/key package
func Meter ¶
Meter writes the time signature meta message in a more comfortable way. Numerator and Denominator are decimals.
func MsbLsb ¶
func MsbLsb(w ChannelWriter, msbControl, lsbControl uint8, value uint16) error
MsbLsb writes a Msb control change message, followed by a Lsb control change message for the current channel For more comfortable use, used it in conjunction with the gomidi/cc package
func NRPN ¶
func NRPN(w ChannelWriter, val99, val98, msbVal, lsbVal uint8) error
NRPN message consisting of a val99 and val98 to identify the RPN and a msb and lsb for the value
func NRPNDecrement ¶
func NRPNDecrement(w ChannelWriter, val99, val98 uint8) error
func NRPNIncrement ¶
func NRPNIncrement(w ChannelWriter, val99, val98 uint8) error
func NoteOff ¶
func NoteOff(w ChannelWriter, key uint8) error
NoteOff writes a note off message for the current channel By default, midi notes are consolidated (see ConsolidateNotes method)
func NoteOffVelocity ¶
func NoteOffVelocity(w ChannelWriter, key, velocity uint8) error
NoteOffVelocity writes a note off message for the current channel with a velocity. By default, midi notes are consolidated (see ConsolidateNotes method)
func NoteOn ¶
func NoteOn(w ChannelWriter, key, velocity uint8) error
NoteOn writes a note on message for the current channel By default, midi notes are consolidated (see ConsolidateNotes method)
func PitchBendSensitivityRPN ¶
func PitchBendSensitivityRPN(w ChannelWriter, msbVal, lsbVal uint8) error
PitchBendSensitivityRPN sets the pitch bend range via RPN
func Pitchbend ¶
func Pitchbend(w ChannelWriter, value int16) error
Pitchbend writes a pitch bend message for the current channel For reset value, use 0, for lowest -8191 and highest 8191 Or use the pitch constants of midimessage/channel
func Plan ¶
Plan plans the given midi.Message at the given position. That leads to the message being written when the Forward method is crossing the corresponding position
func PolyAftertouch ¶
func PolyAftertouch(w ChannelWriter, key, pressure uint8) error
PolyAftertouch writes a key pressure message for the current channel
func ProgramChange ¶
func ProgramChange(w ChannelWriter, program uint8) error
ProgramChange writes a program change message for the current channel Program numbers start with 0 for program 1.
func RPN ¶
func RPN(w ChannelWriter, val101, val100, msbVal, lsbVal uint8) error
RPN message consisting of a val101 and val100 to identify the RPN and a msb and lsb for the value
func RPNDecrement ¶
func RPNDecrement(w ChannelWriter, val101, val100 uint8) error
func RPNIncrement ¶
func RPNIncrement(w ChannelWriter, val101, val100 uint8) error
func RTActivesense ¶
ActiveSensing writes the active sensing realtime message
func Reset ¶
func Reset(w ChannelWriter, bank uint8, prog uint8) error
Reset "resets" channel to some established defaults
bank select -> bank program change -> prog cc all controllers off cc volume -> 100 cc expression -> 127 cc hold pedal -> off cc pan position -> 64 cc RPN pitch bend sensitivity -> 2 (semitones)
func RestoreTimeline ¶
func RestoreTimeline(wr *SMF)
func SequenceNo ¶
SequenceNo writes the sequence number meta message
func SequencerData ¶
SequencerData writes a custom sequences specific meta message
func SongSelect ¶
SongSelect writes the song select system message
func TimeSig ¶
TimeSig writes the time signature meta message. Numerator and Denominator are decimal. If you don't want to deal with clocks per click and demisemiquaverperquarter, user the Meter method instead.
func TrackSequenceName ¶
TrackSequenceName writes the track / sequence name meta 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.
func TuningBankSelectRPN ¶
func TuningBankSelectRPN(w ChannelWriter, msbVal, lsbVal uint8) error
TuningBankSelectRPN
func TuningProgramSelectRPN ¶
func TuningProgramSelectRPN(w ChannelWriter, msbVal, lsbVal uint8) error
TuningProgramSelectRPN
func WriteMessages ¶
func WriteMessages(w ChannelWriter, msgs []midi.Message) error
func WriteSMF ¶
func WriteSMF(file string, numtracks uint16, writer func(*SMF) error, options ...smfwriter.Option) error
WriteSMF creates a new SMF file and allows writer to write to it. The file is guaranteed to be closed when returning. The last track is closed automatically, if needed. It panics if numtracks is == 0.
Types ¶
type ChannelWriter ¶
type SMF ¶
type SMF struct { *Writer //dest io.Writer smf.MetricTicks // contains filtered or unexported fields }
SMFWriter writes SMF MIDI data. Its methods must not be called concurrently
func WrapSMF ¶
WrapSMF returns a new SMF for a given smf.Writer The TimeFormat of the smf.Writer must be metric or this function will panic.
func (*SMF) SetDelta ¶
SetDelta sets the delta ticks to the next message It should mostly not be needed, use Forward instead to advance in musical time.
func (*SMF) WriteHeader ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer writes live MIDI data. Its methods must not be called concurrently
func New ¶
func New(dest io.Writer, options ...midiwriter.Option) *Writer
New creates and new Writer for writing of "live" MIDI data ("over the wire") By default it makes no use of the running status.
func (*Writer) ConsolidateNotes ¶
ConsolidateNotes enables/disables the midi note consolidation (default: enabled) When enabled, midi note on/off messages are consolidated, that means the on/off state of every possible note on every channel is tracked and note on messages are only written, if the corresponding note is off and vice versa. Note on messages with a velocity of 0 behave the same way as note offs. The tracking of the notes is not cross SMF tracks, i.e. a meta.EndOfTrack message will reset the tracking. The consolidation should prevent "hanging" notes in most cases. If on is true, the note will be started tracking again (fresh state), assuming no note is currently running.
func (*Writer) SetChannel ¶
SetChannel sets the channel for the following midi messages Channel numbers are counted from 0 to 15 (MIDI channel 1 to 16). The initial channel number is 0.
func (*Writer) Silence ¶
Silence sends a note off message for every running note on the given channel. If the channel is -1, every channel is affected. If note consolidation is switched off, notes aren't tracked and therefor every possible note will get a note off. This could also be enforced by setting force to true. If force is true, additionally the cc messages AllNotesOff (123) and AllSoundOff (120) are send. If channel is > 15, the method panics. The error or not error of the last write is returned. (i.e. it does not return on the first error, but tries everything instead to make it silent)