aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2021-11-21 18:03:11 +0100
committerEddy Pedroni <eddy@0xf7.com>2021-11-21 18:03:11 +0100
commit96fa61ed7a0f3e08b40f528e272fd73a7dbc9cf4 (patch)
tree99a912c7fbee863bc33a314b68b96038f7da02bd
parentfa5b0f760892bcbc2548ec0e516a716bd854ceef (diff)
Fixed some bugs, added some midi buttons
-rw-r--r--midi.py7
-rw-r--r--requirements.txt1
-rw-r--r--solo-tool.py48
3 files changed, 48 insertions, 8 deletions
diff --git a/midi.py b/midi.py
index 81b6703..7eca87e 100644
--- a/midi.py
+++ b/midi.py
@@ -13,6 +13,8 @@ _outport = None
_callbacks_on_press = dict()
_callbacks_on_release = dict()
+_debug = False
+
def midi_init(device_name="Launchpad Mini MIDI 1"):
global _inport, _outport
_inport = mido.open_input(device_name)
@@ -21,10 +23,11 @@ def midi_init(device_name="Launchpad Mini MIDI 1"):
_inport.callback = _callback
def button_on(button, colour):
- print(f"outport: {_outport}")
+ if _debug: print(f"outport: {_outport}")
+
if _outport:
msg = _light_ctrl_msg.copy(note=button, velocity=colour)
- print(f"sending {msg}")
+ if _debug: print(f"sending {msg}")
_outport.send(msg)
def button_off(button):
diff --git a/requirements.txt b/requirements.txt
index 62999c0..df46354 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,4 @@
PyQt5>=5.6
sip
mido
+python-rtmidi
diff --git a/solo-tool.py b/solo-tool.py
index 26ddca2..788f58f 100644
--- a/solo-tool.py
+++ b/solo-tool.py
@@ -86,6 +86,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.saveSessionButton.pressed.connect(self.saveSession)
self.loadSessionButton.pressed.connect(self.loadSession)
+ self.abRepeatButton.clicked.connect(self.abRepeatToggleClick)
+
self.initMidiButton.pressed.connect(self.initMidi)
self.midiEnabled = False
@@ -125,6 +127,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
else:
self.player.play()
+ if self.midiEnabled:
+ midi.button_on(midi.lp_key[0][1], (midi.GREEN if self.player.state() == QMediaPlayer.PlayingState else midi.RED))
+
def updateDuration(self, duration):
self.songSlider.setMaximum(duration)
self.aSlider.setMaximum(duration)
@@ -159,6 +164,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
import json
with open(path, "r") as f:
session = json.load(f)
+ self.reset()
for song in session:
self.addSong(song)
@@ -174,18 +180,48 @@ class MainWindow(QMainWindow, Ui_MainWindow):
with open(path, "w") as f:
json.dump(self.internalState, f)
+ def abRepeatToggleClick(self):
+ midi.button_on(midi.lp_key[1][1], (midi.GREEN if self.abRepeatButton.isChecked() else midi.RED))
+
def initMidi(self):
- midi.midi_init()
+ if self.midiEnabled:
+ return
+
+ try:
+ midi.midi_init()
+ except e:
+ print(e)
+ return
+
self.midiEnabled = True
# play pause
- midi.button_on(midi.lp_key[0][0], (midi.GREEN if self.player.state() == QMediaPlayer.PlayingState else midi.RED))
- def midiPlayPause():
- midi.button_on(midi.lp_key[0][0], (midi.RED if self.player.state() == QMediaPlayer.PlayingState else midi.GREEN))
- self.playPauseButton.click()
+ midi.button_on(midi.lp_key[0][1], (midi.GREEN if self.player.state() == QMediaPlayer.PlayingState else midi.RED))
+ midi.on_press(midi.lp_key[0][1], self.playPauseButton.click)
+
+ # next song
+ midi.button_on(midi.lp_key[0][2], midi.YELLOW)
+ midi.on_press(midi.lp_key[0][2], self.playlist.next)
- midi.on_press(midi.lp_key[0][0], midiPlayPause)
+ # previous song
+ midi.button_on(midi.lp_key[0][0], midi.YELLOW)
+ midi.on_press(midi.lp_key[0][0], self.playlist.previous)
+ # a/b repeat
+ midi.button_on(midi.lp_key[1][1], (midi.GREEN if self.abRepeatButton.isChecked() else midi.RED))
+ midi.on_press(midi.lp_key[1][1], self.abRepeatButton.click)
+
+ # next ab
+ # TODO continue here
+ midi.button_on(midi.lp_key[1][2], midi.YELLOW)
+ #midi.on_press(midi.lp_key[1][2], nextAb)
+
+
+ def reset(self):
+ self.playlist.clear()
+ self.playlistModel.layoutChanged.emit()
+ self.abListModel.abList.clear()
+ self.abListModel.layoutChanged.emit()
if __name__ == '__main__':
app = QApplication([])