aboutsummaryrefslogtreecommitdiffstats
path: root/solo_tool_qt.py
diff options
context:
space:
mode:
Diffstat (limited to 'solo_tool_qt.py')
-rw-r--r--solo_tool_qt.py122
1 files changed, 117 insertions, 5 deletions
diff --git a/solo_tool_qt.py b/solo_tool_qt.py
index 8697764..14c0fe1 100644
--- a/solo_tool_qt.py
+++ b/solo_tool_qt.py
@@ -3,21 +3,133 @@ from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from MainWindow import Ui_MainWindow
-import logging
-LOGLEVEL = logging.DEBUG
+from solo_tool import SoloTool
-import solo_tool
+POSITION_FACTOR = 100000
+UI_REFRESH_PERIOD_MS = 500
+
+class PlaylistModel(QAbstractListModel):
+ def __init__(self, soloTool, *args, **kwargs):
+ super(PlaylistModel, self).__init__(*args, **kwargs)
+ self.soloTool = soloTool
+
+ def data(self, index, role):
+ if role == Qt.DisplayRole:
+ return self.soloTool.getSongs()[index.row()]
+
+ def rowCount(self, index):
+ return len(self.soloTool.getSongs())
+
+class ABListModel(QAbstractListModel):
+ def __init__(self, soloTool, *args, **kwargs):
+ super(ABListModel, self).__init__(*args, **kwargs)
+ self.soloTool = soloTool
+
+ def data(self, index, role):
+ if role == Qt.DisplayRole:
+ ab = self.soloTool.getAbLimits()[index.row()]
+ return f"{ab[0]} - {ab[1]}"
+
+ def rowCount(self, index):
+ return len(self.soloTool.getAbLimits())
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setupUi(self)
+
+ self.timer = QTimer(self)
+ self.timer.setInterval(UI_REFRESH_PERIOD_MS)
+ self.timer.timeout.connect(self.timerCallback)
+
+ self.soloTool = SoloTool()
+
+ self.playlistModel = PlaylistModel(self.soloTool)
+ self.songListView.setModel(self.playlistModel)
+ self.songListView.selectionModel().selectionChanged.connect(self.playlistSelectionChanged)
+
+ self.abListModel = ABListModel(self.soloTool)
+ self.abListView.setModel(self.abListModel)
+ self.abListView.selectionModel().selectionChanged.connect(self.abListSelectionChanged)
+
+ self.songSlider.setMaximum(POSITION_FACTOR)
+ self.songSlider.sliderPressed.connect(self.songSliderPressed)
+ self.songSlider.sliderReleased.connect(self.songSliderReleased)
+
+ self.aSlider.setMaximum(POSITION_FACTOR)
+ self.bSlider.setMaximum(POSITION_FACTOR)
+
+ self.playButton.pressed.connect(self.soloTool.play)
+ self.pauseButton.pressed.connect(self.soloTool.pause)
+ self.saveAbButton.pressed.connect(self.saveAbLimits)
+ self.saveSessionButton.pressed.connect(self.saveSession)
+ self.loadSessionButton.pressed.connect(self.loadSession)
+ self.addSongButton.pressed.connect(self.addSong)
+ #self.initMidiButton.pressed.connect()
+ self.abRepeatCheckBox.clicked.connect(self.toggleAbRepeat)
+ self.timer.start()
self.show()
-if __name__ == '__main__':
- logging.basicConfig(level=LOGLEVEL)
+ def timerCallback(self):
+ position = self.soloTool.getPlaybackPosition() * POSITION_FACTOR
+ self.songSlider.setValue(int(position))
+ self.soloTool.tick()
+
+ def addSong(self):
+ path, _ = QFileDialog.getOpenFileName(self, "Open file", "", "mp3 Audio (*.mp3);FLAC audio (*.flac);All files (*.*)")
+ if path:
+ self.soloTool.addSong(path)
+ self.playlistModel.layoutChanged.emit()
+
+ def saveAbLimits(self):
+ a = self.aSlider.value() / float(POSITION_FACTOR)
+ b = self.bSlider.value() / float(POSITION_FACTOR)
+ self.soloTool.addAbLimit(a, b)
+ self.abListModel.layoutChanged.emit()
+
+ def toggleAbRepeat(self):
+ enable = self.abRepeatCheckBox.isChecked()
+ self.soloTool.setAbLimitEnable(enable)
+
+ def saveSession(self):
+ path, _ = QFileDialog.getSaveFileName(self, "Open file", "", "session file (*.json);All files (*.*)")
+ if path:
+ self.soloTool.saveSession(path)
+
+ def loadSession(self):
+ path, _ = QFileDialog.getOpenFileName(self, "Open file", "", "session file (*.json);All files (*.*)")
+ if path:
+ self.soloTool.loadSession(path)
+ self.playlistModel.layoutChanged.emit()
+ self.abListModel.layoutChanged.emit()
+
+ def songSliderPressed(self):
+ self.timer.stop()
+ def songSliderReleased(self):
+ position = self.songSlider.value() / float(POSITION_FACTOR)
+ self.soloTool.setPlaybackPosition(position)
+ self.timer.start()
+
+ def playlistSelectionChanged(self, i):
+ index = i.indexes()[0].row()
+ self.soloTool.setSong(index)
+ self.abListModel.layoutChanged.emit()
+ self.abListSelectionChanged(None)
+
+ def abListSelectionChanged(self, i):
+ if i is not None:
+ index = i.indexes()[0].row()
+ ab = self.soloTool.getAbLimits()[index]
+ self.soloTool.setAbLimit(index)
+ else:
+ ab = (0, 0)
+ self.aSlider.setValue(int(ab[0] * POSITION_FACTOR))
+ self.bSlider.setValue(int(ab[1] * POSITION_FACTOR))
+
+
+if __name__ == '__main__':
app = QApplication([])
app.setApplicationName("Solo Tool")
app.setStyle("Fusion")