Skip to content

Commit c33c9bb

Browse files
committed
feat: seek position in right status
1 parent 6d9ed96 commit c33c9bb

3 files changed

Lines changed: 62 additions & 40 deletions

File tree

‎player/src/gui.rs‎

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ pub enum UIEvent {
8181
VolumeSlider(f32),
8282
VolumeUp,
8383
VolumeDown,
84-
SeekBar(f32),
84+
SeekBarMoved(f32),
85+
SeekBarFinished(f32),
8586
DroppedFiles(String),
8687
HideQueue,
8788
HideConnectionWindow,
@@ -413,7 +414,6 @@ impl UIThread {
413414
self.gui.reset();
414415

415416
self.update_status();
416-
self.update_right_status();
417417
}
418418
UIUpdateEvent::SetTime(elapsed, total) => {
419419
// TODO: switch between elapsed and remaining on there
@@ -452,8 +452,6 @@ impl UIThread {
452452
}
453453
}
454454
UIUpdateEvent::UserListChanged => {
455-
self.update_right_status();
456-
457455
let s = self.state.blocking_read();
458456

459457
self.gui.users.clear();
@@ -476,11 +474,12 @@ impl UIThread {
476474
} else {
477475
// not connected
478476
}
477+
478+
drop(s);
479+
self.update_status();
479480
}
480481
UIUpdateEvent::RoomChanged => {}
481482
UIUpdateEvent::QueueChanged => {
482-
self.update_right_status();
483-
484483
let s = self.state.blocking_read();
485484

486485
self.queue_gui.queue_browser.clear();
@@ -547,8 +546,7 @@ impl UIThread {
547546
}
548547

549548
drop(s);
550-
551-
self.update_right_status();
549+
self.update_status();
552550
}
553551
UIUpdateEvent::UpdateConnectionTree(list) => {
554552
self.connection_gui.populate(list);
@@ -562,21 +560,6 @@ impl UIThread {
562560
}
563561
}
564562

565-
fn update_right_status(&mut self) {
566-
let s = self.state.blocking_read();
567-
568-
let (users, queue) = s
569-
.connection
570-
.as_ref()
571-
.and_then(|c| c.room.as_ref())
572-
.map(|r| (r.connected_users.len(), r.queue.len()))
573-
.unwrap_or_default();
574-
575-
self.gui
576-
.status_right_display
577-
.set_label(&format!("U{:0>2} Q{:0>2}", users, queue));
578-
}
579-
580563
// set status based on state and priorities
581564
fn update_status(&mut self) {
582565
let status = self.get_status();
@@ -585,21 +568,11 @@ impl UIThread {
585568
// and the little thingy too
586569
let play_status = self.get_play_status();
587570
self.gui.play_status.update(play_status);
588-
}
589571

590-
fn get_play_status(&self) -> PlayStatusIcon {
591-
let state = self.state.blocking_read();
592-
593-
// i love shared and reusable logic ^-^
594-
if state.is_stopped() {
595-
PlayStatusIcon::Stop
596-
} else if state.is_paused() {
597-
PlayStatusIcon::Pause
598-
} else if state.is_transmitter() {
599-
PlayStatusIcon::PlayTx
600-
} else {
601-
PlayStatusIcon::PlayRx
602-
}
572+
// and probably just do the right status at the same time too
573+
// if we really want fine grained updates then we should do something else
574+
let right_status = self.get_right_status();
575+
self.gui.status_right_display.set_label(&right_status);
603576
}
604577

605578
fn get_status(&self) -> String {
@@ -647,6 +620,38 @@ impl UIThread {
647620
"<not connected>".to_string()
648621
}
649622
}
623+
624+
fn get_play_status(&self) -> PlayStatusIcon {
625+
let state = self.state.blocking_read();
626+
627+
// i love shared and reusable logic ^-^
628+
if state.is_stopped() {
629+
PlayStatusIcon::Stop
630+
} else if state.is_paused() {
631+
PlayStatusIcon::Pause
632+
} else if state.is_transmitter() {
633+
PlayStatusIcon::PlayTx
634+
} else {
635+
PlayStatusIcon::PlayRx
636+
}
637+
}
638+
639+
fn get_right_status(&self) -> String {
640+
let s = self.state.blocking_read();
641+
642+
if let Some(seek_pos) = s.seek_position {
643+
return format!("[{}]", min_secs(seek_pos));
644+
}
645+
646+
let (users, queue) = s
647+
.connection
648+
.as_ref()
649+
.and_then(|c| c.room.as_ref())
650+
.map(|r| (r.connected_users.len(), r.queue.len()))
651+
.unwrap_or_default();
652+
653+
format!("U{:0>2} Q{:0>2}", users, queue)
654+
}
650655
}
651656

652657
fn handle_window_drag(

‎player/src/gui/main_window.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,16 @@ impl MainWindow {
114114

115115
true
116116
}
117+
fltk::enums::Event::Drag => {
118+
ui_send!(UIEvent::SeekBarMoved(sb.value() as f32));
119+
120+
true
121+
}
117122
fltk::enums::Event::Released => {
118123
let mut d = seek_bar_dragging2.blocking_lock();
119124
*d = false;
120125

121-
ui_send!(UIEvent::SeekBar(sb.value() as f32));
126+
ui_send!(UIEvent::SeekBarFinished(sb.value() as f32));
122127

123128
true
124129
}

‎player/src/main.rs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub struct State {
6767
connection: Option<ConnectionState>,
6868

6969
loading_count: usize,
70+
seek_position: Option<f32>,
7071
}
7172

7273
#[derive(Debug)]
@@ -154,6 +155,7 @@ impl MainThread {
154155
preferences: prefs,
155156
loading_count: 0,
156157
connection: None,
158+
seek_position: None,
157159
}));
158160

159161
let ui_rx = UIThread::spawn(state.clone());
@@ -277,12 +279,22 @@ impl MainThread {
277279
conn.send(Message::PlaybackCommand(PlaybackCommand::Prev)).unwrap();
278280
}
279281

280-
UIEvent::SeekBar(progress) => {
282+
UIEvent::SeekBarMoved(progress) => {
283+
let mut state = self.state.write().await;
284+
if let Some(track) = state.current_track() {
285+
let secs = track.metadata.duration * progress;
286+
state.seek_position = Some(secs);
287+
ui_update!(UIUpdateEvent::Status);
288+
}
289+
}
290+
UIEvent::SeekBarFinished(progress) => {
281291
let Some(conn) = self.connection.as_mut() else { continue };
282292

283-
let state = self.state.read().await;
293+
let mut state = self.state.write().await;
284294
if let Some(track) = state.current_track() {
285295
let secs = track.metadata.duration * progress;
296+
state.seek_position = None;
297+
ui_update!(UIUpdateEvent::Status);
286298
conn.send(Message::PlaybackCommand(PlaybackCommand::SeekTo(secs))).unwrap();
287299
}
288300
}

0 commit comments

Comments
 (0)