tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_EditItem.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
14//==============================================================================
19{
20 EditItemID() = default;
21 EditItemID (const EditItemID&) = default;
22 EditItemID& operator= (const EditItemID&) = default;
23
24 bool isValid() const noexcept { return itemID != 0; }
25 bool isInvalid() const noexcept { return itemID == 0; }
26
27 static EditItemID fromID (const juce::ValueTree&);
28 static EditItemID readOrCreateNewID (Edit&, const juce::ValueTree&);
29 void writeID (juce::ValueTree&, juce::UndoManager*) const;
30
31 static EditItemID fromVar (const juce::var&);
32 static EditItemID fromString (const juce::String&);
33 static EditItemID fromProperty (const juce::ValueTree&, const juce::Identifier&);
34 static EditItemID fromXML (const juce::XmlElement&, const char* attributeName);
35 static EditItemID fromXML (const juce::XmlElement&, const juce::Identifier&);
36
37 static EditItemID findFirstIDNotIn (const std::vector<EditItemID>& existingIDsSorted,
38 uint64_t startFrom = 1001);
39
40 void setProperty (juce::ValueTree&, const juce::Identifier&, juce::UndoManager*) const;
41 void setXML (juce::XmlElement&, const juce::Identifier& attributeName) const;
42 void setXML (juce::XmlElement&, const char* attributeName) const;
43
44 operator juce::var() const { return toVar(); }
45 juce::var toVar() const;
46 juce::String toString() const;
47
48 uint64_t getRawID() const noexcept { return itemID; }
49 static EditItemID fromRawID (uint64_t);
50
51 bool operator== (EditItemID other) const noexcept { return itemID == other.itemID; }
52 bool operator!= (EditItemID other) const noexcept { return itemID != other.itemID; }
53 bool operator< (EditItemID other) const noexcept { return itemID < other.itemID; }
54
55 static juce::Array<EditItemID> parseStringList (const juce::String& list);
56 static juce::String listToString (const juce::Array<EditItemID>& list);
57
58 //==============================================================================
59 static std::vector<EditItemID> findAllIDs (const juce::XmlElement&);
60 static std::vector<EditItemID> findAllIDs (const juce::ValueTree&);
61
63
64 static void remapIDs (juce::XmlElement&, std::function<EditItemID()> createNewID, IDMap* remappedIDs = nullptr);
65 static void remapIDs (juce::XmlElement&, Edit&, IDMap* remappedIDs = nullptr);
66 static void remapIDs (juce::ValueTree&, juce::UndoManager*, std::function<EditItemID()> createNewID, IDMap* remappedIDs = nullptr);
67 static void remapIDs (juce::ValueTree&, juce::UndoManager*, Edit&, IDMap* remappedIDs = nullptr);
68
69 //==============================================================================
71 static std::function<void (juce::ValueTree&, const juce::Identifier& /*propertyName*/,
73
75 static std::function<void (juce::XmlElement&, const juce::String& /*propertyName*/,
77
78private:
79 uint64_t itemID = 0;
80};
81
82//==============================================================================
87{
88public:
90 virtual ~EditItem() = default;
91
92 //==============================================================================
93 Edit& edit;
94
97
98 virtual juce::String getName() const = 0;
99
100private:
102};
103
104
105//==============================================================================
107template<typename EditItemType>
109{
110 EditItemCache() = default;
111 ~EditItemCache() { jassert (knownEditItems.empty()); }
112
113 EditItemType* findItem (EditItemID id) const
114 {
115 auto o = knownEditItems.find (id);
116
117 if (o != knownEditItems.cend())
118 return o->second;
119
120 return {};
121 }
122
123 template<typename Visitor>
124 void visitItems (Visitor&& visitor) const
125 {
126 for (auto iter : knownEditItems)
127 std::forward<Visitor> (visitor)(iter.second);
128 }
129
130 void addItem (EditItemType& item)
131 {
132 jassert (knownEditItems.find (item.itemID) == knownEditItems.end());
133
134 if (item.itemID.isValid())
135 knownEditItems[item.itemID] = &item;
136 }
137
138 void removeItem (EditItemType& item)
139 {
140 if (item.itemID.isValid())
141 knownEditItems.erase (item.itemID);
142 }
143
144private:
146
148};
149
150}} // namespace tracktion { inline namespace engine
151
152namespace juce
153{
154 template <>
155 struct VariantConverter<tracktion::engine::EditItemID>
156 {
157 static tracktion::engine::EditItemID fromVar (const juce::var& v) { return tracktion::engine::EditItemID::fromVar (v); }
158 static juce::var toVar (const tracktion::engine::EditItemID& v) { return juce::var ((juce::int64) v.getRawID()); }
159 };
160}
161
162#ifndef DOXYGEN
163namespace std
164{
165 template<>
166 struct hash<tracktion::engine::EditItemID>
167 {
168 size_t operator() (const tracktion::engine::EditItemID& e) const noexcept { return (size_t) e.getRawID(); }
169 };
170}
171#endif
Base class for objects that live inside an edit - e.g.
const EditItemID itemID
Every EditItem has an ID which is unique within the edit.
The Tracktion Edit class!
T is_pointer_v
#define jassert(expression)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
long long int64
size_t hash(size_t seed, const T &v)
Hashes a type with a given seed and returns the new hash value.
T operator()(T... args)
typedef uint64_t
ID for objects of type EditElement - e.g.
static std::function< void(juce::ValueTree &, const juce::Identifier &, const std::map< juce::String, EditItemID > &, juce::UndoManager *)> applyNewIDsToExternalValueTree
Callback that can be set in order to update any reassigned IDs in ValueTree client code.
static std::function< void(juce::XmlElement &, const juce::String &, const std::map< juce::String, EditItemID > &)> applyNewIDsToExternalXML
Callback that can be set in order to update any reassigned IDs in XML client code.