Presets
File: Rhapsodist/Core/Includes/Presets.js · Namespace: Presets
Overview
Presets owns the preset browser UI, the save/overwrite flow, and, outside the HISE IDE, external automation-data storage.
Two things worth knowing up front: MIDI/host automation assignments are stored in an external file rather than the preset XML, and Presets exposes broadcasters so other scripts can react to preset load/save without embedding state in the preset itself.
User Preset Migration
If your project needs to migrate presets saved under an older version, create an App/UserPresetProcessor.js file with a UserPresetProcessor namespace.
Within that namespace add an inline function process(data). Include the file after Manifest.js and before Core.js.
process() will be called when the user loads a preset with a saved version that is older than the running project version, using HISE’s own semantic-version comparison.
The Data Object
The data object passed to process() uses this structure:
data.version, the preset’s saved version string.data.Content, per-component saved-state objects (id,value, anddatafor sliderpacks/tables), already decoded.data.Modules,data.MPEData, module state and MPE data.data.MidiAutomation.Children, saved automation assignments, each with anAttributenaming the target component ID.
Whatever process() returns replaces the corresponding section wholesale, HISE doesn’t merge it with the original. Mutating the existing objects in place naturally keeps everything else; building new data from scratch means including every entry you want to survive. Returning a falsy value aborts the load.
Typical uses: remapping a renamed component ID in both data.Content and data.MidiAutomation.Children, expanding one saved component into several, reshaping a sliderpack’s saved data after a layout change, or dropping automation for a removed component.
State and persistence
Outside the HISE IDE, MIDI automation, MPE data, and macro-control assignments are routed to an external automation.xml file (under the expansion’s app data folder) instead of being embedded in the preset. Inside the IDE this redirection doesn’t apply.
Usage
Presets wires itself up once Core.js is included, the preset browser, save flow, and broadcasters are all ready without further setup.
Call Presets.show()/hide() from other scripts to open or close the browser programmatically, and listen to Presets.broadcasters.preLoad/postLoad to react to preset loads.
Look and Feel
| Function | Draws |
|---|---|
drawPresetBrowserPanel | The whole pnlPresetBrowser panel, replacing its default background/border. |
drawPresetBrowserBackground | The floating tile’s background fill. |
drawPresetBrowserColumnBackground | A whole bank/category/preset column: its background, border, and label text. |
drawPresetBrowserColumnAfterFill | An extra pass after the default column background/border, before its label text; only reached when drawPresetBrowserColumnBackground isn’t overridden. |
drawPresetBrowserListItem | A single item row in a column. |
drawPresetBrowserEditButton | The Add/Rename/Delete/More edit icon buttons. |
drawPresetBrowserSearchBar | The search bar. |
drawPresetBrowserScrollbar | Each column’s scrollbar. |
Public API
| Function | Description | Returns |
|---|---|---|
show() | Opens the preset browser overlay. | — |
hide() | Closes the preset browser overlay. | — |
savePreset() | The save/overwrite flow bound to btnPresetSave. If a non-read-only preset is already loaded it offers to overwrite it, otherwise opens a save dialog. Presets must be saved into a bank/category folder directly inside the expansion’s user presets folder; read-only presets can’t be overwritten. | — |
setDataProperty(property: string, value: NotUndefined) | Patches a single property into the PresetBrowser floating tile’s Data JSON. The property must already exist in that JSON. | — |
Broadcasters
| Broadcaster | Description |
|---|---|
broadcasters.preLoad | Broadcaster that fires before every preset load/save, carrying a single isInternal argument. Use it to snapshot state that should survive a preset load, see Header for the master volume/pan example. |
broadcasters.postLoad | Broadcaster that fires after every preset load/save, with the same isInternal argument. Use it to restore state snapshotted in preLoad. |
Internal Reference
| Function | Description | Returns |
|---|---|---|
updatePresetLabel(nameOnly: number) | Updates btnPresetBrowser’s displayed text from currentPresetFile. | — |
overwriteCurrentPreset(presetName: string) | Confirms and overwrites the currently loaded preset, called by savePreset() when one is loaded and not read-only. | — |
createNewPreset() | Opens a save dialog, validates the chosen location is a bank/category folder inside the user presets folder and that it isn’t read-only, then saves. Called by savePreset() when no preset is loaded, or the loaded one is read-only. | — |
setStyleDataProperties() | Applies LookAndFeel.style.presets.dataProperties, if defined, to the PresetBrowser floating tile via setDataProperty(). Runs once at load. | — |