aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/test/midi_actition_pedal_integrationtest.py
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2025-08-21 18:56:43 +0200
committerEddy Pedroni <epedroni@pm.me>2025-08-21 18:56:43 +0200
commit4ea8344fba863d3ff113cf790b6327d44ced62ee (patch)
tree0db18a3b5039258567d36d782687b83ed0ff9baa /solo-tool-project/test/midi_actition_pedal_integrationtest.py
parent748f056faf16b08ac41de991b1aeb664f2b86d8e (diff)
Actition controller prototype
Diffstat (limited to 'solo-tool-project/test/midi_actition_pedal_integrationtest.py')
-rw-r--r--solo-tool-project/test/midi_actition_pedal_integrationtest.py118
1 files changed, 118 insertions, 0 deletions
diff --git a/solo-tool-project/test/midi_actition_pedal_integrationtest.py b/solo-tool-project/test/midi_actition_pedal_integrationtest.py
new file mode 100644
index 0000000..092ff64
--- /dev/null
+++ b/solo-tool-project/test/midi_actition_pedal_integrationtest.py
@@ -0,0 +1,118 @@
+import pytest
+from fixtures import mockPlayer, testSongs
+from solo_tool.solo_tool import SoloTool
+from solo_tool.midi_controller_actition import ActitionController
+
+CHANNEL = 15
+REWIND = 102
+SET = 103
+JUMP = 104
+PLAY = 105
+
+class MidiWrapperMock:
+ def __init__(self):
+ self.sentMessages = list()
+
+ def setCallback(self, callback):
+ self.callback = callback
+
+ def simulateInput(self, control, channel):
+ if self.callback is not None:
+ self.callback(control, channel)
+
+ def getLatestMessage(self):
+ return self.sentMessages[-1]
+
+@pytest.fixture
+def soloTool(mockPlayer, testSongs):
+ st = SoloTool(player=mockPlayer)
+ for song in testSongs:
+ st.addSong(song)
+ return st
+
+@pytest.fixture
+def midiWrapperMock(soloTool):
+ return MidiWrapperMock()
+
+@pytest.fixture
+def uut(soloTool, midiWrapperMock):
+ uut = ActitionController(midiWrapperMock)
+ uut.setSoloTool(soloTool)
+ return uut
+
+def test_rewindMessage(uut, soloTool, mockPlayer, midiWrapperMock):
+ soloTool.song = 1
+ mockPlayer.position = 0.5
+
+ # Sending rewind goes back to the start of the song
+ midiWrapperMock.simulateInput(REWIND, CHANNEL)
+ assert mockPlayer.getPlaybackPosition() == 0.0
+
+ # Sending again does not change the song
+ assert soloTool.song == 1
+ midiWrapperMock.simulateInput(REWIND, CHANNEL)
+ assert soloTool.song == 1
+ assert mockPlayer.position == 0.0
+
+def test_setMessage(uut, soloTool, mockPlayer, midiWrapperMock):
+ callbackValue = None
+ callbackCalled = False
+
+ def callback(keyPoint):
+ nonlocal callbackCalled, callbackValue
+ callbackValue = keyPoint
+ callbackCalled = True
+
+ soloTool.registerKeyPointSelectionCallback(callback)
+
+ # Sending set sets the current position as the key point
+ assert soloTool.keyPoint == 0.0
+
+ mockPlayer.position = 0.3
+ midiWrapperMock.simulateInput(SET, CHANNEL)
+ assert soloTool.keyPoint == 0.3
+ assert callbackCalled
+ assert callbackValue == 0.3
+
+ # Sending it again does nothing
+ callbackCalled = False
+ midiWrapperMock.simulateInput(SET, CHANNEL)
+ assert soloTool.keyPoint == 0.3
+ assert not callbackCalled
+
+def test_jumpMessage(uut, soloTool, mockPlayer, midiWrapperMock):
+ soloTool.keyPoint = 0.5
+ mockPlayer.position = 0.0
+
+ # Sending jump sets the player position to the current key point
+ midiWrapperMock.simulateInput(JUMP, CHANNEL)
+ assert mockPlayer.position == 0.5
+
+ # Sending again does nothing
+ midiWrapperMock.simulateInput(JUMP, CHANNEL)
+ assert mockPlayer.position == 0.5
+
+def test_playMessage(uut, soloTool, mockPlayer, midiWrapperMock):
+ callbackValue = None
+ callbackCalled = False
+
+ def callback(state):
+ nonlocal callbackCalled, callbackValue
+ callbackValue = state
+ callbackCalled = True
+
+ soloTool.registerPlayingStateCallback(callback)
+
+ # Sending play starts playing
+ assert not mockPlayer.isPlaying()
+ midiWrapperMock.simulateInput(PLAY, CHANNEL)
+ assert mockPlayer.isPlaying()
+ assert callbackCalled
+ assert callbackValue == True
+
+ # Sending again stops playing
+ callbackCalled = False
+ midiWrapperMock.simulateInput(PLAY, CHANNEL)
+ assert not mockPlayer.isPlaying()
+ assert callbackCalled
+ assert callbackValue == False