Sound Byte Libs 0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::midi::Sequencer< Outputs > Class Template Reference

Detailed Description

template<uint8_t Outputs = 4>
class sbl::midi::Sequencer< Outputs >

Definition at line 56 of file sequencer.hpp.

#include <sequencer.hpp>

Public Types

using Sink = void(*)(void *context, uint8_t output, const MidiEvent &event)
 

Public Member Functions

 Sequencer (Sink sink, void *context)
 
void set_sample_rate (uint32_t hz)
 Natural units, before start(): the rate advance() counts in.
 
bool load (const SmfReader &smf)
 Take a parsed file and apply the default map. Stops playback.
 
void set_track_output (uint8_t track, uint8_t output)
 Format 1: which output a track plays into (NO_OUTPUT for none).
 
void set_channel_output (uint8_t channel, uint8_t output)
 Format 0: which output a channel plays into (NO_OUTPUT for none).
 
void set_output_channel (uint8_t output, uint8_t channel)
 Send every event on an output on this channel (KEEP_CHANNEL to leave them).
 
void set_loop (bool on)
 
bool looping () const
 
void start ()
 Start: play from the top with every output reset.
 
void stop ()
 Stop: hold the playhead, silence the outputs.
 
void resume ()
 Continue: play on from the playhead. Nothing to continue after the end.
 
bool playing () const
 
bool finished () const
 
bool loaded () const
 
uint64_t position_us () const
 Where the playhead is in the song, in microseconds from the top.
 
void advance (uint32_t elapsed_samples)
 Let elapsed_samples pass: emit every event that falls due.
 

Static Public Attributes

static constexpr uint8_t OUTPUTS = Outputs
 
static constexpr uint8_t MAX_TRACKS = SmfReader::MAX_TRACKS
 
static constexpr uint8_t CHANNELS = 16
 
static constexpr uint8_t NO_OUTPUT = 0xFF
 
static constexpr uint8_t KEEP_CHANNEL = 0xFF
 
static constexpr uint8_t MAX_SNAPSHOT = 64
 distinct (output, channel, controller) first values
 
static constexpr uint32_t DEFAULT_TEMPO_US = 500000
 120 bpm: the SMF default
 
static constexpr uint32_t DEFAULT_SAMPLE_RATE = 48000
 
static constexpr uint8_t ALL_NOTES_OFF = 123
 

Member Typedef Documentation

◆ Sink

template<uint8_t Outputs = 4>
using sbl::midi::Sequencer< Outputs >::Sink = void (*)(void* context, uint8_t output, const MidiEvent& event)

Definition at line 70 of file sequencer.hpp.

Constructor & Destructor Documentation

◆ Sequencer()

template<uint8_t Outputs = 4>
sbl::midi::Sequencer< Outputs >::Sequencer ( Sink  sink,
void *  context 
)
inline

Definition at line 72 of file sequencer.hpp.

References sbl::midi::Sequencer< Outputs >::KEEP_CHANNEL.

Member Function Documentation

◆ set_sample_rate()

template<uint8_t Outputs = 4>
void sbl::midi::Sequencer< Outputs >::set_sample_rate ( uint32_t  hz)
inline

Natural units, before start(): the rate advance() counts in.

Definition at line 77 of file sequencer.hpp.

References sbl::midi::Sequencer< Outputs >::DEFAULT_SAMPLE_RATE.

◆ load()

◆ set_track_output()

template<uint8_t Outputs = 4>
void sbl::midi::Sequencer< Outputs >::set_track_output ( uint8_t  track,
uint8_t  output 
)
inline

Format 1: which output a track plays into (NO_OUTPUT for none).

Definition at line 99 of file sequencer.hpp.

References sbl::midi::Sequencer< Outputs >::MAX_TRACKS, and sbl::midi::Sequencer< Outputs >::NO_OUTPUT.

◆ set_channel_output()

template<uint8_t Outputs = 4>
void sbl::midi::Sequencer< Outputs >::set_channel_output ( uint8_t  channel,
uint8_t  output 
)
inline

Format 0: which output a channel plays into (NO_OUTPUT for none).

Definition at line 106 of file sequencer.hpp.

References sbl::midi::Sequencer< Outputs >::CHANNELS, and sbl::midi::Sequencer< Outputs >::NO_OUTPUT.

◆ set_output_channel()

template<uint8_t Outputs = 4>
void sbl::midi::Sequencer< Outputs >::set_output_channel ( uint8_t  output,
uint8_t  channel 
)
inline

Send every event on an output on this channel (KEEP_CHANNEL to leave them).

Definition at line 113 of file sequencer.hpp.

References sbl::midi::Sequencer< Outputs >::CHANNELS, and sbl::midi::Sequencer< Outputs >::KEEP_CHANNEL.

◆ set_loop()

template<uint8_t Outputs = 4>
void sbl::midi::Sequencer< Outputs >::set_loop ( bool  on)
inline

Definition at line 119 of file sequencer.hpp.

◆ looping()

template<uint8_t Outputs = 4>
bool sbl::midi::Sequencer< Outputs >::looping ( ) const
inline

Definition at line 120 of file sequencer.hpp.

◆ start()

template<uint8_t Outputs = 4>
void sbl::midi::Sequencer< Outputs >::start ( )
inline

Start: play from the top with every output reset.

Definition at line 125 of file sequencer.hpp.

◆ stop()

template<uint8_t Outputs = 4>
void sbl::midi::Sequencer< Outputs >::stop ( )
inline

Stop: hold the playhead, silence the outputs.

Definition at line 139 of file sequencer.hpp.

◆ resume()

template<uint8_t Outputs = 4>
void sbl::midi::Sequencer< Outputs >::resume ( )
inline

Continue: play on from the playhead. Nothing to continue after the end.

Definition at line 146 of file sequencer.hpp.

◆ playing()

template<uint8_t Outputs = 4>
bool sbl::midi::Sequencer< Outputs >::playing ( ) const
inline

Definition at line 150 of file sequencer.hpp.

◆ finished()

template<uint8_t Outputs = 4>
bool sbl::midi::Sequencer< Outputs >::finished ( ) const
inline

Definition at line 151 of file sequencer.hpp.

◆ loaded()

template<uint8_t Outputs = 4>
bool sbl::midi::Sequencer< Outputs >::loaded ( ) const
inline

Definition at line 152 of file sequencer.hpp.

◆ position_us()

template<uint8_t Outputs = 4>
uint64_t sbl::midi::Sequencer< Outputs >::position_us ( ) const
inline

Where the playhead is in the song, in microseconds from the top.

Definition at line 155 of file sequencer.hpp.

◆ advance()

template<uint8_t Outputs = 4>
void sbl::midi::Sequencer< Outputs >::advance ( uint32_t  elapsed_samples)
inline

Let elapsed_samples pass: emit every event that falls due.

Time counts while stopped too, so a resume picks up at the playhead without replaying the pause.

Definition at line 163 of file sequencer.hpp.

References sbl::midi::SmfEvent::Channel, sbl::midi::SmfEvent::kind, sbl::midi::SmfEvent::midi, sbl::midi::SmfTrack::peek(), sbl::midi::SmfTrack::pop(), sbl::midi::SmfEvent::Tempo, sbl::midi::SmfEvent::tempo_us, and sbl::midi::SmfEvent::tick.

Member Data Documentation

◆ OUTPUTS

template<uint8_t Outputs = 4>
constexpr uint8_t sbl::midi::Sequencer< Outputs >::OUTPUTS = Outputs
staticconstexpr

Definition at line 60 of file sequencer.hpp.

◆ MAX_TRACKS

template<uint8_t Outputs = 4>
constexpr uint8_t sbl::midi::Sequencer< Outputs >::MAX_TRACKS = SmfReader::MAX_TRACKS
staticconstexpr

◆ CHANNELS

template<uint8_t Outputs = 4>
constexpr uint8_t sbl::midi::Sequencer< Outputs >::CHANNELS = 16
staticconstexpr

◆ NO_OUTPUT

template<uint8_t Outputs = 4>
constexpr uint8_t sbl::midi::Sequencer< Outputs >::NO_OUTPUT = 0xFF
staticconstexpr

◆ KEEP_CHANNEL

template<uint8_t Outputs = 4>
constexpr uint8_t sbl::midi::Sequencer< Outputs >::KEEP_CHANNEL = 0xFF
staticconstexpr

◆ MAX_SNAPSHOT

template<uint8_t Outputs = 4>
constexpr uint8_t sbl::midi::Sequencer< Outputs >::MAX_SNAPSHOT = 64
staticconstexpr

distinct (output, channel, controller) first values

Definition at line 65 of file sequencer.hpp.

◆ DEFAULT_TEMPO_US

template<uint8_t Outputs = 4>
constexpr uint32_t sbl::midi::Sequencer< Outputs >::DEFAULT_TEMPO_US = 500000
staticconstexpr

120 bpm: the SMF default

Definition at line 66 of file sequencer.hpp.

◆ DEFAULT_SAMPLE_RATE

template<uint8_t Outputs = 4>
constexpr uint32_t sbl::midi::Sequencer< Outputs >::DEFAULT_SAMPLE_RATE = 48000
staticconstexpr

Definition at line 67 of file sequencer.hpp.

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

◆ ALL_NOTES_OFF

template<uint8_t Outputs = 4>
constexpr uint8_t sbl::midi::Sequencer< Outputs >::ALL_NOTES_OFF = 123
staticconstexpr

Definition at line 68 of file sequencer.hpp.


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