5454]
5555
5656
57+ _PRESET_BY_VALUE = {
58+ 0 : EQPreset .BALANCED ,
59+ 1 : EQPreset .VOICE ,
60+ 2 : EQPreset .MORE_TREBLE ,
61+ 3 : EQPreset .MORE_BASS ,
62+ }
63+
64+
5765class _EqWorker (QObject ):
5866 applied = Signal ()
67+ loaded = Signal (object , object )
5968 failed = Signal (str )
6069
6170 def __init__ (self ) -> None :
@@ -69,6 +78,9 @@ def set_preset(self, preset: EQPreset) -> None:
6978 def apply_custom (self , bands : list [EqBand ]) -> None :
7079 self ._spawn (self ._apply_custom , bands )
7180
81+ def load (self ) -> None :
82+ self ._spawn (self ._load )
83+
7284 def _spawn (self , fn , * args ) -> None :
7385 if self .address :
7486 threading .Thread (target = fn , args = args , daemon = True ).start ()
@@ -89,6 +101,15 @@ def _apply_custom(self, bands: list[EqBand]) -> None:
89101 except Exception as exc :
90102 self .failed .emit (str (exc ))
91103
104+ def _load (self ) -> None :
105+ try :
106+ with NothingController (self .address , channel = self .channel ) as ctrl :
107+ bands = ctrl .get_custom_eq ()
108+ mode = ctrl .get_eq_mode ()
109+ self .loaded .emit (bands , mode )
110+ except Exception as exc :
111+ self .failed .emit (str (exc ))
112+
92113
93114class EqTab (QWidget ):
94115 def __init__ (self , mock : bool = False ) -> None :
@@ -98,6 +119,7 @@ def __init__(self, mock: bool = False) -> None:
98119
99120 self ._worker = _EqWorker ()
100121 self ._worker .applied .connect (lambda : self ._set_hint ("Applied." ))
122+ self ._worker .loaded .connect (self ._on_loaded )
101123 self ._worker .failed .connect (lambda m : self ._set_hint (f"Error: { m } " ))
102124
103125 self ._build ()
@@ -179,15 +201,29 @@ def _build(self) -> None:
179201 self ._set_enabled (False )
180202
181203 def set_device (self , address : str | None , channel : int = 15 ) -> None :
204+ changed = address != self ._address
182205 self ._address = address
183206 self ._worker .address = address
184207 self ._worker .channel = channel
185208 self ._set_enabled (address is not None )
186- self ._set_hint (
187- "Drag the points, or import a profile, then Apply."
188- if address
189- else "No connected Nothing device."
190- )
209+ if address is None :
210+ self ._set_hint ("No connected Nothing device." )
211+ elif changed and not self ._mock :
212+ self ._set_hint ("Reading current EQ from device ..." )
213+ self ._worker .load ()
214+ elif self ._mock :
215+ self ._set_hint ("Mock mode: commands are not sent." )
216+
217+ def _on_loaded (self , bands , mode ) -> None :
218+ if isinstance (bands , list ) and len (bands ) >= len (self ._curve .bands ()):
219+ self ._curve .set_bands (bands [: len (self ._curve .bands ())])
220+ active = _PRESET_BY_VALUE .get (mode )
221+ for btn , (_label , preset ) in zip (self ._preset_buttons , _PRESETS ):
222+ btn .setChecked (preset == active )
223+ if active is not None :
224+ self ._set_hint (f"Synced. Active preset: { active .value } ." )
225+ else :
226+ self ._set_hint ("Synced custom EQ from device." )
191227
192228 def _set_enabled (self , enabled : bool ) -> None :
193229 self ._apply_btn .setEnabled (enabled )
0 commit comments