Added next_song_index property
- Consolidated logic for deciding the next song index to select
This commit is contained in:
@@ -226,6 +226,7 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
self.app_config.state.current_song_index
|
self.app_config.state.current_song_index
|
||||||
== len(self.app_config.state.play_queue) - 1
|
== len(self.app_config.state.play_queue) - 1
|
||||||
)
|
)
|
||||||
|
at_end = self.app_config.state.next_song_index is None
|
||||||
no_repeat = self.app_config.state.repeat_type == RepeatType.NO_REPEAT
|
no_repeat = self.app_config.state.repeat_type == RepeatType.NO_REPEAT
|
||||||
if at_end and no_repeat:
|
if at_end and no_repeat:
|
||||||
self.app_config.state.playing = False
|
self.app_config.state.playing = False
|
||||||
@@ -672,20 +673,11 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
if self.app_config.state.current_song is None:
|
if self.app_config.state.current_song is None:
|
||||||
# This may happen due to DBUS, ignore.
|
# This may happen due to DBUS, ignore.
|
||||||
return
|
return
|
||||||
# Handle song repeating
|
|
||||||
if self.app_config.state.repeat_type == RepeatType.REPEAT_SONG:
|
song_index_to_play = self.app_config.state.next_song_index
|
||||||
song_index_to_play = self.app_config.state.current_song_index
|
if song_index_to_play is None:
|
||||||
# Wrap around the play queue if at the end.
|
# We may end up here due to D-Bus.
|
||||||
elif (
|
return
|
||||||
self.app_config.state.current_song_index
|
|
||||||
== len(self.app_config.state.play_queue) - 1
|
|
||||||
):
|
|
||||||
# This may happen due to D-Bus.
|
|
||||||
if self.app_config.state.repeat_type == RepeatType.NO_REPEAT:
|
|
||||||
return
|
|
||||||
song_index_to_play = 0
|
|
||||||
else:
|
|
||||||
song_index_to_play = self.app_config.state.current_song_index + 1
|
|
||||||
|
|
||||||
self.app_config.state.current_song_index = song_index_to_play
|
self.app_config.state.current_song_index = song_index_to_play
|
||||||
self.app_config.state.song_progress = timedelta(0)
|
self.app_config.state.song_progress = timedelta(0)
|
||||||
@@ -701,6 +693,7 @@ class SublimeMusicApp(Gtk.Application):
|
|||||||
# Go back to the beginning of the song if we are past 5 seconds.
|
# Go back to the beginning of the song if we are past 5 seconds.
|
||||||
# Otherwise, go to the previous song.
|
# Otherwise, go to the previous song.
|
||||||
no_repeat = self.app_config.state.repeat_type == RepeatType.NO_REPEAT
|
no_repeat = self.app_config.state.repeat_type == RepeatType.NO_REPEAT
|
||||||
|
|
||||||
if self.app_config.state.repeat_type == RepeatType.REPEAT_SONG:
|
if self.app_config.state.repeat_type == RepeatType.REPEAT_SONG:
|
||||||
song_index_to_play = self.app_config.state.current_song_index
|
song_index_to_play = self.app_config.state.current_song_index
|
||||||
elif self.app_config.state.song_progress.total_seconds() < 5:
|
elif self.app_config.state.song_progress.total_seconds() < 5:
|
||||||
|
@@ -137,6 +137,28 @@ class UIState:
|
|||||||
|
|
||||||
return self._current_song
|
return self._current_song
|
||||||
|
|
||||||
|
@property
|
||||||
|
def next_song_index(self) -> Optional[int]:
|
||||||
|
# If nothing is playing there is no next song
|
||||||
|
if self.current_song_index < 0:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if self.repeat_type == RepeatType.REPEAT_SONG:
|
||||||
|
return self.current_song_index
|
||||||
|
|
||||||
|
# If we are at the end of the play queue
|
||||||
|
if self.current_song_index == len(self.play_queue) - 1:
|
||||||
|
|
||||||
|
# If we are repeating the queue, jump back to the beginning
|
||||||
|
if self.repeat_type == RepeatType.REPEAT_QUEUE:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# Otherwise, there isn't a next song
|
||||||
|
return None
|
||||||
|
|
||||||
|
# In all other cases, it's the song after the current one
|
||||||
|
return self.current_song_index + 1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def volume(self) -> float:
|
def volume(self) -> float:
|
||||||
return self._volume.get(self.current_device, 100.0)
|
return self._volume.get(self.current_device, 100.0)
|
||||||
|
Reference in New Issue
Block a user