gfx/preset_bar.h
The preset bar: the strip along the top of an editor that says which preset is playing and does everything a user does with presets.
#include <sonore/gfx/preset_bar.h>- 1type
- Guides: The native editor
On this page
Design notes
[ < ][ > ][ Warm Glue * v ][ Save ]
The name, with " *" when the sound has moved since the preset was loaded or saved; previous and next through factory and user presets as one list; and one menu -- Save, Save As, Rename, Delete, Duplicate, the factory list, the user's list, Import, Export, Show Folder, Rescan. Everything it does goes through the instance's PresetManager (user_presets.h), which is what puts a preset on the audio thread by the same path a host's session restore takes.
Asking, without a dialog
"Save as what?", "Replace it?", "Delete it?" are questions, and a plugin asks questions with overlays drawn inside its own editor (alert.h says why: an OS dialog from a plugin can land behind the host and hang it). The bar attaches them to the editor's root when it asks, so they cover the whole editor and not a 28-pixel strip. Only Import and Export open the OS's file dialog -- choosing a file is what that dialog is for, and every plugin that loads a sample already does it -- and both can be replaced (chooseFile), so a test drives them with no dialog at all.
One undo step
A load can be wrapped (wrapLoad): an editor with an undo history -- an AudioProcessorValueTreeState -- hands the load to editWholeState, and loading a preset becomes one step that Undo takes back whole, parameters and the plugin's own state together. An editor without one loads directly.
Headless
It is a Widget and nothing else: the menu is a PopupMenuOverlay, the questions are overlays, and the clock is tick(). tests/user_presets_test.cpp renders it into a Bitmap and drives every item.
Types 1
class PresetBar : public Widget
The strip along the top of an editor that names the current preset and does everything a user does with presets, through a PresetManager. The file comment covers the layout, the questions it asks, and how a load becomes one undo step.
The manager is not owned and must outlive the bar (or be replaced with setManager); with none the bar shows nothing to do. Call tick() from the editor's frame clock: it is what notices the sound changing and presets appearing in the folder, and it reads that folder on the calling thread. Message thread only; kHeight is the height it is designed for.