writer

package
v1.23.7 Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: MIT Imports: 17 Imported by: 47

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

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 Copyright(w *SMF, text string) error

Copyright writes the copyright meta message

func Cuepoint

func Cuepoint(w *SMF, text string) error

Cuepoint writes the cuepoint meta message

func DeprecatedChannel

func DeprecatedChannel(w *SMF, ch uint8) error

DeprecatedChannel writes the deprecated MIDI channel meta message

func DeprecatedPort

func DeprecatedPort(w *SMF, port uint8) error

DeprecatedPort writes the deprecated MIDI port meta message

func Device

func Device(w *SMF, port string) error

Device writes the device port meta message

func EndOfTrack

func EndOfTrack(w *SMF) error

EndOfTrack signals the end of a track

func FineTuningRPN

func FineTuningRPN(w ChannelWriter, msbVal, lsbVal uint8) error

FineTuningRPN

func FinishPlanned

func FinishPlanned(w *SMF)

FinishPlanned finishes the planned midi.Messages

func Forward

func Forward(w *SMF, nbars, num, denom uint32)

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:

  1. Always put time signature changes at the beginning of a bar.
  2. 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

func Instrument(w *SMF, name string) error

Instrument writes the instrument name meta message

func Key

func Key(w *SMF, keysig meta.Key) error

Key writes the given key signature meta message. It is supposed to be used with the gomidi/midi/midimessage/meta/key package

func KeySig

func KeySig(w *SMF, key uint8, ismajor bool, num uint8, isflat bool) error

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 Lyric

func Lyric(w *SMF, text string) error

Lyric writes the lyric meta message

func MTC

func MTC(w *Writer, code uint8) error

MTC writes the MIDI Timing Code system message

func Marker

func Marker(w *SMF, text string) error

Marker writes the marker meta message

func Meter

func Meter(w *SMF, numerator, denominator uint8) error

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

func Plan(w *SMF, nbars, num, denom uint32, msg midi.Message)

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 Program

func Program(w *SMF, text string) error

Program writes the program name meta message

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

func RTActivesense(w *Writer) error

ActiveSensing writes the active sensing realtime message

func RTClock

func RTClock(w *Writer) error

Clock writes the timing clock realtime message

func RTContinue

func RTContinue(w *Writer) error

Continue writes the continue realtime message

func RTReset

func RTReset(w *Writer) error

Reset writes the reset realtime message

func RTStart

func RTStart(w *Writer) error

Start writes the start realtime message

func RTStop

func RTStop(w *Writer) error

Stop writes the stop realtime message

func RTTick

func RTTick(w *Writer) error

Tick writes the tick 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 ResetNRPN

func ResetNRPN(w ChannelWriter) error

ResetNRPN aka Null

func ResetRPN

func ResetRPN(w ChannelWriter) error

ResetRPN aka Null

func RestoreTimeline

func RestoreTimeline(wr *SMF)

func SMPTE

func SMPTE(w *SMF, hour, minute, second, frame, fractionalFrame byte) error

SMPTE writes the SMPTE offset meta message

func SPP

func SPP(w *Writer, ptr uint16) error

SPP writes the song position pointer system message

func SequenceNo

func SequenceNo(w *SMF, no uint16) error

SequenceNo writes the sequence number meta message

func SequencerData

func SequencerData(w *SMF, data []byte) error

SequencerData writes a custom sequences specific meta message

func SongSelect

func SongSelect(w *Writer, song uint8) error

SongSelect writes the song select system message

func SysEx

func SysEx(w ChannelWriter, data []byte) error

SysEx writes system exclusive data

func TempoBPM

func TempoBPM(w *SMF, bpm float64) error

Tempo writes the tempo meta message

func Text

func Text(w *SMF, text string) error

Text writes the text meta message

func TimeSig

func TimeSig(w *SMF, numerator, denominator, clocksPerClick, demiSemiQuaverPerQuarter uint8) error

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

func TrackSequenceName(w *SMF, name string) error

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 Tune

func Tune(w *Writer) error

Tune writes the tune request system message

func TuningBankSelectRPN

func TuningBankSelectRPN(w ChannelWriter, msbVal, lsbVal uint8) error

TuningBankSelectRPN

func TuningProgramSelectRPN

func TuningProgramSelectRPN(w ChannelWriter, msbVal, lsbVal uint8) error

TuningProgramSelectRPN

func Undefined

func Undefined(w *SMF, typ byte, bt []byte) error

Writes an undefined meta message

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 ChannelWriter interface {
	Channel() uint8 /* 0-15 */
	SetChannel(no uint8)
	midi.Writer
}

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 NewSMF

func NewSMF(dest io.Writer, numtracks uint16, options ...smfwriter.Option) *SMF

NewSMF returns a new SMF that writes to dest. It panics if numtracks is == 0.

func WrapSMF

func WrapSMF(wr smf.Writer) *SMF

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

func (wr *SMF) Delta() uint32

func (*SMF) Header

func (wr *SMF) Header() smf.Header

func (*SMF) Position

func (w *SMF) Position() uint64

Position returns absolute position of the last written message in ticks

func (*SMF) SetDelta

func (w *SMF) SetDelta(deltatime uint32)

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

func (wr *SMF) WriteHeader() error

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 Wrap

func Wrap(wr midi.Writer) *Writer

func (*Writer) Channel

func (w *Writer) Channel() uint8

func (*Writer) ConsolidateNotes

func (w *Writer) ConsolidateNotes(on bool)

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

func (w *Writer) SetChannel(no uint8)

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

func (w *Writer) Silence(ch int8, force bool) (err error)

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)

func (*Writer) Write

func (w *Writer) Write(msg midi.Message) error

Write writes the given midi.Message. By default, midi notes are consolidated (see ConsolidateNotes method)

Jump to

Keyboard shortcuts

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