Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit ce305d1

Browse files
'Backup'
1 parent 4c4399b commit ce305d1

5 files changed

Lines changed: 48 additions & 41 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from protocol0.application.command.LoadMinitaurCommand import LoadMinitaurCommand
22
from protocol0.application.command_handler.CommandHandlerInterface import CommandHandlerInterface
3+
from protocol0.domain.lom.instrument.InstrumentInterface import load_instrument_track
34
from protocol0.domain.lom.instrument.instrument.InstrumentMinitaur import InstrumentMinitaur
45

56

67
class LoadMinitaurCommandHandler(CommandHandlerInterface):
78
def handle(self, command):
89
# type: (LoadMinitaurCommand) -> None
9-
InstrumentMinitaur.load_instrument_track()
10+
load_instrument_track(InstrumentMinitaur)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from protocol0.application.command.LoadRev2Command import LoadRev2Command
22
from protocol0.application.command_handler.CommandHandlerInterface import CommandHandlerInterface
3+
from protocol0.domain.lom.instrument.InstrumentInterface import load_instrument_track
34
from protocol0.domain.lom.instrument.instrument.InstrumentRev2 import InstrumentRev2
45

56

67
class LoadRev2CommandHandler(CommandHandlerInterface):
78
def handle(self, command):
89
# type: (LoadRev2Command) -> None
9-
InstrumentRev2.load_instrument_track()
10+
load_instrument_track(InstrumentRev2)
1011

domain/lom/instrument/InstrumentInterface.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from functools import partial
2+
13
from _Framework.SubjectSlot import SlotManager
2-
from typing import Optional, Type
4+
from typing import Optional, Type, TYPE_CHECKING
35

46
from protocol0.domain.lom.device.Device import Device
57
from protocol0.domain.lom.device.DeviceEnum import DeviceEnum
@@ -22,10 +24,48 @@
2224
from protocol0.domain.lom.instrument.preset.preset_initializer.PresetInitializerInterface import (
2325
PresetInitializerInterface,
2426
)
27+
from protocol0.domain.shared.backend.Backend import Backend
2528
from protocol0.domain.shared.errors.Protocol0Warning import Protocol0Warning
29+
from protocol0.shared.SongFacade import SongFacade
2630
from protocol0.shared.sequence.Sequence import Sequence
2731

2832

33+
if TYPE_CHECKING:
34+
from protocol0.domain.lom.track.abstract_track.AbstractTrack import AbstractTrack
35+
36+
37+
def _get_insert_instrument_track(instrument_cls):
38+
# type: (Type["InstrumentInterface"]) -> AbstractTrack
39+
"""Current track or last instrument track or last track"""
40+
target_color = instrument_cls.TRACK_COLOR.value
41+
42+
if SongFacade.current_track().color == target_color:
43+
return SongFacade.current_track()
44+
45+
instrument_tracks = [
46+
t
47+
for t in SongFacade.simple_tracks()
48+
if t.group_track is None and t.color == target_color
49+
]
50+
51+
last_track = list(SongFacade.simple_tracks())[-1]
52+
53+
return next(reversed(instrument_tracks), last_track)
54+
55+
56+
def load_instrument_track(instrument_cls):
57+
# type: (Type["InstrumentInterface"]) -> Sequence
58+
insert_track = _get_insert_instrument_track(instrument_cls)
59+
track_color = insert_track.color
60+
61+
insert_track.focus()
62+
seq = Sequence()
63+
seq.add(partial(Backend.client().load_instrument_track, instrument_cls.INSTRUMENT_TRACK_NAME))
64+
seq.wait_for_backend_event("instrument_loaded")
65+
seq.add(partial(setattr, insert_track, "color", track_color))
66+
return seq.done()
67+
68+
2969
class InstrumentInterface(SlotManager):
3070
NAME = ""
3171
DEVICE = None # type: Optional[DeviceEnum]
@@ -39,6 +79,7 @@ class InstrumentInterface(SlotManager):
3979
PRESET_OFFSET = 0 # if we store presets not at the beginning of the list
4080
PRESET_CHANGER = ProgramChangePresetChanger # type: Type[PresetChangerInterface]
4181
PRESET_INITIALIZER = PresetInitializerDevicePresetName # type: Type[PresetInitializerInterface]
82+
INSTRUMENT_TRACK_NAME = ""
4283

4384
def __init__(self, device, track_name):
4485
# type: (Optional[Device], str) -> None
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
from functools import partial
2-
31
from protocol0.domain.lom.instrument.InstrumentColorEnum import InstrumentColorEnum
42
from protocol0.domain.lom.instrument.InstrumentInterface import InstrumentInterface
53
from protocol0.domain.lom.instrument.preset.PresetProgramSelectedEvent import \
64
PresetProgramSelectedEvent
75
from protocol0.domain.lom.instrument.preset.preset_initializer.PresetInitializerGroupTrackName import (
86
PresetInitializerGroupTrackName,
97
)
10-
from protocol0.domain.shared.backend.Backend import Backend
118
from protocol0.domain.shared.event.DomainEventBus import DomainEventBus
12-
from protocol0.shared.SongFacade import SongFacade
13-
from protocol0.shared.sequence.Sequence import Sequence
149

1510

1611
class InstrumentMinitaur(InstrumentInterface):
1712
NAME = "Minitaur"
1813
PRESET_EXTENSION = ".syx"
1914
TRACK_COLOR = InstrumentColorEnum.MINITAUR
15+
INSTRUMENT_TRACK_NAME = "Bass"
2016
CAN_BE_SHOWN = False
2117
PRESETS_PATH = (
2218
"C:\\Users\\thiba\\AppData\\Roaming\\Moog Music Inc\\Minitaur\\Presets Library\\User"
@@ -28,18 +24,3 @@ class InstrumentMinitaur(InstrumentInterface):
2824
def set_default_preset(self):
2925
# type: () -> None
3026
DomainEventBus.emit(PresetProgramSelectedEvent(2))
31-
32-
@classmethod
33-
def load_instrument_track(cls):
34-
# type: () -> Sequence
35-
minitaur_track = next(SongFacade.external_synth_tracks(InstrumentMinitaur), None)
36-
37-
track_to_focus = minitaur_track or list(SongFacade.simple_tracks())[-1]
38-
track_color = track_to_focus.color
39-
40-
track_to_focus.focus()
41-
seq = Sequence()
42-
seq.add(Backend.client().load_instrument_track)
43-
seq.wait_for_backend_event("instrument_loaded")
44-
seq.add(partial(setattr, track_to_focus, "color", track_color))
45-
return seq.done()

domain/lom/instrument/instrument/InstrumentRev2.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
from functools import partial
2-
31
from typing import Optional, Any
42

53
from protocol0.domain.lom.device.DeviceEnum import DeviceEnum
64
from protocol0.domain.lom.instrument.InstrumentColorEnum import InstrumentColorEnum
75
from protocol0.domain.lom.instrument.InstrumentInterface import InstrumentInterface
8-
from protocol0.domain.lom.instrument.instrument.InstrumentMinitaur import InstrumentMinitaur
96
from protocol0.domain.lom.track.simple_track.SimpleTrackArmedEvent import SimpleTrackArmedEvent
107
from protocol0.domain.shared.backend.Backend import Backend
118
from protocol0.domain.shared.event.DomainEventBus import DomainEventBus
@@ -23,6 +20,7 @@ class InstrumentRev2(InstrumentInterface):
2320
NAME = "Rev2"
2421
DEVICE = DeviceEnum.REV2_EDITOR
2522
TRACK_COLOR = InstrumentColorEnum.REV2
23+
INSTRUMENT_TRACK_NAME = "Synth"
2624
ACTIVE_INSTANCE = None # type: Optional[InstrumentRev2]
2725

2826
def __init__(self, *a, **k):
@@ -39,21 +37,6 @@ def __init__(self, *a, **k):
3937
ExternalSynthAudioRecordingEndedEvent, self._on_audio_recording_ended_event
4038
)
4139

42-
@classmethod
43-
def load_instrument_track(cls):
44-
# type: () -> Sequence
45-
minitaur_track = next(SongFacade.external_synth_tracks(InstrumentMinitaur), None)
46-
47-
track_to_focus = minitaur_track or list(SongFacade.simple_tracks())[-1]
48-
track_color = track_to_focus.color
49-
50-
track_to_focus.focus()
51-
seq = Sequence()
52-
seq.add(Backend.client().load_instrument_track)
53-
seq.wait_for_backend_event("instrument_loaded")
54-
seq.add(partial(setattr, track_to_focus, "color", track_color))
55-
return seq.done()
56-
5740
@property
5841
def needs_exclusive_activation(self):
5942
# type: () -> bool

0 commit comments

Comments
 (0)