Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
chord_track.h
1// SPDX-FileCopyrightText: © 2018-2020, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "structure/arrangement/arranger_object_owner.h"
7#include "structure/arrangement/chord_region.h"
8#include "structure/arrangement/scale_object.h"
9#include "structure/tracks/track.h"
10
11namespace zrythm::structure::tracks
12{
17class ChordTrack
18 : public Track,
19 public arrangement::ArrangerObjectOwner<arrangement::ChordRegion>,
20 public arrangement::ArrangerObjectOwner<arrangement::ScaleObject>
21{
22 Q_OBJECT
23 QML_ELEMENT
24 QML_UNCREATABLE ("")
25 DEFINE_ARRANGER_OBJECT_OWNER_QML_PROPERTIES (
26 ChordTrack,
27 chordRegions,
29 DEFINE_ARRANGER_OBJECT_OWNER_QML_PROPERTIES (
30 ChordTrack,
31 scaleObjects,
33
34public:
35 using ScaleObject = arrangement::ScaleObject;
36 using ChordRegion = arrangement::ChordRegion;
37 using ChordObject = arrangement::ChordObject;
38 using ScaleObjectPtr = ScaleObject *;
39 using NotePitchToChordDescriptorFunc =
40 dsp::MidiEventVector::NotePitchToChordDescriptorFunc;
41
42 ChordTrack (FinalTrackDependencies dependencies);
43
44 // ========================================================================
45 // QML Interface
46 // ========================================================================
47
48 // ========================================================================
49
51 note_pitch_to_chord_descriptor (midi_byte_t note_pitch) const
52 {
53 assert (note_pitch_to_descriptor_.has_value ());
54 return std::invoke (*note_pitch_to_descriptor_, note_pitch);
55 }
56
57 // FIXME: eventually this dependency should be injected via a constructor
58 // argument
59 void set_note_pitch_to_descriptor_func (NotePitchToChordDescriptorFunc func)
60 {
61 note_pitch_to_descriptor_ = func;
62 }
63
64 ScaleObject * get_scale_at (size_t index) const;
65
70 ChordObject * get_chord_at_ticks (units::precise_tick_t timeline_ticks) const;
71
76 ScaleObject * get_scale_at_ticks (units::precise_tick_t timeline_ticks) const;
77
78 friend void init_from (
79 ChordTrack &obj,
80 const ChordTrack &other,
81 utils::ObjectCloneType clone_type);
82
83 std::string
84 get_field_name_for_serialization (const ChordRegion *) const override
85 {
86 return "regions";
87 }
88 std::string
89 get_field_name_for_serialization (const ScaleObject *) const override
90 {
91 return "scales";
92 }
93
94private:
95 friend void to_json (nlohmann::json &j, const ChordTrack &track)
96 {
97 to_json (j, static_cast<const Track &> (track));
98 to_json (j, static_cast<const ArrangerObjectOwner<ChordRegion> &> (track));
99 to_json (j, static_cast<const ArrangerObjectOwner<ScaleObject> &> (track));
100 }
101 friend void from_json (const nlohmann::json &j, ChordTrack &track)
102 {
103 from_json (j, static_cast<Track &> (track));
104 from_json (j, static_cast<ArrangerObjectOwner<ChordRegion> &> (track));
105 from_json (j, static_cast<ArrangerObjectOwner<ScaleObject> &> (track));
106 }
107
108 bool initialize ();
109 void set_playback_caches () override;
110
111private:
112 std::optional<dsp::MidiEventVector::NotePitchToChordDescriptorFunc>
113 note_pitch_to_descriptor_;
114};
115
116} // namespace zrythm::structure::tracks
A ChordDescriptor describes a chord and is not linked to any specific object by itself.
The ChordObject class represents a chord inside the chord editor.
ChordObject * get_chord_at_ticks(units::precise_tick_t timeline_ticks) const
Returns the ChordObject at the given Position in the TimelineArranger.
ScaleObject * get_scale_at_ticks(units::precise_tick_t timeline_ticks) const
Returns the ScaleObject at the given Position in the TimelineArranger.
Track(Type type, PortType in_signal_type, PortType out_signal_type, TrackFeatures enabled_features, BaseTrackDependencies dependencies)
Constructor to be used by subclasses.
virtual void set_playback_caches()
Set the playback caches for a track.
Definition track.h:570
uint8_t midi_byte_t
MIDI byte.
Definition types.h:55