Vital
Loading...
Searching...
No Matches
PresetBrowser Class Reference

A UI for browsing, loading, and organizing presets. More...

#include <preset_browser.h>

Inheritance diagram for PresetBrowser:
SynthSection PresetList::Listener SaveSection::Listener DeleteSection::Listener SelectionList::Listener SynthButton::ButtonListener

Classes

class  Listener
 Interface for events from the PresetBrowser (e.g. preset selected, deleted, or browser hidden). More...
 

Public Member Functions

 PresetBrowser ()
 Constructs a PresetBrowser.
 
 ~PresetBrowser ()
 Destructor.
 
void paintBackground (Graphics &g) override
 Paints the background of the section. Calls paintContainer, heading, knobs, children.
 
void paintBackgroundShadow (Graphics &g) override
 Stub for painting background shadows. Overridden by subclasses if needed.
 
void resized () override
 Called when the component is resized. Arranges layout of child components.
 
void buttonClicked (Button *clicked_button) override
 Called when a button is clicked. Updates the synth parameter accordingly.
 
bool keyPressed (const KeyPress &key, Component *origin) override
 
bool keyStateChanged (bool is_key_down, Component *origin) override
 
void visibilityChanged () override
 
Rectangle< int > getSearchRect ()
 Returns the rectangle reserved for the search area.
 
Rectangle< int > getInfoRect ()
 Returns the rectangle reserved for the preset info area.
 
void filterPresets ()
 Filters the displayed presets based on search text and selected styles.
 
void textEditorTextChanged (TextEditor &editor) override
 
void textEditorEscapeKeyPressed (TextEditor &editor) override
 
void newPresetSelected (File preset) override
 Called when a new preset is selected.
 
void deleteRequested (File preset) override
 Called when a preset deletion is requested.
 
void loadPresets ()
 Loads all presets from known directories.
 
void save (File preset) override
 Called after saving a preset.
 
void fileDeleted (File deleted_file) override
 Called after a file is deleted.
 
void jumpToPreset (int indices)
 Jumps to a preset a certain number of steps away.
 
void loadNextPreset ()
 Loads the next preset in the list.
 
void loadPrevPreset ()
 Loads the previous preset in the list.
 
void externalPresetLoaded (File file)
 Loads an external preset file and sets it as the current selection.
 
void clearExternalPreset ()
 Clears the reference to any external preset.
 
void addListener (Listener *listener)
 Adds a listener to receive events from the PresetBrowser.
 
void setSaveSection (SaveSection *save_section)
 Sets the SaveSection for handling preset saving.
 
void setDeleteSection (DeleteSection *delete_section)
 Sets the DeleteSection for handling preset deletion.
 
void newSelection (File selection) override
 Called when a new File is selected.
 
void allSelected () override
 Called when "All" special selection is made.
 
void favoritesSelected () override
 Called when "Favorites" special selection is made.
 
void doubleClickedSelected (File selection) override
 Called when a file is double-clicked.
 
- Public Member Functions inherited from SynthSection
 SynthSection (const String &name)
 Constructs a SynthSection with a given name.
 
virtual ~SynthSection ()=default
 
void setParent (const SynthSection *parent)
 Sets the parent SynthSection.
 
float findValue (Skin::ValueId value_id) const
 Finds a value in the skin overrides or from the parent if not found locally.
 
virtual void reset ()
 Resets the section and all sub-sections.
 
virtual void paint (Graphics &g) override
 Called when the component should paint itself.
 
virtual void paintSidewaysHeadingText (Graphics &g)
 Paints the section name heading text vertically if sideways_heading_ is true.
 
virtual void paintHeadingText (Graphics &g)
 Paints the heading text for this section, either sideways or horizontally.
 
virtual void setSkinValues (const Skin &skin, bool top_level)
 Sets skin values (colors, sizes) and applies them to sub-sections.
 
void setSkinOverride (Skin::SectionOverride skin_override)
 
virtual void repaintBackground ()
 Requests a repaint of the background.
 
void showPopupBrowser (SynthSection *owner, Rectangle< int > bounds, std::vector< File > directories, String extensions, std::string passthrough_name, std::string additional_folders_name)
 Shows a file browser popup (e.g., for loading samples or wavetables).
 
void updatePopupBrowser (SynthSection *owner)
 Updates the currently visible popup browser if any.
 
void showPopupSelector (Component *source, Point< int > position, const PopupItems &options, std::function< void(int)> callback, std::function< void()> cancel={ })
 Shows a popup selector with options.
 
void showDualPopupSelector (Component *source, Point< int > position, int width, const PopupItems &options, std::function< void(int)> callback)
 Shows a dual popup selector for hierarchical selection.
 
void showPopupDisplay (Component *source, const std::string &text, BubbleComponent::BubblePlacement placement, bool primary)
 Shows a brief popup display (like a tooltip).
 
void hidePopupDisplay (bool primary)
 Hides the currently shown popup display.
 
virtual void loadFile (const File &file)
 Loads a file (e.g., a sample or wavetable). Overridden by subclasses.
 
virtual File getCurrentFile ()
 Gets the currently loaded file. Overridden by subclasses.
 
virtual std::string getFileName ()
 Gets the name of the currently loaded file. Overridden by subclasses.
 
virtual std::string getFileAuthor ()
 Gets the author metadata of the currently loaded file. Overridden by subclasses.
 
virtual void paintContainer (Graphics &g)
 Paints the container background, body, heading, etc.
 
virtual void paintBody (Graphics &g, Rectangle< int > bounds)
 Paints the body background within given bounds.
 
virtual void paintBorder (Graphics &g, Rectangle< int > bounds)
 Paints the border around given bounds.
 
virtual void paintBody (Graphics &g)
 Paints the section body background using the entire component area.
 
virtual void paintBorder (Graphics &g)
 Paints the border around the entire component.
 
int getComponentShadowWidth ()
 Gets the width of shadow around components.
 
virtual void paintTabShadow (Graphics &g)
 Paints a tab-like shadow effect around the component.
 
void paintTabShadow (Graphics &g, Rectangle< int > bounds)
 Paints a tab shadow effect within specified bounds.
 
virtual void setSizeRatio (float ratio)
 Sets the size ratio for scaling UI elements.
 
void paintKnobShadows (Graphics &g)
 Paints knob shadows for all sliders.
 
Font getLabelFont ()
 Gets a suitable font for label text.
 
void setLabelFont (Graphics &g)
 Sets the Graphics context font and color for labels.
 
void drawLabelConnectionForComponents (Graphics &g, Component *left, Component *right)
 Draws a rectangular connection between labels of two components.
 
void drawLabelBackground (Graphics &g, Rectangle< int > bounds, bool text_component=false)
 Draws a background for a label area.
 
void drawLabelBackgroundForComponent (Graphics &g, Component *component)
 Draws label background for a specific component.
 
Rectangle< int > getDividedAreaBuffered (Rectangle< int > full_area, int num_sections, int section, int buffer)
 Divides an area into equal sections with buffering, returns the specified section.
 
Rectangle< int > getDividedAreaUnbuffered (Rectangle< int > full_area, int num_sections, int section, int buffer)
 Divides an area into equal sections without extra buffering, returns the specified section.
 
Rectangle< int > getLabelBackgroundBounds (Rectangle< int > bounds, bool text_component=false)
 Gets the background bounds for a label.
 
Rectangle< int > getLabelBackgroundBounds (Component *component, bool text_component=false)
 Gets the label background bounds for a component.
 
void drawLabel (Graphics &g, String text, Rectangle< int > component_bounds, bool text_component=false)
 Draws a label text below a component.
 
void drawLabelForComponent (Graphics &g, String text, Component *component, bool text_component=false)
 Draws a label for a given component.
 
void drawTextBelowComponent (Graphics &g, String text, Component *component, int space, int padding=0)
 Draws text below a component with optional padding.
 
virtual void paintChildrenShadows (Graphics &g)
 Paints shadows for child sections.
 
void paintChildrenBackgrounds (Graphics &g)
 Paints the backgrounds for all child sections.
 
void paintOpenGlChildrenBackgrounds (Graphics &g)
 Paints the backgrounds for all OpenGL child components.
 
void paintChildBackground (Graphics &g, SynthSection *child)
 Paints a child's background specifically.
 
void paintChildShadow (Graphics &g, SynthSection *child)
 Paints a child's shadow specifically.
 
void paintOpenGlBackground (Graphics &g, OpenGlComponent *child)
 Paints the background of an OpenGlComponent child.
 
void drawTextComponentBackground (Graphics &g, Rectangle< int > bounds, bool extend_to_label)
 Draws a background for a text component area.
 
void drawTempoDivider (Graphics &g, Component *sync)
 Draws a divider line for tempo-related controls.
 
virtual void initOpenGlComponents (OpenGlWrapper &open_gl)
 Initializes all OpenGL components in this section and sub-sections.
 
virtual void renderOpenGlComponents (OpenGlWrapper &open_gl, bool animate)
 Renders all OpenGL components in this section and sub-sections.
 
virtual void destroyOpenGlComponents (OpenGlWrapper &open_gl)
 Destroys all OpenGL components in this section and sub-sections.
 
virtual void sliderValueChanged (Slider *moved_slider) override
 Called when a slider value changes. Updates the synth parameter accordingly.
 
virtual void guiChanged (SynthButton *button) override
 Called when a SynthButton state changes (GUI interaction).
 
std::map< std::string, SynthSlider * > getAllSliders ()
 Gets all sliders registered in this section.
 
std::map< std::string, ToggleButton * > getAllButtons ()
 Gets all toggle buttons registered in this section.
 
std::map< std::string, ModulationButton * > getAllModulationButtons ()
 Gets all modulation buttons registered in this section.
 
virtual void setActive (bool active)
 Sets the active state of this section and sub-sections.
 
bool isActive () const
 Checks if the section is currently active.
 
virtual void animate (bool animate)
 Triggers animation state change in sub-sections if needed.
 
virtual void setAllValues (vital::control_map &controls)
 Sets values for all known parameters from a control map.
 
virtual void setValue (const std::string &name, vital::mono_float value, NotificationType notification)
 Sets a single parameter value for a known control.
 
void addModulationButton (ModulationButton *button, bool show=true)
 Adds a modulation button to this section.
 
void addSubSection (SynthSection *section, bool show=true)
 Adds a subsection (another SynthSection) as a child.
 
void removeSubSection (SynthSection *section)
 Removes a previously added subsection.
 
virtual void setScrollWheelEnabled (bool enabled)
 Enables or disables scroll wheel support for this section and sub-sections.
 
ToggleButton * activator () const
 Gets the activator toggle button if any.
 
void setSkinValues (std::map< Skin::ValueId, float > values)
 Sets custom skin values for this section.
 
void setSkinValue (Skin::ValueId id, float value)
 Sets a single skin value override.
 
float getTitleWidth ()
 
float getPadding ()
 
float getPowerButtonOffset () const
 
float getKnobSectionHeight ()
 
float getSliderWidth ()
 
float getSliderOverlap ()
 
float getSliderOverlapWithSpace ()
 
float getTextComponentHeight ()
 
float getStandardKnobSize ()
 
float getTotalKnobHeight ()
 
float getTextSectionYOffset ()
 
float getModButtonWidth ()
 
float getModFontSize ()
 
float getWidgetMargin ()
 
float getWidgetRounding ()
 
float getSizeRatio () const
 
int getPopupWidth () const
 
int getDualPopupWidth () const
 
- Public Member Functions inherited from SynthButton::ButtonListener
virtual ~ButtonListener ()
 Virtual destructor.
 
- Public Member Functions inherited from PresetList::Listener
virtual ~Listener ()
 
- Public Member Functions inherited from SaveSection::Listener
virtual ~Listener ()=default
 
- Public Member Functions inherited from DeleteSection::Listener
virtual ~Listener ()=default
 Virtual destructor for proper cleanup.
 
- Public Member Functions inherited from SelectionList::Listener
virtual ~Listener ()=default
 

Static Public Attributes

static constexpr int kLeftPadding = 24
 
static constexpr int kTopPadding = 24
 
static constexpr int kMiddlePadding = 15
 
static constexpr int kNameFontHeight = 26
 
static constexpr int kAuthorFontHeight = 19
 
static constexpr int kStoreHeight = 33
 
static constexpr int kCommentsFontHeight = 15
 
- Static Public Attributes inherited from SynthSection
static constexpr int kDefaultPowerButtonOffset = 0
 
static constexpr float kPowerButtonPaddingPercent = 0.29f
 
static constexpr float kTransposeHeightPercent = 0.5f
 
static constexpr float kTuneHeightPercent = 0.4f
 
static constexpr float kJointModulationRadiusPercent = 0.1f
 
static constexpr float kJointModulationExtensionPercent = 0.6666f
 
static constexpr float kPitchLabelPercent = 0.33f
 
static constexpr float kJointLabelHeightPercent = 0.4f
 
static constexpr double kTransposeMouseSensitivity = 0.2
 
static constexpr float kJointLabelBorderRatioX = 0.05f
 
static constexpr int kDefaultBodyRounding = 4
 
static constexpr int kDefaultLabelHeight = 10
 
static constexpr int kDefaultLabelBackgroundHeight = 16
 
static constexpr int kDefaultLabelBackgroundWidth = 56
 
static constexpr int kDefaultLabelBackgroundRounding = 4
 
static constexpr int kDefaultPadding = 2
 
static constexpr int kDefaultPopupMenuWidth = 150
 
static constexpr int kDefaultDualPopupMenuWidth = 340
 
static constexpr int kDefaultStandardKnobSize = 32
 
static constexpr int kDefaultKnobThickness = 2
 
static constexpr float kDefaultKnobModulationAmountThickness = 2.0f
 
static constexpr int kDefaultKnobModulationMeterSize = 43
 
static constexpr int kDefaultKnobModulationMeterThickness = 4
 
static constexpr int kDefaultModulationButtonWidth = 64
 
static constexpr int kDefaultModFontSize = 10
 
static constexpr int kDefaultKnobSectionHeight = 64
 
static constexpr int kDefaultSliderWidth = 24
 
static constexpr int kDefaultTextWidth = 80
 
static constexpr int kDefaultTextHeight = 24
 
static constexpr int kDefaultWidgetMargin = 6
 
static constexpr float kDefaultWidgetFillFade = 0.3f
 
static constexpr float kDefaultWidgetLineWidth = 4.0f
 
static constexpr float kDefaultWidgetFillCenter = 0.0f
 

Additional Inherited Members

- Protected Member Functions inherited from SynthSection
void setSliderHasHzAlternateDisplay (SynthSlider *slider)
 
void setSidewaysHeading (bool sideways)
 
void addToggleButton (ToggleButton *button, bool show)
 
void addButton (OpenGlToggleButton *button, bool show=true)
 
void addButton (OpenGlShapeButton *button, bool show=true)
 
void addSlider (SynthSlider *slider, bool show=true, bool listen=true)
 
void addOpenGlComponent (OpenGlComponent *open_gl_component, bool to_beginning=false)
 
void setActivator (SynthButton *activator)
 
void createOffOverlay ()
 
void setPresetSelector (PresetSelector *preset_selector, bool half=false)
 
void paintJointControlSliderBackground (Graphics &g, int x, int y, int width, int height)
 
void paintJointControlBackground (Graphics &g, int x, int y, int width, int height)
 
void paintJointControl (Graphics &g, int x, int y, int width, int height, const std::string &name)
 
void placeJointControls (int x, int y, int width, int height, SynthSlider *left, SynthSlider *right, Component *widget=nullptr)
 
void placeTempoControls (int x, int y, int width, int height, SynthSlider *tempo, SynthSlider *sync)
 
void placeRotaryOption (Component *option, SynthSlider *rotary)
 
void placeKnobsInArea (Rectangle< int > area, std::vector< Component * > knobs)
 
void lockCriticalSection ()
 
void unlockCriticalSection ()
 
Rectangle< int > getPresetBrowserBounds ()
 
int getTitleTextRight ()
 
Rectangle< int > getPowerButtonBounds ()
 
Rectangle< int > getTitleBounds ()
 
float getDisplayScale () const
 
virtual int getPixelMultiple () const
 
- Protected Attributes inherited from SynthSection
std::map< Skin::ValueId, float > value_lookup_
 
std::vector< SynthSection * > sub_sections_
 
std::vector< OpenGlComponent * > open_gl_components_
 
std::map< std::string, SynthSlider * > slider_lookup_
 
std::map< std::string, Button * > button_lookup_
 
std::map< std::string, ModulationButton * > modulation_buttons_
 
std::map< std::string, SynthSlider * > all_sliders_
 
std::map< std::string, ToggleButton * > all_buttons_
 
std::map< std::string, ModulationButton * > all_modulation_buttons_
 
const SynthSectionparent_
 
SynthButtonactivator_
 
PresetSelectorpreset_selector_
 
bool preset_selector_half_width_
 
std::unique_ptr< OffOverlayoff_overlay_
 
Skin::SectionOverride skin_override_
 
float size_ratio_
 
bool active_
 
bool sideways_heading_
 

Detailed Description

A UI for browsing, loading, and organizing presets.

The PresetBrowser combines a PresetList (for preset files) and a SelectionList (for folders), and includes searching, filtering by style, displaying metadata (author, comments), and links to browse or purchase more presets.

Constructor & Destructor Documentation

◆ PresetBrowser()

PresetBrowser::PresetBrowser ( )

Constructs a PresetBrowser.

◆ ~PresetBrowser()

PresetBrowser::~PresetBrowser ( )

Destructor.

Member Function Documentation

◆ addListener()

void PresetBrowser::addListener ( Listener * listener)

Adds a listener to receive events from the PresetBrowser.

Parameters
listenerThe listener to add.

◆ allSelected()

void PresetBrowser::allSelected ( )
overridevirtual

Called when "All" special selection is made.

Reimplemented from SelectionList::Listener.

◆ buttonClicked()

void PresetBrowser::buttonClicked ( Button * clicked_button)
overridevirtual

Called when a button is clicked. Updates the synth parameter accordingly.

Parameters
clicked_buttonThe button clicked.

Reimplemented from SynthSection.

◆ clearExternalPreset()

void PresetBrowser::clearExternalPreset ( )
inline

Clears the reference to any external preset.

◆ deleteRequested()

void PresetBrowser::deleteRequested ( File preset)
inlineoverridevirtual

Called when a preset deletion is requested.

Parameters
presetThe preset file to delete.

Implements PresetList::Listener.

◆ doubleClickedSelected()

void PresetBrowser::doubleClickedSelected ( File selection)
inlineoverridevirtual

Called when a file is double-clicked.

Parameters
selectionThe double-clicked file.

Implements SelectionList::Listener.

◆ externalPresetLoaded()

void PresetBrowser::externalPresetLoaded ( File file)

Loads an external preset file and sets it as the current selection.

Parameters
fileThe external preset file.

◆ favoritesSelected()

void PresetBrowser::favoritesSelected ( )
overridevirtual

Called when "Favorites" special selection is made.

Reimplemented from SelectionList::Listener.

◆ fileDeleted()

void PresetBrowser::fileDeleted ( File deleted_file)
overridevirtual

Called after a file is deleted.

Parameters
deleted_fileThe deleted file.

Implements DeleteSection::Listener.

◆ filterPresets()

void PresetBrowser::filterPresets ( )

Filters the displayed presets based on search text and selected styles.

◆ getInfoRect()

Rectangle< int > PresetBrowser::getInfoRect ( )

Returns the rectangle reserved for the preset info area.

Returns
The info rectangle.

◆ getSearchRect()

Rectangle< int > PresetBrowser::getSearchRect ( )

Returns the rectangle reserved for the search area.

Returns
The search rectangle.

◆ jumpToPreset()

void PresetBrowser::jumpToPreset ( int indices)

Jumps to a preset a certain number of steps away.

Parameters
indicesThe number of steps (negative for previous).

◆ keyPressed()

bool PresetBrowser::keyPressed ( const KeyPress & key,
Component * origin )
override

◆ keyStateChanged()

bool PresetBrowser::keyStateChanged ( bool is_key_down,
Component * origin )
override

◆ loadNextPreset()

void PresetBrowser::loadNextPreset ( )

Loads the next preset in the list.

◆ loadPresets()

void PresetBrowser::loadPresets ( )

Loads all presets from known directories.

◆ loadPrevPreset()

void PresetBrowser::loadPrevPreset ( )

Loads the previous preset in the list.

◆ newPresetSelected()

void PresetBrowser::newPresetSelected ( File preset)
inlineoverridevirtual

Called when a new preset is selected.

Parameters
presetThe selected preset file.

Implements PresetList::Listener.

◆ newSelection()

void PresetBrowser::newSelection ( File selection)
overridevirtual

Called when a new File is selected.

Parameters
selectionThe newly selected file.

Implements SelectionList::Listener.

◆ paintBackground()

void PresetBrowser::paintBackground ( Graphics & g)
overridevirtual

Paints the background of the section. Calls paintContainer, heading, knobs, children.

Parameters
gThe Graphics context.

Reimplemented from SynthSection.

◆ paintBackgroundShadow()

void PresetBrowser::paintBackgroundShadow ( Graphics & g)
overridevirtual

Stub for painting background shadows. Overridden by subclasses if needed.

Parameters
gThe Graphics context.

Reimplemented from SynthSection.

◆ resized()

void PresetBrowser::resized ( )
overridevirtual

Called when the component is resized. Arranges layout of child components.

Reimplemented from SynthSection.

◆ save()

void PresetBrowser::save ( File preset)
overridevirtual

Called after saving a preset.

Parameters
presetThe saved preset file.

Implements SaveSection::Listener.

◆ setDeleteSection()

void PresetBrowser::setDeleteSection ( DeleteSection * delete_section)

Sets the DeleteSection for handling preset deletion.

Parameters
delete_sectionThe DeleteSection instance.

◆ setSaveSection()

void PresetBrowser::setSaveSection ( SaveSection * save_section)

Sets the SaveSection for handling preset saving.

Parameters
save_sectionThe SaveSection instance.

◆ textEditorEscapeKeyPressed()

void PresetBrowser::textEditorEscapeKeyPressed ( TextEditor & editor)
override

◆ textEditorTextChanged()

void PresetBrowser::textEditorTextChanged ( TextEditor & editor)
override

◆ visibilityChanged()

void PresetBrowser::visibilityChanged ( )
override

Member Data Documentation

◆ kAuthorFontHeight

int PresetBrowser::kAuthorFontHeight = 19
staticconstexpr

◆ kCommentsFontHeight

int PresetBrowser::kCommentsFontHeight = 15
staticconstexpr

◆ kLeftPadding

int PresetBrowser::kLeftPadding = 24
staticconstexpr

◆ kMiddlePadding

int PresetBrowser::kMiddlePadding = 15
staticconstexpr

◆ kNameFontHeight

int PresetBrowser::kNameFontHeight = 26
staticconstexpr

◆ kStoreHeight

int PresetBrowser::kStoreHeight = 33
staticconstexpr

◆ kTopPadding

int PresetBrowser::kTopPadding = 24
staticconstexpr

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