Krotos Modules 3
Loading...
Searching...
No Matches
krotos::SamplesTree Class Reference

A CustomParameterTree for managing a list of samples, with parameters for mute, solo, path and name. Defines the Types and Properties used within their respective structs as well as methods for getting/setting/serialising data. More...

#include <SampleDataTree.h>

Inheritance diagram for krotos::SamplesTree:
krotos::CustomParameterTree

Classes

struct  Property
 
class  Sample
 A wrapper around an individual sample in the tree, with parameters for mute, solo, path and name. You can set these values directly and their value in the tree will be updated, and listeners will be called. More...
 
struct  Type
 

Public Member Functions

 SamplesTree ()
 Creates a SamplesTree with a predefined type of Type::Samples.
 
 SamplesTree (const Identifier &type)
 Creates a SamplesTree of a given type.
 
 SamplesTree (const SamplesTree &other)
 Copy constructor, creates a copy of a SamplesTree and populates Samples object array.
 
 SamplesTree (const ValueTree &other)
 Creates a SamplesTree from a ValueTree. Expects the input tree to have a child tree of type Type::Samples.
 
SamplesTreeoperator= (const SamplesTree &other)
 Copy assignment operator.
 
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 be updated. If it does not, it is added.
 
void addSample (const String &name, const String &path, bool isMuted)
 Add a new sample into the tree.
 
Sample getSample (const String &name)
 Returns a Sample object from the tree by name. This is a wrapper around the ValueTree object with type safe variables you can use to get/set the sample's properties.
 
void removeSample (const String &name)
 Removes a sample from the tree by name.
 
void removeSample (int index)
 
const OwnedArray< Sample > & getSamples () const
 
const int getNumSamples () const
 Returns the number of samples in the samples tree.
 
const StringArray getFiles () const
 Compatibility method for KrotosSampleOscillatorSound which requires samples to be loaded all at once as a StringArray of paths.
 
void setSampleSelection (int index, const Range< int > selection)
 Set the selection range for a sample by index.
 
Range< int > getSampleSelection (int index) const
 Get the selection range for a sample by index.
 
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 corresponds to the index of the sample in the tree.
 
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 corresponds to the index of the sample in the tree.
 
OwnedArray< SampleBrowser::SamplegetSampleDataAsBrowserSamples ()
 Helper function to return an array of SampleBrowser::Sample objects populated from the SamplesTree. Assigns the Value object references so these will update and listen to the tree values.
 
void setSampleIndex (int index)
 Set the current index of the sample playback queue.
 
- Public Member Functions inherited from krotos::CustomParameterTree
 CustomParameterTree (const Identifier &type, UndoManager *undoManager=nullptr)
 
 CustomParameterTree (ValueTree customTree, UndoManager *undoManager=nullptr)
 
 CustomParameterTree (const CustomParameterTree &other)
 
 ~CustomParameterTree () override
 
CustomParameterTreeoperator= (const CustomParameterTree &other)
 
bool operator== (const CustomParameterTree &other) const
 
bool isValid () const
 
void setUndoManager (UndoManager *um)
 
UndoManager * getUndoManager () const
 
const ValueTree & getParameterTree () const
 
const Identifier getType () const
 
void addChild (const ValueTree &child, int index=-1)
 
ValueTree getChild (int index) const
 
ValueTree getChildWithName (const Identifier &type) const
 
void removeChild (const ValueTree &child)
 
void removeAllChildren ()
 Removes all children from the tree.
 

Static Public Member Functions

static String rangeToString (const Range< int > &range)
 Converts a range to a string in the format "start:end:length". Convert it back using stringToRange.
 
static Range< int > stringToRange (const String &rangeString)
 Converts a string to a range. The expected string is one generated from rangeToString. Convert it back using rangeToString.
 
static Result rewriteSamplePaths (ValueTree &engineKwidgetTree, File newAbsolutePath)
 Rewrite relative SamplePath path values created by the PresetBundler into absolute ones of a given path. It also clears the legacy SamplePaths parameter value, as it doesn't need to be re-written and will cause problems if left.
 

Public Attributes

std::function< void(Sample &newSample)> sampleAdded {nullptr}
 Assign this to do something when a sample has been added to the tree.
 
std::function< void(ValueTree &childWhichHasBeenRemoved, int indexFromWhichChildWasRemoved)> sampleRemoved
 Assign this to do something when a sample has been removed from the tree.
 
std::function< void()> dropCompleted
 Assign this to do something once a "drop" action has been completed. This is called internally by the ValueTree listener when the parent tree is changed, i.e. During state recall. You may call it yourself to notify that a batch of samples has been changed.
 
std::function< void(int sampleIndex)> sampleIndexChanged
 Assign a lambda to this callback to do something when the sample_index property has been changed.
 
std::function< void(int sampleIndex)> selectedSampleChanged
 Assign a lambda to this callback to do something when the selected_sample property has been changed.
 
CachedValue< int > sampleIndexValue
 Get the current index of the sample playback queue.
 
CachedValue< int > selectedSampleValue
 The index of the last sample to be selected by the user.
 
- Public Attributes inherited from krotos::CustomParameterTree
std::function< void(ValueTree &treeWhosePropertyHasChanged, const Identifier &property)> propertyChanged
 
std::function< void(ValueTree &parentTree, ValueTree &childWhichHasBeenAdded)> childAdded
 
std::function< void(ValueTree &parentTree, ValueTree &childWhichHasBeenRemoved, int indexFromWhichChildWasRemoved)> childRemoved
 

Private Member Functions

void valueTreeChildAdded (ValueTree &parentTree, ValueTree &childWhichHasBeenAdded) override
 
void valueTreeParentChanged (ValueTree &treeWhoseParentHasChanged) override
 
void valueTreeChildRemoved (ValueTree &parentTree, ValueTree &childWhichHasBeenRemoved, int indexFromWhichChildWasRemoved) override
 
void valueTreePropertyChanged (ValueTree &treeWhosePropertyHasChanged, const Identifier &property) override
 

Private Attributes

OwnedArray< Samplem_samples
 

Static Private Attributes

static constexpr const char * m_rangeDelimiter {":"}
 

Additional Inherited Members

- Protected Attributes inherited from krotos::CustomParameterTree
ValueTree m_parameterTree
 

Detailed Description

A CustomParameterTree for managing a list of samples, with parameters for mute, solo, path and name. Defines the Types and Properties used within their respective structs as well as methods for getting/setting/serialising data.

Constructor & Destructor Documentation

◆ SamplesTree() [1/4]

krotos::SamplesTree::SamplesTree ( )

Creates a SamplesTree with a predefined type of Type::Samples.

◆ SamplesTree() [2/4]

krotos::SamplesTree::SamplesTree ( const Identifier & type)

Creates a SamplesTree of a given type.

Parameters
typeThe type of the tree.

◆ SamplesTree() [3/4]

krotos::SamplesTree::SamplesTree ( const SamplesTree & other)

Copy constructor, creates a copy of a SamplesTree and populates Samples object array.

◆ SamplesTree() [4/4]

krotos::SamplesTree::SamplesTree ( const ValueTree & other)

Creates a SamplesTree from a ValueTree. Expects the input tree to have a child tree of type Type::Samples.

Parameters
otherThe ValueTree to create the SamplesTree from.

Member Function Documentation

◆ addSample()

void krotos::SamplesTree::addSample ( const String & name,
const String & path,
bool isMuted )

Add a new sample into the tree.

Parameters
nameThe name of the sample.
pathThe path of the sample.
isMutedShould the sample be muted on addition?

◆ getFiles()

const StringArray krotos::SamplesTree::getFiles ( ) const

Compatibility method for KrotosSampleOscillatorSound which requires samples to be loaded all at once as a StringArray of paths.

Returns
A StringArray of all sample paths in the tree. Note that these paths may require conversion to the target platform.
See also
AssetManager::convertFilePath

◆ getNumSamples()

const int krotos::SamplesTree::getNumSamples ( ) const
inline

Returns the number of samples in the samples tree.

◆ getSample()

Sample krotos::SamplesTree::getSample ( const String & name)

Returns a Sample object from the tree by name. This is a wrapper around the ValueTree object with type safe variables you can use to get/set the sample's properties.

◆ getSampleDataAsBrowserSamples()

OwnedArray< SampleBrowser::Sample > krotos::SamplesTree::getSampleDataAsBrowserSamples ( )

Helper function to return an array of SampleBrowser::Sample objects populated from the SamplesTree. Assigns the Value object references so these will update and listen to the tree values.

Returns
An OwnedArray of SampleBrowser::Sample objects.

◆ getSamples()

const OwnedArray< Sample > & krotos::SamplesTree::getSamples ( ) const
inline

◆ getSampleSelection()

Range< int > krotos::SamplesTree::getSampleSelection ( int index) const

Get the selection range for a sample by index.

Parameters
indexThe index of the sample in the tree.
Returns
The range of the selection.

◆ getSampleSelections()

std::vector< Range< int > > krotos::SamplesTree::getSampleSelections ( ) const

Get the selection ranges for all samples in the tree. The index of the selection range in the vector corresponds to the index of the sample in the tree.

Returns
A vector of selection ranges.

◆ operator=()

SamplesTree & krotos::SamplesTree::operator= ( const SamplesTree & other)

Copy assignment operator.

◆ rangeToString()

String krotos::SamplesTree::rangeToString ( const Range< int > & range)
static

Converts a range to a string in the format "start:end:length". Convert it back using stringToRange.

Parameters
rangeThe range to convert.
Returns
The range as a string in the format "start:end:length"

◆ removeSample() [1/2]

void krotos::SamplesTree::removeSample ( const String & name)

Removes a sample from the tree by name.

◆ removeSample() [2/2]

void krotos::SamplesTree::removeSample ( int index)

◆ rewriteSamplePaths()

Result krotos::SamplesTree::rewriteSamplePaths ( ValueTree & engineKwidgetTree,
File newAbsolutePath )
static

Rewrite relative SamplePath path values created by the PresetBundler into absolute ones of a given path. It also clears the legacy SamplePaths parameter value, as it doesn't need to be re-written and will cause problems if left.

Parameters
engineKwidgetTreeThe ValueTree of the engine kwidget. This kwidget should have a SamplesTree as a child of it's CustomParameter tree.
newAbsolutePathThe new absolute filepath to re-write the paths from.
Returns
The result of the operation.

◆ setSampleIndex()

void krotos::SamplesTree::setSampleIndex ( int index)

Set the current index of the sample playback queue.

◆ setSampleSelection()

void krotos::SamplesTree::setSampleSelection ( int index,
const Range< int > selection )

Set the selection range for a sample by index.

Parameters
indexThe index of the sample in the tree.
selectionThe range of the selection.

◆ setSampleSelections()

void krotos::SamplesTree::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 corresponds to the index of the sample in the tree.

Parameters
selectionsA vector of selection ranges.

◆ stringToRange()

Range< int > krotos::SamplesTree::stringToRange ( const String & rangeString)
static

Converts a string to a range. The expected string is one generated from rangeToString. Convert it back using rangeToString.

Parameters
rangeStringThe range string to convert, in the format "start:end:length".
Returns
The range object.

◆ updateSample()

void krotos::SamplesTree::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 be updated. If it does not, it is added.

Parameters
nameThe name of the sample.
pathThe path of the sample/

◆ valueTreeChildAdded()

void krotos::SamplesTree::valueTreeChildAdded ( ValueTree & parentTree,
ValueTree & childWhichHasBeenAdded )
overrideprivatevirtual

Reimplemented from krotos::CustomParameterTree.

◆ valueTreeChildRemoved()

void krotos::SamplesTree::valueTreeChildRemoved ( ValueTree & parentTree,
ValueTree & childWhichHasBeenRemoved,
int indexFromWhichChildWasRemoved )
overrideprivatevirtual

Reimplemented from krotos::CustomParameterTree.

◆ valueTreeParentChanged()

void krotos::SamplesTree::valueTreeParentChanged ( ValueTree & treeWhoseParentHasChanged)
overrideprivate

◆ valueTreePropertyChanged()

void krotos::SamplesTree::valueTreePropertyChanged ( ValueTree & treeWhosePropertyHasChanged,
const Identifier & property )
overrideprivatevirtual

Reimplemented from krotos::CustomParameterTree.

Member Data Documentation

◆ dropCompleted

std::function<void()> krotos::SamplesTree::dropCompleted

Assign this to do something once a "drop" action has been completed. This is called internally by the ValueTree listener when the parent tree is changed, i.e. During state recall. You may call it yourself to notify that a batch of samples has been changed.

Note that when copying a SamplesTree, the lambda will be copied as well.

This exists in order to support the current mechanism for sample loading into the KrotosSynthesiser which requires an array of sample paths to be passed via a single call, to load them all at once.

Call this after a batch of files has been added to the tree, and use getFiles() to retrieve the file path list as a string array

Todo: Deprecate once KrotosSampleOscillatorSound has been updated to allow efficient sequential sample loading

◆ m_rangeDelimiter

const char* krotos::SamplesTree::m_rangeDelimiter {":"}
staticconstexprprivate

◆ m_samples

OwnedArray<Sample> krotos::SamplesTree::m_samples
private

◆ sampleAdded

std::function<void(Sample& newSample)> krotos::SamplesTree::sampleAdded {nullptr}

Assign this to do something when a sample has been added to the tree.

◆ sampleIndexChanged

std::function<void(int sampleIndex)> krotos::SamplesTree::sampleIndexChanged

Assign a lambda to this callback to do something when the sample_index property has been changed.

Parameters
indexThe current sample index.

◆ sampleIndexValue

CachedValue<int> krotos::SamplesTree::sampleIndexValue

Get the current index of the sample playback queue.

◆ sampleRemoved

std::function<void(ValueTree& childWhichHasBeenRemoved, int indexFromWhichChildWasRemoved)> krotos::SamplesTree::sampleRemoved
Initial value:
{
nullptr}

Assign this to do something when a sample has been removed from the tree.

◆ selectedSampleChanged

std::function<void(int sampleIndex)> krotos::SamplesTree::selectedSampleChanged

Assign a lambda to this callback to do something when the selected_sample property has been changed.

Parameters
indexThe selected sample index.

◆ selectedSampleValue

CachedValue<int> krotos::SamplesTree::selectedSampleValue

The index of the last sample to be selected by the user.


The documentation for this class was generated from the following files: