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

#include <PresetBundler.h>

Classes

struct  AudioAsset
 

Public Member Functions

 PresetBundler (File preset)
 
 PresetBundler (ValueTree presetData)
 
bool createBundle (File outputLocation, String &errors)
 
int setMaximumBundleSizeInMegaBytes (int newSizeMb)
 
void setPresetFileExtension (String fileExtension)
 

Static Public Member Functions

static File openBundle (File bundleArchive)
 Extracts the contents of a bundle archive to the temporary "sandbox" directory.
 
static File getPresetFromBundleDirectory (File bundleDirectory)
 Locates the preset file within a given bundle directory.
 
static bool validateBundleDirectory (File bundleDirectory)
 Validates that a given directory is a valid bundle directory by checking it is a child file of the sandbox directory.
 
static bool isABundlePreset (const File &preset)
 Returns whether this preset file is part of a bundle. This is just a simple check for that the provided file is a child of the sandbox directory that bundles are loaded into.
 
static File getSandboxDirectory ()
 Returns the path to the sandbox directory where the preset bundles are temporarily stored.
 
static File getSandboxDirectoryForBundle (const File &bundleFile)
 Returns the path to the sandbox directory for a particular bundle based on the name of the file being loaded, without extension. e.g.Fish.kspb would return "<sandbox>/Fish".
 
static File getAudioAssetDirectoryForBundle (const File &bundleFile)
 Returns the path to the audio assets directory for a particular bundle based on the name of the file being loaded, without extension. e.g.Fish.kspb would return "<sandbox>/Fish/Audio Assets".
 
static File getPresetDirectoryForBundle (const File &bundleFile)
 Returns the path to the preset directory for a particular bundle based on the name of the file being loaded, without extension. e.g.Fish.kspb would return "<sandbox>/Fish/Presets".
 

Static Public Attributes

static const String BundleFileExtension {".kspb"}
 The file extension for the bundle archive.
 
static const String PresetSubdirectory {"Presets"}
 
static const String AudioAssetsSubdirectory {"Audio Assets"}
 

Protected Member Functions

File getExportBundleRoot ()
 
bool createBundleFileStructure ()
 
void cleanUpFileStructure ()
 
std::vector< AudioAssetgetAssetsListFromPreset ()
 
File copyPresetForExport (String nameForPresetFile)
 
void copyAudioAssetsForExport ()
 
void processExportedPresetFile (File exportPreset)
 
File buildBundleArchive (String outputDirectoryPath)
 
int getEstimatedAssetsSizeMB ()
 
String listMissingFiles ()
 
std::vector< AudioAssetgetAssetFilepaths ()
 

Protected Attributes

String m_factoryAssetsDirectory
 

Private Member Functions

void initialise (ValueTree presetData)
 
void clenseExportIDs ()
 
bool isValueAudioFile (String value)
 
bool isValueMultipleFiles (String value)
 
void getPresetFilepaths (StringArray &listOfFiles, XmlElement widgetElement)
 
void findPathAttributesRecursive (StringArray &listOfFiles, XmlElement customParamsElement)
 
void replacePaths (XmlElement &widgetElement)
 
void replacePathRecursive (XmlElement &widgetElement)
 
String convertFilepath (String filepathFromPreset)
 

Private Attributes

String m_bundleRootId
 
ValueTree m_presetFile
 
std::vector< AudioAssetm_assetFilepaths
 
int m_maxSizeMegaBytes {1000}
 

Static Private Attributes

static String m_presetFileExtension {".ksp"}
 

Detailed Description

Creates preset bundle files (.kspb) for export/import

The resulting .ksp file will be a zip archive. It will contain the preset file and all the assets that preset uses. The class will search and collect audio assets via the preset:

  • It will and will recursively search every widget "CUSTOMPARAMS" branch
  • Stored data that end in .wav, .aif, .aiff, .ogg, .flac will be collected
  • If the audio path is stored in the wrong OS format, it will convert and find them
  • Every audio file will be saved in an asset ID folder (see file structure below)
  • There will be no duplicates of the same audio files, however, different files with identical names will be stored in separate asset ID folders
  • If an audio file contains characters that are not compatible on other OS they will be removed
  • The bundled preset will have path values replaced with the asset ID subfolder and the fixed filename (if needed)

Bundle file structure example: Example.kspb: Presets/ Example.ksp Audio Assets/ Asset1/Afile.wav Asset2/Anotherfile.wav

Constructor & Destructor Documentation

◆ PresetBundler() [1/2]

krotos::PresetBundler::PresetBundler ( File preset)
Parameters
presetThe preset file to be exported.
See also
createBundle to create the .kspb file
Exceptions
APresetManager/std::run_time will be thrown if the presetData value tree is invalid

◆ PresetBundler() [2/2]

krotos::PresetBundler::PresetBundler ( ValueTree presetData)
Parameters
presetThe preset file to be exported.
See also
createBundle to create the .kspb file
Exceptions
Astd::exception will be thrown if the presetData value tree is invalid

Member Function Documentation

◆ buildBundleArchive()

File krotos::PresetBundler::buildBundleArchive ( String outputDirectoryPath)
protected

◆ cleanUpFileStructure()

void krotos::PresetBundler::cleanUpFileStructure ( )
protected

◆ clenseExportIDs()

void krotos::PresetBundler::clenseExportIDs ( )
private

◆ convertFilepath()

String krotos::PresetBundler::convertFilepath ( String filepathFromPreset)
private

◆ copyAudioAssetsForExport()

void krotos::PresetBundler::copyAudioAssetsForExport ( )
protected

◆ copyPresetForExport()

File krotos::PresetBundler::copyPresetForExport ( String nameForPresetFile)
protected

◆ createBundle()

bool krotos::PresetBundler::createBundle ( File outputLocation,
String & errors )

Generate the preset bundle archive

Parameters
outputLocationThe directory to save the bundle to
[out]ifcreateBundle fails then this will instead contain the error why.
Returns
bool result. True if bundle was successfully made, otherwise false

◆ createBundleFileStructure()

bool krotos::PresetBundler::createBundleFileStructure ( )
protected

◆ findPathAttributesRecursive()

void krotos::PresetBundler::findPathAttributesRecursive ( StringArray & listOfFiles,
XmlElement customParamsElement )
private

◆ getAssetFilepaths()

std::vector< AudioAsset > krotos::PresetBundler::getAssetFilepaths ( )
inlineprotected

◆ getAssetsListFromPreset()

std::vector< PresetBundler::AudioAsset > krotos::PresetBundler::getAssetsListFromPreset ( )
protected

◆ getAudioAssetDirectoryForBundle()

File krotos::PresetBundler::getAudioAssetDirectoryForBundle ( const File & bundleFile)
static

Returns the path to the audio assets directory for a particular bundle based on the name of the file being loaded, without extension. e.g.Fish.kspb would return "<sandbox>/Fish/Audio Assets".

Parameters
bundleFileThe name of the bundle file loaded
Returns
The path to the audio assets directory.

◆ getEstimatedAssetsSizeMB()

int krotos::PresetBundler::getEstimatedAssetsSizeMB ( )
protected

◆ getExportBundleRoot()

File krotos::PresetBundler::getExportBundleRoot ( )
protected

◆ getPresetDirectoryForBundle()

File krotos::PresetBundler::getPresetDirectoryForBundle ( const File & bundleFile)
static

Returns the path to the preset directory for a particular bundle based on the name of the file being loaded, without extension. e.g.Fish.kspb would return "<sandbox>/Fish/Presets".

Parameters
bundleFileThe name of the bundle file loaded
Returns
The path to the preset directory.

◆ getPresetFilepaths()

void krotos::PresetBundler::getPresetFilepaths ( StringArray & listOfFiles,
XmlElement widgetElement )
private

◆ getPresetFromBundleDirectory()

File krotos::PresetBundler::getPresetFromBundleDirectory ( File bundleDirectory)
static

Locates the preset file within a given bundle directory.

Parameters
bundleDirectoryThe directory containing the extracted bundle contents.
Returns
The preset file within the bundle directory.

◆ getSandboxDirectory()

File krotos::PresetBundler::getSandboxDirectory ( )
static

Returns the path to the sandbox directory where the preset bundles are temporarily stored.

◆ getSandboxDirectoryForBundle()

File krotos::PresetBundler::getSandboxDirectoryForBundle ( const File & bundleFile)
static

Returns the path to the sandbox directory for a particular bundle based on the name of the file being loaded, without extension. e.g.Fish.kspb would return "<sandbox>/Fish".

Parameters
bundleFileThe name of the bundle file loaded
Returns
The path to the sandbox directory.

◆ initialise()

void krotos::PresetBundler::initialise ( ValueTree presetData)
private

◆ isABundlePreset()

bool krotos::PresetBundler::isABundlePreset ( const File & preset)
static

Returns whether this preset file is part of a bundle. This is just a simple check for that the provided file is a child of the sandbox directory that bundles are loaded into.

Parameters
presetThe preset file to check.
Returns
Whether the preset is a bundle preset or not.

◆ isValueAudioFile()

bool krotos::PresetBundler::isValueAudioFile ( String value)
private

◆ isValueMultipleFiles()

bool krotos::PresetBundler::isValueMultipleFiles ( String value)
private

◆ listMissingFiles()

String krotos::PresetBundler::listMissingFiles ( )
protected

◆ openBundle()

File krotos::PresetBundler::openBundle ( File bundleArchive)
static

Extracts the contents of a bundle archive to the temporary "sandbox" directory.

See also
getSandboxDirectory
getPresetFromBundleDirectory
Parameters
bundleArchiveThe bundle archive file to extract.
Returns
The directory containing the extracted bundle contents.

◆ processExportedPresetFile()

void krotos::PresetBundler::processExportedPresetFile ( File exportPreset)
protected

◆ replacePathRecursive()

void krotos::PresetBundler::replacePathRecursive ( XmlElement & widgetElement)
private

◆ replacePaths()

void krotos::PresetBundler::replacePaths ( XmlElement & widgetElement)
private

◆ setMaximumBundleSizeInMegaBytes()

int krotos::PresetBundler::setMaximumBundleSizeInMegaBytes ( int newSizeMb)
inline

Set the maximum size a bundle can be. The bundle has a maximum size of 1000 MegaBytes by default which can be reset here. The size includes the preset file and all assets included.

◆ setPresetFileExtension()

void krotos::PresetBundler::setPresetFileExtension ( String fileExtension)

Sets the file extension the preset data file will use in the bundle Default is krotos studio's .ksp

Parameters
fileExtensionThe new preset file extension including the '.'

◆ validateBundleDirectory()

bool krotos::PresetBundler::validateBundleDirectory ( File bundleDirectory)
static

Validates that a given directory is a valid bundle directory by checking it is a child file of the sandbox directory.

Parameters
bundleDirectoryThe directory to validate.
Returns
Whether the directory is a valid bundle directory.

Member Data Documentation

◆ AudioAssetsSubdirectory

const String krotos::PresetBundler::AudioAssetsSubdirectory {"Audio Assets"}
static

◆ BundleFileExtension

const String krotos::PresetBundler::BundleFileExtension {".kspb"}
static

The file extension for the bundle archive.

◆ m_assetFilepaths

std::vector<AudioAsset> krotos::PresetBundler::m_assetFilepaths
private

◆ m_bundleRootId

String krotos::PresetBundler::m_bundleRootId
private

◆ m_factoryAssetsDirectory

String krotos::PresetBundler::m_factoryAssetsDirectory
protected

◆ m_maxSizeMegaBytes

int krotos::PresetBundler::m_maxSizeMegaBytes {1000}
private

◆ m_presetFile

ValueTree krotos::PresetBundler::m_presetFile
private

◆ m_presetFileExtension

String krotos::PresetBundler::m_presetFileExtension {".ksp"}
staticprivate

◆ PresetSubdirectory

const String krotos::PresetBundler::PresetSubdirectory {"Presets"}
static

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