Skip to content

Commit d48b901

Browse files
committed
feat: gui (and many other things too) :3
1 parent 62ab7c4 commit d48b901

6 files changed

Lines changed: 395 additions & 42 deletions

File tree

‎Cargo.lock‎

Lines changed: 70 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎player/Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ opus = "0.3.0"
1515
rubato = "0.12.0"
1616
ringbuf = "0.3.3"
1717
hound = "3.5.0"
18+
fltk = "1.4.3"
19+
fltk-theme = "0.7.0"

‎player/src/audio.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,22 @@ impl AudioReader {
231231
pub fn finished(&self) -> bool {
232232
self.finished
233233
}
234+
234235
}
235236

236237
pub struct Player {
237238
decoder: Decoder,
238239
buffer: Arc<Mutex<Ringbuf<f32>>>,
239240
stream: Option<Stream>,
241+
frames_received: usize,
240242
}
241243
impl Player {
242244
pub fn new() -> Self {
243245
Self {
244246
decoder: Decoder::new(48000, opus::Channels::Stereo).unwrap(),
245247
buffer: Arc::new(Mutex::new(Ringbuf::<f32>::new(48000 * 10))), // 10s??
246248
stream: None,
249+
frames_received: 0,
247250
}
248251
}
249252

@@ -252,6 +255,7 @@ impl Player {
252255
// allocate and decode into here
253256
let mut pcm = vec![0.0; 960];
254257
self.decoder.decode_float(&frame, &mut pcm, false).unwrap();
258+
self.frames_received += 1;
255259

256260
let mut buffer = self.buffer.lock().unwrap();
257261
if buffer.len() < buffer.free_len() {
@@ -316,6 +320,7 @@ impl Player {
316320
pub fn clear(&mut self) {
317321
println!("clearing playback buffer");
318322
self.buffer.lock().unwrap().clear();
323+
self.frames_received = 0;
319324
}
320325

321326
pub fn finish(&mut self) -> bool {
@@ -333,6 +338,12 @@ impl Player {
333338
let buffer = self.buffer.lock().unwrap();
334339
buffer.len() > 48000 * 2 // 2s...
335340
}
341+
pub fn get_seconds_elapsed(&self) -> usize {
342+
self.frames_received * 480 / 48000
343+
}
344+
pub fn fake_frames_received(&mut self, frames: usize) {
345+
self.frames_received = frames;
346+
}
336347
}
337348

338349
// callback when the audio output needs more data

‎player/src/gui.rs‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
use fltk::app::Sender;
2+
use fltk::browser::*;
3+
use fltk::button::*;
4+
use fltk::enums::*;
5+
use fltk::frame::*;
6+
use fltk::input::*;
7+
use fltk::prelude::*;
8+
use fltk::valuator::*;
9+
use fltk::window::*;
10+
11+
use crate::UIEvent;
12+
13+
pub struct UserInterface {
14+
pub main_win: Window,
15+
pub seek_bar: HorNiceSlider,
16+
pub status_field: Frame,
17+
pub users: Browser,
18+
pub temp_input: Input,
19+
pub lbl_time: Frame,
20+
}
21+
impl UserInterface {
22+
pub fn make_window(sender: Sender<UIEvent>) -> Self {
23+
let mut main_win = Window::new(100, 100, 400, 180, "multiplayer :3");
24+
25+
let buttons_y = 120;
26+
let side_margin = 18;
27+
28+
let mut temp_input = Input::new(150,buttons_y,120,20,"");
29+
main_win.add(&temp_input);
30+
31+
let mut btn_play = Button::new(side_margin, buttons_y, 36, 26, "@>");
32+
btn_play.emit(sender, UIEvent::BtnPlay);
33+
main_win.add(&btn_play);
34+
35+
let btn_stop = Button::new(42 + side_margin, buttons_y, 36, 26, "@-7square");
36+
main_win.add(&btn_stop);
37+
38+
let btn_pause = Button::new(84 + side_margin, buttons_y, 36, 26, "| |");
39+
main_win.add(&btn_pause);
40+
41+
let seek_bar = HorNiceSlider::new(side_margin, buttons_y - 35, 200, 24, "");
42+
main_win.add(&seek_bar);
43+
44+
let mut status_field =
45+
Frame::new(0, main_win.height() - 21, main_win.width(), 21, "status");
46+
status_field.set_align(Align::Left | Align::Inside);
47+
status_field.set_frame(FrameType::DownBox);
48+
main_win.add(&status_field);
49+
50+
let mut art_frame = Frame::new(side_margin, 16, 50, 50, "");
51+
art_frame.set_frame(FrameType::DownBox);
52+
main_win.add(&art_frame);
53+
54+
let mut lbl_title = Frame::new(side_margin + 54, 22, 50, 16, "Title, thing");
55+
lbl_title.set_align(Align::Left | Align::Inside);
56+
main_win.add(&lbl_title);
57+
58+
let mut lbl_data1 = Frame::new(side_margin + 54, 40, 50, 16, "data1");
59+
lbl_data1.set_align(Align::Left | Align::Inside);
60+
main_win.add(&lbl_data1);
61+
62+
let mut users = Browser::new(main_win.width() - 85 - side_margin, 16, 85, 120, "Users");
63+
users.add("* you");
64+
main_win.add(&users);
65+
66+
let mut btn_connect = Button::new(main_win.width() - 85 - 46, 16, 24, 24, "Cn");
67+
//btn_connect.emit(sender, crate::UIEvent::Test("wow".to_string()));
68+
main_win.add(&btn_connect);
69+
70+
let mut btn_queue = Button::new(main_win.width() - 85 - 46, 16+24+2, 24, 24, "Qu");
71+
main_win.add(&btn_queue);
72+
73+
let mut lbl_time = Frame::new(180,70,80,16,"00:00/00:00");
74+
lbl_time.set_label_font(Font::Courier);
75+
lbl_time.set_align(Align::Left | Align::Inside);
76+
77+
main_win.add(&lbl_time);
78+
79+
80+
Self { main_win, seek_bar, status_field, users, temp_input, lbl_time }
81+
}
82+
}

0 commit comments

Comments
 (0)