diff options
author | Eddy Pedroni <epedroni@pm.me> | 2024-11-10 09:39:29 +0100 |
---|---|---|
committer | Eddy Pedroni <epedroni@pm.me> | 2024-11-10 09:39:29 +0100 |
commit | 85b0116f80515c71e0250e4910c721b9e4fabca1 (patch) | |
tree | f046e140c13c3be744b041193e9100ea748c582b /solo-tool-project | |
parent | 7c00f418caf8f1e9fcb235563127a9c8cea22bb4 (diff) |
Set A and B limits via MIDI controller
Diffstat (limited to 'solo-tool-project')
-rw-r--r-- | solo-tool-project/src/solo_tool/midi_controller_launchpad_mini.py | 41 | ||||
-rw-r--r-- | solo-tool-project/test/midi_launchpad_mini_integrationtest.py | 60 |
2 files changed, 82 insertions, 19 deletions
diff --git a/solo-tool-project/src/solo_tool/midi_controller_launchpad_mini.py b/solo-tool-project/src/solo_tool/midi_controller_launchpad_mini.py index 8f32650..ee77d21 100644 --- a/solo-tool-project/src/solo_tool/midi_controller_launchpad_mini.py +++ b/solo-tool-project/src/solo_tool/midi_controller_launchpad_mini.py @@ -30,16 +30,21 @@ class MidiController: self._soloTool.registerPlaybackRateCallback(self._updateRateRow) self._soloTool.registerAbLimitEnabledCallback(self._updateToggleAbLimitEnableButton) + self._aLimit = 0.0 + self._bLimit = 0.0 + def _registerHandlers(self): self._handlers = { 96 : self._soloTool.stop, - 99 : self._soloTool.jumpToA, + 114 : self._soloTool.jumpToA, 112 : self._playPause, - 101 : self._toggleAbLimitEnable, - 102 : self._soloTool.previousStoredAbLimits, - 103 : self._soloTool.nextStoredAbLimits, - 118 : self._soloTool.previousSong, - 119 : self._soloTool.nextSong + 98 : self._toggleAbLimitEnable, + 118 : self._soloTool.previousStoredAbLimits, + 119 : self._soloTool.nextStoredAbLimits, + 116 : self._setALimit, + 117 : self._setBLimit, + 48 : self._soloTool.previousSong, + 55 : self._soloTool.nextSong } for i in range(0, 8): @@ -71,6 +76,14 @@ class MidiController: else: self._soloTool.play() + def _setALimit(self): + self._aLimit = self._soloTool.getPlaybackPosition() + self._soloTool.setAbLimits(self._aLimit, self._bLimit) + + def _setBLimit(self): + self._bLimit = self._soloTool.getPlaybackPosition() + self._soloTool.setAbLimits(self._aLimit, self._bLimit) + def _toggleAbLimitEnable(self): self._soloTool.setAbLimitEnable(not self._soloTool.isAbLimitEnabled()) @@ -82,9 +95,9 @@ class MidiController: def _updateToggleAbLimitEnableButton(self, enabled): if enabled: - self._setButtonLED(6, 5, MidiController.LED_GREEN) + self._setButtonLED(6, 2, MidiController.LED_GREEN) else: - self._setButtonLED(6, 5, MidiController.LED_RED) + self._setButtonLED(6, 2, MidiController.LED_RED) def _updateVolumeRow(self, volume): t1 = int(round(volume / MidiController.PLAYBACK_VOLUME_STEP, 1)) @@ -138,11 +151,13 @@ class MidiController: self._updateToggleAbLimitEnableButton(self._soloTool.isAbLimitEnabled()) # AB control - self._setButtonLED(6, 3, MidiController.LED_YELLOW) - self._setButtonLED(6, 6, MidiController.LED_RED) - self._setButtonLED(6, 7, MidiController.LED_GREEN) - - # Song control + self._setButtonLED(7, 2, MidiController.LED_YELLOW) self._setButtonLED(7, 6, MidiController.LED_RED) self._setButtonLED(7, 7, MidiController.LED_GREEN) + self._setButtonLED(7, 4, MidiController.LED_YELLOW) + self._setButtonLED(7, 5, MidiController.LED_YELLOW) + + # Song control + self._setButtonLED(3, 0, MidiController.LED_RED) + self._setButtonLED(3, 7, MidiController.LED_GREEN) diff --git a/solo-tool-project/test/midi_launchpad_mini_integrationtest.py b/solo-tool-project/test/midi_launchpad_mini_integrationtest.py index 17649d4..e7c1315 100644 --- a/solo-tool-project/test/midi_launchpad_mini_integrationtest.py +++ b/solo-tool-project/test/midi_launchpad_mini_integrationtest.py @@ -9,14 +9,24 @@ LED_YELLOW = 126 LED_GREEN = 124 LED_OFF = 0 -nextSongButton = 119 -previousSongButton = 118 +nextSongButton = 55 +plus1MinuteButton = 54 +plus30SecondsButton = 53 +plus5SecondsButton = 52 +minus5SecondsButton = 51 +minus30SecondsButton = 50 +minus1MinuteButton = 49 +previousSongButton = 48 + playPauseButton = 112 stopButton = 96 -nextLimitButton = 103 -previousLimitButton = 102 -abToggleButton = 101 -jumpToAButton = 99 + +nextLimitButton = 119 +previousLimitButton = 118 +abToggleButton = 98 +jumpToAButton = 114 +setAButton = 116 +setBButton = 117 class MidiWrapperMock: def __init__(self): @@ -352,6 +362,8 @@ def test_connectDisconnect(uut, midiWrapperMock): (jumpToAButton, LED_YELLOW, 0), (previousLimitButton, LED_RED, 0), (nextLimitButton, LED_GREEN, 0), + (setAButton, LED_YELLOW, 0), + (setBButton, LED_YELLOW, 0), (previousSongButton, LED_RED, 0), (nextSongButton, LED_GREEN, 0) ]) @@ -388,3 +400,39 @@ def test_playingFeedbackWhenChangingSong(uut, midiWrapperMock, soloTool, playerM assert playerMock.state == PlayerMock.STOPPED assert midiWrapperMock.getLatestMessage() == (playPauseButton, LED_YELLOW, 0) +def test_setAbButtons(uut, midiWrapperMock, soloTool, playerMock): + song = "test.flac" + soloTool.addSong(song) + soloTool.setSong(0) + soloTool.setAbLimitEnable(True) + abLimits = (0.6, 0.8) + soloTool.storeAbLimits(abLimits[0], abLimits[1]) + + uut.connect() + + def checkLimit(aLimit, bLimit): + playerMock.position = bLimit - 0.1 + soloTool.tick() + assert playerMock.position == bLimit - 0.1 + + playerMock.position = bLimit + 0.1 + soloTool.tick() + assert playerMock.position == aLimit + + # Set A limit + playerMock.position = 0.3 + midiWrapperMock.simulateInput(setAButton) + playerMock.position = 0.5 + midiWrapperMock.simulateInput(jumpToAButton) + + assert playerMock.position == 0.3 + + # Set B limit + playerMock.position = 0.4 + midiWrapperMock.simulateInput(setBButton) + checkLimit(0.3, 0.4) + + # Selecting preset overrides manually set limits + midiWrapperMock.simulateInput(nextLimitButton) + checkLimit(abLimits[0], abLimits[1]) + |