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 Namespace Reference

MIDI parser, encoder, SMF and sequencer. More...

Detailed Description

MIDI parser, encoder, SMF and sequencer.

Namespaces

namespace  cc
 

Classes

struct  MidiEvent
 
class  Parser
 MIDI byte stream parser - state machine with running status. More...
 
class  Sequencer
 Plays a Standard MIDI File to a set of outputs. More...
 
struct  SmfEvent
 
class  SmfReader
 Checks a Standard MIDI File header in memory and finds its track chunks. More...
 
class  SmfTrack
 A cursor over one track chunk. More...
 

Typedefs

using MidiCallback = void(*)(const MidiEvent &event)
 

Enumerations

enum class  SmfError : uint8_t {
  None , NotSmf , BadHeader , UnsupportedFormat ,
  SmpteDivision , TooManyTracks , Truncated
}
 Result of SmfReader::parse() More...
 
enum class  MessageType : uint8_t {
  NoteOff = 0x80 , NoteOn = 0x90 , PolyPressure = 0xA0 , ControlChange = 0xB0 ,
  ProgramChange = 0xC0 , ChannelPressure = 0xD0 , PitchBend = 0xE0 , Clock = 0xF8 ,
  Start = 0xFA , Continue = 0xFB , Stop = 0xFC , ActiveSensing = 0xFE ,
  SystemReset = 0xFF , SysEx = 0xF0 , SysExEnd = 0xF7 , TimeCode = 0xF1 ,
  SongPosition = 0xF2 , SongSelect = 0xF3 , TuneRequest = 0xF6 , None = 0x00
}
 

Functions

template<typename Source , typename Thru >
uint32_t drain (Parser &parser, Thru &&thru)
 Push everything Source has waiting into parser, copying it to a thru.
 
template<typename Source >
uint32_t drain (Parser &parser)
 Push everything Source has waiting into parser
 
constexpr uint8_t to_7bit (float value)
 
uint8_t expected_data_bytes (uint8_t status)
 

Variables

constexpr uint32_t DRAIN_CHUNK = 64
 
constexpr uint8_t CC_SWITCH_ON = 64
 
constexpr uint8_t DATA_MAX = 127
 

Typedef Documentation

◆ MidiCallback

using sbl::midi::MidiCallback = typedef void (*)(const MidiEvent& event)

Callback type for parsed MIDI events

Definition at line 171 of file types.hpp.

Enumeration Type Documentation

◆ SmfError

enum class sbl::midi::SmfError : uint8_t
strong

Result of SmfReader::parse()

Enumerator
None 

the header and every track were found

NotSmf 

no MThd header chunk at the start

BadHeader 

header too short, zero division, or format 0 with more than one track

UnsupportedFormat 

format 2

SmpteDivision 

division in SMPTE frames rather than ticks per quarter note

TooManyTracks 

more tracks than SmfReader::MAX_TRACKS

Truncated 

a chunk runs past the end of the data, or tracks are missing

Definition at line 17 of file smf_reader.hpp.

◆ MessageType

enum class sbl::midi::MessageType : uint8_t
strong

Definition at line 15 of file types.hpp.

Function Documentation

◆ drain() [1/2]

template<typename Source , typename Thru >
uint32_t sbl::midi::drain ( Parser &  parser,
Thru &&  thru 
)
inline

Push everything Source has waiting into parser, copying it to a thru.

thru(const uint8_t* bytes, uint32_t count) is given every run of bytes as it is read, before the parser has them, to copy to another port.

Template Parameters
SourceA byte source in either shape above; block reads win if both exist
ThruCallable taking (const uint8_t*, uint32_t)
Returns
Bytes pushed
Context
ISR-safe only if the source is: a UART ring buffer is, a USB stack may not be.

Definition at line 63 of file drain.hpp.

References DRAIN_CHUNK, and sbl::midi::Parser::push().

◆ drain() [2/2]

template<typename Source >
uint32_t sbl::midi::drain ( Parser &  parser)
inline

Push everything Source has waiting into parser

Template Parameters
SourceA byte source in either shape above; block reads win if both exist
Returns
Bytes pushed
Context
ISR-safe only if the source is: a UART ring buffer is, a USB stack may not be.

Definition at line 94 of file drain.hpp.

◆ to_7bit()

constexpr uint8_t sbl::midi::to_7bit ( float  value)
inlineconstexpr

A value in [0, 1] as a 7-bit data byte, rounded to nearest; values outside are held to the ends.

Definition at line 56 of file types.hpp.

References DATA_MAX.

Referenced by sbl::control::CcMapper< Target >::on_cc(), and sbl::control::ParamEcho< Target >::poll().

◆ expected_data_bytes()

uint8_t sbl::midi::expected_data_bytes ( uint8_t  status)
inline

Number of data bytes expected for a channel message status byte

Definition at line 174 of file types.hpp.

Referenced by sbl::midi::Parser::push().

Variable Documentation

◆ DRAIN_CHUNK

constexpr uint32_t sbl::midi::DRAIN_CHUNK = 64
inlineconstexpr

Bytes read per block from a block source.

Definition at line 34 of file drain.hpp.

Referenced by drain().

◆ CC_SWITCH_ON

constexpr uint8_t sbl::midi::CC_SWITCH_ON = 64
inlineconstexpr

A controller used as a switch is on from this value up.

Definition at line 50 of file types.hpp.

◆ DATA_MAX

constexpr uint8_t sbl::midi::DATA_MAX = 127
inlineconstexpr

The largest 7-bit data value.

Definition at line 53 of file types.hpp.

Referenced by to_7bit().