Skip to content

Commit fe15e1e

Browse files
committed
bug fix
1 parent 27d4e41 commit fe15e1e

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

midi_app_controller/state/state_manager.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,28 @@ def select_controller_path(self, controller_path: Optional[Path]) -> None:
203203
else None
204204
)
205205

206+
def create_selected_ports_dict(self) -> dict[str, str]:
207+
selected_ports_dict = {}
208+
if self.selected_midi_in is not None:
209+
selected_ports_dict["in"] = self.selected_midi_in
210+
211+
if self.selected_midi_out is not None:
212+
selected_ports_dict["out"] = self.selected_midi_out
213+
return selected_ports_dict
214+
206215
def select_midi_in(self, port_name: Optional[str]) -> None:
207216
"""Updates currently selected MIDI input port name.
208217
209218
Does not have any immediate effect except updating the value.
210219
"""
211220
self.selected_midi_in = port_name
212221
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-
}
222+
selected_ports_dict = self.create_selected_ports_dict()
223+
224+
if selected_ports_dict:
225+
self.recent_midi_ports_for_controller[self.selected_controller.path] = (
226+
selected_ports_dict
227+
)
217228

218229
def select_midi_out(self, port_name: Optional[str]) -> None:
219230
"""Updates currently selected MIDI output port name.
@@ -222,10 +233,12 @@ def select_midi_out(self, port_name: Optional[str]) -> None:
222233
"""
223234
self.selected_midi_out = port_name
224235
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-
}
236+
selected_ports_dict = self.create_selected_ports_dict()
237+
238+
if selected_ports_dict:
239+
self.recent_midi_ports_for_controller[self.selected_controller.path] = (
240+
selected_ports_dict
241+
)
229242

230243
def stop_handling(self) -> None:
231244
"""Stops handling any MIDI signals."""

0 commit comments

Comments
 (0)