Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
chord_preset_pack.h
1// SPDX-FileCopyrightText: © 2022, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#ifndef __SETTINGS_CHORD_PRESET_PACK_H__
5#define __SETTINGS_CHORD_PRESET_PACK_H__
6
7#include "zrythm-config.h"
8
9#include <utility>
10
11#include "gui/backend/backend/settings/chord_preset.h"
12#include "utils/format.h"
13#include "utils/icloneable.h"
14
20
24class ChordPresetPack : public QObject
25{
26 Q_OBJECT
27 Q_PROPERTY (QString name READ getName WRITE setName NOTIFY nameChanged)
28 QML_ELEMENT
29
30public:
31 using NameT = QString;
32 ChordPresetPack (QObject * parent = nullptr);
33 ChordPresetPack (
34 const NameT &name,
35 bool is_standard,
36 QObject * parent = nullptr);
37
38 // ====================================================================
39 // QML Interface
40 // ====================================================================
41
42 QString getName () const { return name_; }
43 void setName (const QString &name);
44 Q_SIGNAL void nameChanged (const QString &name);
45
46 // ============================================================================
47
48 std::string get_document_type () const { return "Zrythm Chord Preset Pack"; }
49 int get_format_major_version () const { return 2; }
50 int get_format_minor_version () const { return 0; }
51
52 friend void init_from (
53 ChordPresetPack &obj,
54 const ChordPresetPack &other,
55 utils::ObjectCloneType clone_type);
56
57 bool contains_name (const NameT &name) const;
58
59 bool contains_preset (const ChordPreset &pset) const;
60
61 void add_preset (const ChordPreset &pset);
62
63 void delete_preset (const ChordPreset &pset);
64
65 int get_preset_index (const ChordPreset &pset) const
66 {
67 auto it = std::ranges::find (presets_, &pset);
68 z_return_val_if_fail (it != presets_.end (), -1);
69 return static_cast<int> (std::distance (presets_.begin (), it));
70 }
71
72 // GMenuModel * generate_context_menu () const;
73
74private:
75 static constexpr std::string_view kNameKey = "name";
76 static constexpr std::string_view kPresetsKey = "presets";
77 static constexpr std::string_view kIsStandardKey = "isStandard";
78 friend void to_json (nlohmann::json &j, const ChordPresetPack &pack)
79 {
80 j[kNameKey] = pack.name_;
81 j[kPresetsKey] = pack.presets_;
82 j[kIsStandardKey] = pack.is_standard_;
83 }
84 friend void from_json (const nlohmann::json &j, ChordPresetPack &pack)
85 {
86 j.at (kNameKey).get_to (pack.name_);
87 for (const auto &pset : j.at (kPresetsKey))
88 {
89 // TODO: check if this is correct
90 auto * pset_ptr = new ChordPreset (&pack);
91 from_json (pset, *pset_ptr);
92 pack.presets_.push_back (pset_ptr);
93 }
94 j.at (kIsStandardKey).get_to (pack.is_standard_);
95 }
96
97public:
99 NameT name_;
100
102 std::vector<ChordPreset *> presets_;
103
105 bool is_standard_ = false;
106};
107
108inline bool
109operator== (const ChordPresetPack &lhs, const ChordPresetPack &rhs)
110{
111 return lhs.name_ == rhs.name_ && lhs.presets_ == rhs.presets_
112 && lhs.is_standard_ == rhs.is_standard_;
113}
114
118
119#endif
Chord preset pack.
NameT name_
Pack name.
std::vector< ChordPreset * > presets_
Presets.
bool is_standard_
Whether this is a standard preset pack (not user-defined).
A preset of chord descriptors.