@@ -73,6 +73,13 @@ public MicrophoneController(MainModel model, ModelStorageService modelStorageSer
7373 microphone .setAlgorithm (model .getStoredAlgorithmIndex ());
7474 microphone .setName (model .getStoredMicrophoneIndex ());
7575 microphone .setConfidence (model .getStoredConfidenceIndex ());
76+ microphone .setChordConfidence (model .getStoredChordConfidenceIndex ());
77+
78+ // Set chord detection enabled based on the "Show Chords" setting
79+ // If showChordIndex is 1, chord display is enabled
80+ microphone .setChordDetectionEnabled (model .getSelectedShowChordIndex () == 1 );
81+ LoggingUtils .logDebug ("Chord detection " + (model .getSelectedShowChordIndex () == 1 ? "enabled" : "disabled" ) +
82+ " based on Show Chords setting: " + model .getSelectedShowChordIndex ());
7683
7784 LoggingUtils .logDebug ("Registering microphone handler" );
7885 microphone .setMicrophoneHandler (this );
@@ -227,6 +234,26 @@ public void initConfidenceList() {
227234 }
228235 }
229236
237+ @ Override
238+ public void initChordConfidenceList () {
239+ LoggingContext .setComponent ("MicrophoneController" );
240+ LoggingUtils .logOperationStarted ("Chord confidence list initialization" );
241+
242+ if (window .isMicrophoneSettingsViewActive ()) {
243+ MicrophoneSettingsView microphoneSettingsView = window .getMicrophoneSettingsView ();
244+
245+ LoggingUtils .logDebug ("Setting chord confidence list in the microphone settings view" );
246+ microphoneSettingsView .setChordConfidences (AbstractMicrophone .getSupportedChordConfidences ());
247+
248+ LoggingUtils .logDebug ("Setting the selected chord confidence in the microphone settings view" );
249+ microphoneSettingsView .setSelectedChordConfidence (model .getSelectedChordConfidenceIndex ());
250+
251+ LoggingUtils .logOperationCompleted ("Chord confidence list initialization" );
252+ } else {
253+ LoggingUtils .logWarning ("Chord confidence list initialization skipped" , "Microphone settings view is not active" );
254+ }
255+ }
256+
230257 @ Override
231258 public void handleConfidenceSelection (int confidenceIndex ) {
232259 LoggingContext .setComponent ("MicrophoneController" );
@@ -251,6 +278,30 @@ public void handleConfidenceSelection(int confidenceIndex) {
251278 LoggingUtils .logPerformance ("Model storage" , duration );
252279 }
253280
281+ @ Override
282+ public void handleChordConfidenceSelection (int chordConfidenceIndex ) {
283+ LoggingContext .setComponent ("MicrophoneController" );
284+ LoggingUtils .logUserAction ("Chord confidence selection" , "chordConfidenceIndex=" + chordConfidenceIndex );
285+
286+ LoggingUtils .logDebug ("Updating stored chord confidence index in the model" );
287+ this .model .setStoredChordConfidenceIndex (chordConfidenceIndex );
288+ this .model .setSelectedChordConfidenceIndex (chordConfidenceIndex );
289+
290+ if (microphone != null ) {
291+ LoggingUtils .logDebug ("Setting chord confidence index on the microphone" , "chordConfidenceIndex=" + chordConfidenceIndex );
292+ microphone .setChordConfidence (chordConfidenceIndex );
293+ LoggingUtils .logOperationCompleted ("Chord confidence selection handling" );
294+ } else {
295+ LoggingUtils .logWarning ("Cannot set chord confidence index" , "Microphone object is null" );
296+ }
297+
298+ LoggingUtils .logDebug ("Storing updated model" );
299+ long startTime = System .currentTimeMillis ();
300+ modelStorageService .storeModel (model );
301+ long duration = System .currentTimeMillis () - startTime ;
302+ LoggingUtils .logPerformance ("Model storage" , duration );
303+ }
304+
254305 /**
255306 * Updates the microphone settings view with the specified frequency.
256307 *
@@ -280,4 +331,21 @@ private void updateMicrophoneSettingsViewVolume(double volume) {
280331 microphoneSettingsView .setVolume (volume );
281332 }
282333 }
334+
335+ /**
336+ * Updates the microphone's chord detection setting based on the model's "Show Chords" setting.
337+ * This method should be called whenever the "Show Chords" setting is changed.
338+ */
339+ public void updateChordDetectionSetting () {
340+ LoggingContext .setComponent ("MicrophoneController" );
341+ LoggingUtils .logOperationStarted ("Updating chord detection setting" );
342+
343+ boolean enableChordDetection = model .getSelectedShowChordIndex () == 1 ;
344+ microphone .setChordDetectionEnabled (enableChordDetection );
345+
346+ LoggingUtils .logDebug ("Chord detection " + (enableChordDetection ? "enabled" : "disabled" ) +
347+ " based on Show Chords setting: " + model .getSelectedShowChordIndex ());
348+
349+ LoggingUtils .logOperationCompleted ("Chord detection setting update" );
350+ }
283351}
0 commit comments