Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
MidiFile Class Reference

MIDI file handling. More...

#include <src/gui/backend/io/midi_file.h>

Public Types

enum class  Format { MIDI0 , MIDI1 , MIDI2 }
using TrackIndex = unsigned int

Public Member Functions

 MidiFile (Format format)
 Construct a new Midi File object for writing.
 MidiFile (const fs::path &path)
 Construct a new Midi File object for reading.
bool track_has_midi_note_events (TrackIndex track_idx) const
 Returns whether the given track in the midi file has data.
int get_num_tracks (bool non_empty_only) const
 Returns the number of tracks in the MIDI file.
Format get_format () const
int get_ppqn () const
 Get the PPQN (Parts Per Quarter Note) of the MIDI file.
void into_region (structure::arrangement::MidiRegion &region, int midi_track_idx) const
 Reads the contents of the MIDI file into a region.

Static Public Member Functions

static void export_midi_region_to_midi_file (const structure::arrangement::MidiRegion &region, const fs::path &full_path, int midi_version, bool export_full)
 Exports the Region to a specified MIDI file.
static void export_midi_lane_to_sequence (juce::MidiMessageSequence &message_sequence, const structure::tracks::Tracklist &tracklist, const structure::tracks::Track &track, const structure::tracks::TrackLane &lane, dsp::MidiEventVector *events, std::optional< double > start, std::optional< double > end, bool lanes_as_tracks, bool use_track_or_lane_pos)
 Writes the lane to the given MIDI sequence.
static void export_track_to_sequence (juce::MidiMessageSequence &message_sequence, const structure::tracks::Tracklist &tracklist, const structure::tracks::Track &track, dsp::MidiEventVector *events, std::optional< double > start, std::optional< double > end, int track_index, bool lanes_as_tracks, bool use_track_pos)
 Writes the track to the given MIDI file.

Detailed Description

MIDI file handling.

Definition at line 33 of file midi_file.h.

Member Typedef Documentation

◆ TrackIndex

using MidiFile::TrackIndex = unsigned int

Definition at line 43 of file midi_file.h.

Member Enumeration Documentation

◆ Format

enum class MidiFile::Format
strong

Definition at line 36 of file midi_file.h.

Constructor & Destructor Documentation

◆ MidiFile()

MidiFile::MidiFile ( const fs::path & path)

Construct a new Midi File object for reading.

Parameters
pathPath to read.
Exceptions
ZrythmExceptionIf the file could not be read.

Member Function Documentation

◆ export_midi_lane_to_sequence()

void MidiFile::export_midi_lane_to_sequence ( juce::MidiMessageSequence & message_sequence,
const structure::tracks::Tracklist & tracklist,
const structure::tracks::Track & track,
const structure::tracks::TrackLane & lane,
dsp::MidiEventVector * events,
std::optional< double > start,
std::optional< double > end,
bool lanes_as_tracks,
bool use_track_or_lane_pos )
static

Writes the lane to the given MIDI sequence.

Parameters
lanes_as_tracksExport lanes as separate MIDI tracks.
use_track_or_lane_posWhether to use the track position (or lane position if lanes_as_tracks is true) in the MIDI data. The MIDI track will be set to 1 if false.
eventsTrack events, if not using lanes as tracks.
startEvents before this position (global ticks) will be skipped.
endEvents after this position (global ticks) will be skipped.

◆ export_midi_region_to_midi_file()

void MidiFile::export_midi_region_to_midi_file ( const structure::arrangement::MidiRegion & region,
const fs::path & full_path,
int midi_version,
bool export_full )
static

Exports the Region to a specified MIDI file.

FIXME: this needs refactoring. taken out of MidiRegion class.

Parameters
full_pathAbsolute path to the MIDI file.
export_fullTraverse loops and export the MIDI file as it would be played inside Zrythm. If this is false, only the original region (from true start to true end) is exported.

◆ export_track_to_sequence()

void MidiFile::export_track_to_sequence ( juce::MidiMessageSequence & message_sequence,
const structure::tracks::Tracklist & tracklist,
const structure::tracks::Track & track,
dsp::MidiEventVector * events,
std::optional< double > start,
std::optional< double > end,
int track_index,
bool lanes_as_tracks,
bool use_track_pos )
inlinestatic

Writes the track to the given MIDI file.

Parameters
use_track_posWhether to use the track position in the MIDI data. The track will be set to 1 if false.
eventsTrack events, if not using lanes as tracks or using track position.
lanes_as_tracksExport lanes as separate tracks (only possible with MIDI type 1). This will calculate a unique MIDI track number for the region's lane.
use_track_or_lane_posWhether to use the track/lane position in the MIDI data. The MIDI track will be set to 1 if false.
startEvents before this position will be skipped.
endEvents after this position will be skipped.

Definition at line 144 of file midi_file.h.

◆ get_ppqn()

int MidiFile::get_ppqn ( ) const

Get the PPQN (Parts Per Quarter Note) of the MIDI file.

Returns
int
Exceptions
ZrythmExceptionIf the MIDI file does not contain a PPQN value.

◆ into_region()

void MidiFile::into_region ( structure::arrangement::MidiRegion & region,
int midi_track_idx ) const

Reads the contents of the MIDI file into a region.

Parameters
regionA freshly created region to fill.
midi_track_idxThe index of this track, starting from 0. This will be sequential, ie, if idx 1 is requested and the MIDI file only has tracks 5 and 7, it will use track 7.
Exceptions
ZrythmExceptionOn error.

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