Skip to content

Commit

Permalink
Remove first song, need to clear some bugs now with removing from queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Oldham committed Aug 7, 2024
1 parent c091fa1 commit 13215a7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
20 changes: 19 additions & 1 deletion psst-core/src/player/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Queue {
user_items_position: usize,
positions: Vec<usize>,
behavior: QueueBehavior,
playing_from_user_items: bool,
}

impl Queue {
Expand All @@ -34,6 +35,7 @@ impl Queue {
user_items_position: 0,
positions: Vec::new(),
behavior: QueueBehavior::default(),
playing_from_user_items: false,
}
}

Expand Down Expand Up @@ -65,7 +67,12 @@ impl Queue {
}

pub fn remove(&mut self, index: usize) {
self.user_items.remove(index);
if self.playing_from_user_items {
self.user_items.remove(index+1);
}
else {
self.user_items.remove(index);
}
if self.user_items_position > 0 {
self.user_items_position -= 1;
}
Expand All @@ -77,9 +84,20 @@ impl Queue {
self.positions.len(),
self.user_items[self.user_items_position],
);

self.positions
.insert(self.position + 1, self.positions.len());
self.user_items_position += 1;

if self.user_items_position > 1 {
self.user_items.remove(0);
self.user_items_position -= 1;
}

self.playing_from_user_items = true;
}
else {
self.playing_from_user_items = false;
}
}

Expand Down
8 changes: 6 additions & 2 deletions psst-gui/src/controller/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use souvlaki::{

use crate::{
cmd,
data::{AppState, Config, Playback, PlaybackOrigin, PlaybackState, QueueBehavior, QueueEntry},
data::{AppState, Config, NowPlaying, Playback, PlaybackOrigin, PlaybackState, QueueBehavior, QueueEntry},
};

pub struct PlaybackController {
Expand Down Expand Up @@ -356,7 +356,11 @@ where
}
Event::Command(cmd) if cmd.is(cmd::PLAYBACK_PLAYING) => {
let (item, progress) = cmd.get_unchecked(cmd::PLAYBACK_PLAYING);

if data.added_queue.len() > 0 {
if data.playback.now_playing.as_mut().is_some_and(|np| np.item.id() == data.added_queue[0].item.id()) {
data.added_queue.remove(0);
}
}
if let Some(queued) = data.queued_entry(*item) {
data.start_playback(queued.item, queued.origin, progress.to_owned());
self.update_media_control_playback(&data.playback);
Expand Down
1 change: 0 additions & 1 deletion psst-gui/src/ui/queued.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub fn queue_widget() -> impl Widget<AppState> {
Either::new(
|data: &AppState, _env: &Env| {
data.config.window_size.width >= 700.0
&& !data.added_queue.is_empty()
&& data.config.show_queue_view
},
Flex::column()
Expand Down

0 comments on commit 13215a7

Please sign in to comment.