Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::midi::SmfReader Class Reference

Checks a Standard MIDI File header in memory and finds its track chunks. More...

Detailed Description

Checks a Standard MIDI File header in memory and finds its track chunks.

Reads a Standard MIDI File already in memory: no filesystem, no allocation, nothing copied. The reader checks the header and finds the track chunks; an SmfTrack walks one track's events in order, one at a time.

What it understands (Standard MIDI Files 1.0):

  • formats 0 and 1 (format 2 is refused)
  • ticks-per-quarter-note division (SMPTE division is refused)
  • variable-length delta times
  • running status, which carries across delta times and is cancelled by SysEx and meta events
  • the meta events a player needs: Set Tempo, Time Signature, Track Name and End of Track; other meta events and SysEx are skipped
  • chunks that are not MTrk, which are skipped

Usage:

if (smf.parse(bytes, size) != sbl::midi::SmfError::None) { ... }
while (const sbl::midi::SmfEvent* ev = track.peek()) { ...; track.pop(); }
Checks a Standard MIDI File header in memory and finds its track chunks.
SmfError parse(const uint8_t *data, size_t size)
Check the header and find the tracks.
SmfTrack track(uint8_t index) const
A fresh cursor at the start of a track.
A cursor over one track chunk.
void pop()
Consume the event peek() returned.
const SmfEvent * peek()
The next event, or nullptr when the track has ended.

Definition at line 267 of file smf_reader.hpp.

#include <smf_reader.hpp>

Public Member Functions

SmfError parse (const uint8_t *data, size_t size)
 Check the header and find the tracks.
 
SmfError error () const
 The result of the last parse()
 
uint16_t format () const
 The file's format, 0 or 1.
 
uint8_t track_count () const
 Track chunks found.
 
uint16_t ticks_per_quarter () const
 The header's division: ticks per quarter note.
 
SmfTrack track (uint8_t index) const
 A fresh cursor at the start of a track.
 

Static Public Attributes

static constexpr uint8_t MAX_TRACKS = 16
 

Member Function Documentation

◆ parse()

SmfError sbl::midi::SmfReader::parse ( const uint8_t *  data,
size_t  size 
)
inline

Check the header and find the tracks.

Parameters
dataFile bytes; they must outlive the reader and its tracks
sizeFile length in bytes
Returns
SmfError::None, or why the file was refused

Definition at line 277 of file smf_reader.hpp.

References sbl::midi::BadHeader, format(), MAX_TRACKS, sbl::midi::None, sbl::midi::NotSmf, sbl::midi::SmpteDivision, sbl::midi::TooManyTracks, sbl::midi::Truncated, and sbl::midi::UnsupportedFormat.

◆ error()

SmfError sbl::midi::SmfReader::error ( ) const
inline

The result of the last parse()

Definition at line 331 of file smf_reader.hpp.

Referenced by sbl::midi::Sequencer< Outputs >::load().

◆ format()

uint16_t sbl::midi::SmfReader::format ( ) const
inline

The file's format, 0 or 1.

Definition at line 333 of file smf_reader.hpp.

Referenced by sbl::midi::Sequencer< Outputs >::load(), and parse().

◆ track_count()

uint8_t sbl::midi::SmfReader::track_count ( ) const
inline

Track chunks found.

Definition at line 335 of file smf_reader.hpp.

Referenced by sbl::midi::Sequencer< Outputs >::load().

◆ ticks_per_quarter()

uint16_t sbl::midi::SmfReader::ticks_per_quarter ( ) const
inline

The header's division: ticks per quarter note.

Definition at line 337 of file smf_reader.hpp.

Referenced by sbl::midi::Sequencer< Outputs >::load().

◆ track()

SmfTrack sbl::midi::SmfReader::track ( uint8_t  index) const
inline

A fresh cursor at the start of a track.

Parameters
indexTrack number, 0 to track_count() - 1
Returns
The cursor, or an empty one if index is out of range

Definition at line 344 of file smf_reader.hpp.

Referenced by sbl::midi::Sequencer< Outputs >::load().

Member Data Documentation

◆ MAX_TRACKS

constexpr uint8_t sbl::midi::SmfReader::MAX_TRACKS = 16
staticconstexpr

track chunks the reader records

Definition at line 269 of file smf_reader.hpp.

Referenced by parse().


The documentation for this class was generated from the following file: