From 355ef0db9305e7d90bffbb6400e63f14eb6afdc2 Mon Sep 17 00:00:00 2001 From: Anas Elgarhy Date: Sun, 12 Feb 2023 05:33:58 +0200 Subject: [PATCH] Add the base main code and create the events enum --- .idea/discord.xml | 7 +++++++ .idea/misc.xml | 4 ---- src/cmus/events.rs | 12 ++++++++++++ src/cmus/mod.rs | 17 +++++++++++++---- src/main.rs | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 .idea/discord.xml create mode 100644 src/cmus/events.rs diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..30bab2a --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 4222f97..1af07c1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,8 +3,4 @@ - - \ No newline at end of file diff --git a/src/cmus/events.rs b/src/cmus/events.rs new file mode 100644 index 0000000..adf6163 --- /dev/null +++ b/src/cmus/events.rs @@ -0,0 +1,12 @@ +use crate::cmus::player_settings::AAAMode; +use crate::cmus::TrackStatus; + +pub enum CmusEvent { + StatusChanged(TrackStatus), + TrackChanged, + VolumeChanged { left: u8, right: u8 }, + PositionChanged(u32), + ShuffleChanged(bool), + RepeatChanged(bool), + AAAMode(AAAMode), +} diff --git a/src/cmus/mod.rs b/src/cmus/mod.rs index cc1fbef..000a768 100644 --- a/src/cmus/mod.rs +++ b/src/cmus/mod.rs @@ -1,8 +1,13 @@ +mod events; +mod query; +mod player_settings; + use std::collections::HashMap; use std::fmt::Display; use std::num::ParseIntError; use std::str::FromStr; use typed_builder::TypedBuilder; +use crate::cmus::query::CmusQueryResponse; #[derive(Debug, PartialEq, Default)] pub struct TrackMetadata { @@ -26,7 +31,7 @@ pub struct Track { pub position: u32, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum CmusError { CmusRunningError(String), UnknownStatus, @@ -35,6 +40,8 @@ pub enum CmusError { DurationError(String), PositionError(String), UnknownError(String), + UnknownAAAMode(String), + UnknownShuffleMode(String), } impl Display for CmusError { @@ -47,6 +54,8 @@ impl Display for CmusError { CmusError::DurationError(s) => write!(f, "Duration error: {}", s), CmusError::PositionError(s) => write!(f, "Position error: {}", s), CmusError::UnknownError(s) => write!(f, "Unknown error: {}", s), + CmusError::UnknownAAAMode(s) => write!(f, "Unknown AAA mode: {}", s), + CmusError::UnknownShuffleMode(s) => write!(f, "Unknown shuffle mode: {}", s), } } } @@ -164,10 +173,10 @@ impl Track { } /// Make a status request to cmus. -/// And collect the output, and parse it into a `Track`. +/// And collect the output, and parse it into a `CmusQueryResponse`. /// If the cmus is not running, or the socket is not available, this function will return an error. #[inline] -pub fn get_track(query_command: &mut std::process::Command) -> Result { +pub fn ping_cmus(query_command: &mut std::process::Command) -> Result { // Just run the command, and collect the output. let output = query_command .output() @@ -182,7 +191,7 @@ pub fn get_track(query_command: &mut std::process::Command) -> Result = None; + + loop { + // Get the track info, and compare it with the previous one. + let Ok(track) = cmus::ping_cmus(&mut query_command) else { + if args.link { + std::process::exit(0) + } else { + // If the track info is the same as the previous one, just sleep for a while and try again. + sleep(); + continue; + } + }; + +/* // Compare the track info with the previous one, and if they are the same, just sleep for a while and try again. + if track == previous_track { + sleep(); + continue; + } + + // If the track info is different from the previous one, get the changes events. + let changes = track.get_changes(&previous_track); +*/ + + sleep(); + } + + }