Skip to content

Commit

Permalink
Merge branch 'main' of github.com:michaelb/ouverture
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelb committed May 29, 2023
2 parents 06ab043 2977f1b commit 60ff89d
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 48 deletions.
22 changes: 14 additions & 8 deletions ouverture-core/src/audio/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 253,7 @@ mod cpal {
sample_rate: cpal::SampleRate(spec.rate),
buffer_size: cpal::BufferSize::Default,
}
}
else {
} else {
// Use the default config for Windows.
device
.default_output_config()
Expand Down Expand Up @@ -300,13 299,21 @@ mod cpal {

let resampler = if spec.rate != config.sample_rate.0 {
info!("resampling {} Hz to {} Hz", spec.rate, config.sample_rate.0);
Some(Resampler::new(spec, config.sample_rate.0 as usize, duration))
}
else {
Some(Resampler::new(
spec,
config.sample_rate.0 as usize,
duration,
))
} else {
None
};

Ok(Box::new(CpalAudioOutputImpl { ring_buf_producer, sample_buf, stream, resampler }))
Ok(Box::new(CpalAudioOutputImpl {
ring_buf_producer,
sample_buf,
stream,
resampler,
}))
}
}

Expand All @@ -324,8 331,7 @@ mod cpal {
Some(resampled) => resampled,
None => return Ok(()),
}
}
else {
} else {
// Resampling is not required. Interleave the sample for cpal using a sample buffer.
self.sample_buf.copy_interleaved_ref(decoded);

Expand Down
19 changes: 9 additions & 10 deletions ouverture-core/src/audio/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 15,9 @@ use super::output;

use std::time;

use tokio::sync::broadcast::{ Sender, Receiver};
use rc_event_queue::mpmc::{DefaultSettings, EventQueue, EventReader};
use rc_event_queue::prelude::*;
use tokio::sync::broadcast::{Receiver, Sender};

use std::thread;

Expand Down Expand Up @@ -60,8 60,7 @@ impl std::fmt::Debug for AudioThread {
}

pub fn start_audio_thread(rx: Receiver<AudioCommand>, tx: Sender<AudioEvent>) -> AudioThread {

let handle = std::thread::spawn(|| audio_thread_fn(rx,tx));
let handle = std::thread::spawn(|| audio_thread_fn(rx, tx));
debug!("audio thread started");

AudioThread {
Expand All @@ -81,10 80,7 @@ pub fn stop_audio_thread(audio_thread: AudioThread) {

const AUDIO_THREAD_EQ_POLL_PERIOD_MS: u64 = 50;

fn audio_thread_fn(
mut rx: Receiver<AudioCommand>,
tx: Sender<AudioEvent>,
) {
fn audio_thread_fn(mut rx: Receiver<AudioCommand>, tx: Sender<AudioEvent>) {
let mut current_seek = 0;
let mut current_song = None;
let mut command_from_decode_loop: Option<AudioCommand> = None;
Expand Down Expand Up @@ -124,7 120,10 @@ fn audio_thread_fn(
}
}
Some(Pause) => None,
Some(Pause) => {current_song = None; None},
Some(Pause) => {
current_song = None;
None
}
_ => unimplemented!(),
}
}
Expand Down Expand Up @@ -256,8 255,8 @@ pub fn decode(
match rx.try_recv() {
Ok(Play) => (),
Ok(cmd) => return Some(cmd.clone()), // TODO exhaust the enum manually to avoid alloc in audio thread
Err(_) => (), // most likely no new cmd
}
Err(_) => (), // most likely no new cmd
}
}
Err(Error::IoError(_)) => {
// The packet failed to decode due to an IO error, skip the packet.
Expand Down
2 changes: 1 addition & 1 deletion ouverture-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 1,10 @@
pub mod audio;
pub mod config;
pub mod database;
pub mod library;
pub mod logger;
pub mod music;
pub mod server;
pub mod audio;

use config::Config;
use server::Server;
Expand Down
4 changes: 2 additions & 2 deletions ouverture-core/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 1,15 @@
extern crate ouverture_core;
mod opt;

use ouverture_core::server::{Command::Stop, Server};
use color_eyre::eyre::eyre;
use color_eyre::Result;
use futures::stream::StreamExt;
use log::LevelFilter::*;
use log::{debug, warn};
use ouverture_core::logger::{setup_logger, LogDestination::*};
use opt::Opt;
use ouverture_core::config::Config;
use ouverture_core::logger::{setup_logger, LogDestination::*};
use ouverture_core::server::{Command::Stop, Server};
use ouverture_core::start;
use signal_hook::consts::signal::*;
use signal_hook_tokio::Signals;
Expand Down
4 changes: 2 additions & 2 deletions ouverture-core/src/music/song.rs
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
use chrono::prelude::{DateTime, Local};
use audiotags::Tag;
use chrono::prelude::{DateTime, Local};
use infer;
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -147,7 147,7 @@ impl Song {

if format == unsupported {
// TODO reject the new song
warn!("format {} is not suported", kind.mime_type() );
warn!("format {} is not suported", kind.mime_type());
}

Song {
Expand Down
2 changes: 1 addition & 1 deletion ouverture-core/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 29,7 @@ use crate::audio::{
pub struct Server {
config: Config,
audio_task: Option<AudioTask>, // this task has for only role to send queued songs to the audio thread
// when it finishes playing a song
// when it finishes playing a song
state: Arc<Mutex<ServerState>>,
}

Expand Down
10 changes: 5 additions & 5 deletions ouverture-ui/src/panes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 12,7 @@ pub struct Panes {
}

use crate::Message;
use log::{trace, debug, warn};
use log::{debug, trace, warn};

use std::any::Any;
use std::rc::Rc;
Expand All @@ -30,10 30,9 @@ pub enum PaneMessage {
// for List
AskRefreshList(pane_grid::Pane),
ReceivedNewList(pane_grid::Pane, Rc<ouverture_core::server::Reply>),
ListMessage(list::ListMessage)
ListMessage(list::ListMessage),
}


impl Panes {
pub fn new() -> Self {
let a: Box<dyn Content> = Box::new(Editor::new(0));
Expand Down Expand Up @@ -155,7 154,9 @@ impl Application for Panes {
if let Some((new_pane, _)) = result {
self.focus = Some(new_pane);
self.panes.close(&pane);
return Command::single(Message::ChildMessage(PaneMessage::AskRefreshList(new_pane)).into());
return Command::single(
Message::ChildMessage(PaneMessage::AskRefreshList(new_pane)).into(),
);
} else {
warn!("failed to close pane, keeping current one");
};
Expand Down Expand Up @@ -287,7 288,6 @@ impl Content for Editor {
self
}
fn view(&self, pane: pane_grid::Pane, total_panes: usize) -> Element<Message> {

let mut controls = column![].spacing(5).max_width(150);
controls = controls
.push(button(text("-")).on_press(Message::Split(pane_grid::Axis::Horizontal, pane)))
Expand Down
6 changes: 3 additions & 3 deletions ouverture-ui/src/panes/control_bar.rs
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
use iced::{Element, Length, Command};
use iced::{Command, Element, Length};

use iced::widget::{button, container, pane_grid, row, text};

Expand Down Expand Up @@ -33,11 33,11 @@ impl ControlBar {
currently_playing: false,
}
}
fn update(&mut self, message:Message) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
let address = "127.0.0.1:6603";

match message {
_ => Command::none()
_ => Command::none(),
}
}

Expand Down
39 changes: 23 additions & 16 deletions ouverture-ui/src/panes/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 48,16 @@ impl ListRow {
pub enum ColumnField {
Title,
Artist,
Album
Album,
}

pub struct List {
rows: Vec<(Song, bool)>, // list of song and whether selected (used for coloring only)
columns: Vec<(ColumnField, f32)>, // size and order of the columns
current_sort: (ColumnField, bool), // current ordering (true = ascending, false) descending)
current_selection: Option<usize> // currently selected row
current_selection: Option<usize>, // currently selected row
}


#[derive(Debug, Clone)]
pub enum ListMessage {
ClickRow(Option<usize>),
Expand All @@ -71,36 70,39 @@ impl Content for List {
let mut button =
button(text(button_text).vertical_alignment(Vertical::Center)).padding(0);
if let Some(order) = sort_order {
button = button.on_press(Message::ChildMessage(PaneMessage::ListMessage(ListMessage::Sort(order))))
button = button.on_press(Message::ChildMessage(PaneMessage::ListMessage(
ListMessage::Sort(order),
)))
}
button
};

const ICON_COLUMN_WIDTH: f32 = 35.0;
let header = container(
{ let mut header_row = row![]
let header = container({
let mut header_row = row![]
.width(Length::Fill)
.height(Length::Fixed(30.0))
// Spacer heading for icons column
.push(heading_button("X", None).width(Length::Fixed(ICON_COLUMN_WIDTH)));

for c in self.columns.iter() {
header_row = header_row.push( heading_button(&c.0.to_string(), Some(c.0)).width(Length::Fixed(c.1)));
}
header_row
})
for c in self.columns.iter() {
header_row = header_row
.push(heading_button(&c.0.to_string(), Some(c.0)).width(Length::Fixed(c.1)));
}
header_row
})
.padding(Padding::from([0, 8]))
.width(Length::Fill);

let mut rows = column![];
for (i, s) in self.rows.iter().enumerate() {
let e: ListRow = s.clone().0.into();
let mut r = row![text("X").width(Length::Fixed(ICON_COLUMN_WIDTH))] .spacing(5);
let mut r = row![text("X").width(Length::Fixed(ICON_COLUMN_WIDTH))].spacing(5);
for c in &self.columns {
let field_content = match c.0 {
ColumnField::Title => e.title.clone(),
ColumnField::Artist => e.artist.clone(),
_ => todo!()
_ => todo!(),
};
r = r.push(text(field_content).width(Length::Fixed(c.1)));
}
Expand Down Expand Up @@ -133,8 135,8 @@ impl Content for List {
Command::none()
}
PaneMessage::ListMessage(ListMessage::ClickRow(Some(i))) => {
if ! &self.rows[i].1 {
* (&mut self.rows[i].1) = true;
if !&self.rows[i].1 {
*(&mut self.rows[i].1) = true;
Command::none()
} else {
Command::single(Message::Play(Some(self.rows[i].0.clone())).into())
Expand All @@ -157,7 159,12 @@ impl Content for List {

impl List {
pub fn new() -> Self {
List { rows: vec![], columns: vec![(ColumnField::Title, 600.0), (ColumnField::Artist, 350.0)], current_sort: (ColumnField::Title, true), current_selection : None }
List {
rows: vec![],
columns: vec![(ColumnField::Title, 600.0), (ColumnField::Artist, 350.0)],
current_sort: (ColumnField::Title, true),
current_selection: None,
}
}

pub fn ask_refresh_list(&mut self, pane: pane_grid::Pane) -> Command<Message> {
Expand Down

0 comments on commit 60ff89d

Please sign in to comment.