6#include "gui/dsp/arranger_object_span.h"
7#include "gui/dsp/track.h"
8#include "gui/dsp/track_span.h"
10#include <QtQmlIntegration>
14#define TRACKLIST (PROJECT->tracklist_)
31class Tracklist final :
public QAbstractListModel,
public ICloneable<Tracklist>
35 Q_PROPERTY (
TempoTrack * tempoTrack READ getTempoTrack CONSTANT FINAL)
52 TrackPtrRole = Qt::UserRole + 1,
57 Tracklist (QObject * parent =
nullptr);
60 PortRegistry &port_registry,
61 TrackRegistry &track_registry,
62 dsp::PortConnectionsManager * port_connections_manager);
64 SampleProcessor &sample_processor,
65 PortRegistry &port_registry,
66 TrackRegistry &track_registry,
67 dsp::PortConnectionsManager * port_connections_manager);
68 Z_DISABLE_COPY_MOVE (Tracklist)
69 ~Tracklist ()
override;
74 QHash<int, QByteArray> roleNames ()
const override;
75 int rowCount (
const QModelIndex &parent = QModelIndex ())
const override;
77 data (
const QModelIndex &index,
int role = Qt::DisplayRole)
const override;
79 TempoTrack * getTempoTrack ()
const;
81 Q_INVOKABLE
void setExclusivelySelectedTrack (QVariant track);
93 auto get_track_span ()
const {
return TrackSpan{ tracks_ }; }
95 bool is_in_active_project ()
const;
97 bool is_auditioner ()
const
99 return sample_processor_ && is_in_active_project ();
109 PortRegistry &port_registry,
120 init_loaded (port_registry,
nullptr, &sample_processor);
131 const TrackUuidReference &track_id,
147 track_id, tracks_.size (), engine, publish_events, recalc_graph);
170 bool always_before_pos,
171 std::optional<std::reference_wrapper<Router>> router);
173 std::optional<TrackPtrVariant> get_track (
const TrackUuid &
id)
const
175 auto span = get_track_span ();
176 auto it = std::ranges::find (span,
id, TrackSpan::uuid_projection);
177 if (it == span.end ()) [[unlikely]]
181 return std::make_optional (*it);
193 bool validate ()
const;
209 std::optional<TrackPtrVariant>
216 std::optional<TrackPtrVariant>
236 std::optional<TrackPtrVariant>
240 return get_track_span ().get_track_by_pos (
252 std::optional<TrackPtrVariant>
263 Track::TrackUuid src_track,
264 Track::TrackUuid dest_track)
const;
280 void handle_click (TrackUuid track_id,
bool ctrl,
bool shift,
bool dragged);
282 std::vector<ArrangerObjectPtrVariant> get_timeline_objects_in_range (
283 std::optional<std::pair<dsp::Position, dsp::Position>> range = std::nullopt)
303 std::vector<std::vector<std::shared_ptr<Region>>> ®ion_arrays,
304 const FileImportInfo * import_info,
325 ArrangerObjectPtrVariant region,
327 int lane_or_at_index,
334 const Plugin::Uuid &plugin_id,
348 const Plugin::Uuid &plugin_id,
351 bool confirm_overwrite);
369 std::optional<std::vector<utils::Utf8String>> uri_list,
385 void handle_move_or_copy (
388 GdkDragAction action);
405 return index < pinned_tracks_cutoff_;
408 auto get_track_index (
const Track::TrackUuid &track_id)
const
410 return std::distance (
412 std::ranges::find (tracks_, track_id, &TrackUuidReference::id));
415 auto get_track_at_index (
size_t index)
const
417 if (index >= tracks_.size ())
418 throw std::out_of_range (
"Track index out of range");
419 return get_track_span ().at (index);
422 auto get_track_ref_at_index (
size_t index)
const
424 if (index >= tracks_.size ())
425 throw std::out_of_range (
"Track index out of range");
426 return tracks_.at (index);
434 auto get_selection_manager ()
436 return TrackSelectionManager{ selected_tracks_, *track_registry_ };
445 auto selected_vec = std::ranges::to<std::vector> (selected_tracks_);
446 TrackSpan span{ *track_registry_, selected_vec };
447 std::ranges::for_each (span, [&] (
auto &&track_var) {
449 [&] (
auto &&track_ref) {
450 using TrackT = base_type<
decltype (track_ref)>;
451 if constexpr (std::derived_from<TrackT, FoldableTrack>)
453 for (
int i = 1; i < track_ref->size_; ++i)
455 const size_t child_pos =
456 get_track_index (track_ref->get_uuid ()) + i;
457 const auto &child_track_var = get_track_at_index (child_pos);
458 get_selection_manager ().append_to_selection (
459 TrackSpan::uuid_projection (child_track_var));
467 auto get_pinned_tracks_cutoff_index ()
const {
return pinned_tracks_cutoff_; }
468 void set_pinned_tracks_cutoff_index (
size_t index)
470 pinned_tracks_cutoff_ = index;
472 auto track_count ()
const {
return tracks_.size (); }
483 TrackPtrVariant track_var,
489 void mark_all_tracks_for_bounce (
bool bounce)
491 get_track_span ().mark_all_tracks_for_bounce (*
this, bounce);
495 static constexpr auto kPinnedTracksCutoffKey =
"pinnedTracksCutoff"sv;
496 static constexpr auto kTracksKey =
"tracks"sv;
497 static constexpr auto kSelectedTracksKey =
"selectedTracks"sv;
498 friend void to_json (nlohmann::json &j,
const Tracklist &t)
501 { kPinnedTracksCutoffKey, t.pinned_tracks_cutoff_ },
502 { kTracksKey, t.tracks_ },
503 { kSelectedTracksKey, t.selected_tracks_ },
506 friend void from_json (
const nlohmann::json &j, Tracklist &t)
508 j.at (kPinnedTracksCutoffKey).get_to (t.pinned_tracks_cutoff_);
509 j.at (kTracksKey).get_to (t.tracks_);
510 j.at (kSelectedTracksKey).get_to (t.selected_tracks_);
513 void swap_tracks (
size_t index1,
size_t index2);
515 auto &get_track_registry ()
const {
return *track_registry_; }
516 auto &get_track_registry () {
return *track_registry_; }
519 OptionalRef<TrackRegistry> track_registry_;
520 OptionalRef<PortRegistry> port_registry_;
521 OptionalRef<PluginRegistry> plugin_registry_;
540 std::vector<TrackUuidReference> tracks_;
547 TrackSelectionManager::UuidSet selected_tracks_;
571 size_t pinned_tracks_cutoff_ = 0;
575 std::atomic<bool> swapping_tracks_ =
false;
The ChordTrack class is responsible for managing the chord and scale information in the project.
A track that can host modulator plugins.
Contains all of the info that will be serialized into a project file.
The Router class manages the processing graph for the audio engine.
A processor to be used in the routing graph for playing samples independent of the timeline.
Represents a track that controls the tempo of the audio.
A TrackLane belongs to a Track (can have many TrackLanes in a Track) and contains Regions.
Track span that offers helper methods on a range of tracks.
Represents a track in the project.
@ Marker
Marker Track's contain named markers at specific Position's in the song.
@ Modulator
Special track to contain global Modulator's.
@ Tempo
Special track for BPM (tempo) and time signature events.
@ Chord
The chord track contains chords that can be used to modify midi in real time or to color the piano ro...
The Tracklist contains all the tracks in the Project.
void select_foldable_children_of_current_selections()
Also selects the children of foldable tracks in the currently selected tracks.
bool track_name_is_unique(const utils::Utf8String &name, TrackUuid track_to_skip) const
Returns whether the track name is not taken.
void import_files(std::optional< std::vector< utils::Utf8String > > uri_list, const FileDescriptor *orig_file, const Track *track, const TrackLane *lane, int index, const zrythm::dsp::Position *pos, TracksReadyCallback ready_cb)
Begins file import Handles a file drop inside the timeline or in empty space in the tracklist.
void mark_track_for_bounce(TrackPtrVariant track_var, bool bounce, bool mark_regions, bool mark_children, bool mark_parents)
Marks the track for bouncing.
MasterTrack * master_track_
The master track, for convenience.
void handle_click(TrackUuid track_id, bool ctrl, bool shift, bool dragged)
Handle a click selection.
void clear_selections_for_object_siblings(const ArrangerObject::Uuid &object_id)
Clears either the timeline selections or the clip editor selections.
Project * project_
Pointer to owner project, if any.
void init_after_cloning(const Tracklist &other, ObjectCloneType clone_type) override
Initializes the cloned object.
PinOption
Used in track search functions.
std::optional< TrackPtrVariant > get_last_track(PinOption pin_opt=PinOption::Both, bool visible_only=false) const
Returns the last Track.
int get_visible_track_diff(Track::TrackUuid src_track, Track::TrackUuid dest_track) const
Returns the number of visible Tracks between src and dest (negative if dest is before src).
void move_plugin(const Plugin::Uuid &plugin_id, const Track::Uuid &target_track_id, plugins::PluginSlot slot, bool confirm_overwrite)
Moves the plugin to the given slot in the given channel.
TrackPtrVariant append_track(auto track_id, AudioEngine &engine, bool publish_events, bool recalc_graph)
Calls insert_track with the given options.
ModulatorTrack * modulator_track_
The modulator track, for convenience.
void set_track_pinned(TrackUuid track_id, bool pinned, int publish_events, int recalc_graph)
Pins or unpins the Track.
void move_track(TrackUuid track_id, int pos, bool always_before_pos, std::optional< std::reference_wrapper< Router > > router)
Moves a track from its current position to the position given by pos.
std::optional< TrackPtrVariant > get_prev_visible_track(Track::TrackUuid track_id) const
Returns the previous visible Track in the same Tracklist as the given one (ie, pinned or not).
TempoTrack * tempo_track_
The tempo track, for convenience.
std::optional< TrackPtrVariant > get_visible_track_after_delta(Track::TrackUuid track_id, int delta) const
Returns the Track after delta visible Track's.
void import_regions(std::vector< std::vector< std::shared_ptr< Region > > > ®ion_arrays, const FileImportInfo *import_info, TracksReadyCallback ready_cb)
Imports regions from a region array.
std::optional< TrackPtrVariant > get_first_visible_track(bool pinned) const
Returns the first visible Track.
static constexpr std::array< Track::Type, 4 > unique_track_types_
A list of track types that must be unique in the tracklist.
void remove_track(const TrackUuid &track_id)
Removes the given track from the tracklist.
void move_plugin_automation(const Plugin::Uuid &plugin_id, const Track::Uuid &prev_track_id, const Track::Uuid &track_id_to_move_to, zrythm::plugins::PluginSlot new_slot)
Moves the Plugin's automation from one Channel to another.
std::optional< TrackPtrVariant > get_next_visible_track(Track::TrackUuid track_id) const
Returns the next visible Track in the same Tracklist as the given one (ie, pinned or not).
ChordTrack * chord_track_
The chord track, for convenience.
bool multiply_track_heights(double multiplier, bool visible_only, bool check_only, bool fire_events)
Multiplies all tracks' heights and returns if the operation was valid.
void init_loaded(PortRegistry &port_registry, Project *project, SampleProcessor *sample_processor)
Initializes the tracklist when loading a project.
bool is_track_pinned(size_t index) const
Returns whether the track at index is pinned.
TrackPtrVariant insert_track(const TrackUuidReference &track_id, int pos, AudioEngine &engine, bool publish_events, bool recalc_graph)
Adds given track to given spot in tracklist.
MarkerTrack * marker_track_
The marker track, for convenience.
QPointer< dsp::PortConnectionsManager > port_connections_manager_
Width of track widgets.
void move_region_to_track(ArrangerObjectPtrVariant region, const Track::Uuid &to_track_id, int lane_or_at_index, int index)
Moves the Region to the given Track, maintaining the selection status of the Region.
int get_last_pos(PinOption pin_opt=PinOption::Both, bool visible_only=false) const
Returns the index of the last Track.
Represents the position of an object.
Represents a channel strip on the mixer.
Lightweight UTF-8 string wrapper with safe conversions.
void(*)(const FileImportInfo *) TracksReadyCallback
Called when track(s) are actually imported into the project.