| 1 |
/* |
| 2 |
* Copyright (C) 2018-2022 Rerrah |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person |
| 5 |
* obtaining a copy of this software and associated documentation |
| 6 |
* files (the "Software"), to deal in the Software without |
| 7 |
* restriction, including without limitation the rights to use, |
| 8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
* copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following |
| 11 |
* conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be |
| 14 |
* included in all copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 23 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
*/ |
| 25 |
|
| 26 |
#include "configuration_handler.hpp" |
| 27 |
#include <vector> |
| 28 |
#include <unordered_map> |
| 29 |
#include <QString> |
| 30 |
#include <QSettings> |
| 31 |
#include <QFile> |
| 32 |
#include "configuration.hpp" |
| 33 |
#include "jamming.hpp" |
| 34 |
#include "enum_hash.hpp" |
| 35 |
#include "gui/gui_utils.hpp" |
| 36 |
#include "utils.hpp" |
| 37 |
|
| 38 |
namespace io |
| 39 |
{ |
| 40 |
namespace |
| 41 |
{ |
| 42 |
// config path (*nix): ~/.config/<organization>/<application>.ini |
| 43 |
const QString APPLICATION = "BambooTracker"; |
| 44 |
|
| 45 |
const std::unordered_map<Configuration::ShortcutAction, QString> SHORTCUTS_NAME_MAP = { |
| 46 |
{ Configuration::ShortcutAction::KeyOff, "keyOff" }, |
| 47 |
{ Configuration::ShortcutAction::KeyCut, "keyCut" }, |
| 48 |
{ Configuration::ShortcutAction::OctaveUp, "octaveUp" }, |
| 49 |
{ Configuration::ShortcutAction::OctaveDown, "octaveDown" }, |
| 50 |
{ Configuration::ShortcutAction::EchoBuffer, "echoBuffer" }, |
| 51 |
{ Configuration::ShortcutAction::PlayAndStop, "playAndStop" }, |
| 52 |
{ Configuration::ShortcutAction::Play, "play" }, |
| 53 |
{ Configuration::ShortcutAction::PlayFromStart, "playFromStart" }, |
| 54 |
{ Configuration::ShortcutAction::PlayPattern, "playPattern" }, |
| 55 |
{ Configuration::ShortcutAction::PlayFromCursor, "playFromCursor" }, |
| 56 |
{ Configuration::ShortcutAction::PlayFromMarker, "playFromMarker" }, |
| 57 |
{ Configuration::ShortcutAction::PlayStep, "playStep" }, |
| 58 |
{ Configuration::ShortcutAction::Stop, "stop" }, |
| 59 |
{ Configuration::ShortcutAction::FocusOnPattern, "ocusOnPattern" }, |
| 60 |
{ Configuration::ShortcutAction::FocusOnOrder, "focusOnOrder" }, |
| 61 |
{ Configuration::ShortcutAction::FocusOnInstrument, "focusOnInstrument" }, |
| 62 |
{ Configuration::ShortcutAction::ToggleEditJam, "toggleEditJam" }, |
| 63 |
{ Configuration::ShortcutAction::SetMarker, "setMarker" }, |
| 64 |
{ Configuration::ShortcutAction::PasteMix, "pasteMix" }, |
| 65 |
{ Configuration::ShortcutAction::PasteOverwrite, "pasteOverwrite" }, |
| 66 |
{ Configuration::ShortcutAction::PasteInsert, "pasteInsert" }, |
| 67 |
{ Configuration::ShortcutAction::SelectAll, "selectAll" }, |
| 68 |
{ Configuration::ShortcutAction::Deselect, "deselect" }, |
| 69 |
{ Configuration::ShortcutAction::SelectRow, "selectRow" }, |
| 70 |
{ Configuration::ShortcutAction::SelectColumn, "selectColumn" }, |
| 71 |
{ Configuration::ShortcutAction::SelectPattern, "selectPattern" }, |
| 72 |
{ Configuration::ShortcutAction::SelectOrder, "selectOrder" }, |
| 73 |
{ Configuration::ShortcutAction::GoToStep, "goToStep" }, |
| 74 |
{ Configuration::ShortcutAction::ToggleTrack, "toggleTrack" }, |
| 75 |
{ Configuration::ShortcutAction::SoloTrack, "soloTrack" }, |
| 76 |
{ Configuration::ShortcutAction::Interpolate, "interpolate" }, |
| 77 |
{ Configuration::ShortcutAction::Reverse, "reverse" }, |
| 78 |
{ Configuration::ShortcutAction::GoToPrevOrder, "goToPrevOrder" }, |
| 79 |
{ Configuration::ShortcutAction::GoToNextOrder, "goToNextOrder" }, |
| 80 |
{ Configuration::ShortcutAction::ToggleBookmark, "toggleBookmark" }, |
| 81 |
{ Configuration::ShortcutAction::PrevBookmark, "prevBookmark" }, |
| 82 |
{ Configuration::ShortcutAction::NextBookmark, "nextBookmark" }, |
| 83 |
{ Configuration::ShortcutAction::DecreaseNote, "decreaseNote" }, |
| 84 |
{ Configuration::ShortcutAction::IncreaseNote, "increaseNote" }, |
| 85 |
{ Configuration::ShortcutAction::DecreaseOctave, "decreaseOctave" }, |
| 86 |
{ Configuration::ShortcutAction::IncreaseOctave, "increaseOctave" }, |
| 87 |
{ Configuration::ShortcutAction::PrevInstrument, "prevInstrument" }, |
| 88 |
{ Configuration::ShortcutAction::NextInstrument, "nextInstrument" }, |
| 89 |
{ Configuration::ShortcutAction::MaskInstrument, "maskInstrument" }, |
| 90 |
{ Configuration::ShortcutAction::MaskVolume, "maskVolume" }, |
| 91 |
{ Configuration::ShortcutAction::EditInstrument, "editInstrument" }, |
| 92 |
{ Configuration::ShortcutAction::FollowMode, "followMode" }, |
| 93 |
{ Configuration::ShortcutAction::DuplicateOrder, "duplicateOrder" }, |
| 94 |
{ Configuration::ShortcutAction::ClonePatterns, "clonePatterns" }, |
| 95 |
{ Configuration::ShortcutAction::CloneOrder, "cloneOrder" }, |
| 96 |
{ Configuration::ShortcutAction::ReplaceInstrument, "replaceInstrument" }, |
| 97 |
{ Configuration::ShortcutAction::ExpandPattern, "expandPattern" }, |
| 98 |
{ Configuration::ShortcutAction::ShrinkPattern, "shrinkPattern" }, |
| 99 |
{ Configuration::ShortcutAction::FineDecreaseValues, "fineDecreaseValues" }, |
| 100 |
{ Configuration::ShortcutAction::FineIncreaseValues, "fineIncreaseValues" }, |
| 101 |
{ Configuration::ShortcutAction::CoarseDecreaseValues, "coarseDecreaseValues" }, |
| 102 |
{ Configuration::ShortcutAction::CoarseIncreaseValuse, "coarseIncreaseValuse" }, |
| 103 |
{ Configuration::ShortcutAction::ExpandEffect, "expandEffect" }, |
| 104 |
{ Configuration::ShortcutAction::ShrinkEffect, "shrinkEffect" }, |
| 105 |
{ Configuration::ShortcutAction::PrevHighlighted, "prevHighlightedStep" }, |
| 106 |
{ Configuration::ShortcutAction::NextHighlighted, "nextHighlightedStep" }, |
| 107 |
{ Configuration::ShortcutAction::IncreasePatternSize, "incPtnSize" }, |
| 108 |
{ Configuration::ShortcutAction::DecreasePatternSize, "decPtnSize" }, |
| 109 |
{ Configuration::ShortcutAction::IncreaseEditStep, "incEditStep" }, |
| 110 |
{ Configuration::ShortcutAction::DecreaseEditStep, "decEditStep" }, |
| 111 |
{ Configuration::ShortcutAction::DisplayEffectList, "dispEffectList" }, |
| 112 |
{ Configuration::ShortcutAction::PreviousSong, "prevSong" }, |
| 113 |
{ Configuration::ShortcutAction::NextSong, "nextSong" }, |
| 114 |
{ Configuration::ShortcutAction::JamVolumeUp, "jamVolumeUp" }, |
| 115 |
{ Configuration::ShortcutAction::JamVolumeDown, "jamVolumeDown" } |
| 116 |
}; |
| 117 |
|
| 118 |
const std::unordered_map<JamKey, QString> JAM_KEY_NAME_MAP = { |
| 119 |
{JamKey::LowC, "lowC"}, |
| 120 |
{JamKey::LowCS, "lowCS"}, |
| 121 |
{JamKey::LowD, "lowD"}, |
| 122 |
{JamKey::LowDS, "lowDS"}, |
| 123 |
{JamKey::LowE, "lowE"}, |
| 124 |
{JamKey::LowF, "lowF"}, |
| 125 |
{JamKey::LowFS, "lowFS"}, |
| 126 |
{JamKey::LowG, "lowG"}, |
| 127 |
{JamKey::LowGS, "lowGS"}, |
| 128 |
{JamKey::LowA, "lowA"}, |
| 129 |
{JamKey::LowAS, "lowAS"}, |
| 130 |
{JamKey::LowB, "lowB"}, |
| 131 |
{JamKey::LowC2, "lowHighC"}, |
| 132 |
{JamKey::LowCS2, "lowHighCS"}, |
| 133 |
{JamKey::LowD2, "lowHighD"}, |
| 134 |
|
| 135 |
{JamKey::HighC, "highC"}, |
| 136 |
{JamKey::HighCS, "highCS"}, |
| 137 |
{JamKey::HighD, "highD"}, |
| 138 |
{JamKey::HighDS, "highDS"}, |
| 139 |
{JamKey::HighE, "highE"}, |
| 140 |
{JamKey::HighF, "highF"}, |
| 141 |
{JamKey::HighFS, "highFS"}, |
| 142 |
{JamKey::HighG, "highG"}, |
| 143 |
{JamKey::HighGS, "highGS"}, |
| 144 |
{JamKey::HighA, "highA"}, |
| 145 |
{JamKey::HighAS, "highAS"}, |
| 146 |
{JamKey::HighB, "highB"}, |
| 147 |
{JamKey::HighC2, "highHighC"}, |
| 148 |
{JamKey::HighCS2, "highHighCS"}, |
| 149 |
{JamKey::HighD2, "highHighD"} |
| 150 |
}; |
| 151 |
} |
| 152 |
|
| 153 |
bool saveConfiguration(std::weak_ptr<Configuration> config) |
| 154 |
{ |
| 155 |
try { |
| 156 |
QSettings settings(QSettings::IniFormat, QSettings::UserScope, io::ORGANIZATION_NAME, APPLICATION); |
| 157 |
std::shared_ptr<Configuration> configLocked = config.lock(); |
| 158 |
|
| 159 |
// Internal // |
| 160 |
settings.beginGroup("Internal"); |
| 161 |
settings.setValue("mainWindowWidth", configLocked->getMainWindowWidth()); |
| 162 |
settings.setValue("mainWindowHeight", configLocked->getMainWindowHeight()); |
| 163 |
settings.setValue("mainWindowMaximized", configLocked->getMainWindowMaximized()); |
| 164 |
settings.setValue("mainWindowX", configLocked->getMainWindowX()); |
| 165 |
settings.setValue("mainWindowY", configLocked->getMainWindowY()); |
| 166 |
settings.setValue("mainWindowVerticalSplit", configLocked->getMainWindowVerticalSplit()); |
| 167 |
settings.setValue("instrumentFMWindowWidth", configLocked->getInstrumentFMWindowWidth()); |
| 168 |
settings.setValue("instrumentFMWindowHeight", configLocked->getInstrumentFMWindowHeight()); |
| 169 |
settings.setValue("instrumentSSGWindowWidth", configLocked->getInstrumentSSGWindowWidth()); |
| 170 |
settings.setValue("instrumentSSGWindowHeight", configLocked->getInstrumentSSGWindowHeight()); |
| 171 |
settings.setValue("instrumentADPCMWindowWidth", configLocked->getInstrumentADPCMWindowWidth()); |
| 172 |
settings.setValue("instrumentADPCMWindowHeight", configLocked->getInstrumentADPCMWindowHeight()); |
| 173 |
settings.setValue("instrumentDrumkitWindowWidth", configLocked->getInstrumentDrumkitWindowWidth()); |
| 174 |
settings.setValue("instrumentDrumkitWindowHeight", configLocked->getInstrumentDrumkitWindowHeight()); |
| 175 |
settings.setValue("instrumentDrumkitWindowHorizontalSplit", configLocked->getInstrumentDrumkitWindowHorizontalSplit()); |
| 176 |
settings.setValue("followMode", configLocked->getFollowMode()); |
| 177 |
settings.setValue("workingDirectory", QString::fromStdString(configLocked->getWorkingDirectory())); |
| 178 |
settings.setValue("instrumentOpenFormat", configLocked->getInstrumentOpenFormat()); |
| 179 |
settings.setValue("bankOpenFormat", configLocked->getBankOpenFormat()); |
| 180 |
settings.setValue("instrumentMask", configLocked->getInstrumentMask()); |
| 181 |
settings.setValue("volumeMask", configLocked->getVolumeMask()); |
| 182 |
settings.setValue("visibleToolbar", configLocked->getVisibleToolbar()); |
| 183 |
settings.setValue("visibleStatusBar", configLocked->getVisibleStatusBar()); |
| 184 |
settings.setValue("visibleWaveView", configLocked->getVisibleWaveView()); |
| 185 |
settings.setValue("pasteMode", static_cast<int>(configLocked->getPasteMode())); |
| 186 |
auto& mainTbConfig = configLocked->getMainToolbarConfiguration(); |
| 187 |
settings.setValue("mainToolbarPosition", static_cast<int>(mainTbConfig.getPosition())); |
| 188 |
settings.setValue("mainToolbarNumber", mainTbConfig.getNumber()); |
| 189 |
settings.setValue("hasBreakBeforeMainToolbar", mainTbConfig.hasBreakBefore()); |
| 190 |
settings.setValue("mainToolbarX", mainTbConfig.getX()); |
| 191 |
settings.setValue("mainToolbarY", mainTbConfig.getY()); |
| 192 |
auto& subTbConfig = configLocked->getSubToolbarConfiguration(); |
| 193 |
settings.setValue("subToolbarPosition", static_cast<int>(subTbConfig.getPosition())); |
| 194 |
settings.setValue("subToolbarNumber", subTbConfig.getNumber()); |
| 195 |
settings.setValue("hasBreakBeforesubToolbar", subTbConfig.hasBreakBefore()); |
| 196 |
settings.setValue("subToolbarX", subTbConfig.getX()); |
| 197 |
settings.setValue("subToolbarY", subTbConfig.getY()); |
| 198 |
settings.endGroup(); |
| 199 |
|
| 200 |
// General // |
| 201 |
// General settings |
| 202 |
settings.beginGroup("General"); |
| 203 |
settings.setValue("warpCursor", configLocked->getWarpCursor()); |
| 204 |
settings.setValue("warpAcrossOrders", configLocked->getWarpAcrossOrders()); |
| 205 |
settings.setValue("showRowNumberInHex", configLocked->getShowRowNumberInHex()); |
| 206 |
settings.setValue("showPreviousNextOrders", configLocked->getShowPreviousNextOrders()); |
| 207 |
settings.setValue("backupModule", configLocked->getBackupModules()); |
| 208 |
settings.setValue("dontSelectOnDoubleClick", configLocked->getDontSelectOnDoubleClick()); |
| 209 |
settings.setValue("reverseFMVolumeOrder", configLocked->getReverseFMVolumeOrder()); |
| 210 |
settings.setValue("moveCursorToRight", configLocked->getMoveCursorToRight()); |
| 211 |
settings.setValue("retrieveChannelState", configLocked->getRetrieveChannelState()); |
| 212 |
settings.setValue("enableTranslation", configLocked->getEnableTranslation()); |
| 213 |
settings.setValue("showFMDetuneAsSigned", configLocked->getShowFMDetuneAsSigned()); |
| 214 |
settings.setValue("fill00ToEffectValue", configLocked->getFill00ToEffectValue()); |
| 215 |
settings.setValue("moveCursorByHScroll", configLocked->getMoveCursorByHorizontalScroll()); |
| 216 |
settings.setValue("overwriteUnusedUnedited", configLocked->getOverwriteUnusedUneditedPropety()); |
| 217 |
settings.setValue("writeOnlyUsedSamples", configLocked->getWriteOnlyUsedSamples()); |
| 218 |
settings.setValue("reflectInstNumChange", configLocked->getReflectInstrumentNumberChange()); |
| 219 |
settings.setValue("fixJammingVolume", configLocked->getFixJammingVolume()); |
| 220 |
settings.setValue("muteHiddenTracks", configLocked->getMuteHiddenTracks()); |
| 221 |
settings.setValue("restoreTrackVisibility", configLocked->getRestoreTrackVisibility()); |
| 222 |
settings.setValue("overflowPaste", configLocked->getOverflowPaste()); |
| 223 |
settings.endGroup(); |
| 224 |
|
| 225 |
// Edit settings |
| 226 |
settings.beginGroup("Editing"); |
| 227 |
settings.setValue("pageJumpLength", static_cast<int>(configLocked->getPageJumpLength())); |
| 228 |
settings.setValue("editableStep", static_cast<int>(configLocked->getEditableStep())); |
| 229 |
settings.setValue("keyRepetition", configLocked->getKeyRepetition()); |
| 230 |
settings.endGroup(); |
| 231 |
|
| 232 |
// Wave view |
| 233 |
settings.beginGroup("WaveView"); |
| 234 |
settings.setValue("frameRate", configLocked->getWaveViewFrameRate()); |
| 235 |
settings.endGroup(); |
| 236 |
|
| 237 |
// Note names |
| 238 |
settings.beginGroup("NoteNames"); |
| 239 |
settings.setValue("notationSystem", static_cast<int>(configLocked->getNotationSystem())); |
| 240 |
settings.endGroup(); |
| 241 |
|
| 242 |
// Keys |
| 243 |
settings.beginGroup("Keys"); |
| 244 |
for (const auto& pair : configLocked->getShortcuts()) { |
| 245 |
settings.setValue("shortcut_" + SHORTCUTS_NAME_MAP.at(pair.first), gui_utils::utf8ToQString(pair.second)); |
| 246 |
} |
| 247 |
settings.setValue("noteEntryLayout", static_cast<int>(configLocked->getNoteEntryLayout())); |
| 248 |
for (const auto& pair : configLocked->getCustomLayoutKeys()) { |
| 249 |
settings.setValue("customLayout_" + JAM_KEY_NAME_MAP.at(pair.second), gui_utils::utf8ToQString(pair.first)); |
| 250 |
} |
| 251 |
settings.endGroup(); |
| 252 |
|
| 253 |
// Sound // |
| 254 |
settings.beginGroup("Sound"); |
| 255 |
settings.setValue("soundAPI", gui_utils::utf8ToQString(configLocked->getSoundAPI())); |
| 256 |
settings.setValue("soundDevice", gui_utils::utf8ToQString(configLocked->getSoundDevice())); |
| 257 |
settings.setValue("realChipInterface", static_cast<int>(configLocked->getRealChipInterface())); |
| 258 |
settings.setValue("emulator", configLocked->getEmulator()); |
| 259 |
settings.setValue("sampleRate", static_cast<int>(configLocked->getSampleRate())); |
| 260 |
settings.setValue("bufferLength", static_cast<int>(configLocked->getBufferLength())); |
| 261 |
settings.setValue("resamplerType", static_cast<int>(configLocked->getResamplerType())); |
| 262 |
settings.setValue("immediateWriteModeEnabled", configLocked->getImmediateWriteModeEnabled()); |
| 263 |
settings.endGroup(); |
| 264 |
|
| 265 |
// Midi // |
| 266 |
settings.beginGroup("Midi"); |
| 267 |
settings.setValue("midiEnabled", configLocked->getMidiEnabled()); |
| 268 |
settings.setValue("midiAPI", QString::fromStdString(configLocked->getMidiAPI())); |
| 269 |
settings.setValue("inputPort", QString::fromStdString(configLocked->getMidiInputPort())); |
| 270 |
settings.endGroup(); |
| 271 |
|
| 272 |
// Mixer // |
| 273 |
settings.beginGroup("Mixer"); |
| 274 |
settings.setValue("mixerVolumeMaster", configLocked->getMixerVolumeMaster()); |
| 275 |
settings.setValue("mixerVolumeFM", configLocked->getMixerVolumeFM()); |
| 276 |
settings.setValue("mixerVolumeSSG", configLocked->getMixerVolumeSSG()); |
| 277 |
settings.endGroup(); |
| 278 |
|
| 279 |
// Input // |
| 280 |
settings.beginGroup("Input"); |
| 281 |
settings.beginWriteArray("fmEnvelopeTextMap"); |
| 282 |
int n = 0; |
| 283 |
for (const FMEnvelopeText& texts : config.lock()->getFMEnvelopeTexts()) { |
| 284 |
settings.setArrayIndex(n++); |
| 285 |
settings.setValue("type", gui_utils::utf8ToQString(texts.name)); |
| 286 |
QStringList typeList; |
| 287 |
std::transform(texts.texts.begin(), texts.texts.end(), std::back_inserter(typeList), |
| 288 |
[](FMEnvelopeTextType type) { return QString::number(static_cast<int>(type)); }); |
| 289 |
settings.setValue("order", typeList.join(",")); |
| 290 |
} |
| 291 |
settings.endArray(); |
| 292 |
settings.endGroup(); |
| 293 |
|
| 294 |
settings.beginGroup("Appearance"); |
| 295 |
settings.setValue("patternEditorHeaderFont", QString::fromStdString(configLocked->getPatternEditorHeaderFont())); |
| 296 |
settings.setValue("patternEditorRowsFont", QString::fromStdString(configLocked->getPatternEditorRowsFont())); |
| 297 |
settings.setValue("orderListHeaderFont", QString::fromStdString(configLocked->getOrderListHeaderFont())); |
| 298 |
settings.setValue("orderListRowsFont", QString::fromStdString(configLocked->getOrderListRowsFont())); |
| 299 |
settings.endGroup(); |
| 300 |
|
| 301 |
return true; |
| 302 |
} catch (...) { |
| 303 |
return false; |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
bool loadConfiguration(std::weak_ptr<Configuration> config) |
| 308 |
{ |
| 309 |
try { |
| 310 |
QSettings settings(QSettings::IniFormat, QSettings::UserScope, io::ORGANIZATION_NAME, APPLICATION); |
| 311 |
if (!QFile(settings.fileName()).exists()) return false; |
| 312 |
|
| 313 |
std::shared_ptr<Configuration> configLocked = config.lock(); |
| 314 |
|
| 315 |
// Internal // |
| 316 |
settings.beginGroup("Internal"); |
| 317 |
configLocked->setMainWindowWidth(settings.value("mainWindowWidth", configLocked->getMainWindowWidth()).toInt()); |
| 318 |
configLocked->setMainWindowHeight(settings.value("mainWindowHeight", configLocked->getMainWindowHeight()).toInt()); |
| 319 |
configLocked->setMainWindowMaximized(settings.value("mainWindowMaximized", configLocked->getMainWindowMaximized()).toBool()); |
| 320 |
configLocked->setMainWindowX(settings.value("mainWindowX", configLocked->getMainWindowX()).toInt()); |
| 321 |
configLocked->setMainWindowY(settings.value("mainWindowY", configLocked->getMainWindowY()).toInt()); |
| 322 |
configLocked->setMainWindowVerticalSplit(settings.value("mainWindowVerticalSplit", configLocked->getMainWindowVerticalSplit()).toInt()); |
| 323 |
configLocked->setInstrumentFMWindowWidth(settings.value("instrumentFMWindowWidth", configLocked->getInstrumentFMWindowWidth()).toInt()); |
| 324 |
configLocked->setInstrumentFMWindowHeight(settings.value("instrumentFMWindowHeight", configLocked->getInstrumentFMWindowHeight()).toInt()); |
| 325 |
configLocked->setInstrumentSSGWindowWidth(settings.value("instrumentSSGWindowWidth", configLocked->getInstrumentSSGWindowWidth()).toInt()); |
| 326 |
configLocked->setInstrumentSSGWindowHeight(settings.value("instrumentSSGWindowHeight", configLocked->getInstrumentSSGWindowHeight()).toInt()); |
| 327 |
configLocked->setInstrumentADPCMWindowWidth(settings.value("instrumentADPCMWindowWidth", configLocked->getInstrumentADPCMWindowWidth()).toInt()); |
| 328 |
configLocked->setInstrumentADPCMWindowHeight(settings.value("instrumentADPCMWindowHeight", configLocked->getInstrumentADPCMWindowHeight()).toInt()); |
| 329 |
configLocked->setInstrumentDrumkitWindowWidth(settings.value("instrumentDrumkitWindowWidth", configLocked->getInstrumentDrumkitWindowWidth()).toInt()); |
| 330 |
configLocked->setInstrumentDrumkitWindowHorizontalSplit(settings.value("instrumentDrumkitWindowHorizontalSplit", configLocked->getInstrumentDrumkitWindowHorizontalSplit()).toInt()); |
| 331 |
configLocked->setInstrumentDrumkitWindowHeight(settings.value("instrumentDrumkitWindowHeight", configLocked->getInstrumentDrumkitWindowHeight()).toInt()); |
| 332 |
configLocked->setFollowMode(settings.value("followMode", configLocked->getFollowMode()).toBool()); |
| 333 |
configLocked->setWorkingDirectory(settings.value("workingDirectory", QString::fromStdString(configLocked->getWorkingDirectory())).toString().toStdString()); |
| 334 |
configLocked->setInstrumentOpenFormat(settings.value("instrumentOpenFormat", configLocked->getInstrumentOpenFormat()).toInt()); |
| 335 |
configLocked->setBankOpenFormat(settings.value("bankOpenFormat", configLocked->getBankOpenFormat()).toInt()); |
| 336 |
configLocked->setInstrumentMask(settings.value("instrumentMask", configLocked->getInstrumentMask()).toBool()); |
| 337 |
configLocked->setVolumeMask(settings.value("volumeMask", configLocked->getVolumeMask()).toBool()); |
| 338 |
configLocked->setVisibleToolbar(settings.value("visibleToolbar", configLocked->getVisibleToolbar()).toBool()); |
| 339 |
configLocked->setVisibleStatusBar(settings.value("visibleStatusBar", configLocked->getVisibleStatusBar()).toBool()); |
| 340 |
configLocked->setVisibleWaveView(settings.value("visibleWaveView", configLocked->getVisibleWaveView()).toBool()); |
| 341 |
configLocked->setPasteMode(static_cast<Configuration::PasteMode>(settings.value("pasteMode", static_cast<int>(configLocked->getPasteMode())).toInt())); |
| 342 |
auto& mainTbConfig = configLocked->getMainToolbarConfiguration(); |
| 343 |
mainTbConfig.setPosition(static_cast<Configuration::ToolbarPosition>(settings.value("mainToolbarPosition", static_cast<int>(mainTbConfig.getPosition())).toInt())); |
| 344 |
mainTbConfig.setNumber(settings.value("mainToolbarNumber", mainTbConfig.getNumber()).toInt()); |
| 345 |
mainTbConfig.setBreakBefore(settings.value("hasBreakBeforeMainToolbar", mainTbConfig.hasBreakBefore()).toBool()); |
| 346 |
mainTbConfig.setX(settings.value("mainToolbarX", mainTbConfig.getX()).toInt()); |
| 347 |
mainTbConfig.setY(settings.value("mainToolbarY", mainTbConfig.getY()).toInt()); |
| 348 |
auto& subTbConfig = configLocked->getSubToolbarConfiguration(); |
| 349 |
subTbConfig.setPosition(static_cast<Configuration::ToolbarPosition>(settings.value("subToolbarPosition", static_cast<int>(subTbConfig.getPosition())).toInt())); |
| 350 |
subTbConfig.setNumber(settings.value("subToolbarNumber", subTbConfig.getNumber()).toInt()); |
| 351 |
subTbConfig.setBreakBefore(settings.value("hasBreakBeforesubToolbar", subTbConfig.hasBreakBefore()).toBool()); |
| 352 |
subTbConfig.setX(settings.value("subToolbarX", subTbConfig.getX()).toInt()); |
| 353 |
subTbConfig.setY(settings.value("subToolbarY", subTbConfig.getY()).toInt()); |
| 354 |
settings.endGroup(); |
| 355 |
|
| 356 |
// General // |
| 357 |
// General settings |
| 358 |
settings.beginGroup("General"); |
| 359 |
configLocked->setWarpCursor(settings.value("warpCursor", configLocked->getWarpCursor()).toBool()); |
| 360 |
configLocked->setWarpAcrossOrders(settings.value("warpAcrossOrders", configLocked->getWarpAcrossOrders()).toBool()); |
| 361 |
configLocked->setShowRowNumberInHex(settings.value("showRowNumberInHex", configLocked->getShowRowNumberInHex()).toBool()); |
| 362 |
configLocked->setShowPreviousNextOrders(settings.value("showPreviousNextOrders", configLocked->getShowPreviousNextOrders()).toBool()); |
| 363 |
configLocked->setBackupModules(settings.value("backupModule", configLocked->getBackupModules()).toBool()); |
| 364 |
configLocked->setDontSelectOnDoubleClick(settings.value("dontSelectOnDoubleClick", configLocked->getDontSelectOnDoubleClick()).toBool()); |
| 365 |
configLocked->setReverseFMVolumeOrder(settings.value("reverseFMVolumeOrder", configLocked->getReverseFMVolumeOrder()).toBool()); |
| 366 |
configLocked->setMoveCursorToRight(settings.value("moveCursorToRight", configLocked->getMoveCursorToRight()).toBool()); |
| 367 |
configLocked->setRetrieveChannelState(settings.value("retrieveChannelState", configLocked->getRetrieveChannelState()).toBool()); |
| 368 |
configLocked->setEnableTranslation(settings.value("enableTranslation", configLocked->getEnableTranslation()).toBool()); |
| 369 |
configLocked->setShowFMDetuneAsSigned(settings.value("showFMDetuneAsSigned", configLocked->getShowFMDetuneAsSigned()).toBool()); |
| 370 |
configLocked->setFill00ToEffectValue(settings.value("fill00ToEffectValue", configLocked->getFill00ToEffectValue()).toBool()); |
| 371 |
configLocked->setMoveCursorByHorizontalScroll(settings.value("moveCursorByHScroll", configLocked->getMoveCursorByHorizontalScroll()).toBool()); |
| 372 |
configLocked->setOverwriteUnusedUneditedPropety(settings.value("overwriteUnusedUnedited", configLocked->getOverwriteUnusedUneditedPropety()).toBool()); |
| 373 |
configLocked->setWriteOnlyUsedSamples(settings.value("writeOnlyUsedSamples", configLocked->getWriteOnlyUsedSamples()).toBool()); |
| 374 |
configLocked->setReflectInstrumentNumberChange(settings.value("reflectInstNumChange", configLocked->getReflectInstrumentNumberChange()).toBool()); |
| 375 |
configLocked->setFixJammingVolume(settings.value("fixJammingVolume", configLocked->getFixJammingVolume()).toBool()); |
| 376 |
configLocked->setMuteHiddenTracks(settings.value("muteHiddenTracks", configLocked->getMuteHiddenTracks()).toBool()); |
| 377 |
configLocked->setRestoreTrackVisibility(settings.value("restoreTrackVisibility", configLocked->getRestoreTrackVisibility()).toBool()); |
| 378 |
configLocked->setOverflowPaste(settings.value("overflowPaste", configLocked->getOverflowPaste()).toBool()); |
| 379 |
if (settings.contains("autosetInstrument")) { // For compatibility before v0.4.0 |
| 380 |
configLocked->setInstrumentMask(!settings.value("autosetInstrument").toBool()); |
| 381 |
settings.remove("autosetInstrument"); |
| 382 |
} |
| 383 |
if (settings.contains("showWaveVisual")) { // For compatibility before v0.4.2 |
| 384 |
configLocked->setVisibleWaveView(settings.value("showWaveVisual").toBool()); |
| 385 |
settings.remove("showWaveVisual"); |
| 386 |
} |
| 387 |
settings.endGroup(); |
| 388 |
|
| 389 |
// Edit settings |
| 390 |
settings.beginGroup("Editing"); |
| 391 |
QVariant pageJumpLengthWorkaround; |
| 392 |
pageJumpLengthWorkaround.setValue(configLocked->getPageJumpLength()); |
| 393 |
configLocked->setPageJumpLength(static_cast<size_t>(settings.value("pageJumpLength", pageJumpLengthWorkaround).toInt())); |
| 394 |
QVariant editableStepWorkaround; |
| 395 |
editableStepWorkaround.setValue(configLocked->getEditableStep()); |
| 396 |
configLocked->setEditableStep(static_cast<size_t>(settings.value("editableStep", editableStepWorkaround).toInt())); |
| 397 |
configLocked->setKeyRepetition(settings.value("keyRepetition", configLocked->getKeyRepetition()).toBool()); |
| 398 |
settings.endGroup(); |
| 399 |
|
| 400 |
// Wave view |
| 401 |
settings.beginGroup("WaveView"); |
| 402 |
configLocked->setWaveViewFrameRate(settings.value("frameRate", configLocked->getWaveViewFrameRate()).toInt()); |
| 403 |
settings.endGroup(); |
| 404 |
|
| 405 |
// Note names |
| 406 |
settings.beginGroup("NoteNames"); |
| 407 |
configLocked->setNotationSystem( |
| 408 |
static_cast<NoteNotationSystem>(settings.value("notationSystem", static_cast<int>(configLocked->getNotationSystem())).toInt())); |
| 409 |
settings.endGroup(); |
| 410 |
|
| 411 |
// Keys |
| 412 |
settings.beginGroup("Keys"); |
| 413 |
std::unordered_map<Configuration::ShortcutAction, std::string> shortcuts; |
| 414 |
for (const auto& pair : SHORTCUTS_NAME_MAP) { |
| 415 |
std::string def = configLocked->getShortcuts().at(pair.first); |
| 416 |
shortcuts[pair.first] = settings.value("shortcut_" + pair.second, gui_utils::utf8ToQString(def)).toString().toUtf8().toStdString(); |
| 417 |
} |
| 418 |
configLocked->setShortcuts(shortcuts); |
| 419 |
configLocked->setNoteEntryLayout(static_cast<Configuration::KeyboardLayout>( |
| 420 |
settings.value("noteEntryLayout", |
| 421 |
static_cast<int>(configLocked->getNoteEntryLayout())).toInt())); |
| 422 |
std::unordered_map<std::string, JamKey> customLayoutNewKeys; |
| 423 |
for (const auto& pair : JAM_KEY_NAME_MAP) { |
| 424 |
JamKey currentlyWantedJamKey = pair.first; |
| 425 |
customLayoutNewKeys[ |
| 426 |
settings.value("customLayout_" + pair.second, |
| 427 |
QString::fromStdString((*utils::findIf(configLocked->mappingLayouts.at(Configuration::KeyboardLayout::QWERTY), |
| 428 |
[currentlyWantedJamKey](const std::pair<std::string, JamKey>& t) -> bool { |
| 429 |
return (t.second) == currentlyWantedJamKey;}) |
| 430 |
).first)).toString().toUtf8().toStdString()] |
| 431 |
= currentlyWantedJamKey; |
| 432 |
} |
| 433 |
configLocked->setCustomLayoutKeys(customLayoutNewKeys); |
| 434 |
settings.endGroup(); |
| 435 |
|
| 436 |
// Sound // |
| 437 |
settings.beginGroup("Sound"); |
| 438 |
configLocked->setSoundAPI(settings.value("soundAPI", QString::fromStdString(configLocked->getSoundAPI())).toString().toUtf8().toStdString()); |
| 439 |
configLocked->setSoundDevice(settings.value("soundDevice", QString::fromStdString(configLocked->getSoundDevice())).toString().toUtf8().toStdString()); |
| 440 |
configLocked->setRealChipInterface(static_cast<RealChipInterfaceType>( |
| 441 |
settings.value("realChipInterface", static_cast<int>(configLocked->getRealChipInterface())).toInt())); |
| 442 |
configLocked->setEmulator(settings.value("emulator", configLocked->getEmulator()).toInt()); |
| 443 |
QVariant sampleRateWorkaround; |
| 444 |
sampleRateWorkaround.setValue(configLocked->getSampleRate()); |
| 445 |
configLocked->setSampleRate(static_cast<uint32_t>(settings.value("sampleRate", sampleRateWorkaround).toInt())); |
| 446 |
QVariant bufferLengthWorkaround; |
| 447 |
bufferLengthWorkaround.setValue(configLocked->getBufferLength()); |
| 448 |
configLocked->setBufferLength(static_cast<size_t>(settings.value("bufferLength", bufferLengthWorkaround).toInt())); |
| 449 |
configLocked->setResamplerType(static_cast<chip::ResamplerType>( |
| 450 |
settings.value("resamplerType", static_cast<int>(configLocked->getResamplerType())).toInt())); |
| 451 |
configLocked->setImmediateWriteModeEnabled(settings.value("immediateWriteModeEnabled", configLocked->getImmediateWriteModeEnabled()).toBool()); |
| 452 |
settings.endGroup(); |
| 453 |
|
| 454 |
// Midi // |
| 455 |
settings.beginGroup("Midi"); |
| 456 |
configLocked->setMidiEnabled(settings.value("midiEnabled", configLocked->getMidiEnabled()).toBool()); |
| 457 |
configLocked->setMidiAPI(settings.value("midiAPI", QString::fromStdString(configLocked->getMidiAPI())).toString().toStdString()); |
| 458 |
configLocked->setMidiInputPort(settings.value("inputPort", QString::fromStdString(configLocked->getMidiInputPort())).toString().toStdString()); |
| 459 |
settings.endGroup(); |
| 460 |
|
| 461 |
// Mixer // |
| 462 |
settings.beginGroup("Mixer"); |
| 463 |
configLocked->setMixerVolumeMaster(settings.value("mixerVolumeMaster", configLocked->getMixerVolumeMaster()).toInt()); |
| 464 |
configLocked->setMixerVolumeFM(settings.value("mixerVolumeFM", configLocked->getMixerVolumeFM()).toDouble()); |
| 465 |
configLocked->setMixerVolumeSSG(settings.value("mixerVolumeSSG", configLocked->getMixerVolumeSSG()).toDouble()); |
| 466 |
settings.endGroup(); |
| 467 |
|
| 468 |
// Input // |
| 469 |
settings.beginGroup("Input"); |
| 470 |
int size = settings.beginReadArray("fmEnvelopeTextMap"); |
| 471 |
std::vector<FMEnvelopeText> fmEnvelopeTexts; |
| 472 |
for (int i = 0; i < size; ++i) { |
| 473 |
settings.setArrayIndex(i); |
| 474 |
std::string type = settings.value("type").toString().toUtf8().toStdString(); |
| 475 |
std::vector<FMEnvelopeTextType> data; |
| 476 |
const QStringList list = settings.value("order").toString().split(","); |
| 477 |
for (const QString& d : list) { |
| 478 |
data.push_back(static_cast<FMEnvelopeTextType>(d.toInt())); |
| 479 |
} |
| 480 |
fmEnvelopeTexts.push_back({ type, data }); |
| 481 |
} |
| 482 |
if (!fmEnvelopeTexts.empty()) config.lock()->setFMEnvelopeTexts(fmEnvelopeTexts); |
| 483 |
settings.endArray(); |
| 484 |
settings.endGroup(); |
| 485 |
|
| 486 |
// Appearance |
| 487 |
settings.beginGroup("Appearance"); |
| 488 |
configLocked->setPatternEditorHeaderFont(settings.value("patternEditorHeaderFont", QString::fromStdString(configLocked->getPatternEditorHeaderFont())).toString().toStdString()); |
| 489 |
configLocked->setPatternEditorRowsFont(settings.value("patternEditorRowsFont", QString::fromStdString(configLocked->getPatternEditorRowsFont())).toString().toStdString()); |
| 490 |
configLocked->setOrderListHeaderFont(settings.value("orderListHeaderFont", QString::fromStdString(configLocked->getOrderListHeaderFont())).toString().toStdString()); |
| 491 |
configLocked->setOrderListRowsFont(settings.value("orderListRowsFont", QString::fromStdString(configLocked->getOrderListRowsFont())).toString().toStdString()); |
| 492 |
settings.endGroup(); |
| 493 |
|
| 494 |
return true; |
| 495 |
} |
| 496 |
catch (...) { |
| 497 |
return false; |
| 498 |
} |
| 499 |
} |
| 500 |
} |