From 4ea8344fba863d3ff113cf790b6327d44ced62ee Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Thu, 21 Aug 2025 18:56:43 +0200 Subject: Actition controller prototype --- .../test/midi_actition_pedal_integrationtest.py | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 solo-tool-project/test/midi_actition_pedal_integrationtest.py (limited to 'solo-tool-project/test/midi_actition_pedal_integrationtest.py') 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 -- cgit v1.2.3