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 "tracks/track_all.h"
9#include <juce_audio_basics/juce_audio_basics.h>
10
11namespace zrythm
12{
13namespace structure
14{
15namespace arrangement
16{
17class MidiRegion;
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_region (structure::arrangement::MidiRegion &region, int midi_track_idx)
90 const;
91
104 const std::filesystem::path &full_path,
105 int midi_version,
106 bool export_full);
107
120 juce::MidiMessageSequence &message_sequence,
121 const structure::tracks::Tracklist &tracklist,
122 const structure::tracks::Track &track,
124 dsp::MidiEventVector * events,
125 std::optional<double> start,
126 std::optional<double> end,
127 bool lanes_as_tracks,
128 bool use_track_or_lane_pos);
129
146 juce::MidiMessageSequence &message_sequence,
147 const structure::tracks::Tracklist &tracklist,
148 const structure::tracks::Track &track,
149 dsp::MidiEventVector * events,
150 std::optional<double> start,
151 std::optional<double> end,
152 int track_index,
153 bool lanes_as_tracks,
154 bool use_track_pos)
155 {
156// TODO
157#if 0
158 std::unique_ptr<dsp::MidiEventVector> own_events;
159 if (!lanes_as_tracks && use_track_pos)
160 {
161 z_return_if_fail (!events);
162 midiTrackAddText (mf, track_index, textTrackName, name_.c_str ());
163 own_events = std::make_unique<dsp::MidiEventVector> ();
164 }
165
166 for (auto &lane : laned_track_mixin_->lanes ())
167 {
168 lane->write_to_midi_file (
169 mf, own_events ? own_events.get () : events, start, end,
170 lanes_as_tracks, use_track_pos);
171 }
172
173 if (own_events)
174 {
175 own_events->write_to_midi_file (mf, midi_track_pos);
176 }
177#endif
178 }
179
180private:
181 juce::MidiFile midi_file_;
182 Format format_ = Format::MIDI0;
183 bool for_reading_ = false;
184};
185
189}
static void export_midi_region_to_midi_file(const structure::arrangement::MidiRegion &region, const std::filesystem::path &full_path, int midi_version, bool export_full)
Exports the Region to a specified MIDI file.
void into_region(structure::arrangement::MidiRegion &region, int midi_track_idx) const
Reads the contents of the MIDI file into a region.
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.
MidiFile(const std::filesystem::path &path)
Construct a new Midi File object for reading.
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:145
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.
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.
A lock-free thread-safe vector of MidiEvents.
Definition midi_event.h:74
A Region containing MIDI events.
Definition midi_region.h:20
A container of MIDI or Audio regions.
Definition track_lane.h:28
Represents a track in the project.
Definition track.h:61
A higher level wrapper over a track collection that serves as the project's only tracklist.
Definition tracklist.h:23