49 friend class ArrangerObjectFactory;
53 : dependencies_ (std::move (dependencies))
57 Builder &with_clip (dsp::FileAudioSourceUuidReference clip_id)
58 requires (std::is_same_v<ObjT, AudioRegion>)
60 clip_id_.emplace (std::move (clip_id));
65 Builder &with_start_ticks (
double start_ticks)
67 start_ticks_ = start_ticks;
72 Builder &with_end_ticks (
double end_ticks)
75 end_ticks_ = end_ticks;
79 Builder &with_name (
const QString &name)
86 Builder &with_pitch (
const int pitch)
87 requires (std::is_same_v<ObjT, MidiNote>)
93 Builder &with_velocity (
const int vel)
94 requires (std::is_same_v<ObjT, MidiNote>)
100 Builder &with_automatable_value (
const double automatable_val)
101 requires (std::is_same_v<ObjT, AutomationPoint>)
103 automatable_value_ = automatable_val;
107 Builder &with_chord_descriptor (
const int chord_descriptor_index)
108 requires (std::is_same_v<ObjT, ChordObject>)
110 chord_descriptor_index_ = chord_descriptor_index;
115 requires (std::is_same_v<ObjT, ScaleObject>)
117 scale_ = std::move (scale);
122 requires (std::is_same_v<ObjT, Marker>)
124 marker_type_ = marker_type;
133 std::unique_ptr<ObjT> ret;
134 if constexpr (std::is_same_v<ObjT, AudioRegion>)
136 ret = std::make_unique<ObjT> (
137 dependencies_.tempo_map_, dependencies_.object_registry_,
138 dependencies_.file_audio_source_registry_,
139 dependencies_.musical_mode_getter_);
143 ret = std::make_unique<ObjT> (
144 dependencies_.tempo_map_, dependencies_.object_registry_,
145 dependencies_.file_audio_source_registry_);
147 else if constexpr (std::is_same_v<ObjT, Marker>)
149 ret = std::make_unique<ObjT> (
152 else if constexpr (std::is_same_v<ObjT, AudioSourceObject>)
154 ret = std::make_unique<ObjT> (
155 dependencies_.tempo_map_, dependencies_.file_audio_source_registry_,
156 dsp::FileAudioSourceUuidReference{
157 dependencies_.file_audio_source_registry_ });
161 ret = std::make_unique<ObjT> (dependencies_.tempo_map_);
166 auto build_in_registry ()
168 auto obj_ref = [&] () {
170 dependencies_.object_registry_.register_object (obj_unique_ptr.get ());
171 structure::arrangement::ArrangerObjectUuidReference ret_ref{
172 obj_unique_ptr->get_uuid (), dependencies_.object_registry_
174 obj_unique_ptr.release ();
178 auto * obj = std::get<ObjT *> (obj_ref.get_object ());
180 if constexpr (RegionObject<ObjT>)
182 obj->loopRange ()->setTrackBounds (
true);
187 if (!end_ticks_ && !clip_id_)
189 if constexpr (BoundedObject<ObjT>)
192 if constexpr (TimelineObject<ObjT>)
195 dependencies_.last_timeline_obj_len_provider_ ();
199 len_ticks = dependencies_.last_editor_obj_len_provider_ ();
201 get_object_bounds (*obj)->length ()->setTicks (len_ticks);
204 obj->position ()->setTicks (*start_ticks_);
209 if constexpr (std::is_same_v<ObjT, AudioRegion>)
211 auto source_object = dependencies_.object_registry_.create_object<
213 dependencies_.tempo_map_,
214 dependencies_.file_audio_source_registry_, clip_id_.value ());
215 obj->set_source (source_object);
216 obj->bounds ()->length ()->setSamples (
218 .template get_object_as<dsp::FileAudioSource> ()
219 ->get_num_frames ());
225 if constexpr (BoundedObject<ObjT>)
227 get_object_bounds (*obj)->length ()->setTicks (
228 *end_ticks_ - obj->position ()->ticks ());
234 if constexpr (NamedObject<ObjT>)
236 if constexpr (RegionObject<ObjT>)
238 obj->name ()->setName (*name_);
242 obj->name ()->setName (*name_);
249 if constexpr (std::is_same_v<ObjT, MidiNote>)
251 obj->setPitch (*pitch_);
257 if constexpr (std::is_same_v<ObjT, MidiNote>)
259 obj->setVelocity (*velocity_);
263 if (automatable_value_)
265 if constexpr (std::is_same_v<ObjT, AutomationPoint>)
267 obj->setValue (
static_cast<float> (*automatable_value_));
273 if constexpr (std::is_same_v<ObjT, ScaleObject>)
275 obj->setScale (scale_.release ());
279 if constexpr (std::is_same_v<ObjT, AutomationPoint>)
281 obj->curveOpts ()->setAlgorithm (
282 dependencies_.automation_curve_algorithm_provider_ ());
285 if (chord_descriptor_index_)
287 if constexpr (std::is_same_v<ObjT, ChordObject>)
289 obj->setChordDescriptorIndex (*chord_descriptor_index_);
297 Dependencies dependencies_;
298 std::optional<dsp::FileAudioSourceUuidReference> clip_id_;
299 std::optional<double> start_ticks_;
300 std::optional<double> end_ticks_;
301 std::optional<QString> name_;
302 std::optional<int> pitch_;
303 std::optional<double> automatable_value_;
304 std::optional<int> chord_descriptor_index_;
305 utils::QObjectUniquePtr<dsp::MusicalScale> scale_;
306 std::optional<int> velocity_;
307 std::optional<Marker::MarkerType> marker_type_;
378 requires (!std::is_same_v<RegionT, structure::arrangement::AudioRegion>)
380 using ChildT =
typename RegionT::ArrangerObjectChildType;
382 std::move (get_builder<ChildT> ().with_start_ticks (startTicks));
383 if constexpr (std::is_same_v<ChildT, MidiNote>)
385 const auto ival = std::get<int> (value);
386 assert (ival >= 0 && ival < 128);
387 builder.with_pitch (ival);
389 else if constexpr (std::is_same_v<ChildT, AutomationPoint>)
391 builder.with_automatable_value (std::get<double> (value));
393 else if constexpr (std::is_same_v<ChildT, ChordObject>)
395 builder.with_chord_descriptor (std::get<int> (value));
397 return builder.build_in_registry ();