Zrythm v2.0.0-alpha.1
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 "tracks/track_all.h"
9#include <juce_audio_basics/juce_audio_basics.h>
10
11namespace zrythm
12{
13namespace structure
14{
15namespace arrangement
16{
17class MidiClip;
18}
19namespace tracks
20{
21class Tracklist;
22}
23}
24
30
35{
36public:
37 enum class Format
38 {
39 MIDI0,
40 MIDI1,
41 MIDI2,
42 };
43
44 using TrackIndex = unsigned int;
45
49 MidiFile (Format format);
50
57 MidiFile (const std::filesystem::path &path);
58
62 bool track_has_midi_note_events (TrackIndex track_idx) const;
63
67 int get_num_tracks (bool non_empty_only) const;
68
69 [[nodiscard]] Format get_format () const;
70
77 int get_ppqn () const;
78
88 void
89 into_clip (structure::arrangement::MidiClip &clip, int midi_track_idx) const;
90
103 const std::filesystem::path &full_path,
104 int midi_version,
105 bool export_full);
106
107 // TODO
108#if 0
120 static void export_midi_lane_to_sequence (
121 juce::MidiMessageSequence &message_sequence,
122 const structure::tracks::Tracklist &tracklist,
123 const structure::tracks::Track &track,
125 dsp::MidiEventVector * events,
126 std::optional<double> start,
127 std::optional<double> end,
128 bool lanes_as_tracks,
129 bool use_track_or_lane_pos);
130
146 static void export_track_to_sequence (
147 juce::MidiMessageSequence &message_sequence,
148 const structure::tracks::Tracklist &tracklist,
149 const structure::tracks::Track &track,
150 dsp::MidiEventVector * events,
151 std::optional<double> start,
152 std::optional<double> end,
153 int track_index,
154 bool lanes_as_tracks,
155 bool use_track_pos)
156 {
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 }
177#endif
178
179private:
180 juce::MidiFile midi_file_;
181 Format format_ = Format::MIDI0;
182 bool for_reading_ = false;
183};
184
188}
static void export_midi_clip_to_midi_file(const structure::arrangement::MidiClip &clip, const std::filesystem::path &full_path, int midi_version, bool export_full)
Exports the Clip to a specified MIDI file.
MidiFile(Format format)
Construct a new Midi File object for writing.
bool track_has_midi_note_events(TrackIndex track_idx) const
Returns whether the given track in the midi file has data.
void into_clip(structure::arrangement::MidiClip &clip, int midi_track_idx) const
Reads the contents of the MIDI file into a clip.
MidiFile(const std::filesystem::path &path)
Construct a new Midi File object for reading.
int get_ppqn() const
Get the PPQN (Parts Per Quarter Note) of the MIDI file.
int get_num_tracks(bool non_empty_only) const
Returns the number of tracks in the MIDI file.
A Clip containing MIDI events.
Definition midi_clip.h:26
A container of MIDI or Audio clips.
Definition track_lane.h:28
Represents a track in the project.
Definition track.h:60
A higher level wrapper over a track collection that serves as the project's only tracklist.
Definition tracklist.h:22