@@ -49,6 +49,10 @@ class StateManager:
49
49
recent_binds_for_controller: dict[Path, Path] = {}
50
50
Mapping of controller schemas to the binds set most recently used
51
51
with the schema.
52
+ recent_midi_ports_for_controller: dict[Path, dict[str, str]]
53
+ Mapping of controller schemas to the MIDI ports most
54
+ recently used (precisely dict with keys "in" and "out")
55
+ with the schema.
52
56
selected_midi_in : Optional[str]
53
57
Name of currently selected MIDI input.
54
58
selected_midi_out : Optional[str]
@@ -68,7 +72,8 @@ class StateManager:
68
72
def __init__ (self , app : Application ):
69
73
self .selected_controller = None
70
74
self .selected_binds = None
71
- self .recent_binds_for_controller : dict [Path , Path ] = {}
75
+ self .recent_binds_for_controller = {}
76
+ self .recent_midi_ports_for_controller = {}
72
77
self .selected_midi_in = None
73
78
self .selected_midi_out = None
74
79
self .app = app
@@ -204,13 +209,23 @@ def select_midi_in(self, port_name: Optional[str]) -> None:
204
209
Does not have any immediate effect except updating the value.
205
210
"""
206
211
self .selected_midi_in = port_name
212
+ if self .selected_controller :
213
+ self .recent_midi_ports_for_controller [self .selected_controller .path ] = {
214
+ "in" : self .selected_midi_in ,
215
+ "out" : self .selected_midi_out ,
216
+ }
207
217
208
218
def select_midi_out (self , port_name : Optional [str ]) -> None :
209
219
"""Updates currently selected MIDI output port name.
210
220
211
221
Does not have any immediate effect except updating the value.
212
222
"""
213
223
self .selected_midi_out = port_name
224
+ if self .selected_controller :
225
+ self .recent_midi_ports_for_controller [self .selected_controller .path ] = {
226
+ "in" : self .selected_midi_in ,
227
+ "out" : self .selected_midi_out ,
228
+ }
214
229
215
230
def stop_handling (self ) -> None :
216
231
"""Stops handling any MIDI signals."""
@@ -269,6 +284,18 @@ def start_handling(self) -> None:
269
284
midi_out = self ._midi_out ,
270
285
)
271
286
287
+ def select_recent_midi_ports (self ):
288
+ """Select MIDI ports that were recently used with the current controller."""
289
+ if (
290
+ self .selected_controller
291
+ and self .selected_controller .path in self .recent_midi_ports_for_controller
292
+ ):
293
+ ports = self .recent_midi_ports_for_controller [self .selected_controller .path ]
294
+ if ports ["in" ] in self .get_available_midi_in ():
295
+ self .selected_midi_in = ports ["in" ]
296
+ if ports ["out" ] in self .get_available_midi_out ():
297
+ self .selected_midi_out = ports ["out" ]
298
+
272
299
def save_state (self ):
273
300
"""Saves the current settings to the disk."""
274
301
AppState (
@@ -281,6 +308,7 @@ def save_state(self):
281
308
selected_midi_in = self .selected_midi_in ,
282
309
selected_midi_out = self .selected_midi_out ,
283
310
recent_binds_for_controller = self .recent_binds_for_controller ,
311
+ recent_midi_ports_for_controller = self .recent_midi_ports_for_controller ,
284
312
).save_to (Config .APP_STATE_FILE )
285
313
286
314
def load_state (self ):
@@ -316,6 +344,7 @@ def load_state(self):
316
344
self .select_midi_in (state .selected_midi_in )
317
345
self .select_midi_out (state .selected_midi_out )
318
346
self .recent_binds_for_controller = state .recent_binds_for_controller
347
+ self .recent_midi_ports_for_controller = state .recent_midi_ports_for_controller
319
348
320
349
321
350
_STATE_MANAGER = None
0 commit comments