|
Gin
|
Plays back MIDI files with configurable tempo. More...
#include <gin_midifileplayer.h>
Public Member Functions | |
| MidiFilePlayer ()=default | |
| bool | load (const juce::File &file) |
| Loads a MIDI file for playback. | |
| void | setSampleRate (double sr) |
| Sets the sample rate for playback timing. | |
| void | setFallbackBpm (double bpm) |
| Sets the fallback tempo to use when the MIDI file contains no tempo events. | |
| void | play () |
| Starts playback from the current position. | |
| void | stop () |
| Stops playback and sends note-off messages for any playing notes. | |
| bool | isPlaying () const |
| Returns true if currently playing. | |
| double | getPlayheadPosition () const |
| Returns the current playhead position in seconds. | |
| void | setPlayheadPosition (double positionInSeconds) |
| Sets the playhead position in seconds. | |
| void | processBlock (int numSamples, juce::MidiBuffer &midiBuffer) |
| Processes a block, filling the buffer with MIDI events. | |
| double | getLengthInSeconds () const |
| Returns the total length of the MIDI file in seconds. | |
| void | setLooping (bool shouldLoop) |
| Sets whether playback should loop. | |
| bool | isLooping () const |
| Returns true if looping is enabled. | |
| const juce::MidiMessageSequence & | getSequence () const |
| Returns the merged MIDI sequence for display purposes. | |
| double | getLengthInTicks () const |
| Returns the length in ticks (for display purposes). | |
| bool | hasFileLoaded () const |
| Returns true if a file has been loaded. | |
| juce::File | getLoadedFile () const |
| Returns the path of the currently loaded file, or empty if none. | |
| void | clear () |
| Clears the currently loaded file. | |
| juce::AudioPlayHead::PositionInfo | populatePositionInfo () |
| Returns position info for use with an AudioPlayHead. | |
Plays back MIDI files with configurable tempo.
MidiFilePlayer loads a standard MIDI file and plays it back through processBlock calls, filling a MidiBuffer with the appropriate events for each audio block based on the current playhead position.
Thread Safety:
Key Features:
Usage:
|
default |
Loads a MIDI file for playback.
Call from the message thread only.
| file | The MIDI file to load |
Sets the sample rate for playback timing.
| sr | The sample rate in Hz |
Referenced by StandaloneAudioProcessorPlayer::audioDeviceAboutToStart().
Sets the fallback tempo to use when the MIDI file contains no tempo events.
Call from the message thread only.
| bpm | The fallback tempo in beats per minute (default: 120) |
Referenced by StandaloneAudioProcessorPlayer::StandaloneAudioProcessorPlayer().
| void MidiFilePlayer::play | ( | ) |
Starts playback from the current position.
| void MidiFilePlayer::stop | ( | ) |
Stops playback and sends note-off messages for any playing notes.
| bool MidiFilePlayer::isPlaying | ( | ) | const |
Returns true if currently playing.
| double MidiFilePlayer::getPlayheadPosition | ( | ) | const |
Returns the current playhead position in seconds.
Sets the playhead position in seconds.
| positionInSeconds | The new playhead position |
Processes a block, filling the buffer with MIDI events.
Call from the audio thread only.
| numSamples | The number of samples in this block |
| midiBuffer | The buffer to fill with MIDI events |
Referenced by StandaloneAudioProcessorPlayer::preProcessBlock().
| double MidiFilePlayer::getLengthInSeconds | ( | ) | const |
Returns the total length of the MIDI file in seconds.
Sets whether playback should loop.
Referenced by StandaloneAudioProcessorPlayer::StandaloneAudioProcessorPlayer().
| bool MidiFilePlayer::isLooping | ( | ) | const |
Returns true if looping is enabled.
| const juce::MidiMessageSequence & MidiFilePlayer::getSequence | ( | ) | const |
Returns the merged MIDI sequence for display purposes.
Note: Only safe to call when not loading a new file.
| double MidiFilePlayer::getLengthInTicks | ( | ) | const |
Returns the length in ticks (for display purposes).
| bool MidiFilePlayer::hasFileLoaded | ( | ) | const |
Returns true if a file has been loaded.
Referenced by StandaloneAudioProcessorPlayer::preProcessBlock().
| juce::File MidiFilePlayer::getLoadedFile | ( | ) | const |
Returns the path of the currently loaded file, or empty if none.
| void MidiFilePlayer::clear | ( | ) |
Clears the currently loaded file.
| juce::AudioPlayHead::PositionInfo MidiFilePlayer::populatePositionInfo | ( | ) |
Returns position info for use with an AudioPlayHead.
Call from the audio thread before processing.
Referenced by StandaloneAudioProcessorPlayer::preProcessBlock().