Compare commits
2 Commits
iced
...
0afc497f78
| Author | SHA1 | Date | |
|---|---|---|---|
| 0afc497f78 | |||
| b281f8af00 |
@@ -9,6 +9,7 @@ crate_type = "bin"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dirs = "^3.0.1"
|
dirs = "^3.0.1"
|
||||||
iced = "^0.1.1"
|
gdk = "^0.13.2"
|
||||||
|
gio = "^0"
|
||||||
|
gtk = "^0"
|
||||||
rodio = "^0.11.0"
|
rodio = "^0.11.0"
|
||||||
env_logger = "^0.8.1"
|
|
||||||
|
|||||||
290
src/main.rs
290
src/main.rs
@@ -1,6 +1,8 @@
|
|||||||
#![windows_subsystem = "windows"]
|
#![windows_subsystem = "windows"]
|
||||||
|
|
||||||
use iced::{Settings, Application, Element, executor, Length, Container, Column, Scrollable, Slider};
|
use gio::prelude::*;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
use gtk::Orientation;
|
||||||
use rodio::{Sink, Source};
|
use rodio::{Sink, Source};
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
@@ -10,51 +12,29 @@ use std::process::Command;
|
|||||||
|
|
||||||
const SPACING: i32 = 16;
|
const SPACING: i32 = 16;
|
||||||
|
|
||||||
struct Sound {
|
#[cfg(target_os = "windows")]
|
||||||
name: String,
|
fn file_manager() -> &'static str {
|
||||||
path: String, // bytes instead?
|
"explorer"
|
||||||
sink: Sink,
|
|
||||||
volume: f32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// todo: maybe add a play/pause state or global volume? saved presets?
|
#[cfg(not(target_os = "windows"))]
|
||||||
struct State {
|
fn file_manager() -> &'static str {
|
||||||
sounds: Vec<Sound>
|
"xdg-open"
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Lull {
|
fn error_popup(message: &str) {
|
||||||
Loading,
|
let popup = gtk::Window::new(gtk::WindowType::Toplevel);
|
||||||
Loaded(State),
|
popup.set_title("error");
|
||||||
}
|
popup.set_border_width(SPACING as u32);
|
||||||
|
popup.set_position(gtk::WindowPosition::Center);
|
||||||
|
popup.set_default_size(256, 64);
|
||||||
|
popup.set_type_hint(gdk::WindowTypeHint::Dialog);
|
||||||
|
popup.set_resizable(false);
|
||||||
|
|
||||||
impl Application for Lull {
|
let message = gtk::Label::new(Some(message));
|
||||||
type Executor = executor::Default;
|
popup.add(&message);
|
||||||
type Message = Message;
|
|
||||||
type Flags = ();
|
|
||||||
|
|
||||||
fn new(_flags: Self::Flags) -> (Self, Command) {
|
popup.show_all();
|
||||||
(
|
|
||||||
Lull {sounds: Vec::new()},
|
|
||||||
Command::none(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn title(&self) -> String {
|
|
||||||
String::from("lull")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, message: Self::Message) -> Command {
|
|
||||||
match self {
|
|
||||||
self::Loading => {},
|
|
||||||
self::Loaded => {},
|
|
||||||
}
|
|
||||||
|
|
||||||
Command::none()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&mut self) -> Element<'_, Self::Message> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_data_dir() -> PathBuf {
|
fn get_data_dir() -> PathBuf {
|
||||||
@@ -69,130 +49,114 @@ fn get_data_dir() -> PathBuf {
|
|||||||
data_dir
|
data_dir
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
fn build_ui(application: >k::Application) {
|
||||||
env_logger::init();
|
let window = gtk::ApplicationWindow::new(application);
|
||||||
|
|
||||||
Lull::run(Settings::default())
|
window.set_title("lull");
|
||||||
|
window.set_border_width(SPACING as u32);
|
||||||
|
window.set_position(gtk::WindowPosition::Center);
|
||||||
|
window.set_default_size(256, 256);
|
||||||
|
|
||||||
|
let vertical = gtk::Box::new(Orientation::Vertical, SPACING);
|
||||||
|
vertical.set_homogeneous(true);
|
||||||
|
|
||||||
|
window.add(&vertical);
|
||||||
|
|
||||||
|
let device = rodio::default_output_device().unwrap();
|
||||||
|
|
||||||
|
let paths = std::fs::read_dir(get_data_dir())
|
||||||
|
.expect("Couldn't read from lull data directory");
|
||||||
|
|
||||||
|
for path in paths {
|
||||||
|
let path = path.unwrap().path();
|
||||||
|
let name: &str = path.file_stem().unwrap().to_str().unwrap();
|
||||||
|
|
||||||
|
let file = File::open(&path)
|
||||||
|
.expect("Couldn't open audio file");
|
||||||
|
|
||||||
|
let source = rodio::Decoder::new(
|
||||||
|
BufReader::new(file)
|
||||||
|
);
|
||||||
|
|
||||||
|
if source.is_err() {
|
||||||
|
error_popup(&format!(
|
||||||
|
"Couldn't parse file {}. \n{}.",
|
||||||
|
path.to_str().unwrap(),
|
||||||
|
source.err().unwrap()
|
||||||
|
));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn error_popup(message: &str) {
|
let source = source.unwrap().repeat_infinite();
|
||||||
// let popup = gtk::Window::new(gtk::WindowType::Toplevel);
|
|
||||||
// popup.set_title("error");
|
|
||||||
// popup.set_border_width(SPACING as u32);
|
|
||||||
// popup.set_position(gtk::WindowPosition::Center);
|
|
||||||
// popup.set_default_size(256, 64);
|
|
||||||
//
|
|
||||||
// let vertical = gtk::Box::new(Orientation::Vertical, SPACING);
|
|
||||||
// popup.add(&vertical);
|
|
||||||
//
|
|
||||||
// let message = gtk::Label::new(Some(message));
|
|
||||||
// vertical.add(&message);
|
|
||||||
//
|
|
||||||
// let button_ok = gtk::Button::with_label("OK");
|
|
||||||
// vertical.add(&button_ok);
|
|
||||||
//
|
|
||||||
// popup.show_all();
|
|
||||||
//
|
|
||||||
// button_ok.connect_clicked(move |_| unsafe {
|
|
||||||
// popup.destroy();
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn build_ui(application: >k::Application) {
|
let sink = Sink::new(&device);
|
||||||
// let window = gtk::ApplicationWindow::new(application);
|
sink.append(source);
|
||||||
//
|
sink.pause();
|
||||||
// window.set_title("lull");
|
|
||||||
// window.set_border_width(SPACING as u32);
|
let row = gtk::Box::new(Orientation::Horizontal, SPACING);
|
||||||
// window.set_position(gtk::WindowPosition::Center);
|
row.set_homogeneous(true);
|
||||||
// window.set_default_size(256, 256);
|
|
||||||
//
|
let label = gtk::Label::new(Some(name));
|
||||||
// let vertical = gtk::Box::new(Orientation::Vertical, SPACING);
|
row.add(&label);
|
||||||
// vertical.set_homogeneous(true);
|
|
||||||
//
|
let adjustment = gtk::Adjustment::new(
|
||||||
// window.add(&vertical);
|
0.0,
|
||||||
//
|
0.0,
|
||||||
// let device = rodio::default_output_device().unwrap();
|
1.0,
|
||||||
//
|
0.0,
|
||||||
// let paths = std::fs::read_dir(get_data_dir())
|
0.0,
|
||||||
// .expect("Couldn't read from lull data directory");
|
0.0
|
||||||
//
|
);
|
||||||
// for path in paths {
|
|
||||||
// let path = path.unwrap().path();
|
let slider = gtk::Scale::new(
|
||||||
// let name: &str = path.file_stem().unwrap().to_str().unwrap();
|
Orientation::Horizontal,
|
||||||
//
|
Some(&adjustment)
|
||||||
// let file = File::open(&path)
|
);
|
||||||
// .expect("Couldn't open audio file");
|
|
||||||
//
|
slider.set_draw_value(false);
|
||||||
// let source = rodio::Decoder::new(
|
|
||||||
// BufReader::new(file)
|
slider.connect_value_changed(move |scale| {
|
||||||
// );
|
let volume = scale.get_value();
|
||||||
//
|
|
||||||
// if source.is_err() {
|
if volume == 0. {
|
||||||
// error_popup(&format!(
|
sink.pause();
|
||||||
// "Couldn't parse file {}. \n{}.",
|
} else {
|
||||||
// path.to_str().unwrap(),
|
sink.play();
|
||||||
// source.err().unwrap()
|
sink.set_volume(volume as f32);
|
||||||
// ));
|
}
|
||||||
// continue;
|
});
|
||||||
// }
|
|
||||||
//
|
row.add(&slider);
|
||||||
// let source = source.unwrap().repeat_infinite();
|
|
||||||
//
|
vertical.add(&row);
|
||||||
// let sink = Sink::new(&device);
|
}
|
||||||
// sink.append(source);
|
|
||||||
// sink.pause();
|
let row_add = gtk::Box::new(Orientation::Horizontal, SPACING);
|
||||||
//
|
row_add.set_homogeneous(true);
|
||||||
// let row = gtk::Box::new(Orientation::Horizontal, SPACING);
|
|
||||||
// row.set_homogeneous(true);
|
let button_manage_sounds = gtk::Button::with_label("manage sounds");
|
||||||
//
|
|
||||||
// let label = gtk::Label::new(Some(name));
|
button_manage_sounds.connect_clicked(|_| {
|
||||||
// row.add(&label);
|
let mut file_manager = Command::new(file_manager());
|
||||||
//
|
file_manager.arg(get_data_dir());
|
||||||
// let adjustment = gtk::Adjustment::new(
|
file_manager.output().unwrap();
|
||||||
// 0.0,
|
});
|
||||||
// 0.0,
|
|
||||||
// 1.0,
|
row_add.add(&button_manage_sounds);
|
||||||
// 0.0,
|
vertical.add(&row_add);
|
||||||
// 0.0,
|
|
||||||
// 0.0
|
window.show_all();
|
||||||
// );
|
}
|
||||||
//
|
|
||||||
// let slider = gtk::Scale::new(
|
fn main() {
|
||||||
// Orientation::Horizontal,
|
let application = gtk::Application::new(
|
||||||
// Some(&adjustment)
|
Some("dev.tinybird.max.lull"),
|
||||||
// );
|
Default::default()
|
||||||
//
|
).expect("Initialization failed...");
|
||||||
// slider.set_draw_value(false);
|
|
||||||
//
|
application.connect_activate(|app| {
|
||||||
// slider.connect_value_changed(move |scale| {
|
build_ui(app);
|
||||||
// let volume = scale.get_value();
|
});
|
||||||
//
|
|
||||||
// if volume == 0. {
|
application.run(&args().collect::<Vec<_>>());
|
||||||
// sink.pause();
|
}
|
||||||
// } else {
|
|
||||||
// sink.play();
|
|
||||||
// sink.set_volume(volume as f32);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// row.add(&slider);
|
|
||||||
//
|
|
||||||
// vertical.add(&row);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// let row_add = gtk::Box::new(Orientation::Horizontal, SPACING);
|
|
||||||
// row_add.set_homogeneous(true);
|
|
||||||
//
|
|
||||||
// let button_manage_sounds = gtk::Button::with_label("manage sounds");
|
|
||||||
//
|
|
||||||
// button_manage_sounds.connect_clicked(|_| {
|
|
||||||
// let mut file_manager = Command::new("xdg-open");
|
|
||||||
// file_manager.arg(get_data_dir());
|
|
||||||
// file_manager.output().unwrap();
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// row_add.add(&button_manage_sounds);
|
|
||||||
// vertical.add(&row_add);
|
|
||||||
//
|
|
||||||
// window.show_all();
|
|
||||||
// }
|
|
||||||
|
|||||||
Reference in New Issue
Block a user