Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
arranger_object_creator.h
1// SPDX-FileCopyrightText: © 2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <utility>
7
8#include "commands/add_arranger_object_command.h"
9#include "dsp/snap_grid.h"
10#include "structure/arrangement/arranger_object_all.h"
11#include "structure/arrangement/arranger_object_factory.h"
12#include "structure/arrangement/arranger_object_owner.h"
13#include "structure/arrangement/tempo_object_manager.h"
14#include "structure/scenes/clip_slot.h"
15#include "structure/tracks/track_all.h"
16#include "undo/undo_stack.h"
17
18namespace zrythm::actions
19{
20class ArrangerObjectCreator : public QObject
21{
22 Q_OBJECT
23 QML_ELEMENT
24 QML_UNCREATABLE ("One instance per project")
25
26public:
27 explicit ArrangerObjectCreator (
28 undo::UndoStack &undo_stack,
29 structure::arrangement::ArrangerObjectFactory &arranger_object_factory,
30 dsp::SnapGrid &snap_grid_timeline,
31 dsp::SnapGrid &snap_grid_editor,
32 QObject * parent = nullptr)
33 : QObject (parent), arranger_object_factory_ (arranger_object_factory),
34 snap_grid_timeline_ (snap_grid_timeline),
35 snap_grid_editor_ (snap_grid_editor), undo_stack_ (undo_stack)
36 {
37 }
38
39 Q_INVOKABLE structure::arrangement::Marker * addMarker (
42 const QString &name,
43 double startTicks);
44
45 Q_INVOKABLE structure::arrangement::TempoObject * addTempoObject (
47 double bpm,
48 structure::arrangement::TempoObject::CurveType curveType,
49 double startTicks);
50
52 addTimeSignatureObject (
54 int numerator,
55 int denominator,
56 double startTicks);
57
58 Q_INVOKABLE structure::arrangement::MidiClip * addEmptyMidiClip (
61 double startTicks);
62
63 Q_INVOKABLE structure::arrangement::MidiClip * addEmptyMidiClipToClip (
66
68 addEmptyChordClip (structure::tracks::ChordTrack * track, double startTicks);
69
70 Q_INVOKABLE structure::arrangement::AutomationClip * addEmptyAutomationClip (
72 structure::tracks::AutomationTrack * automationTrack,
73 double startTicks);
74
86 dsp::FileAudioSourceUuidReference clip_id,
87 units::precise_tick_t start_ticks);
88
89 structure::arrangement::ScaleObject * add_scale_object (
92 units::precise_tick_t start_ticks);
93
94 structure::arrangement::ArrangerObjectUuidReference
95 add_audio_clip_for_recording (
98 const utils::audio::AudioBuffer &initial_frames,
99 const utils::Utf8String &clip_name,
100 units::precise_tick_t start_ticks);
101
102 structure::arrangement::ArrangerObjectUuidReference
103 add_midi_clip_for_recording (
106 units::precise_tick_t start_ticks);
107
108 structure::arrangement::MidiControlEvent * add_midi_control_event (
110 units::precise_tick_t startTicks,
111 structure::arrangement::MidiControlEvent::EventType type,
112 int channel,
113 int controller,
114 int value);
115
116 Q_INVOKABLE structure::arrangement::AudioClip * addAudioClipFromFile (
119 const QString &absPath,
120 double startTicks);
121
123 addAudioClipToClipSlotFromFile (
126 const QString &absPath);
127 Q_INVOKABLE structure::arrangement::MidiClip * addMidiClipToClipSlotFromFile (
130 const QString &absPath);
131
140 const dsp::ChordDescriptor &descr,
141 double startTicks);
142
154 const QString &absolutePath,
155 double startTicks,
156 int midiTrackIndex);
157
158 Q_INVOKABLE structure::arrangement::MidiNote * addMidiNote (
160 double startTicks,
161 int pitch);
162
163 Q_INVOKABLE structure::arrangement::AutomationPoint * addAutomationPoint (
165 double startTicks,
166 double value);
167
168 Q_INVOKABLE structure::arrangement::ChordObject * addChordObject (
170 double startTicks,
171 const int chordIndex);
172
173 Q_INVOKABLE structure::arrangement::ChordObject * addChordObjectFromFields (
175 double startTicks,
176 dsp::MusicalNote rootNote,
177 dsp::ChordType chordType,
178 dsp::ChordAccent chordAccent,
179 bool hasBass,
180 dsp::MusicalNote bassNote,
181 int inversion);
182
184 addChordObjectFromDescriptor (
186 double startTicks,
187 zrythm::dsp::ChordDescriptor * descriptor);
188
195 Q_INVOKABLE void editChordObjectsDescriptor (
196 QVariantList chordObjects,
197 dsp::MusicalNote rootNote,
198 dsp::ChordType chordType,
199 dsp::ChordAccent chordAccent,
200 bool hasBass,
201 dsp::MusicalNote bassNote,
202 int inversion);
203
204private:
208 void add_laned_object (
211 structure::arrangement::ArrangerObjectUuidReference obj_ref);
212
213 void add_object_to_clip_slot (
216 structure::arrangement::ArrangerObjectUuidReference obj_ref);
217
226 template <structure::arrangement::EditorObject ChildT>
227 auto add_editor_object (
229 units::precise_tick_t startTicks,
230 std::variant<int, double> value) -> ChildT *
231 {
232 auto obj_ref =
233 arranger_object_factory_.create_editor_object<ChildT> (startTicks, value);
234 undo_stack_.push (
236 auto obj = obj_ref.template get_object_as<ChildT> ();
237 return obj;
238 }
239
240private:
241 structure::arrangement::ArrangerObjectFactory &arranger_object_factory_;
242 dsp::SnapGrid &snap_grid_timeline_;
243 dsp::SnapGrid &snap_grid_editor_;
244 undo::UndoStack &undo_stack_;
245};
246} // namespace zrythm::actions
structure::arrangement::AudioClip * add_audio_clip_with_clip(structure::tracks::Track &track, structure::tracks::TrackLane &lane, dsp::FileAudioSourceUuidReference clip_id, units::precise_tick_t start_ticks)
Q_INVOKABLE structure::arrangement::MidiClip * addMidiClipFromMidiFile(structure::tracks::Track *track, structure::tracks::TrackLane *lane, const QString &absolutePath, double startTicks, int midiTrackIndex)
Creates a MIDI clip at lane from MIDI file path abs_path starting at startTicks.
Q_INVOKABLE structure::arrangement::MidiClip * addMidiClipFromChordDescriptor(structure::tracks::Track *track, structure::tracks::TrackLane *lane, const dsp::ChordDescriptor &descr, double startTicks)
Creates a MIDI clip at lane from the given descr starting at startTicks.
Q_INVOKABLE void editChordObjectsDescriptor(QVariantList chordObjects, dsp::MusicalNote rootNote, dsp::ChordType chordType, dsp::ChordAccent chordAccent, bool hasBass, dsp::MusicalNote bassNote, int inversion)
Sets the descriptor of one or more chord objects to the given fields.
Describes a musical chord by its root note, type, accent, inversion, and optional bass note.
Snap/grid information.
Definition snap_grid.h:23
A clip for playing back audio samples.
Definition audio_clip.h:24
Represents an automation clip, which contains a collection of automation points.
An automation point inside an AutomationTrack.
A chord placed inside a ChordClip on the chord track.
Marker for the MarkerTrack.
Definition marker.h:18
A Clip containing MIDI events.
Definition midi_clip.h:26
A MIDI note inside a Clip shown in the piano roll.
Definition midi_note.h:23
Manages tempo and time signature objects for a project.
The ChordTrack class is responsible for managing the chord and scale information in the project.
Definition chord_track.h:25
A container of MIDI or Audio clips.
Definition track_lane.h:28
Represents a track in the project.
Definition track.h:60
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:36
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:37