OpenShot Audio Library | OpenShotAudio 0.3.2
Loading...
Searching...
No Matches
juce::MidiFile Class Reference

#include <juce_MidiFile.h>

Public Member Functions

 MidiFile ()
 
 ~MidiFile ()
 
 MidiFile (const MidiFile &)
 
MidiFileoperator= (const MidiFile &)
 
 MidiFile (MidiFile &&)
 
MidiFileoperator= (MidiFile &&)
 
int getNumTracks () const noexcept
 
const MidiMessageSequencegetTrack (int index) const noexcept
 
void addTrack (const MidiMessageSequence &trackSequence)
 
void clear ()
 
short getTimeFormat () const noexcept
 
void setTicksPerQuarterNote (int ticksPerQuarterNote) noexcept
 
void setSmpteTimeFormat (int framesPerSecond, int subframeResolution) noexcept
 
void findAllTempoEvents (MidiMessageSequence &tempoChangeEvents) const
 
void findAllTimeSigEvents (MidiMessageSequence &timeSigEvents) const
 
void findAllKeySigEvents (MidiMessageSequence &keySigEvents) const
 
double getLastTimestamp () const
 
bool readFrom (InputStream &sourceStream, bool createMatchingNoteOffs=true)
 
bool writeTo (OutputStream &destStream, int midiFileType=1) const
 
void convertTimestampTicksToSeconds ()
 

Detailed Description

Reads/writes standard midi format files.

To read a midi file, create a MidiFile object and call its readFrom() method. You can then get the individual midi tracks from it using the getTrack() method.

To write a file, create a MidiFile object, add some MidiMessageSequence objects to it using the addTrack() method, and then call its writeTo() method to stream it out.

See also
MidiMessageSequence

Definition at line 41 of file juce_MidiFile.h.

Constructor & Destructor Documentation

◆ MidiFile() [1/3]

juce::MidiFile::MidiFile ( )

Creates an empty MidiFile object.

Definition at line 155 of file juce_MidiFile.cpp.

◆ ~MidiFile()

juce::MidiFile::~MidiFile ( )

Destructor.

Definition at line 156 of file juce_MidiFile.cpp.

◆ MidiFile() [2/3]

juce::MidiFile::MidiFile ( const MidiFile other)

Creates a copy of another MidiFile.

Definition at line 158 of file juce_MidiFile.cpp.

◆ MidiFile() [3/3]

juce::MidiFile::MidiFile ( MidiFile &&  other)

Creates a copy of another MidiFile.

Definition at line 171 of file juce_MidiFile.cpp.

Member Function Documentation

◆ addTrack()

void juce::MidiFile::addTrack ( const MidiMessageSequence trackSequence)

Adds a midi track to the file. This will make its own internal copy of the sequence that is passed-in.

See also
getNumTracks, getTrack

Definition at line 200 of file juce_MidiFile.cpp.

◆ clear()

void juce::MidiFile::clear ( )

Removes all midi tracks from the file.

See also
getNumTracks

Definition at line 184 of file juce_MidiFile.cpp.

Referenced by operator=(), and readFrom().

◆ convertTimestampTicksToSeconds()

void juce::MidiFile::convertTimestampTicksToSeconds ( )

Converts the timestamp of all the midi events from midi ticks to seconds.

This will use the midi time format and tempo/time signature info in the tracks to convert all the timestamps to absolute values in seconds.

Definition at line 347 of file juce_MidiFile.cpp.

◆ findAllKeySigEvents()

void juce::MidiFile::findAllKeySigEvents ( MidiMessageSequence keySigEvents) const

Makes a list of all the time-signature meta-events from all tracks in the midi file.

Parameters
keySigEventsa list to which all the events will be added

Definition at line 232 of file juce_MidiFile.cpp.

◆ findAllTempoEvents()

void juce::MidiFile::findAllTempoEvents ( MidiMessageSequence tempoChangeEvents) const

Makes a list of all the tempo-change meta-events from all tracks in the midi file. Useful for finding the positions of all the tempo changes in a file.

Parameters
tempoChangeEventsa list to which all the events will be added

Definition at line 222 of file juce_MidiFile.cpp.

Referenced by convertTimestampTicksToSeconds().

◆ findAllTimeSigEvents()

void juce::MidiFile::findAllTimeSigEvents ( MidiMessageSequence timeSigEvents) const

Makes a list of all the time-signature meta-events from all tracks in the midi file. Useful for finding the positions of all the tempo changes in a file.

Parameters
timeSigEventsa list to which all the events will be added

Definition at line 227 of file juce_MidiFile.cpp.

Referenced by convertTimestampTicksToSeconds().

◆ getLastTimestamp()

double juce::MidiFile::getLastTimestamp ( ) const

Returns the latest timestamp in any of the tracks. (Useful for finding the length of the file).

Definition at line 237 of file juce_MidiFile.cpp.

◆ getNumTracks()

int juce::MidiFile::getNumTracks ( ) const
noexcept

Returns the number of tracks in the file.

See also
getTrack, addTrack

Definition at line 190 of file juce_MidiFile.cpp.

◆ getTimeFormat()

short juce::MidiFile::getTimeFormat ( ) const
noexcept

Returns the raw time format code that will be written to a stream.

After reading a midi file, this method will return the time-format that was read from the file's header. It can be changed using the setTicksPerQuarterNote() or setSmpteTimeFormat() methods.

If the value returned is positive, it indicates the number of midi ticks per quarter-note - see setTicksPerQuarterNote().

It it's negative, the upper byte indicates the frames-per-second (but negative), and the lower byte is the number of ticks per frame - see setSmpteTimeFormat().

Definition at line 206 of file juce_MidiFile.cpp.

◆ getTrack()

const MidiMessageSequence * juce::MidiFile::getTrack ( int  index) const
noexcept

Returns a pointer to one of the tracks in the file.

Returns
a pointer to the track, or nullptr if the index is out-of-range
See also
getNumTracks, addTrack

Definition at line 195 of file juce_MidiFile.cpp.

◆ operator=() [1/2]

MidiFile & juce::MidiFile::operator= ( const MidiFile other)

Copies from another MidiFile object

Definition at line 163 of file juce_MidiFile.cpp.

◆ operator=() [2/2]

MidiFile & juce::MidiFile::operator= ( MidiFile &&  other)

Copies from another MidiFile object

Definition at line 177 of file juce_MidiFile.cpp.

◆ readFrom()

bool juce::MidiFile::readFrom ( InputStream sourceStream,
bool  createMatchingNoteOffs = true 
)

Reads a midi file format stream.

After calling this, you can get the tracks that were read from the file by using the getNumTracks() and getTrack() methods.

The timestamps of the midi events in the tracks will represent their positions in terms of midi ticks. To convert them to seconds, use the convertTimestampTicksToSeconds() method.

Parameters
sourceStreamthe source stream
createMatchingNoteOffsif true, any missing note-offs for previous note-ons will be automatically added at the end of the file by calling MidiMessageSequence::updateMatchedPairs on each track.
Returns
true if the stream was read successfully

Definition at line 248 of file juce_MidiFile.cpp.

◆ setSmpteTimeFormat()

void juce::MidiFile::setSmpteTimeFormat ( int  framesPerSecond,
int  subframeResolution 
)
noexcept

Sets the time format to use when this file is written to a stream.

If this is called, the file will be written using absolute times, rather than bars/beats as would be the case if setTicksPerBeat() had been called instead.

Parameters
framesPerSecondmust be 24, 25, 29 or 30
subframeResolutionthe sub-second resolution, e.g. 4 (midi time code), 8, 10, 80 (SMPTE bit resolution), or 100. For millisecond timing, setSmpteTimeFormat (25, 40)
See also
setTicksPerBeat

Definition at line 216 of file juce_MidiFile.cpp.

◆ setTicksPerQuarterNote()

void juce::MidiFile::setTicksPerQuarterNote ( int  ticksPerQuarterNote)
noexcept

Sets the time format to use when this file is written to a stream.

If this is called, the file will be written as bars/beats using the specified resolution, rather than SMPTE absolute times, as would be used if setSmpteTimeFormat() had been called instead.

Parameters
ticksPerQuarterNotee.g. 96, 960
See also
setSmpteTimeFormat

Definition at line 211 of file juce_MidiFile.cpp.

◆ writeTo()

bool juce::MidiFile::writeTo ( OutputStream destStream,
int  midiFileType = 1 
) const

Writes the midi tracks as a standard midi file. The midiFileType value is written as the file's format type, which can be 0, 1 or 2 - see the midi file spec for more info about that.

Parameters
destStreamthe destination stream
midiFileTypethe type of midi file
Returns
true if the operation succeeded.

Definition at line 367 of file juce_MidiFile.cpp.


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