From 59b13af09a5e35ea1364eb1031be4ce9410f6f03 Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Wed, 22 Dec 2021 17:06:53 +0100 Subject: Added MVP Qt implementation, known issues tracking, removed old files --- solo_tool_qt.py | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 5 deletions(-) (limited to 'solo_tool_qt.py') 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") -- cgit v1.2.3