Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
arranger_object_all.h
1// SPDX-FileCopyrightText: © 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "structure/arrangement/audio_region.h"
7#include "structure/arrangement/audio_source_object.h"
8#include "structure/arrangement/automation_region.h"
9#include "structure/arrangement/chord_object.h"
10#include "structure/arrangement/chord_region.h"
11#include "structure/arrangement/marker.h"
12#include "structure/arrangement/midi_note.h"
13#include "structure/arrangement/midi_region.h"
14#include "structure/arrangement/scale_object.h"
15#include "structure/arrangement/tempo_object.h"
16#include "structure/arrangement/time_signature_object.h"
17
18namespace zrythm::structure::arrangement
19{
20
21template <FinalArrangerObjectSubclass ObjT>
22bool
23is_arranger_object_deletable (const ObjT &obj)
24{
25 if constexpr (std::is_same_v<ObjT, Marker>)
26 {
27 return obj.markerType () == Marker::MarkerType::Custom;
28 }
29 else
30 {
31 return true;
32 }
33}
34
43template <RegionObject ObjectT>
44[[gnu::nonnull]] std::pair<signed_frame_t, bool>
45get_frames_till_next_loop_or_end (
46 const ObjectT &obj,
47 signed_frame_t timeline_frames)
48{
49 const auto * loop_range = obj.loopRange ();
50 const auto loop_size = loop_range->get_loop_length_in_frames ();
51 assert (loop_size > 0);
52 const auto object_position_frames = obj.position ()->samples ();
53 const signed_frame_t loop_end_frames =
54 loop_range->loopEndPosition ()->samples ();
55 const signed_frame_t clip_start_frames =
56 loop_range->clipStartPosition ()->samples ();
57
58 signed_frame_t local_frames = timeline_frames - object_position_frames;
59 local_frames += clip_start_frames;
60 while (local_frames >= loop_end_frames)
61 {
62 local_frames -= loop_size;
63 }
64
65 const signed_frame_t frames_till_next_loop = loop_end_frames - local_frames;
66 const signed_frame_t frames_till_end =
67 obj.bounds ()->get_end_position_samples (true) - timeline_frames;
68
69 return std::make_pair (
70 std::min (frames_till_end, frames_till_next_loop),
71 frames_till_next_loop < frames_till_end);
72}
73
74inline auto
75get_object_tick_range (const ArrangerObject * obj)
76{
77 return std::make_pair (
78 obj->position ()->ticks (),
79 obj->position ()->ticks ()
80 + (obj->bounds () != nullptr ? obj->bounds ()->length ()->ticks () : 0));
81}
82}
Base class for all objects in the arranger.
int_fast64_t signed_frame_t
Signed type for frame index.
Definition types.h:75