Compare commits
No commits in common. "57b6024845ecc78b9c60bfc3b75745a3ed3f7bdc" and "9599ee669dbf44b41cbe1c1344be907cc15676f9" have entirely different histories.
57b6024845
...
9599ee669d
1 changed files with 19 additions and 72 deletions
|
@ -11,22 +11,10 @@ mod imp {
|
|||
use tracing::{event, span, Level};
|
||||
use zbus::object_server::InterfaceRef;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
enum State {
|
||||
Idle,
|
||||
FileLoading,
|
||||
FileLoaded,
|
||||
Active,
|
||||
FileEnded,
|
||||
Seeking,
|
||||
}
|
||||
|
||||
#[derive(gtk::CompositeTemplate, glib::Properties)]
|
||||
#[template(resource = "/eu/callcc/audrey/window.ui")]
|
||||
#[properties(wrapper_type = super::Window)]
|
||||
pub struct Window {
|
||||
state: Cell<State>,
|
||||
|
||||
#[template_child]
|
||||
pub(super) playbar: TemplateChild<crate::ui::Playbar>,
|
||||
|
||||
|
@ -95,6 +83,9 @@ mod imp {
|
|||
mpv.set_property("vid", false).unwrap();
|
||||
mpv.set_property("prefetch-playlist", true).unwrap();
|
||||
|
||||
mpv.observe_property(0, "volume").unwrap();
|
||||
mpv.observe_property(1, "mute").unwrap();
|
||||
mpv.observe_property(2, "pause").unwrap();
|
||||
mpv.observe_property(3, "playlist-pos").unwrap();
|
||||
mpv.observe_property(4, "idle-active").unwrap();
|
||||
mpv.observe_property(6, "playlist-count").unwrap();
|
||||
|
@ -104,8 +95,6 @@ mod imp {
|
|||
mpv.add_hook(0, "on_before_start_file", 0).unwrap();
|
||||
|
||||
Self {
|
||||
state: Cell::new(State::Idle),
|
||||
|
||||
playbar: Default::default(),
|
||||
play_queue: Default::default(),
|
||||
can_click_shuffle_all: Cell::new(false),
|
||||
|
@ -382,9 +371,7 @@ mod imp {
|
|||
}
|
||||
|
||||
fn playlist_count(&self) -> i64 {
|
||||
let count = self.mpv.get_property::<i64>("playlist-count").unwrap();
|
||||
assert_eq!(count as u32, self.playlist_model.n_items());
|
||||
count
|
||||
self.mpv.get_property::<i64>("playlist-count").unwrap()
|
||||
}
|
||||
|
||||
fn song(&self) -> Option<Song> {
|
||||
|
@ -433,6 +420,21 @@ mod imp {
|
|||
|
||||
fn on_property_change(&self, event: crate::mpv::event::PropertyEvent) {
|
||||
match event.reply_userdata {
|
||||
0 => {
|
||||
assert_eq!(event.name, "volume");
|
||||
self.obj().notify("volume");
|
||||
}
|
||||
|
||||
1 => {
|
||||
assert_eq!(event.name, "mute");
|
||||
self.obj().notify("mute");
|
||||
}
|
||||
|
||||
2 => {
|
||||
assert_eq!(event.name, "pause");
|
||||
self.obj().notify("pause");
|
||||
}
|
||||
|
||||
3 => {
|
||||
assert_eq!(event.name, "playlist-pos");
|
||||
self.obj().notify("playlist-pos");
|
||||
|
@ -441,9 +443,6 @@ mod imp {
|
|||
4 => {
|
||||
assert_eq!(event.name, "idle-active");
|
||||
self.obj().notify("idle-active");
|
||||
if self.obj().idle_active() {
|
||||
self.on_idle_active();
|
||||
}
|
||||
}
|
||||
|
||||
6 => {
|
||||
|
@ -504,25 +503,7 @@ mod imp {
|
|||
};
|
||||
}
|
||||
|
||||
fn on_idle_active(&self) {
|
||||
match self.state.get() {
|
||||
State::Idle => {}
|
||||
State::FileEnded => {}
|
||||
|
||||
other => panic!("invalid state transition: IdleActive from {other:?}"),
|
||||
}
|
||||
self.state.set(State::Idle);
|
||||
}
|
||||
|
||||
fn on_start_file(&self) {
|
||||
match self.state.get() {
|
||||
State::Idle => {}
|
||||
State::FileEnded => {}
|
||||
|
||||
other => panic!("invalid state transition: StartFile from {other:?}"),
|
||||
}
|
||||
self.state.set(State::FileLoading);
|
||||
|
||||
event!(Level::INFO, "StartFile");
|
||||
self.obj().notify("song");
|
||||
self.buffering_start();
|
||||
|
@ -561,13 +542,6 @@ mod imp {
|
|||
}
|
||||
|
||||
fn on_file_loaded(&self) {
|
||||
match self.state.get() {
|
||||
State::FileLoading => {}
|
||||
|
||||
other => panic!("invalid state transition: FileLoaded from {other:?}"),
|
||||
}
|
||||
self.state.set(State::FileLoaded);
|
||||
|
||||
event!(Level::INFO, "FileLoaded");
|
||||
// sanity check
|
||||
// i think "path" is only available after this event is dispatched
|
||||
|
@ -579,27 +553,10 @@ mod imp {
|
|||
|
||||
fn on_seek(&self) {
|
||||
event!(Level::INFO, "Seek");
|
||||
|
||||
match self.state.get() {
|
||||
State::Active => {}
|
||||
State::Seeking => {}
|
||||
|
||||
other => panic!("invalid state transition: Seek from {other:?}"),
|
||||
}
|
||||
self.state.set(State::Seeking);
|
||||
|
||||
self.buffering_start();
|
||||
}
|
||||
|
||||
fn on_playback_restart(&self) {
|
||||
match self.state.get() {
|
||||
State::FileLoaded => {}
|
||||
State::Seeking => {}
|
||||
|
||||
other => panic!("invalid state transition: PlaybackRestart from {other:?}"),
|
||||
}
|
||||
self.state.set(State::Active);
|
||||
|
||||
event!(Level::INFO, "PlaybackRestart");
|
||||
self.buffering_end();
|
||||
self.obj().notify("time-pos");
|
||||
|
@ -613,16 +570,6 @@ mod imp {
|
|||
|
||||
fn on_end_file(&self, event: crate::mpv::event::EndFileEvent) {
|
||||
event!(Level::INFO, "EndFile: {event:?}");
|
||||
|
||||
match self.state.get() {
|
||||
State::Active => {}
|
||||
State::FileLoading => {}
|
||||
State::Seeking => {}
|
||||
|
||||
other => panic!("invalid state transition: EndFile from {other:?}"),
|
||||
}
|
||||
self.state.set(State::FileEnded);
|
||||
|
||||
self.obj().notify("song");
|
||||
self.buffering_end();
|
||||
|
||||
|
|
Loading…
Reference in a new issue