From 8cdeb3d1a9b5abf494515210870d0314c1163ccc Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sun, 4 Apr 2021 21:50:20 +0100 Subject: [PATCH] Implement end times in playlist --- app/model.py | 9 +++++++++ app/playlists.py | 30 +++++++++++++++++++++++++++++- app/ui/main_window.ui | 27 +++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/app/model.py b/app/model.py index d2c67f4..602a50a 100644 --- a/app/model.py +++ b/app/model.py @@ -179,6 +179,15 @@ class Tracks(Base): session.add(track) return track + @staticmethod + def get_duration(id): + try: + return session.query( + Tracks.duration).filter(Tracks.id == id).one()[0] + except NoResultFound: + ERROR(f"Can't find track id {id}") + return None + @staticmethod def get_path(id): try: diff --git a/app/playlists.py b/app/playlists.py index 0209ccd..cb04c5d 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -13,6 +13,7 @@ from PyQt5.QtWidgets import ( import helpers from config import Config +from datetime import datetime, timedelta from log import DEBUG, ERROR from model import Playdates, Playlists, Settings, Tracks @@ -203,6 +204,13 @@ class Playlist(QTableWidget): except AttributeError: return "" + def get_row_endtime(self, row, start): + "Return this row's end time given its start time" + + duration = Tracks.get_duration( + int(self.item(row, self.COL_INDEX).text())) + return start + timedelta(milliseconds=duration) + def is_below(self, pos, index): rect = self.visualRect(index) margin = 2 @@ -358,8 +366,14 @@ class Playlist(QTableWidget): # Update metadata self.meta_set_current(self.meta_get_next()) - # Set up metadata for next track in playlist if there is one. + # Set track start time current_row = self.meta_get_current() + endtime = datetime.now() + timedelta( + milliseconds=self.current_track.silence_at) + item = QTableWidgetItem(endtime.strftime("%H:%M:%S")) + self.setItem(current_row, self.COL_ENDTIME, item) + + # Set up metadata for next track in playlist if there is one. if current_row is not None: start = current_row + 1 else: @@ -417,16 +431,24 @@ class Playlist(QTableWidget): next = self.meta_get_next() notes = self.meta_get_notes() + # Set colours and start times + previous_end = None for row in range(self.rowCount()): if row == current: self.set_row_colour( row, QColor(Config.COLOUR_CURRENT_PLAYLIST) ) + previous_end = datetime.strptime(self.item( + row, self.COL_ENDTIME).text(), "%H:%M:%S") self.set_row_bold(row) elif row == next: self.set_row_colour( row, QColor(Config.COLOUR_NEXT_PLAYLIST) ) + if previous_end: + previous_end = self.get_row_endtime(row, previous_end) + item = QTableWidgetItem(previous_end.strftime("%H:%M:%S")) + self.setItem(row, self.COL_ENDTIME, item) self.set_row_bold(row) elif row in notes: self.set_row_colour( @@ -441,6 +463,12 @@ class Playlist(QTableWidget): self.set_row_colour(row, colour) if self.item(row, self.COL_INDEX): if int(self.item(row, self.COL_INDEX).text()) > 0: + if previous_end: + previous_end = self.get_row_endtime( + row, previous_end) + item = QTableWidgetItem( + previous_end.strftime("%H:%M:%S")) + self.setItem(row, self.COL_ENDTIME, item) track_id = int(self.item(row, self.COL_INDEX).text()) if track_id in self.played_tracks: self.set_row_not_bold(row) diff --git a/app/ui/main_window.ui b/app/ui/main_window.ui index 3735fc9..3f6771a 100644 --- a/app/ui/main_window.ui +++ b/app/ui/main_window.ui @@ -11,7 +11,7 @@ - MainWindow + Music Muster @@ -718,6 +718,7 @@ border: 1px solid rgb(85, 87, 83); Fi&le + @@ -819,6 +820,11 @@ border: 1px solid rgb(85, 87, 83); &Resume previous + + + E&xit + + @@ -828,5 +834,22 @@ border: 1px solid rgb(85, 87, 83); - + + + actionE_xit + triggered() + MainWindow + close() + + + -1 + -1 + + + 383 + 299 + + + +