aboutsummaryrefslogtreecommitdiffstats
path: root/control.py
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2021-11-21 18:03:11 +0100
committerEddy Pedroni <eddy@eddy.dev>2021-11-29 22:24:37 +0100
commit9d92121a67188995ced4aa2cc26d320475bb8c94 (patch)
tree0625499feaa11638e2df2139e87982c839b3c371 /control.py
parentfa5b0f760892bcbc2548ec0e516a716bd854ceef (diff)
Fixed some bugs, added some midi buttons
Diffstat (limited to 'control.py')
-rw-r--r--control.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/control.py b/control.py
new file mode 100644
index 0000000..30fe868
--- /dev/null
+++ b/control.py
@@ -0,0 +1,52 @@
+from PyQt5.QtCore import *
+
+import midi
+import logging
+
+MIDI_PLAY = midi.lp_key[0][1]
+
+class Control:
+ def __init__(self, window):
+ self.window = window
+ self.player = window.player
+ self.playlist = window.playlist
+
+ window.playButton.pressed.connect(self.play)
+ window.pauseButton.pressed.connect(self.pause)
+ window.songSlider.setMaximum(100000)
+ window.songSlider.sliderPressed.connect(self.sliderPressed)
+ window.songSlider.sliderReleased.connect(self.sliderReleased)
+
+ self.timer = QTimer(window)
+ self.timer.setInterval(1000)
+ self.timer.timeout.connect(self.updateSongSlider)
+
+ def pause(self):
+ self.player.pause()
+
+ self.updateMidi()
+
+ def play(self):
+ selected = self.playlist.medialist.media()
+ self.player.play_item(selected)
+ self.timer.start()
+
+ self.updateMidi()
+
+ def updateSongSlider(self):
+ position = self.player.get_media_player().get_position() * 100000
+ self.window.songSlider.setValue(position)
+
+ def sliderPressed(self):
+ self.timer.stop()
+
+ def sliderReleased(self):
+ position = self.window.songSlider.value() / 100000.0
+ logging.info(f"Setting position: {position}")
+ self.player.get_media_player().set_position(position)
+ self.timer.start()
+
+ def updateMidi(self):
+ if self.window.midiEnabled:
+ midi.button_on(MIDI_PLAY, (midi.GREEN if self.player.is_playing() else midi.RED))
+