Documentation ¶
Overview ¶
Package smf provides constants and interfaces for reading and writing of Standard MIDI Files (SMF).
The readers/writers can be found here:
gitlab.com/gomidi/midi/smf/smfreader (read MIDI messages from SMF) gitlab.com/gomidi/midi/smf/smfwriter (writes MIDI messages to SMF)
The MIDI messages that can be read/written from/to a SMF file can be found here:
gitlab.com/gomidi/midi/midimessage/channel (Channel Messages) gitlab.com/gomidi/midi/midimessage/cc (Control Change Messages) gitlab.com/gomidi/midi/midimessage/meta (Meta Messages) gitlab.com/gomidi/midi/midimessage/sysex (System Exclusive Messages)
Index ¶
- Constants
- Variables
- type Chunk
- type Format
- type Header
- type MetricTicks
- func (q MetricTicks) Duration(tempoBPM uint32, deltaTicks uint32) time.Duration
- func (q MetricTicks) FractionalDuration(fractionalBPM float64, deltaTicks uint32) time.Duration
- func (q MetricTicks) FractionalTicks(fractionalBPM float64, d time.Duration) (ticks uint32)
- func (q MetricTicks) In64ths(deltaTicks uint32) uint32
- func (q MetricTicks) Resolution() uint16
- func (q MetricTicks) String() string
- func (q MetricTicks) Ticks(tempoBPM uint32, d time.Duration) (ticks uint32)
- func (q MetricTicks) Ticks1024th() uint32
- func (q MetricTicks) Ticks128th() uint32
- func (q MetricTicks) Ticks16th() uint32
- func (q MetricTicks) Ticks256th() uint32
- func (q MetricTicks) Ticks32th() uint32
- func (q MetricTicks) Ticks4th() uint32
- func (q MetricTicks) Ticks512th() uint32
- func (q MetricTicks) Ticks64th() uint32
- func (q MetricTicks) Ticks8th() uint32
- type Reader
- type TimeCode
- type TimeFormat
- type Writer
Constants ¶
const ( // SMF0 represents the singletrack SMF format (0). SMF0 = format(0) // SMF1 represents the multitrack SMF format (1). SMF1 = format(1) // SMF2 represents the sequential track SMF format (2). SMF2 = format(2) )
Variables ¶
var ErrFinished = errors.New("SMF action finished successfully")
ErrFinished indicates that the read or write operation has been finished successfully
Functions ¶
This section is empty.
Types ¶
type Chunk ¶
type Chunk struct {
// contains filtered or unexported fields
}
Chunk is a chunk of a SMF file.
func (*Chunk) ReadHeader ¶
ReadHeader reads the header from the given reader and returns the length of the following body. For errors, length of 0 is returned.
type Format ¶
type Format interface { // String returns the string representation of the SMF format. String() string // Type returns the type of the SMF file: 0 for SMF0, 1 for SMF1 and 2 for SMF2 Type() uint16 // contains filtered or unexported methods }
Format is the common interface of all SMF file formats
type Header ¶
type Header struct { // Format is the SMF file format: SMF0, SMF1 or SMF2. Format // NumTracks is the number of tracks (always > 0). NumTracks uint16 // TimeFormat is the time format (either MetricTicks or TimeCode). TimeFormat }
Header represents the header of a SMF file.
type MetricTicks ¶
type MetricTicks uint16
MetricTicks represents the "ticks per quarter note" (metric) time format. It defaults to 960 (i.e. 0 is treated as if it where 960 ticks per quarter note).
func (MetricTicks) Duration ¶
func (q MetricTicks) Duration(tempoBPM uint32, deltaTicks uint32) time.Duration
Duration returns the time.Duration for a number of ticks at a certain tempo (in BPM).
func (MetricTicks) FractionalDuration ¶ added in v1.7.0
func (q MetricTicks) FractionalDuration(fractionalBPM float64, deltaTicks uint32) time.Duration
FractionalDuration returns the time.Duration for a number of ticks at a certain tempo (in fractional BPM)
func (MetricTicks) FractionalTicks ¶ added in v1.7.0
func (q MetricTicks) FractionalTicks(fractionalBPM float64, d time.Duration) (ticks uint32)
FractionalTicks returns the ticks for a given time.Duration at a certain tempo (in fractional BPM)
func (MetricTicks) In64ths ¶ added in v1.7.0
func (q MetricTicks) In64ths(deltaTicks uint32) uint32
In64ths returns the deltaTicks in 64th notes. To get 32ths, divide result by 2. To get 16ths, divide result by 4. To get 8ths, divide result by 8. To get 4ths, divide result by 16.
func (MetricTicks) Resolution ¶ added in v1.7.7
func (q MetricTicks) Resolution() uint16
Resolution returns the number of the metric ticks (ticks for a quarter note, defaults to 960)
func (MetricTicks) String ¶
func (q MetricTicks) String() string
String returns the string representation of the quarter note resolution
func (MetricTicks) Ticks ¶
func (q MetricTicks) Ticks(tempoBPM uint32, d time.Duration) (ticks uint32)
Ticks returns the ticks for a given time.Duration at a certain tempo (in BPM)
func (MetricTicks) Ticks1024th ¶
func (q MetricTicks) Ticks1024th() uint32
Ticks1024th returns the ticks for a 1024th note
func (MetricTicks) Ticks128th ¶
func (q MetricTicks) Ticks128th() uint32
Ticks128th returns the ticks for a 128th note
func (MetricTicks) Ticks16th ¶
func (q MetricTicks) Ticks16th() uint32
Ticks16th returns the ticks for a 16th note
func (MetricTicks) Ticks256th ¶
func (q MetricTicks) Ticks256th() uint32
Ticks256th returns the ticks for a 256th note
func (MetricTicks) Ticks32th ¶
func (q MetricTicks) Ticks32th() uint32
Ticks32th returns the ticks for a 32th note
func (MetricTicks) Ticks4th ¶
func (q MetricTicks) Ticks4th() uint32
Ticks4th returns the ticks for a quarter note
func (MetricTicks) Ticks512th ¶
func (q MetricTicks) Ticks512th() uint32
Ticks512th returns the ticks for a 512th note
func (MetricTicks) Ticks64th ¶
func (q MetricTicks) Ticks64th() uint32
Ticks64th returns the ticks for a 64th note
func (MetricTicks) Ticks8th ¶
func (q MetricTicks) Ticks8th() uint32
Ticks8th returns the ticks for a quaver note
type Reader ¶
type Reader interface { // ReadHeader reads the header of the SMF file. If Header is called before ReadHeader, it will panic. // ReadHeader is also implicitly called with the first call of Read() (if it has not been run before). ReadHeader() error // Read reads a MIDI message from a SMF file. // any error will be tracked and stops reading and prevents any other attempt to read. // At the end, smf.ErrFinished will be returned. Read() (midi.Message, error) // Header returns the header of SMF file. // If the header is not yet read, it will be read before. Header() Header // Delta returns the time distance between the last read midi message and the message before in ticks. // The meaning of a tick depends on the time format that is set in the header of the SMF file. // Use Header.TimeFormat.(MetricTicks).In64ths() to convert the ticks to 64ths notes. From there you may calculate // 16ths,quaver,4ths etc by dividing by 4,8,16 etc. Delta() (ticks uint32) // Track returns the number of the track of the last read midi message (starting with 0). // It returns -1 if no message has been read yet. Track() int16 }
Reader reads midi messages from a standard midi file (SMF). Reader is also a midi.Reader.
type TimeCode ¶
TimeCode is the SMPTE time format. It can be comfortable created with the SMPTE* functions.
func SMPTE30DropFrame ¶
SMPTE30DropFrame returns a SMPTE30 drop frame TimeCode with the given subframes.
type TimeFormat ¶
type TimeFormat interface { String() string // contains filtered or unexported methods }
TimeFormat is the common interface of all SMF time formats
type Writer ¶
type Writer interface { // Header returns the header. Header() Header // WriteHeader writes the midi header. // If WriteHeader was not called before the first run of Write, // it will implicitly be called when calling Write. WriteHeader() error // Write writes a midi message to the SMF file. // // Due to the nature of SMF files there is some maybe surprising behavior. // - If the header has not been written yet, it will be written before writing the first message. // - The first message will be written to track 0 which will be implicitly created. // - All messages of a track will be buffered inside the track and only be written if an EndOfTrack // message is written. // - The number of tracks that are written will never execeed the NumTracks that have been defined when creating the writer. // If the last track has been written, io.EOF will be returned. (Also for any further attempt to write). // - It is the responsibility of the caller to make sure the provided NumTracks (which defaults to 1) is not // larger as the number of tracks in the file. // Any error stops the writing, is tracked and prohibits further writing. // At the end smf.ErrFinished will be returned Write(midi.Message) error // SetDelta sets a time distance between the last written and the following message in ticks. // The meaning of a tick depends on the time format that is set in the header of the SMF file. // Use Header.TimeFormat.(MetricTicks).Ticks*th() to get the ticks of quarter notes etc. SetDelta(ticks uint32) // Position returns the absolut position of the last written message in ticks Position() uint64 }
Writer writes midi messages to a standard midi file (SMF). Writer is also a midi.Writer.
Directories ¶
Path | Synopsis |
---|---|
Package smfreader provides a reader of Standard MIDI Files (SMF).
|
Package smfreader provides a reader of Standard MIDI Files (SMF). |
Package smfwriter provides a writer of Standard MIDI Files (SMF).
|
Package smfwriter provides a writer of Standard MIDI Files (SMF). |