mirror of
https://github.com/Dummi26/musicdb.git
synced 2025-12-14 20:06:16 +01:00
fix playback position being lost when moving
when moving a folder, loop, or any other queue element containing the currently playing song (unless the song was the first song in the element), the player would reset the element and jump to playing its first song again. this is now fixed.
This commit is contained in:
@@ -552,12 +552,12 @@ impl Database {
|
||||
}
|
||||
Command::QueueAdd(index, new_data) => {
|
||||
if let Some(v) = self.queue.get_item_at_index_mut(&index, 0) {
|
||||
v.add_to_end(new_data);
|
||||
v.add_to_end(new_data, false);
|
||||
}
|
||||
}
|
||||
Command::QueueInsert(index, pos, new_data) => {
|
||||
if let Some(v) = self.queue.get_item_at_index_mut(&index, 0) {
|
||||
v.insert(new_data, pos);
|
||||
v.insert(new_data, pos, false);
|
||||
}
|
||||
}
|
||||
Command::QueueRemove(index) => {
|
||||
@@ -598,9 +598,9 @@ impl Database {
|
||||
.queue
|
||||
.get_item_at_index_mut(&index_to[0..index_to.len() - 1], 0)
|
||||
{
|
||||
parent.insert(vec![elem], index_to[index_to.len() - 1]);
|
||||
parent.insert(vec![elem], index_to[index_to.len() - 1], true);
|
||||
if was_current {
|
||||
self.queue.set_index_inner(&index_to, 0, vec![]);
|
||||
self.queue.set_index_inner(&index_to, 0, vec![], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -619,10 +619,10 @@ impl Database {
|
||||
parent_to[index_from.len() - 1] -= 1;
|
||||
}
|
||||
if let Some(parent) = self.queue.get_item_at_index_mut(&parent_to, 0) {
|
||||
if let Some(i) = parent.add_to_end(vec![elem]) {
|
||||
if let Some(i) = parent.add_to_end(vec![elem], true) {
|
||||
if was_current {
|
||||
parent_to.push(i);
|
||||
self.queue.set_index_inner(&parent_to, 0, vec![]);
|
||||
self.queue.set_index_inner(&parent_to, 0, vec![], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +34,10 @@ impl Queue {
|
||||
&mut self.content
|
||||
}
|
||||
|
||||
pub fn add_to_end(&mut self, v: Vec<Self>) -> Option<usize> {
|
||||
pub fn add_to_end(&mut self, v: Vec<Self>, skip_init: bool) -> Option<usize> {
|
||||
match &mut self.content {
|
||||
QueueContent::Song(_) => None,
|
||||
QueueContent::Folder(folder) => folder.add_to_end(v),
|
||||
QueueContent::Folder(folder) => folder.add_to_end(v, skip_init),
|
||||
QueueContent::Loop(..) => None,
|
||||
}
|
||||
}
|
||||
@@ -56,10 +56,10 @@ impl Queue {
|
||||
QueueContent::Loop(_, _, inner) => index[0] == 0 && inner.is_current(&index[1..]),
|
||||
}
|
||||
}
|
||||
pub fn insert(&mut self, v: Vec<Self>, index: usize) -> bool {
|
||||
pub fn insert(&mut self, v: Vec<Self>, index: usize, skip_init: bool) -> bool {
|
||||
match &mut self.content {
|
||||
QueueContent::Song(_) => false,
|
||||
QueueContent::Folder(folder) => folder.insert(v, index),
|
||||
QueueContent::Folder(folder) => folder.insert(v, index, skip_init),
|
||||
QueueContent::Loop(..) => false,
|
||||
}
|
||||
}
|
||||
@@ -215,9 +215,15 @@ impl Queue {
|
||||
|
||||
pub fn set_index_db(db: &mut Database, index: &[usize]) {
|
||||
db.queue.reset_index();
|
||||
db.queue.set_index_inner(index, 0, vec![]);
|
||||
db.queue.set_index_inner(index, 0, vec![], false);
|
||||
}
|
||||
pub fn set_index_inner(&mut self, index: &[usize], depth: usize, mut build_index: Vec<usize>) {
|
||||
pub fn set_index_inner(
|
||||
&mut self,
|
||||
index: &[usize],
|
||||
depth: usize,
|
||||
mut build_index: Vec<usize>,
|
||||
keep_child_indices: bool,
|
||||
) {
|
||||
let i = if let Some(i) = index.get(depth) {
|
||||
*i
|
||||
} else {
|
||||
@@ -229,13 +235,17 @@ impl Queue {
|
||||
QueueContent::Folder(folder) => {
|
||||
folder.index = i;
|
||||
if let Some(c) = folder.get_current_mut() {
|
||||
c.init();
|
||||
c.set_index_inner(index, depth + 1, build_index);
|
||||
if !keep_child_indices {
|
||||
c.init();
|
||||
}
|
||||
c.set_index_inner(index, depth + 1, build_index, keep_child_indices);
|
||||
}
|
||||
}
|
||||
QueueContent::Loop(_, _, inner) => {
|
||||
inner.init();
|
||||
inner.set_index_inner(index, depth + 1, build_index)
|
||||
if !keep_child_indices {
|
||||
inner.init();
|
||||
}
|
||||
inner.set_index_inner(index, depth + 1, build_index, keep_child_indices)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -347,11 +357,13 @@ impl QueueFolder {
|
||||
index: 0,
|
||||
}
|
||||
}
|
||||
pub fn add_to_end(&mut self, v: Vec<Queue>) -> Option<usize> {
|
||||
pub fn add_to_end(&mut self, v: Vec<Queue>, skip_init: bool) -> Option<usize> {
|
||||
let add_len = v.len();
|
||||
let len = self.content.len();
|
||||
for mut v in v.into_iter() {
|
||||
v.init();
|
||||
if !skip_init {
|
||||
v.init();
|
||||
}
|
||||
self.content.push(v);
|
||||
}
|
||||
if let Some(order) = &mut self.order {
|
||||
@@ -361,7 +373,7 @@ impl QueueFolder {
|
||||
}
|
||||
Some(len)
|
||||
}
|
||||
pub fn insert(&mut self, v: Vec<Queue>, index: usize) -> bool {
|
||||
pub fn insert(&mut self, v: Vec<Queue>, index: usize, skip_init: bool) -> bool {
|
||||
if index <= self.content.len() {
|
||||
if self.index >= index {
|
||||
self.index += v.len();
|
||||
@@ -377,7 +389,9 @@ impl QueueFolder {
|
||||
vec.extend(end);
|
||||
}
|
||||
let mapfunc = |mut v: Queue| {
|
||||
v.init();
|
||||
if !skip_init {
|
||||
v.init();
|
||||
}
|
||||
v
|
||||
};
|
||||
if let Some(order) = &mut self.order {
|
||||
|
||||
Reference in New Issue
Block a user