55#include " ../GUI/Layout/TrackComponent.h"
66#include " ../GUI/Layout/MasterUtilityComponent.h"
77#include " ../GUI/Layout/PresetBarComponent.h"
8+ // <<< FIX: Include the full definition for MenubarComponent >>>
89#include " ../GUI/Layout/MenubarComponent.h"
910#include " juce_audio_devices/juce_audio_devices.h"
1011#include < juce_cryptography/juce_cryptography.h>
@@ -23,6 +24,7 @@ namespace SessionIds
2324 const juce::Identifier ACTIVE_PRESET (" ACTIVE_PRESET" );
2425 const juce::Identifier presetName (" name" );
2526 const juce::Identifier OPEN_WINDOWS (" OPEN_WINDOWS" );
27+ const juce::Identifier QUICK_PRESETS (" QUICK_PRESETS" );
2628}
2729
2830namespace WindowStateIds
@@ -39,6 +41,9 @@ AppState& AppState::getInstance()
3941AppState::AppState ()
4042{
4143 currentPresetName = LanguageManager::getInstance ().get (" presetbar.noPresetLoaded" );
44+ // <<< MODIFIED: Initialize for 5 quick preset slots >>>
45+ for (int i = 0 ; i < numQuickSlots; ++i)
46+ quickPresetSlots.add ({});
4247}
4348
4449AppState::~AppState () {}
@@ -91,6 +96,7 @@ juce::File AppState::getSessionFile() const
9196
9297void AppState::saveState (MainComponent& mainComponent)
9398{
99+ // ... (code to save other settings is unchanged) ...
94100 auto & deviceManager = mainComponent.getAudioDeviceManager ();
95101 auto & audioEngine = mainComponent.getAudioEngine ();
96102
@@ -112,6 +118,13 @@ void AppState::saveState(MainComponent& mainComponent)
112118 auto * presetStateXml = sessionXml->createNewChildElement (SessionIds::ACTIVE_PRESET);
113119 presetStateXml->setAttribute (SessionIds::presetName, getCurrentPresetName ());
114120
121+ // <<< MODIFIED: Save 5 quick preset assignments >>>
122+ auto * quickPresetsXml = sessionXml->createNewChildElement (SessionIds::QUICK_PRESETS);
123+ for (int i = 0 ; i < quickPresetSlots.size (); ++i)
124+ {
125+ quickPresetsXml->setAttribute (" slot" + juce::String (i), quickPresetSlots[i]);
126+ }
127+
115128 auto * openWindowsStateXml = sessionXml->createNewChildElement (SessionIds::OPEN_WINDOWS);
116129 auto vocalWindowsState = mainComponent.getVocalTrack ().getOpenWindowsState ();
117130 if (vocalWindowsState.getNumChildren () > 0 )
@@ -154,32 +167,40 @@ void AppState::loadPostDeviceState(MainComponent& mainComponent)
154167
155168 if (auto xml = juce::parseXML (sessionFile))
156169 {
170+ // ... (loading routing state is unchanged) ...
157171 auto * routingStateXml = xml->getChildByName (SessionIds::ROUTING);
158172 if (routingStateXml != nullptr )
159173 {
160174 auto vocalInputName = routingStateXml->getStringAttribute (SessionIds::VOCAL_INPUT);
161175 auto musicInputName = routingStateXml->getStringAttribute (SessionIds::MUSIC_INPUT);
162176 auto appOutputName = routingStateXml->getStringAttribute (SessionIds::APP_OUTPUT);
163177
164- // Cập nhật AudioEngine (không đổi)
165178 mainComponent.getAudioEngine ().setVocalInputChannelByName (vocalInputName);
166179 mainComponent.getAudioEngine ().setMusicInputChannelByName (musicInputName);
167180 mainComponent.getAudioEngine ().setSelectedOutputChannelsByName (appOutputName);
168181
169- // Cập nhật giao diện thông qua các component mới
170182 if (auto * vocalSelector = mainComponent.getVocalTrack ().getChannelSelector ())
171183 vocalSelector->setSelectedChannelByName (vocalInputName);
172184
173185 if (auto * musicSelector = mainComponent.getMusicTrack ().getChannelSelector ())
174186 musicSelector->setSelectedChannelByName (musicInputName);
175187
176- // <<< SỬA: Cách cập nhật MenubarComponent >>>
177188 if (auto * menubar = mainComponent.getMenubarComponent ())
178189 if (auto * outputSelector = menubar->getOutputSelector ())
179190 outputSelector->setSelectedChannelByName (appOutputName);
180191 }
181192
182- // ... (phần còn lại của hàm không đổi) ...
193+ // <<< MODIFIED: Load 5 quick preset assignments >>>
194+ auto * quickPresetsXml = xml->getChildByName (SessionIds::QUICK_PRESETS);
195+ if (quickPresetsXml != nullptr )
196+ {
197+ for (int i = 0 ; i < quickPresetSlots.size (); ++i)
198+ {
199+ quickPresetSlots.set (i, quickPresetsXml->getStringAttribute (" slot" + juce::String (i), {}));
200+ }
201+ }
202+
203+ // ... (loading active preset and open windows is unchanged) ...
183204 auto * presetStateXml = xml->getChildByName (SessionIds::ACTIVE_PRESET);
184205 if (presetStateXml != nullptr )
185206 {
@@ -258,4 +279,29 @@ void AppState::loadLockState(bool isLocked, const juce::String& passwordHash)
258279 systemLocked = isLocked;
259280 lockPasswordHash = passwordHash;
260281 sendChangeMessage ();
282+ }
283+
284+ // <<< ADDED: Implementation for Quick Preset Slot Management >>>
285+ void AppState::assignQuickPreset (int slotIndex, const juce::String& presetName)
286+ {
287+ if (juce::isPositiveAndBelow (slotIndex, quickPresetSlots.size ()))
288+ {
289+ if (quickPresetSlots[slotIndex] != presetName)
290+ {
291+ quickPresetSlots.set (slotIndex, presetName);
292+ sendChangeMessage (); // Notify listeners (like PresetBarComponent)
293+ }
294+ }
295+ }
296+
297+ juce::String AppState::getQuickPresetName (int slotIndex) const
298+ {
299+ if (juce::isPositiveAndBelow (slotIndex, quickPresetSlots.size ()))
300+ return quickPresetSlots[slotIndex];
301+ return {};
302+ }
303+
304+ int AppState::getNumQuickPresetSlots () const
305+ {
306+ return numQuickSlots;
261307}
0 commit comments