Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
midi_file.h
1// SPDX-FileCopyrightText: © 2020-2021, 2024 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <filesystem>
7
8#include "utils/types.h"
9
10#include "juce_wrapper.h"
11
12namespace zrythm::structure
13{
14namespace arrangement
15{
16class MidiRegion;
17}
18namespace tracks
19{
20class Tracklist;
21}
22}
23
29
34{
35public:
36 enum class Format
37 {
38 MIDI0,
39 MIDI1,
40 MIDI2,
41 };
42
43 using TrackIndex = unsigned int;
44
48 MidiFile (Format format);
49
56 MidiFile (const fs::path &path);
57
61 bool track_has_midi_note_events (TrackIndex track_idx) const;
62
66 int get_num_tracks (bool non_empty_only) const;
67
68 [[nodiscard]] Format get_format () const;
69
76 int get_ppqn () const;
77
87 void
88 into_region (structure::arrangement::MidiRegion &region, int midi_track_idx)
89 const;
90
102 const structure::arrangement::MidiRegion &region,
103 const fs::path &full_path,
104 int midi_version,
105 bool export_full);
106
119 juce::MidiMessageSequence &message_sequence,
120 const structure::tracks::Tracklist &tracklist,
121 const structure::tracks::Track &track,
122 const structure::tracks::TrackLane &lane,
123 dsp::MidiEventVector * events,
124 std::optional<double> start,
125 std::optional<double> end,
126 bool lanes_as_tracks,
127 bool use_track_or_lane_pos);
128
145 juce::MidiMessageSequence &message_sequence,
146 const structure::tracks::Tracklist &tracklist,
147 const structure::tracks::Track &track,
148 dsp::MidiEventVector * events,
149 std::optional<double> start,
150 std::optional<double> end,
151 int track_index,
152 bool lanes_as_tracks,
153 bool use_track_pos)
154 {
155// TODO
156#if 0
157 std::unique_ptr<dsp::MidiEventVector> own_events;
158 if (!lanes_as_tracks && use_track_pos)
159 {
160 z_return_if_fail (!events);
161 midiTrackAddText (mf, track_index, textTrackName, name_.c_str ());
162 own_events = std::make_unique<dsp::MidiEventVector> ();
163 }
164
165 for (auto &lane : laned_track_mixin_->lanes ())
166 {
167 lane->write_to_midi_file (
168 mf, own_events ? own_events.get () : events, start, end,
169 lanes_as_tracks, use_track_pos);
170 }
171
172 if (own_events)
173 {
174 own_events->write_to_midi_file (mf, midi_track_pos);
175 }
176#endif
177 }
178
179private:
180 juce::MidiFile midi_file_;
181 Format format_ = Format::MIDI0;
182 bool for_reading_ = false;
183};
184
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.
Definition midi_file.h:144
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_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.
bool track_has_midi_note_events(TrackIndex track_idx) const
Returns whether the given track in the midi file has data.
MidiFile(const fs::path &path)
Construct a new Midi File object for reading.
MidiFile(Format format)
Construct a new Midi File object for writing.
void into_region(structure::arrangement::MidiRegion &region, int midi_track_idx) const
Reads the contents of the MIDI file into a region.
int get_num_tracks(bool non_empty_only) const
Returns the number of tracks in the MIDI file.
int get_ppqn() const
Get the PPQN (Parts Per Quarter Note) of the MIDI file.
A Region containing MIDI events.
Definition midi_region.h:20
A higher level wrapper over a track collection that serves as the project's only tracklist.
Definition tracklist.h:23