aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2025-02-22 08:17:29 +0100
committerEddy Pedroni <epedroni@pm.me>2025-02-22 08:17:29 +0100
commiteaec524a233c9ee11023f21d430bcbc2f4d5a17e (patch)
tree9028a1879aaa07c373bd51198f6aed60eb6dfd1b
parentb676f88b21ef8046dcd3d9dac4b270007f2b959a (diff)
Moved nextSong and previousSong to SoloToolController
-rw-r--r--solo-tool-project/src/solo_tool/midi_controller_launchpad_mini.py6
-rw-r--r--solo-tool-project/src/solo_tool/playlist.py14
-rw-r--r--solo-tool-project/src/solo_tool/solo_tool.py15
-rw-r--r--solo-tool-project/src/solo_tool/solo_tool_controller.py22
-rw-r--r--solo-tool-project/test/midi_launchpad_mini_integrationtest.py2
-rw-r--r--solo-tool-project/test/playlist_unittest.py45
-rw-r--r--solo-tool-project/test/solo_tool_controller_integrationtest.py86
-rw-r--r--solo-tool-project/test/solo_tool_integrationtest.py39
8 files changed, 116 insertions, 113 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 fb6e385..4fde8fc 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
@@ -1,4 +1,5 @@
from .midi_wrapper_mido import MidiWrapper
+from .solo_tool_controller import SoloToolController
class MidiController:
DEVICE_NAME = "Launchpad Mini MIDI 1"
@@ -19,6 +20,7 @@ class MidiController:
def __init__(self, soloTool, midiWrapperOverride=None):
self._soloTool = soloTool
+ self._soloToolController = SoloToolController(soloTool)
if midiWrapperOverride is not None:
self._midiWrapper = midiWrapperOverride
else:
@@ -43,14 +45,14 @@ class MidiController:
119 : self._soloTool.nextStoredAbLimits,
116 : self._setALimit,
117 : self._setBLimit,
- 48 : self._soloTool.previousSong,
+ 48 : self._soloToolController.previousSong,
49 : self._createSeekHandler(-0.25),
50 : self._createSeekHandler(-0.05),
51 : self._createSeekHandler(-0.01),
52 : self._createSeekHandler(0.01),
53 : self._createSeekHandler(0.05),
54 : self._createSeekHandler(0.25),
- 55 : self._soloTool.nextSong,
+ 55 : self._soloToolController.nextSong,
}
for i in range(0, 8):
diff --git a/solo-tool-project/src/solo_tool/playlist.py b/solo-tool-project/src/solo_tool/playlist.py
index bbfd8f5..988cc04 100644
--- a/solo-tool-project/src/solo_tool/playlist.py
+++ b/solo-tool-project/src/solo_tool/playlist.py
@@ -24,17 +24,3 @@ class Playlist:
def clear(self):
self.__init__(self._setSongCallback)
-
- def nextSong(self):
- if self._currentSong is None:
- nextSong = 0
- else:
- nextSong = self._currentSong + 1
- self.setCurrentSong(nextSong)
-
- def previousSong(self):
- if self._currentSong is None:
- prevSong = 0
- else:
- prevSong = self._currentSong - 1
- self.setCurrentSong(prevSong)
diff --git a/solo-tool-project/src/solo_tool/solo_tool.py b/solo-tool-project/src/solo_tool/solo_tool.py
index 211babf..38e3d11 100644
--- a/solo-tool-project/src/solo_tool/solo_tool.py
+++ b/solo-tool-project/src/solo_tool/solo_tool.py
@@ -36,19 +36,8 @@ class SoloTool:
if previous != new:
self._notifier.notify(Notifier.CURRENT_SONG_EVENT, new)
- def nextSong(self):
- previous = self._playlist.getCurrentSongIndex()
- self._playlist.nextSong()
- new = self._playlist.getCurrentSongIndex()
- if previous != new:
- self._notifier.notify(Notifier.CURRENT_SONG_EVENT, new)
-
- def previousSong(self):
- previous = self._playlist.getCurrentSongIndex()
- self._playlist.previousSong()
- new = self._playlist.getCurrentSongIndex()
- if previous != new:
- self._notifier.notify(Notifier.CURRENT_SONG_EVENT, new)
+ def getCurrentSong(self):
+ return self._playlist.getCurrentSongIndex()
def getSongs(self):
return self._playlist.getSongs()
diff --git a/solo-tool-project/src/solo_tool/solo_tool_controller.py b/solo-tool-project/src/solo_tool/solo_tool_controller.py
new file mode 100644
index 0000000..d283725
--- /dev/null
+++ b/solo-tool-project/src/solo_tool/solo_tool_controller.py
@@ -0,0 +1,22 @@
+import os
+
+from solo_tool.solo_tool import SoloTool
+
+class SoloToolController:
+ def __init__(self, soloTool: SoloTool):
+ self._soloTool = soloTool
+
+ def nextSong(self):
+ current = self._soloTool.getCurrentSong()
+ if current is None:
+ self._soloTool.setSong(0)
+ else:
+ self._soloTool.setSong(current + 1)
+
+ def previousSong(self):
+ current = self._soloTool.getCurrentSong()
+ if current is None:
+ self._soloTool.setSong(0)
+ else:
+ self._soloTool.setSong(current - 1)
+
diff --git a/solo-tool-project/test/midi_launchpad_mini_integrationtest.py b/solo-tool-project/test/midi_launchpad_mini_integrationtest.py
index 8fd09bb..b0105a9 100644
--- a/solo-tool-project/test/midi_launchpad_mini_integrationtest.py
+++ b/solo-tool-project/test/midi_launchpad_mini_integrationtest.py
@@ -402,7 +402,7 @@ def test_playingFeedbackWhenChangingSong(uut, midiWrapperMock, soloTool, playerM
assert playerMock.state == PlayerMock.PLAYING
assert midiWrapperMock.getLatestMessage() == (playPauseButton, LED_GREEN, 0)
- soloTool.nextSong()
+ soloTool.setSong(1)
assert playerMock.state == PlayerMock.STOPPED
assert midiWrapperMock.getLatestMessage() == (playPauseButton, LED_YELLOW, 0)
diff --git a/solo-tool-project/test/playlist_unittest.py b/solo-tool-project/test/playlist_unittest.py
index 842ce51..4b0186b 100644
--- a/solo-tool-project/test/playlist_unittest.py
+++ b/solo-tool-project/test/playlist_unittest.py
@@ -101,48 +101,3 @@ def test_clearPlaylist():
assert uut.getSongs() == []
assert uut.getCurrentSong() == None
assert uut.getCurrentSongIndex() == None
-
-def test_nextSong():
- songAddedByUser = ["/path/to/song", "/path/to/second/song"]
-
- uut = Playlist(lambda index: None)
- for s in songAddedByUser:
- uut.addSong(s)
- assert uut.getCurrentSong() == None
- assert uut.getCurrentSongIndex() == None
-
- uut.nextSong()
- assert uut.getCurrentSong() == songAddedByUser[0]
- assert uut.getCurrentSongIndex() == 0
-
- uut.nextSong()
- assert uut.getCurrentSong() == songAddedByUser[1]
- assert uut.getCurrentSongIndex() == 1
-
- uut.nextSong()
- assert uut.getCurrentSong() == songAddedByUser[1]
- assert uut.getCurrentSongIndex() == 1
-
-def test_previousSong():
- songAddedByUser = ["/path/to/song", "/path/to/second/song"]
-
- uut = Playlist(lambda index: None)
- for s in songAddedByUser:
- uut.addSong(s)
- assert uut.getCurrentSong() == None
- assert uut.getCurrentSongIndex() == None
-
- uut.previousSong()
- assert uut.getCurrentSong() == songAddedByUser[0]
- assert uut.getCurrentSongIndex() == 0
-
- uut.previousSong()
- assert uut.getCurrentSong() == songAddedByUser[0]
- assert uut.getCurrentSongIndex() == 0
-
- uut.setCurrentSong(1)
- assert uut.getCurrentSong() == songAddedByUser[1]
- assert uut.getCurrentSongIndex() == 1
- uut.previousSong()
- assert uut.getCurrentSong() == songAddedByUser[0]
- assert uut.getCurrentSongIndex() == 0
diff --git a/solo-tool-project/test/solo_tool_controller_integrationtest.py b/solo-tool-project/test/solo_tool_controller_integrationtest.py
new file mode 100644
index 0000000..c161c70
--- /dev/null
+++ b/solo-tool-project/test/solo_tool_controller_integrationtest.py
@@ -0,0 +1,86 @@
+import pathlib
+import shutil
+import pytest
+
+from solo_tool.solo_tool_controller import SoloToolController
+from solo_tool.solo_tool import SoloTool
+
+@pytest.fixture
+def prepared_tmp_path(tmp_path):
+ testFiles = [
+ "test.flac",
+ "test.mp3",
+ "test_session.json"
+ ]
+ for f in testFiles:
+ shutil.copy(pathlib.Path(f), tmp_path)
+ return tmp_path
+
+@pytest.fixture
+def soloTool(prepared_tmp_path):
+ st = SoloTool()
+ st.loadSession(prepared_tmp_path / "test_session.json")
+ return st
+
+@pytest.fixture
+def uut(soloTool):
+ return SoloToolController(soloTool)
+
+def test_previousSong(uut, soloTool):
+ called = False
+ receivedValue = None
+ def callback(value):
+ nonlocal called, receivedValue
+ called = True
+ receivedValue = value
+
+ soloTool.registerCurrentSongCallback(callback)
+
+ soloTool.getCurrentSong() == None
+ assert not called
+
+ uut.previousSong()
+ soloTool.getCurrentSong() == 0
+ assert called
+ assert receivedValue == 0
+ called = False
+
+ uut.previousSong()
+ soloTool.getCurrentSong() == 0
+ assert not called
+
+ soloTool.setSong(1)
+ uut.previousSong()
+ soloTool.getCurrentSong() == 0
+ assert called
+ assert receivedValue == 0
+ called = False
+
+def test_nextSong(uut, soloTool):
+ called = False
+ receivedValue = None
+ def callback(value):
+ nonlocal called, receivedValue
+ called = True
+ receivedValue = value
+
+ soloTool.registerCurrentSongCallback(callback)
+
+ soloTool.getCurrentSong() == None
+ assert not called
+
+ uut.nextSong()
+ soloTool.getCurrentSong() == 0
+ assert called
+ assert receivedValue == 0
+ called = False
+
+ uut.nextSong()
+ soloTool.getCurrentSong() == 1
+ assert called
+ assert receivedValue == 1
+ called = False
+
+ uut.nextSong()
+ soloTool.getCurrentSong() == 1
+ assert not called
diff --git a/solo-tool-project/test/solo_tool_integrationtest.py b/solo-tool-project/test/solo_tool_integrationtest.py
index 5903abf..ee33468 100644
--- a/solo-tool-project/test/solo_tool_integrationtest.py
+++ b/solo-tool-project/test/solo_tool_integrationtest.py
@@ -72,28 +72,7 @@ def test_addAndSetSongs(uut, mockPlayer):
for i, s in enumerate(songs):
uut.setSong(i)
assert mockPlayer.currentSong == songs[i]
-
-def test_nextAndPreviousSong(uut, mockPlayer):
- songs = [
- "test.flac",
- "test.mp3"
- ]
-
- for s in songs:
- uut.addSong(s)
- assert mockPlayer.currentSong == None
-
- uut.nextSong()
- assert mockPlayer.currentSong == songs[0]
-
- uut.previousSong()
- assert mockPlayer.currentSong == songs[0]
-
- uut.nextSong()
- assert mockPlayer.currentSong == songs[1]
-
- uut.nextSong()
- assert mockPlayer.currentSong == songs[1]
+ assert uut.getCurrentSong() == i
def test_addAndSetAbLimits(uut, mockPlayer):
song = "test.flac"
@@ -495,22 +474,6 @@ def test_currentSongNotification(uut):
assert receivedValue == 1
called = False
- uut.previousSong()
- assert called
- assert receivedValue == 0
- called = False
-
- uut.previousSong()
- assert not called
-
- uut.nextSong()
- assert called
- assert receivedValue == 1
- called = False
-
- uut.nextSong()
- assert not called
-
def test_currentAbNotification(uut):
called = False
receivedValue = None