HISE Logo Forum
    • Categories
    • Register
    • Login

    Engine.saveUserPreset() doesn't hold its promise on Cancel

    Scheduled Pinned Locked Moved Bug Reports
    4 Posts 2 Posters 61 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ustkU
      ustk
      last edited by

      The message box states (Press cancel to create a new user preset), but it doesn't...

      Can't help pressing F5 in the forum...

      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @ustk
        last edited by d.healey

        @ustk I don't even see a popup.

        Edit: Just noticed I built HISE with HISE_DEACTIVATE_OVERLAY=1 so that's possibly why I don't see it.

        I made a video about this function a while ago and it looks like I'm passing in a file object rather than a string even though the docs say it should be a preset name.

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        ustkU 2 Replies Last reply Reply Quote 1
        • ustkU
          ustk @d.healey
          last edited by ustk

          @d-healey Interesting behaviour... I reckon seeing your video but I might have overseen the file part! 👍

          Effectively the function takes both:

          void ScriptingApi::Engine::saveUserPreset(var presetName)
          {
          	if (auto sf = dynamic_cast<ScriptingObjects::ScriptFile*>(presetName.getObject()))
          	{
          		UserPresetHelpers::saveUserPreset(getProcessor()->getMainController()->getMainSynthChain(), sf->f.getFullPathName());
          	}
          	else
          	{
          		getProcessor()->getMainController()->getUserPresetHandler().savePreset(presetName);
          	}
          }
          

          Can't help pressing F5 in the forum...

          1 Reply Last reply Reply Quote 1
          • ustkU
            ustk @d.healey
            last edited by

            @d-healey So I might have found the culprit

            I have CONFIRM_PRESET_OVERWRITE=1 and the confirmation message doesn't seem to handle the CANCEL case so this would better be either removed from the message box or handled

            void UserPresetHelpers::saveUserPreset(ModulatorSynthChain *chain, const String& targetFile/*=String()*/, NotificationType notify/*=sendNotification*/)
            {
            #if USE_BACKEND
            
            	const String version = dynamic_cast<GlobalSettingManager*>(chain->getMainController())->getSettingsObject().getSetting(HiseSettings::Project::Version);
            
            	SemanticVersionChecker versionChecker(version, version);
            
            	if (!versionChecker.newVersionNumberIsValid())
            	{
            		PresetHandler::showMessageWindow("Invalid version number", "You need semantic versioning (something like 1.0.0) in order to support user presets", PresetHandler::IconType::Error);
            		return;
            	}
            
            	if (!GET_PROJECT_HANDLER(chain).isActive()) return;
            #endif
                
            	File presetFile = File(targetFile);
            	
                String existingNote;
            	StringArray existingTags;
                
            #if CONFIRM_PRESET_OVERWRITE
            
            	if (presetFile.existsAsFile() && (!MessageManager::getInstance()->isThisTheMessageThread() || PresetHandler::showYesNoWindow("Confirm overwrite", "Do you want to overwrite the preset (Press cancel to create a new user preset?")))
            	{
                    existingNote = PresetBrowser::DataBaseHelpers::getNoteFromXml(presetFile);
                    existingTags = PresetBrowser::DataBaseHelpers::getTagsFromXml(presetFile);
            
            		presetFile.deleteFile();
            	}
            #else
            
            	if (presetFile.existsAsFile())
            	{
                    existingNote = PresetBrowser::DataBaseHelpers::getNoteFromXml(presetFile);
                    existingTags = PresetBrowser::DataBaseHelpers::getTagsFromXml(presetFile);
            
            		presetFile.deleteFile();
            	}
            #endif
            	
            	if (!presetFile.existsAsFile())
            	{
            		auto preset = createUserPreset(chain);
            
            		if (preset.isValid())
            		{
            			auto xml = preset.createXml();
            
            			presetFile.replaceWithText(xml->createDocument(""));
            
            			if (existingNote.isNotEmpty())
            				PresetBrowser::DataBaseHelpers::writeNoteInXml(presetFile, existingNote);
            
            			if (!existingTags.isEmpty())
            				PresetBrowser::DataBaseHelpers::writeTagsInXml(presetFile, existingTags);
            
            			if (notify)
            			{
            
            				chain->getMainController()->getUserPresetHandler().currentlyLoadedFile = presetFile;
            				chain->getMainController()->getUserPresetHandler().sendRebuildMessage();
            			}
            		}
            	}
            
            	chain->getMainController()->getUserPresetHandler().postPresetSave();
            }
            

            Can't help pressing F5 in the forum...

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            12

            Online

            1.7k

            Users

            11.8k

            Topics

            102.6k

            Posts