Implement end times in playlist
This commit is contained in:
parent
233cce7800
commit
8cdeb3d1a9
@ -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:
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
<string>Music Muster</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
@ -718,6 +718,7 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
<property name="title">
|
||||
<string>Fi&le</string>
|
||||
</property>
|
||||
<addaction name="actionE_xit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuPlaylist">
|
||||
<property name="title">
|
||||
@ -819,6 +820,11 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
<string>&Resume previous</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionE_xit">
|
||||
<property name="text">
|
||||
<string>E&xit</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
@ -828,5 +834,22 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>actionE_xit</sender>
|
||||
<signal>triggered()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>close()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>383</x>
|
||||
<y>299</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user