diff --git a/default_presets/V4 Factory Presets.piBank b/default_presets/V4 Factory Presets.piBank new file mode 100644 index 0000000..5b59a8b Binary files /dev/null and b/default_presets/V4 Factory Presets.piBank differ diff --git a/default_presets/build_factory_presets.sh b/default_presets/build_factory_presets.sh index 218a377..933d140 100755 --- a/default_presets/build_factory_presets.sh +++ b/default_presets/build_factory_presets.sh @@ -1,5 +1,5 @@ #!/usr/bin/bash -export SRC_ZIP="V3 Factory Presets.piBank" +export SRC_ZIP="V4 Factory Presets.piBank" export DST_ZIP="Factory Presets.piBank" rm "presets/$DST_ZIP" diff --git a/default_presets/presets/Factory Presets.piBank b/default_presets/presets/Factory Presets.piBank index 34f07de..a48181f 100644 Binary files a/default_presets/presets/Factory Presets.piBank and b/default_presets/presets/Factory Presets.piBank differ diff --git a/default_presets/presets/banks.versionInfo b/default_presets/presets/banks.versionInfo index 00750ed..b8626c4 100644 --- a/default_presets/presets/banks.versionInfo +++ b/default_presets/presets/banks.versionInfo @@ -1 +1 @@ -3 +4 diff --git a/src/Banks.hpp b/src/Banks.hpp index 550bb78..4576623 100644 --- a/src/Banks.hpp +++ b/src/Banks.hpp @@ -188,6 +188,18 @@ namespace pipedal } return false; } + + BankFileEntry* getPresetByName(const std::string&presetName) { + for (std::unique_ptr &preset: presets_) + { + if (preset->preset().name() == presetName) + { + return &(*preset); + } + } + return nullptr; + } + bool renamePreset(int64_t instanceId, const std::string &name) { if (hasName(name)) diff --git a/src/Storage.cpp b/src/Storage.cpp index e924191..7b8c981 100644 --- a/src/Storage.cpp +++ b/src/Storage.cpp @@ -294,8 +294,33 @@ void Storage::MoveExistingFactoryPresetsBank() namespace pipedal::implementation { extern int64_t ImportBankFile(PiPedalModel &model, const std::filesystem::path& filePath,uint64_t uploadAfter = -1); + extern void UpgradeBank( + PiPedalModel&model, + const std::filesystem::path &existingBankFile, + const std::filesystem::path &piBank, + const std::vector&presetsToUpgrade + ); + } +void Storage::UpgradeV3FactoryPresets() +{ + std::vector presetsToUpgrade = { + "Marshall JCM800 + TS9", + "Huge Lead 2" + }; + + fs::path factoryPresetPath = GetBankFileName("Factory Presets"); + + UpgradeBank( + *this->model, + factoryPresetPath, + this->configRoot / "default_presets" / "presets" / "Factory Presets.piBank", + presetsToUpgrade + ); + +} + void Storage::InstallFactoryPresets() { fs::path defaultBankFilePath = this->configRoot / "default_presets" / "presets" / "Factory Presets.piBank"; @@ -367,14 +392,22 @@ void Storage::ProvisionDefaultBanks() constexpr uint32_t V2_VERSION_NUMBER = 2; // first to have a Factory Presets constexpr uint32_t V3_VERSION_NUMBER = 3; // New A2 Presets, completely replacing the previons version. + constexpr uint32_t V4_VERSION_NUMBER = 4; // Fix incorrect Cab IR settings. - if (varPresetVersion < V3_VERSION_NUMBER) { + if (varPresetVersion < V4_VERSION_NUMBER) { Lv2Log::info("Installing Factory Presets"); // Move the old factory presets bank out of the way. - MoveExistingFactoryPresetsBank(); - InstallFactoryPresets(); - SetVarPresetVersion(V3_VERSION_NUMBER); + if (varPresetVersion < V3_VERSION_NUMBER) { + MoveExistingFactoryPresetsBank(); + } + if (varPresetVersion == V3_VERSION_NUMBER) + { + UpgradeV3FactoryPresets(); + } else { + InstallFactoryPresets(); + } + SetVarPresetVersion(V4_VERSION_NUMBER); SaveBankIndex(); // checkpoint. } // Next time we will have to MERGE factor presets. diff --git a/src/Storage.hpp b/src/Storage.hpp index 9001748..63e93ad 100644 --- a/src/Storage.hpp +++ b/src/Storage.hpp @@ -86,6 +86,7 @@ private: void SetVarPresetVersion(int32_t version); void UpgradeV1FactoryPresets(); void MoveExistingFactoryPresetsBank(); + void UpgradeV3FactoryPresets(); void InstallFactoryPresets(); void CopyFactoryPresetsToDefaultBank(); void ProvisionDefaultBanks(); diff --git a/src/WebServerConfig.cpp b/src/WebServerConfig.cpp index 094c7a6..4d33bc4 100644 --- a/src/WebServerConfig.cpp +++ b/src/WebServerConfig.cpp @@ -183,6 +183,67 @@ static fs::path GetTone3000ThumbnailFile(const fs::path& thumbnailDirectory, con namespace pipedal::implementation { + void UpgradeBank(PiPedalModel& model, + const std::filesystem::path& existingBankFilePath, + const std::filesystem::path& piBankFilePath, + const std::vector& presetsToUpgrade + ) { + BankFile sourceBankFile; + + + if (piBankFilePath.empty()) + { + throw std::runtime_error("Unexpected."); + } + if (IsZipFile(piBankFilePath)) + { + auto presetReader = PresetBundleReader::LoadPresetsFile(model, piBankFilePath); + presetReader->ExtractMediaFiles(); + + std::stringstream ss(presetReader->GetPresetJson()); + json_reader reader(ss); + reader.read(&sourceBankFile); + } + else + { + std::ifstream f{ piBankFilePath }; + if (!f.is_open()) { + throw std::runtime_error(SS("Unable to open file " << piBankFilePath)); + } + // legacy json format, no zip, no media files. + json_reader reader(f); + reader.read(&sourceBankFile); + } + + BankFile existingBankFile; + { + std::ifstream ifs{ existingBankFilePath }; + if (!ifs.is_open()) { + return; + } + json_reader reader{ ifs }; + reader.read(&existingBankFile); + } + + for (const std::string& presetToUpgrade : presetsToUpgrade) + { + BankFileEntry* existingEntry = existingBankFile.getPresetByName(presetToUpgrade); + if (existingEntry) { + BankFileEntry* newEntry = sourceBankFile.getPresetByName(presetToUpgrade); + if (newEntry) + { + existingEntry->preset(newEntry->preset()); + } + } + } + { + std::ofstream ofs{ existingBankFilePath }; + json_writer writer{ ofs }; + writer.write(existingBankFile); + } + + + } int64_t ImportBankFile(PiPedalModel& model, const std::filesystem::path& filePath, uint64_t uploadAfter = -1) { BankFile bankFile; @@ -211,6 +272,7 @@ namespace pipedal::implementation { json_reader reader(f); reader.read(&bankFile); } + uint64_t instanceId = model.UploadBank(bankFile, uploadAfter); return instanceId; @@ -623,7 +685,7 @@ public: fs::path path = GetTone3000ThumbnailFile(this->model->Tone3000ThumbnailDirectory(), id); if (!fs::exists(path)) { - path = GetTone3000ThumbnailFile(this->model->OldTone3000ThumbnailDirectory(),id); + path = GetTone3000ThumbnailFile(this->model->OldTone3000ThumbnailDirectory(), id); if (!fs::exists(path)) { throw PiPedalException("File not found.");