diff options
Diffstat (limited to 'solo-tool.py')
-rw-r--r-- | solo-tool.py | 105 |
1 files changed, 15 insertions, 90 deletions
diff --git a/solo-tool.py b/solo-tool.py index 788f58f..5db6d3f 100644 --- a/solo-tool.py +++ b/solo-tool.py @@ -1,78 +1,30 @@ from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * -from PyQt5.QtMultimedia import * -from PyQt5.QtMultimediaWidgets import * - from MainWindow import Ui_MainWindow -import midi - -class PlaylistModel(QAbstractListModel): - def __init__(self, playlist, *args, **kwargs): - super(PlaylistModel, self).__init__(*args, **kwargs) - self.playlist = playlist +import vlc - def data(self, index, role): - if role == Qt.DisplayRole: - media = self.playlist.media(index.row()) - return media.canonicalUrl().fileName() +import logging +LOGLEVEL = logging.DEBUG - def rowCount(self, index): - return self.playlist.mediaCount() - -class AbListModel(QAbstractListModel): - def __init__(self, *args, **kwargs): - super(AbListModel, self).__init__(*args, **kwargs) - self.abList = list() - - def data(self, index, role): - if role == Qt.DisplayRole: - ab = self.abList[index.row()] - return f"{hhmmss(ab[0])} - {hhmmss(ab[1])}" - - def rowCount(self, index): - return len(self.abList) - -def hhmmss(ms): - # s = 1000 - # m = 60000 - # h = 360000 - h, r = divmod(ms, 36000) - m, r = divmod(r, 60000) - s, _ = divmod(r, 1000) - return ("%d:%02d:%02d" % (h,m,s)) if h else ("%d:%02d" % (m,s)) +import midi +import playlist +import control class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.setupUi(self) - self.player = QMediaPlayer() - - # Setup the playlist. - self.playlist = QMediaPlaylist() - self.player.setPlaylist(self.playlist) - - self.playlistModel = PlaylistModel(self.playlist) - self.songListView.setModel(self.playlistModel) - self.playlist.currentIndexChanged.connect(self.playlistPositionChanged) - selection_model = self.songListView.selectionModel() - selection_model.selectionChanged.connect(self.playlistSelectionChanged) - - # set button context menu policy - self.songListView.customContextMenuRequested.connect(self.onContextMenu) - - # create context menu - self.songListMenu = QMenu(self) - self.addSongAction.triggered.connect(self.openSoundFile) - self.songListMenu.addAction(self.addSongAction) - - self.playPauseButton.pressed.connect(self.playPause) + self.midiEnabled = False + self.player = vlc.MediaListPlayer() + self.playlist = playlist.Playlist(self) + self.control = control.Control(self) + """ self.player.durationChanged.connect(self.updateDuration) self.player.positionChanged.connect(self.updatePosition) - self.songSlider.valueChanged.connect(self.player.setPosition) self.player.positionChanged.connect(self.positionChanged) @@ -89,20 +41,10 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.abRepeatButton.clicked.connect(self.abRepeatToggleClick) self.initMidiButton.pressed.connect(self.initMidi) - self.midiEnabled = False + """ self.show() - def playlistSelectionChanged(self, ix): - i = ix.indexes()[0].row() - self.playlist.setCurrentIndex(i) - path = self.playlist.currentMedia().canonicalUrl().path() - self.abListModel.abList = self.internalState[path] - self.abListView.selectionModel().clearSelection() - self.abListModel.layoutChanged.emit() - self.aSlider.setValue(0) - self.bSlider.setValue(0) - def playlistPositionChanged(self, i): if i > -1: ix = self.playlistModel.index(i) @@ -121,17 +63,11 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.abListModel.abList.append(abState) self.abListModel.layoutChanged.emit() - def playPause(self): - if self.player.state() == QMediaPlayer.PlayingState: - self.player.pause() - 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) self.bSlider.setMaximum(duration) @@ -145,19 +81,6 @@ class MainWindow(QMainWindow, Ui_MainWindow): if self.abRepeatButton.isChecked() and position > self.bSlider.value(): self.player.setPosition(self.aSlider.value()) - def onContextMenu(self, point): - self.songListMenu.exec_(self.songListView.mapToGlobal(point)) - - def openSoundFile(self): - path, _ = QFileDialog.getOpenFileName(self, "Open file", "", "mp3 Audio (*.mp3);FLAC audio (*.flac);All files (*.*)") - if path: - self.addSong(path) - - def addSong(self, path): - self.playlist.addMedia(QMediaContent(QUrl.fromLocalFile(path))) - self.internalState[path] = list() - self.playlistModel.layoutChanged.emit() - def loadSession(self): path, _ = QFileDialog.getOpenFileName(self, "Open file", "", "session (*.json)") if path: @@ -189,7 +112,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): try: midi.midi_init() - except e: + except Exception as e: print(e) return @@ -224,6 +147,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.abListModel.layoutChanged.emit() if __name__ == '__main__': + logging.basicConfig(level=LOGLEVEL) + app = QApplication([]) app.setApplicationName("Solo Tool") app.setStyle("Fusion") |