Krotos Modules 3
Loading...
Searching...
No Matches
SampleDataTree.h
Go to the documentation of this file.
1namespace krotos
2{
9 {
10 public:
11 struct Type
12 {
13 static const Identifier Samples;
14 static const Identifier Sample;
15 };
16
17 struct Property
18 {
19 static const Identifier Name;
20 static const Identifier Path;
21 static const Identifier Selection;
22 static const Identifier Mute;
23 static const Identifier Solo;
24
25 // The current index of the sample playback queue.
26 static const Identifier SampleIndex;
27 // The index of the last sample selected by the user.
28 static const Identifier SelectedSample;
29 };
30
37 class Sample : public ValueTree::Listener
38 {
39 public:
45 Sample(ValueTree tree, UndoManager* undoManager = nullptr);
46
50 std::function<void(Identifier parameterProperty, const var& value)> onChanged{nullptr};
54 std::function<void()> muteChanged{nullptr};
55 std::function<void()> soloChanged{nullptr};
56
57 void valueTreePropertyChanged(ValueTree& treeWhosePropertyHasChanged, const Identifier& property) override;
61 int getIndex() const
62 {
63 return valueTree.getParent().isValid() ? valueTree.getParent().indexOf(valueTree) : 0;
64 };
65
66 CachedValue<bool> muteValue;
67 CachedValue<bool> soloValue;
68 CachedValue<String> pathValue;
69 CachedValue<String> nameValue;
70 ValueTree valueTree;
71
72 private:
73 UndoManager* m_undoManager{nullptr};
74
75 JUCE_LEAK_DETECTOR(Sample)
76 };
77
83
88 SamplesTree(const Identifier& type);
89
94 SamplesTree(const SamplesTree& other);
95
101 SamplesTree(const ValueTree& other);
102
106 SamplesTree& operator=(const SamplesTree& other);
107
115 void updateSample(const String& name, const String& path);
116
123 void addSample(const String& name, const String& path, bool isMuted);
124
130 Sample getSample(const String& name);
131
135 void removeSample(const String& name);
136
137 void removeSample(int index);
138
139 // Function to return a read only reference to m_samples
140 const OwnedArray<Sample>& getSamples() const { return m_samples; }
141
145 const int getNumSamples() const { return m_parameterTree.getNumChildren(); };
146
151 std::function<void(Sample& newSample)> sampleAdded{nullptr};
155 std::function<void(ValueTree& childWhichHasBeenRemoved, int indexFromWhichChildWasRemoved)> sampleRemoved{
156 nullptr};
157
175 std::function<void()> dropCompleted;
176
181 std::function<void(int sampleIndex)> sampleIndexChanged;
182
187 std::function<void(int sampleIndex)> selectedSampleChanged;
188
195 const StringArray getFiles() const;
196
202 void setSampleSelection(int index, const Range<int> selection);
203
209 Range<int> getSampleSelection(int index) const;
210
216 std::vector<Range<int>> getSampleSelections() const;
222 void setSampleSelections(const std::vector<Range<int>>& selections);
223
230 static String rangeToString(const Range<int>& range);
238 static Range<int> stringToRange(const String& rangeString);
239
245 OwnedArray<SampleBrowser::Sample> getSampleDataAsBrowserSamples();
246
250 void setSampleIndex(int index);
251
255 CachedValue<int> sampleIndexValue;
256
260 CachedValue<int> selectedSampleValue;
261
271 static Result rewriteSamplePaths(ValueTree& engineKwidgetTree, File newAbsolutePath);
272
273 private:
274 void valueTreeChildAdded(ValueTree& parentTree, ValueTree& childWhichHasBeenAdded) override;
275
276 void valueTreeParentChanged(ValueTree& treeWhoseParentHasChanged) override;
277
278 void valueTreeChildRemoved(ValueTree& parentTree, ValueTree& childWhichHasBeenRemoved,
279 int indexFromWhichChildWasRemoved) override;
280
281 void valueTreePropertyChanged(ValueTree& treeWhosePropertyHasChanged, const Identifier& property) override;
282
283 OwnedArray<Sample> m_samples;
284 static constexpr const char* m_rangeDelimiter{":"};
285
286 JUCE_LEAK_DETECTOR(SamplesTree)
287 };
288} // namespace krotos
Definition CustomParameterTree.h:15
ValueTree m_parameterTree
Definition CustomParameterTree.h:113
A wrapper around an individual sample in the tree, with parameters for mute, solo,...
Definition SampleDataTree.h:38
CachedValue< bool > soloValue
Definition SampleDataTree.h:67
UndoManager * m_undoManager
Definition SampleDataTree.h:73
ValueTree valueTree
Definition SampleDataTree.h:70
std::function< void()> muteChanged
Assign a lambda to this to get a callback when the mute parameter changes.
Definition SampleDataTree.h:54
Sample(ValueTree tree, UndoManager *undoManager=nullptr)
Creates a Sample wrapper object.
Definition SampleDataTree.cpp:247
CachedValue< bool > muteValue
Definition SampleDataTree.h:66
CachedValue< String > pathValue
Definition SampleDataTree.h:68
std::function< void()> soloChanged
Definition SampleDataTree.h:55
std::function< void(Identifier parameterProperty, const var &value)> onChanged
Assign a lambda to be called when the sample is changed.
Definition SampleDataTree.h:50
int getIndex() const
Returns the index of the sample within the parent tree.
Definition SampleDataTree.h:61
void valueTreePropertyChanged(ValueTree &treeWhosePropertyHasChanged, const Identifier &property) override
Definition SampleDataTree.cpp:257
CachedValue< String > nameValue
Definition SampleDataTree.h:69
A CustomParameterTree for managing a list of samples, with parameters for mute, solo,...
Definition SampleDataTree.h:9
void valueTreeParentChanged(ValueTree &treeWhoseParentHasChanged) override
Definition SampleDataTree.cpp:226
void setSampleIndex(int index)
Set the current index of the sample playback queue.
Definition SampleDataTree.cpp:193
std::function< void()> dropCompleted
Assign this to do something once a "drop" action has been completed. This is called internally by the...
Definition SampleDataTree.h:175
std::function< void(int sampleIndex)> sampleIndexChanged
Assign a lambda to this callback to do something when the sample_index property has been changed.
Definition SampleDataTree.h:181
void valueTreePropertyChanged(ValueTree &treeWhosePropertyHasChanged, const Identifier &property) override
Definition SampleDataTree.cpp:234
void valueTreeChildAdded(ValueTree &parentTree, ValueTree &childWhichHasBeenAdded) override
Definition SampleDataTree.cpp:204
static String rangeToString(const Range< int > &range)
Converts a range to a string in the format "start:end:length". Convert it back using stringToRange.
Definition SampleDataTree.cpp:165
std::function< void(Sample &newSample)> sampleAdded
Assign this to do something when a sample has been added to the tree.
Definition SampleDataTree.h:151
OwnedArray< Sample > m_samples
Definition SampleDataTree.h:283
const OwnedArray< Sample > & getSamples() const
Definition SampleDataTree.h:140
static constexpr const char * m_rangeDelimiter
Definition SampleDataTree.h:284
CachedValue< int > sampleIndexValue
Get the current index of the sample playback queue.
Definition SampleDataTree.h:255
void valueTreeChildRemoved(ValueTree &parentTree, ValueTree &childWhichHasBeenRemoved, int indexFromWhichChildWasRemoved) override
Definition SampleDataTree.cpp:215
OwnedArray< SampleBrowser::Sample > getSampleDataAsBrowserSamples()
Helper function to return an array of SampleBrowser::Sample objects populated from the SamplesTree....
Definition SampleDataTree.cpp:180
SamplesTree()
Creates a SamplesTree with a predefined type of Type::Samples.
Definition SampleDataTree.cpp:14
void removeSample(const String &name)
Removes a sample from the tree by name.
Definition SampleDataTree.cpp:116
CachedValue< int > selectedSampleValue
The index of the last sample to be selected by the user.
Definition SampleDataTree.h:260
void setSampleSelections(const std::vector< Range< int > > &selections)
Set the selection ranges for all samples in the tree. The index of the selection range in the vector ...
Definition SampleDataTree.cpp:157
Sample getSample(const String &name)
Returns a Sample object from the tree by name. This is a wrapper around the ValueTree object with typ...
void updateSample(const String &name, const String &path)
Updates a sample in the tree with a new name and path. If the sample exists, it's name and path will ...
Definition SampleDataTree.cpp:85
const int getNumSamples() const
Returns the number of samples in the samples tree.
Definition SampleDataTree.h:145
void addSample(const String &name, const String &path, bool isMuted)
Add a new sample into the tree.
Definition SampleDataTree.cpp:98
void setSampleSelection(int index, const Range< int > selection)
Set the selection range for a sample by index.
Definition SampleDataTree.cpp:134
static Range< int > stringToRange(const String &rangeString)
Converts a string to a range. The expected string is one generated from rangeToString....
Definition SampleDataTree.cpp:171
std::vector< Range< int > > getSampleSelections() const
Get the selection ranges for all samples in the tree. The index of the selection range in the vector ...
Definition SampleDataTree.cpp:145
std::function< void(ValueTree &childWhichHasBeenRemoved, int indexFromWhichChildWasRemoved)> sampleRemoved
Assign this to do something when a sample has been removed from the tree.
Definition SampleDataTree.h:155
const StringArray getFiles() const
Compatibility method for KrotosSampleOscillatorSound which requires samples to be loaded all at once ...
Definition SampleDataTree.cpp:122
Range< int > getSampleSelection(int index) const
Get the selection range for a sample by index.
Definition SampleDataTree.cpp:140
static Result rewriteSamplePaths(ValueTree &engineKwidgetTree, File newAbsolutePath)
Rewrite relative SamplePath path values created by the PresetBundler into absolute ones of a given pa...
Definition SampleDataTree.cpp:281
std::function< void(int sampleIndex)> selectedSampleChanged
Assign a lambda to this callback to do something when the selected_sample property has been changed.
Definition SampleDataTree.h:187
SamplesTree & operator=(const SamplesTree &other)
Copy assignment operator.
Definition SampleDataTree.cpp:68
Definition AirAbsorptionFilter.cpp:2
Definition SampleDataTree.h:18
static const Identifier Path
Definition SampleDataTree.h:20
static const Identifier Selection
Definition SampleDataTree.h:21
static const Identifier SelectedSample
Definition SampleDataTree.h:28
static const Identifier SampleIndex
Definition SampleDataTree.h:26
static const Identifier Name
Definition SampleDataTree.h:19
static const Identifier Solo
Definition SampleDataTree.h:23
static const Identifier Mute
Definition SampleDataTree.h:22
Definition SampleDataTree.h:12
static const Identifier Sample
Definition SampleDataTree.h:14
static const Identifier Samples
Definition SampleDataTree.h:13