aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/test
diff options
context:
space:
mode:
Diffstat (limited to 'solo-tool-project/test')
-rw-r--r--solo-tool-project/test/midi_actition_pedal_integrationtest.py118
-rw-r--r--solo-tool-project/test/midi_launchpad_mini_integrationtest.py18
-rw-r--r--solo-tool-project/test/player_mock.py2
3 files changed, 129 insertions, 9 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
diff --git a/solo-tool-project/test/midi_launchpad_mini_integrationtest.py b/solo-tool-project/test/midi_launchpad_mini_integrationtest.py
index 1a99cd4..6841f24 100644
--- a/solo-tool-project/test/midi_launchpad_mini_integrationtest.py
+++ b/solo-tool-project/test/midi_launchpad_mini_integrationtest.py
@@ -1,7 +1,7 @@
import pytest
from mido import Message
-from solo_tool.midi_controller_launchpad_mini import MidiController
+from solo_tool.midi_controller_launchpad_mini import LaunchpadMiniController
from fixtures import soloTool, mockPlayer, testSongs
LED_RED = 3
@@ -38,10 +38,10 @@ class MidiWrapperMock:
def disconnect(self):
self.connectedDevice = None
-
- def sendMessage(self, note, velocity, channel):
+
+ def sendNoteOn(self, note, velocity, channel):
self.sentMessages.append((note, velocity, channel))
-
+
def simulateInput(self, note, velocity=127, channel=0):
if self.callback is not None:
msg = Message("note_on", note=note, velocity=velocity, channel=channel)
@@ -56,7 +56,7 @@ def midiWrapperMock():
@pytest.fixture
def uut(soloTool, midiWrapperMock):
- return MidiController(soloTool, midiWrapperMock)
+ return LaunchpadMiniController(soloTool, midiWrapperMock)
def test_startAndPauseButtons(uut, midiWrapperMock, mockPlayer):
uut.connect()
@@ -65,11 +65,11 @@ def test_startAndPauseButtons(uut, midiWrapperMock, mockPlayer):
midiWrapperMock.simulateInput(playPauseButton)
assert mockPlayer.playing
- assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_GREEN, 0)
+ assert midiWrapperMock.getLatestMessage() == (playPauseButton, LaunchpadMiniController.LED_GREEN, 0)
midiWrapperMock.simulateInput(playPauseButton)
assert not mockPlayer.playing
- assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_YELLOW, 0)
+ assert midiWrapperMock.getLatestMessage() == (playPauseButton, LaunchpadMiniController.LED_YELLOW, 0)
def test_startPauseButtonLed(uut, midiWrapperMock, mockPlayer, soloTool):
uut.connect()
@@ -78,11 +78,11 @@ def test_startPauseButtonLed(uut, midiWrapperMock, mockPlayer, soloTool):
mockPlayer.playing = True
mockPlayer.simulatePlayingStateChanged()
- assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_GREEN, 0)
+ assert midiWrapperMock.getLatestMessage() == (playPauseButton, LaunchpadMiniController.LED_GREEN, 0)
mockPlayer.playing = False
mockPlayer.simulatePlayingStateChanged()
- assert midiWrapperMock.getLatestMessage() == (playPauseButton, MidiController.LED_YELLOW, 0)
+ assert midiWrapperMock.getLatestMessage() == (playPauseButton, LaunchpadMiniController.LED_YELLOW, 0)
def test_jumpToKeyPositionButton(uut, midiWrapperMock, soloTool, mockPlayer, testSongs):
soloTool.addSong(testSongs[0])
diff --git a/solo-tool-project/test/player_mock.py b/solo-tool-project/test/player_mock.py
index e9e9ead..a234e80 100644
--- a/solo-tool-project/test/player_mock.py
+++ b/solo-tool-project/test/player_mock.py
@@ -30,9 +30,11 @@ class Player():
return self.rate
def setPlaybackPosition(self, position):
+ print(f"{self} Setting playback position to {position}")
self.position = position
def getPlaybackPosition(self):
+ print(f"{self} Getting playback position: {self.position}")
return self.position
def setPlaybackVolume(self, volume):