diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2021-11-21 18:03:11 +0100 |
---|---|---|
committer | Eddy Pedroni <eddy@eddy.dev> | 2021-11-29 22:24:37 +0100 |
commit | 9d92121a67188995ced4aa2cc26d320475bb8c94 (patch) | |
tree | 0625499feaa11638e2df2139e87982c839b3c371 /playlist.py | |
parent | fa5b0f760892bcbc2548ec0e516a716bd854ceef (diff) |
Fixed some bugs, added some midi buttons
Diffstat (limited to 'playlist.py')
-rw-r--r-- | playlist.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/playlist.py b/playlist.py new file mode 100644 index 0000000..12fd9ed --- /dev/null +++ b/playlist.py @@ -0,0 +1,57 @@ +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * +from PyQt5.QtCore import * + +import logging +import vlc + +class PlaylistModel(QAbstractListModel): + def __init__(self, medialist, *args, **kwargs): + super(PlaylistModel, self).__init__(*args, **kwargs) + self.medialist = medialist + + def data(self, index, role): + if role == Qt.DisplayRole: + return self.medialist.item_at_index(index.row()).get_mrl() + + def rowCount(self, index): + return self.medialist.count() + +class Playlist: + def __init__(self, window): + self.medialist = vlc.MediaList() + self.model = PlaylistModel(self.medialist) + self.window = window + + window.player.set_media_list(self.medialist) + window.songListView.setModel(self.model) + window.songListView.selectionModel().selectionChanged.connect(self.playlistSelectionChanged) + window.addSongButton.pressed.connect(self.addSong) + + def addSong(self): + path, _ = QFileDialog.getOpenFileName(self.window, "Open file", "", "mp3 Audio (*.mp3);FLAC audio (*.flac);All files (*.*)") + if path: + media = vlc.Media(path) + self.medialist.add_media(media) + self.model.layoutChanged.emit() + logging.debug(f"Added song: {path}") + + def playlistSelectionChanged(self, ix): + i = ix.indexes()[0].row() + self.setCurrent(i) + #path = self.playlist.current.filePath + #self.player.set_media(path) + """ + self.abListModel.abList = self.internalState[path] + self.abListView.selectionModel().clearSelection() + self.abListModel.layoutChanged.emit() + self.aSlider.setValue(0) + self.bSlider.setValue(0) + """ + + def setCurrent(self, index): + media = self.medialist.item_at_index(index) + if not media: + raise Exception(f"Invalid playlist index {index}") + self.medialist.set_media(media) + logging.debug(f"Selected song: {self.medialist.media().get_mrl()}") |