2025-12-28 17:45:06 +01:00
|
|
|
use crate::RendererInfo;
|
2025-12-06 13:37:42 +01:00
|
|
|
use crate::control_point::openhome_queue::OpenHomeQueue;
|
2025-12-28 17:45:06 +01:00
|
|
|
use crate::errors::ControlPointError;
|
2025-12-06 13:37:42 +01:00
|
|
|
use crate::openhome_playlist::OpenHomePlaylistSnapshot;
|
2025-12-28 17:45:06 +01:00
|
|
|
use crate::queue::backend::{PlaybackItem, QueueBackend, QueueSnapshot};
|
|
|
|
|
use crate::queue::interne::InternalQueue;
|
2025-12-06 13:37:42 +01:00
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub enum MusicQueue {
|
|
|
|
|
Internal(InternalQueue),
|
|
|
|
|
OpenHome(OpenHomeQueue),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl MusicQueue {
|
2025-12-28 17:45:06 +01:00
|
|
|
|
|
|
|
|
pub fn from_renderer_info(info: &RendererInfo) -> Result<MusicQueue, ControlPointError> {
|
|
|
|
|
if info.capabilities().has_oh_playlist() {
|
|
|
|
|
|
|
|
|
|
Ok(MusicQueue::OpenHome(OpenHomeQueue::from_renderer_info(info)?))
|
|
|
|
|
} else {
|
|
|
|
|
Ok(MusicQueue::Internal(InternalQueue::from_renderer_info(info)?))
|
|
|
|
|
}
|
2025-12-06 13:37:42 +01:00
|
|
|
}
|
|
|
|
|
|
2025-12-28 17:45:06 +01:00
|
|
|
pub fn openhome_playlist_snapshot(&self) -> Result<OpenHomePlaylistSnapshot, ControlPointError> {
|
2025-12-06 13:37:42 +01:00
|
|
|
match self {
|
|
|
|
|
MusicQueue::OpenHome(queue) => queue.openhome_playlist_snapshot(),
|
2025-12-28 17:45:06 +01:00
|
|
|
_ => Err(ControlPointError::QueueError(format!(
|
2025-12-06 13:37:42 +01:00
|
|
|
"OpenHome playlist snapshot is only available for OpenHome queues"
|
2025-12-28 17:45:06 +01:00
|
|
|
))),
|
2025-12-06 13:37:42 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-12-17 21:41:24 +01:00
|
|
|
|
|
|
|
|
pub fn replace_with_attached_playlist(
|
|
|
|
|
&mut self,
|
|
|
|
|
items: Vec<PlaybackItem>,
|
|
|
|
|
current_index: Option<usize>,
|
2025-12-28 17:45:06 +01:00
|
|
|
) -> Result<(), ControlPointError> {
|
2025-12-17 21:41:24 +01:00
|
|
|
match self {
|
|
|
|
|
MusicQueue::OpenHome(queue) => queue.replace_entire_playlist(items, current_index),
|
|
|
|
|
MusicQueue::Internal(queue) => queue.replace_queue(items, current_index),
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-06 13:37:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl QueueBackend for MusicQueue {
|
2025-12-28 17:45:06 +01:00
|
|
|
fn queue_snapshot(&self) -> Result<QueueSnapshot, ControlPointError> {
|
2025-12-06 13:37:42 +01:00
|
|
|
match self {
|
|
|
|
|
MusicQueue::Internal(q) => q.queue_snapshot(),
|
|
|
|
|
MusicQueue::OpenHome(q) => q.queue_snapshot(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-28 17:45:06 +01:00
|
|
|
fn set_index(&mut self, index: Option<usize>) -> Result<(), ControlPointError> {
|
2025-12-06 13:37:42 +01:00
|
|
|
match self {
|
|
|
|
|
MusicQueue::Internal(q) => q.set_index(index),
|
|
|
|
|
MusicQueue::OpenHome(q) => q.set_index(index),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn replace_queue(
|
|
|
|
|
&mut self,
|
|
|
|
|
items: Vec<PlaybackItem>,
|
|
|
|
|
current_index: Option<usize>,
|
2025-12-28 17:45:06 +01:00
|
|
|
) -> Result<(), ControlPointError> {
|
2025-12-06 13:37:42 +01:00
|
|
|
match self {
|
|
|
|
|
MusicQueue::Internal(q) => q.replace_queue(items, current_index),
|
|
|
|
|
MusicQueue::OpenHome(q) => q.replace_queue(items, current_index),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-28 17:45:06 +01:00
|
|
|
fn get_item(&self, index: usize) -> Result<Option<PlaybackItem>, ControlPointError> {
|
2025-12-06 13:37:42 +01:00
|
|
|
match self {
|
|
|
|
|
MusicQueue::Internal(q) => q.get_item(index),
|
|
|
|
|
MusicQueue::OpenHome(q) => q.get_item(index),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-28 17:45:06 +01:00
|
|
|
fn replace_item(&mut self, index: usize, item: PlaybackItem) -> Result<(), ControlPointError> {
|
2025-12-06 13:37:42 +01:00
|
|
|
match self {
|
|
|
|
|
MusicQueue::Internal(q) => q.replace_item(index, item),
|
|
|
|
|
MusicQueue::OpenHome(q) => q.replace_item(index, item),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|