21 if (preset_selector ==
nullptr)
56 String redactEmail(
const String& email) {
57 static constexpr int kLeaveCharacters = 2;
60 tokens.addTokens(email,
"@",
"");
61 String beginning = tokens[0];
62 String result = beginning.substring(0, 2);
63 for (
int i = kLeaveCharacters; i < beginning.length(); ++i)
66 return result +
"@" + tokens[1];
71 browser_(nullptr), save_section_(nullptr), modified_(false) {
72 static const PathStrokeType arrow_stroke(0.05f, PathStrokeType::JointStyle::curved,
73 PathStrokeType::EndCapStyle::rounded);
74 full_skin_ = std::make_unique<Skin>();
75 selector_ = std::make_unique<PresetSelector>();
77 selector_->addListener(
this);
79 menu_button_ = std::make_unique<OpenGlShapeButton>(
"Menu");
80 addAndMakeVisible(menu_button_.get());
82 menu_button_->addListener(
this);
83 menu_button_->setTriggeredOnMouseDown(
true);
86 save_button_ = std::make_unique<OpenGlShapeButton>(
"Save");
87 addAndMakeVisible(save_button_.get());
89 save_button_->addListener(
this);
95 skin_designer_.deleteAndZero();
99 static constexpr float kSelectorButtonPaddingHeightPercent = 0.2f;
101 int height = getHeight();
102 selector_->setRoundAmount(height / 2.0f);
103 int padding = kSelectorButtonPaddingHeightPercent * height;
104 selector_->setBounds(0, 0, getWidth() - 2 * height - padding, height);
105 save_button_->setBounds(getWidth() - 2 * height, 0, height, height);
107 menu_button_->setBounds(getWidth() - height, 0, height, height);
112 Component::resized();
116 if (clicked_button == menu_button_.get()) {
117 if (ModifierKeys::getCurrentModifiersRealtime().isAltDown())
122 else if (clicked_button == save_button_.get())
134 error =
"There was an error open the preset. " + error;
135 AlertWindow::showNativeDialogBox(
"Error opening preset", error,
false);
140 for (
Listener* listener : listeners_)
141 listener->deleteRequested(preset);
145 for (
Listener* listener : listeners_)
146 listener->setPresetBrowserVisibility(
false);
150 for (
Listener* listener : listeners_)
151 listener->setBankExporterVisibility(
false);
156 if (parent ==
nullptr)
160 if (preset_text ==
"")
161 preset_text = TRANS(
"Init Preset");
164 preset_text =
"*" + preset_text;
166 selector_->setText(preset_text);
181 if (e.mods.isPopupMenu())
204 if (logged_in_as.empty())
207 options.
addItem(
kLogOut,
"Log out - " + redactEmail(logged_in_as).toStdString());
214 showPopupSelector(
this, Point<int>(anchor->getX(), anchor->getBottom()), options,
215 [=](
int selection) { menuCallback(selection, this); });
226 showPopupSelector(
this, Point<int>(anchor->getX(), anchor->getBottom()), options,
227 [=](
int selection) { menuCallback(selection, this); });
231 if (modified_ == modified)
234 modified_ = modified;
235 String text = selector_->getText();
236 if (modified_ && text.length() && text[0] !=
'*')
237 selector_->setText(
"*" + text);
238 else if (!modified_ && text.length() && text[0] ==
'*')
239 selector_->setText(text.substring(1));
242void SynthPresetSelector::loadFromFile(File& preset) {
249 for (
Listener* listener : listeners_)
250 listener->setPresetBrowserVisibility(visible);
254 for (
Listener* listener : listeners_)
255 listener->setBankExporterVisibility(
true);
279 if (!open_box.browseForFileToOpen())
282 File choice = open_box.getResult();
283 if (!choice.exists())
288 std::string name = ProjectInfo::projectName;
289 error =
"There was an error open the preset. " + error;
290 AlertWindow::showNativeDialogBox(
"Error opening preset", error,
false);
298 if (parent ==
nullptr)
304 if (!save_box.browseForFileToSave(
true))
313 if (import_box.browseForFileToOpen()) {
314 File result = import_box.getResult();
315 FileInputStream input_stream(result);
316 if (input_stream.openedOk()) {
318 data_directory.createDirectory();
322 ZipFile import_zip(input_stream);
323 Result unzip_result = import_zip.uncompressTo(data_directory);
324 if (unzip_result == Result::ok())
329 for (
Listener* listener : listeners_)
330 listener->bankImported();
344 if (load_box.browseForFileToOpen())
364 FullInterface* full_interface = findParentComponentOfClass<FullInterface>();
371 FullInterface* full_interface = findParentComponentOfClass<FullInterface>();
372 return full_interface->
signOut();
376 FullInterface* full_interface = findParentComponentOfClass<FullInterface>();
377 return full_interface->
signIn();
381 skin_designer_.deleteAndZero();
383 RectanglePlacement placement(RectanglePlacement::xLeft |
384 RectanglePlacement::yTop |
385 RectanglePlacement::doNotResize);
387 Rectangle<int> area(0, 0, 700, 800);
388 Rectangle<int> bounds = Desktop::getInstance().getDisplays().getMainDisplay().userArea.reduced(20);
389 Rectangle<int> bounds_result(placement.appliedTo(area, bounds));
391 skin_designer->setBounds(bounds_result);
392 skin_designer->setResizable(
true,
false);
393 skin_designer->setUsingNativeTitleBar(
true);
394 skin_designer->setVisible(
true);
395 skin_designer_ = skin_designer;
400 if (open_box.browseForFileToOpen()) {
401 File loaded = open_box.getResult();
403 full_skin_->loadFromFile(loaded);
410 if (default_skin.exists() && default_skin.hasWriteAccess())
411 default_skin.deleteFile();
413 full_skin_->loadDefaultSkin();
418 FullInterface* full_interface = findParentComponentOfClass<FullInterface>();
The main GUI container for the entire synthesizer interface.
Definition full_interface.h:61
std::string getSignedInName()
Gets the name of the currently signed-in user, if any.
Definition full_interface.cpp:792
void reloadSkin(const Skin &skin)
Reloads and applies a new skin, then adjusts layout accordingly.
Definition full_interface.cpp:276
void signIn()
Opens the sign-in interface, if available.
Definition full_interface.cpp:804
void signOut()
Signs out the current user, if signed in.
Definition full_interface.cpp:799
static void markPackInstalled(int id)
Marks a pack as installed by ID in the packs file.
Definition load_save.cpp:1494
static File getDataDirectory()
Gets the current data directory from the config.
Definition load_save.cpp:1718
static void saveDataDirectory(const File &data_directory)
Saves the given directory as the data directory in the configuration.
Definition load_save.cpp:1508
static File getDefaultSkin()
Retrieves the file specifying the default skin.
Definition load_save.cpp:1168
static void writeErrorLog(String error_log)
Appends an error message to an error log file.
Definition load_save.cpp:1140
static bool hasDataDirectory()
Checks if a data directory is properly configured (exists and has packs.json).
Definition load_save.cpp:1417
static Path save()
Definition paths.h:607
static Path menu()
Creates a menu icon path (three horizontal lines).
Definition paths.h:271
void clearExternalPreset()
Clears the reference to any external preset.
Definition preset_browser.h:545
void externalPresetLoaded(File file)
Loads an external preset file and sets it as the current selection.
Definition preset_browser.cpp:943
void loadNextPreset()
Loads the next preset in the list.
Definition preset_browser.cpp:939
void loadPrevPreset()
Loads the previous preset in the list.
Definition preset_browser.cpp:935
void setIsPreset(bool preset)
Configures the section for saving a preset (true) or another file type.
Definition save_section.h:135
void setVisible(bool should_be_visible) override
Sets the visibility of this overlay. Adjusts layout when becoming visible.
Definition save_section.cpp:267
A DocumentWindow that allows interactive editing of the Skin.
Definition skin.h:418
A base class providing foundational functionality for the Vital synthesizer’s engine,...
Definition synth_base.h:42
Tuning * getTuning()
Returns a pointer to the synth's Tuning object.
Definition synth_base.h:554
bool saveToFile(File preset)
Saves the current preset state to the specified file.
Definition synth_base.cpp:531
bool loadFromFile(File preset, std::string &error)
Attempts to load a preset from a file.
Definition synth_base.cpp:338
File getActiveFile()
Gets the currently active preset file.
Definition synth_base.h:342
String getPresetName()
Gets the current preset’s name.
Definition synth_base.cpp:713
void loadInitPreset()
Loads an "init" preset, resetting Vital to its default initial state.
Definition synth_base.cpp:316
void loadTuningFile(const File &file)
Loads a tuning file into the synthesizer’s tuning system.
Definition synth_base.cpp:312
An interface class linking the Vital synthesizer backend (SynthBase) with a GUI.
Definition synth_gui_interface.h:56
SynthBase * getSynth()
Returns the SynthBase instance this interface is managing.
Definition synth_gui_interface.h:85
virtual void updateFullGui()
Updates the entire GUI to reflect the current synth state.
Definition synth_gui_interface.cpp:62
void externalPresetLoaded(File preset)
Notifies the GUI that a preset was loaded externally (outside the GUI controls).
Definition synth_gui_interface.cpp:186
void notifyFresh()
Notifies the GUI that a fresh state (like a new preset load) has occurred, prompting a full refresh.
Definition synth_gui_interface.cpp:172
Interface for components that need to respond to preset selector events.
Definition synth_preset_selector.h:29
A UI section that allows the user to select, load, save, and browse presets, and manage associated re...
Definition synth_preset_selector.h:25
void buttonClicked(Button *buttonThatWasClicked) override
Definition synth_preset_selector.cpp:115
void signIn()
Opens the sign-in dialog for the user.
Definition synth_preset_selector.cpp:375
void setModified(bool modified)
Definition synth_preset_selector.cpp:230
void textMouseUp(const MouseEvent &e) override
Definition synth_preset_selector.cpp:180
void makeBankExporterVisibile()
Makes the bank exporter visible.
Definition synth_preset_selector.cpp:253
void resetText()
Resets the text displayed in the PresetSelector to reflect current state.
Definition synth_preset_selector.cpp:154
void exportBank()
Exports the current bank.
Definition synth_preset_selector.cpp:337
void loadTuningFile()
Loads a tuning file and applies it to the synthesizer.
Definition synth_preset_selector.cpp:341
void loadSkin()
Loads a skin from a file.
Definition synth_preset_selector.cpp:398
void nextClicked() override
Called when the next preset button is clicked in the PresetSelector.
Definition synth_preset_selector.cpp:175
void initPreset()
Initializes the current preset to a default state.
Definition synth_preset_selector.cpp:258
~SynthPresetSelector()
Destructor.
Definition synth_preset_selector.cpp:94
void browsePresets()
Shows the preset browser UI.
Definition synth_preset_selector.cpp:422
SynthPresetSelector()
Constructor.
Definition synth_preset_selector.cpp:70
void setPresetBrowserVisibile(bool visible)
Definition synth_preset_selector.cpp:248
void hidePresetBrowser() override
Called when the PresetBrowser is requested to be hidden.
Definition synth_preset_selector.cpp:144
void prevClicked() override
Called when the previous preset button is clicked in the PresetSelector.
Definition synth_preset_selector.cpp:170
void resized() override
Resizes and lays out UI components.
Definition synth_preset_selector.cpp:98
void savePreset()
Saves the current preset.
Definition synth_preset_selector.cpp:268
@ kImportBank
Definition synth_preset_selector.h:57
@ kInitPreset
Definition synth_preset_selector.h:53
@ kLoadSkin
Definition synth_preset_selector.h:63
@ kBrowsePresets
Definition synth_preset_selector.h:59
@ kImportPreset
Definition synth_preset_selector.h:55
@ kExportPreset
Definition synth_preset_selector.h:56
@ kClearTuning
Definition synth_preset_selector.h:61
@ kLoadTuning
Definition synth_preset_selector.h:60
@ kExportBank
Definition synth_preset_selector.h:58
@ kLogIn
Definition synth_preset_selector.h:66
@ kSavePreset
Definition synth_preset_selector.h:54
@ kClearSkin
Definition synth_preset_selector.h:64
@ kOpenSkinDesigner
Definition synth_preset_selector.h:62
@ kLogOut
Definition synth_preset_selector.h:65
void clearTuning()
Clears the currently loaded tuning, reverting to default.
Definition synth_preset_selector.cpp:348
std::string loggedInName()
Definition synth_preset_selector.cpp:363
void showAlternatePopupMenu(Component *anchor)
Definition synth_preset_selector.cpp:218
bool hasDefaultTuning()
Definition synth_preset_selector.cpp:358
void deleteRequested(File preset) override
Definition synth_preset_selector.cpp:139
void clearSkin()
Clears the current skin and reverts to the default.
Definition synth_preset_selector.cpp:408
void importPreset()
Imports a preset from an external file.
Definition synth_preset_selector.cpp:275
void showPopupMenu(Component *anchor)
Definition synth_preset_selector.cpp:187
void openSkinDesigner()
Opens the skin designer tool.
Definition synth_preset_selector.cpp:380
void newPresetSelected(File preset) override
Definition synth_preset_selector.cpp:126
void repaintWithSkin()
Repaints the interface with the current skin settings.
Definition synth_preset_selector.cpp:417
void hideBankExporter() override
Called when the BankExporter is requested to be hidden.
Definition synth_preset_selector.cpp:149
std::string getTuningName()
Definition synth_preset_selector.cpp:353
void exportPreset()
Exports the current preset to a file.
Definition synth_preset_selector.cpp:296
void importBank()
Imports a bank from an external file.
Definition synth_preset_selector.cpp:311
void signOut()
Signs out the currently logged-in user.
Definition synth_preset_selector.cpp:370
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
void addSubSection(SynthSection *section, bool show=true)
Adds a subsection (another SynthSection) as a child.
Definition synth_section.cpp:457
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.
Definition synth_section.cpp:119
void addOpenGlComponent(OpenGlComponent *open_gl_component, bool to_beginning=false)
Definition synth_section.cpp:489
static String allFileExtensions()
Returns a string listing all supported tuning file extensions.
Definition tuning.cpp:93
std::string getName() const
Gets the name of the current tuning, combining tuning and mapping names if both exist.
Definition tuning.h:157
void setDefaultTuning()
Resets the tuning to the default 12-tone equal temperament with a standard reference pitch.
Definition tuning.cpp:354
bool isDefault() const
Checks if the tuning is the default equal temperament.
Definition tuning.h:180
const std::string kBankExtension
File extension for Vital bank files, which group multiple presets.
Definition synth_constants.h:103
const std::string kSkinExtension
File extension for Vital skin/theme files.
Definition synth_constants.h:97
const std::string kPresetExtension
File extension for Vital preset files.
Definition synth_constants.h:85
Declares the SynthPresetSelector class, which provides UI elements for selecting, browsing,...