AudioDataLib
A C++ library of classes supporting a variety of audio-data tasks.
Loading...
Searching...
No Matches
AudioDataLib::MidiPlayer Class Reference

This class knows how to playback MIDI files. More...

#include <MidiPlayer.h>

Inheritance diagram for AudioDataLib::MidiPlayer:
AudioDataLib::MidiMsgSource

Classes

class  TrackPlayer
 

Public Member Functions

 MidiPlayer (Timer *timer)
 
virtual ~MidiPlayer ()
 
virtual bool Setup (Error &error) override
 
virtual bool Shutdown (Error &error) override
 
virtual bool Process (Error &error) override
 
void SetMidiData (const MidiData *midiData)
 
const MidiDataGetMidiData () const
 
bool NoMoreToPlay ()
 
void ConfigureToPlayAllTracks () const
 
std::set< uint32_t > & GetTracksConfiguredToPlay ()
 
TimerGetTimer ()
 
- Public Member Functions inherited from AudioDataLib::MidiMsgSource
 MidiMsgSource ()
 
virtual ~MidiMsgSource ()
 
void AddDestination (std::shared_ptr< MidiMsgDestination > destination)
 
void Clear ()
 
template<typename T >
T * FindDestination ()
 

Protected Member Functions

void Clear ()
 
bool SilenceAllChannels (Error &error)
 
- Protected Member Functions inherited from AudioDataLib::MidiMsgSource
bool BroadcastMidiMessage (double deltaTimeSeconds, const uint8_t *messageBuffer, uint64_t messageBufferSize, Error &error)
 

Protected Attributes

const MidiDatamidiData
 
Timertimer
 
std::vector< TrackPlayer * > * trackPlayerArray
 
std::set< uint32_t > * tracksToPlaySet
 
- Protected Attributes inherited from AudioDataLib::MidiMsgSource
std::vector< std::shared_ptr< MidiMsgDestination > > * destinationArray
 

Detailed Description

This class knows how to playback MIDI files.

Again, since a goal of AudioDataLib is to depend at most on the C++ standard library, we are not sending MIDI message directly to a MIDI port for sound synthesis. Rather, we are sending them (in proper sequence and time) to any connected MidiMsgDestination classes which, in turn, may send them to a MIDI port, or be used to synthesize the MIDI messages into sound (such as is the case with any MidiSynth derivative.)

Constructor & Destructor Documentation

◆ MidiPlayer()

MidiPlayer::MidiPlayer ( Timer * timer)

Construct a MIDI player to use the given timer for timing.

Parameters
[in]timerA heap allocation for a Timer class derivative. This class takes ownership of the memory.

◆ ~MidiPlayer()

MidiPlayer::~MidiPlayer ( )
virtual

Member Function Documentation

◆ Clear()

void MidiPlayer::Clear ( )
protected

◆ ConfigureToPlayAllTracks()

void MidiPlayer::ConfigureToPlayAllTracks ( ) const

While a subset of the set of all MIDI tracks of the given MidiData can be configured to play, this method insures that all tracks are configured to play.

◆ GetMidiData()

const MidiData * AudioDataLib::MidiPlayer::GetMidiData ( ) const
inline

Return the MidiData class instance being used for playback by this player.

◆ GetTimer()

Timer * AudioDataLib::MidiPlayer::GetTimer ( )
inline

Return a pointer to the Timer instance keeping time during playback. This could be used by the caller to know where (in time) playback is currently at.

◆ GetTracksConfiguredToPlay()

std::set< uint32_t > & AudioDataLib::MidiPlayer::GetTracksConfiguredToPlay ( )
inline

Return a reference to the set of tracks that should play during playback. The caller can then modify this set as they see fit before playback begins. Once playback begins, this doing so does nothing.

◆ NoMoreToPlay()

bool MidiPlayer::NoMoreToPlay ( )

At any time, this can be called to determine if the player is still playing.

◆ Process()

bool MidiPlayer::Process ( Error & error)
overridevirtual

This is called once per frame in a program's main loop, and should do any necessary processing of the MIDI message source (e.g., poll messages from a port), but should also call the base-class method here to process each connected MidiMsgDestination class.

Reimplemented from AudioDataLib::MidiMsgSource.

◆ SetMidiData()

void AudioDataLib::MidiPlayer::SetMidiData ( const MidiData * midiData)
inline

Set the MidiData class instance containing the MIDI data that will be played back by this player. Note that we do not take ownership of the memory, and we assume that the given pointer will not go stale before this class goes out of scope.

◆ Setup()

bool MidiPlayer::Setup ( Error & error)
overridevirtual

Perform any setup that is required, but also call this base-class method as it will attempt to initialize each MidiMsgDestination added to this class instance. If any one of those fails, then setup should fail.

Reimplemented from AudioDataLib::MidiMsgSource.

◆ Shutdown()

bool MidiPlayer::Shutdown ( Error & error)
overridevirtual

Perform any shutdown that is required, but also call this base-class method as it will shutdown each MidiMsgDestination added to this class instance. Though setup and shutdown routines (or, using alternative terms, initialization and finalization routines) have the same signature, it is convention that shutdown routines always succeed, at least as far as doing any clean-up needed to reclaim the state of the program after a successful or failed initialization. Still failure can be returned here if it's useful, and error information can be provided, but the return value is usually not checked.

Reimplemented from AudioDataLib::MidiMsgSource.

◆ SilenceAllChannels()

bool MidiPlayer::SilenceAllChannels ( Error & error)
protected

Member Data Documentation

◆ midiData

const MidiData* AudioDataLib::MidiPlayer::midiData
protected

◆ timer

Timer* AudioDataLib::MidiPlayer::timer
protected

◆ trackPlayerArray

std::vector<TrackPlayer*>* AudioDataLib::MidiPlayer::trackPlayerArray
protected

◆ tracksToPlaySet

std::set<uint32_t>* AudioDataLib::MidiPlayer::tracksToPlaySet
protected

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