9 Commits

Author SHA1 Message Date
d46e1f48e2 +x 2020-10-27 08:08:11 +00:00
4f821fccd5 change styling 2020-10-27 08:08:03 +00:00
4f58c1eece update sounds todo 2020-10-20 22:23:25 +01:00
e3087bfa63 add repository field 2020-10-20 22:18:55 +01:00
3255fe5d47 version bump 2020-10-20 21:54:08 +01:00
ae81570c07 alphabetical order 2020-10-20 21:36:55 +01:00
6e203c3fbd added sound 2020-10-20 21:33:15 +01:00
0afc497f78 better error popup 2020-10-04 12:28:28 +01:00
b281f8af00 target-specific file manager 2020-10-03 13:17:20 +01:00
5 changed files with 142 additions and 169 deletions

View File

@@ -1,14 +1,16 @@
[package] [package]
name = "lull" name = "lull"
description = "a looping sound player for generating aural atmospheres" description = "a looping sound player for generating atmospheric soundscapes"
version = "1.0.0" version = "1.0.1"
authors = ["Max Bradbury <max@tinybird.info>"] authors = ["Max Bradbury <max@tinybird.info>"]
repository = "https://tinybird.dev/max/lull"
license = "MIT" license = "MIT"
edition = "2018" edition = "2018"
crate_type = "bin" 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"

View File

@@ -16,12 +16,10 @@ released under the MIT license.
* watch data dir for new sounds? * watch data dir for new sounds?
* disown file manager subcommand * disown file manager subcommand
* get some good nature sounds * get some good nature sounds
* rain on tin roof
* wind * wind
* tape hiss * tape hiss
* vinyl crackle * vinyl crackle
* white noise? * white noise?
* fan * fan
* birdsong
* set a window icon * set a window icon
* create a nice icon? * create a nice icon?

View File

@@ -17,3 +17,5 @@ you can skip/remove any unwanted sounds, and add your own.
*campfire* by [sagetyrtle](https://freesound.org/people/sagetyrtle/) *campfire* by [sagetyrtle](https://freesound.org/people/sagetyrtle/)
*rain on glass* by [Benboncan](https://freesound.org/people/Benboncan/) *rain on glass* by [Benboncan](https://freesound.org/people/Benboncan/)
*birdsong* by [reinsamba](https://freesound.org/people/reinsamba/)

0
deploy.sh Normal file → Executable file
View File

View File

@@ -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,121 @@ fn get_data_dir() -> PathBuf {
data_dir data_dir
} }
pub fn main() -> iced::Result { fn build_ui(application: &gtk::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, 128);
let button_manage_sounds = gtk::Button::with_label("manage sounds");
button_manage_sounds.connect_clicked(|_| {
let mut file_manager = Command::new(file_manager());
file_manager.arg(get_data_dir());
file_manager.output().unwrap();
});
let sounds_manage = gtk::Box::new(Orientation::Vertical, SPACING);
let columns = gtk::Box::new(Orientation::Horizontal, SPACING);
let column_labels = gtk::Box::new(Orientation::Vertical, SPACING);
let column_sliders = gtk::Box::new(Orientation::Vertical, SPACING);
columns.set_homogeneous(false);
column_labels.set_homogeneous(true);
column_sliders.set_homogeneous(true);
column_labels.set_property_expand(false);
column_sliders.set_property_expand(true);
column_sliders.set_property_width_request(128);
window.add(&sounds_manage);
sounds_manage.add(&columns);
sounds_manage.add(&button_manage_sounds);
columns.add(&column_labels);
columns.add(&column_sliders);
let device = rodio::default_output_device().unwrap();
let mut paths = std::fs::read_dir(get_data_dir())
.expect("Couldn't read lull sounds directory")
.map(|res| res.map(|e| e.path()))
.collect::<Result<Vec<_>, std::io::Error>>()
.expect("Couldn't read files from lull sounds directory");
paths.sort();
for path in paths {
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: &gtk::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 label = gtk::Label::new(Some(name));
// window.set_position(gtk::WindowPosition::Center); label.set_halign(gtk::Align::End);
// window.set_default_size(256, 256); column_labels.add(&label);
//
// let vertical = gtk::Box::new(Orientation::Vertical, SPACING); let adjustment = gtk::Adjustment::new(
// vertical.set_homogeneous(true); 0.0,
// 0.0,
// window.add(&vertical); 1.0,
// 0.0,
// let device = rodio::default_output_device().unwrap(); 0.0,
// 0.0
// let paths = std::fs::read_dir(get_data_dir()) );
// .expect("Couldn't read from lull data directory");
// let slider = gtk::Scale::new(
// for path in paths { Orientation::Horizontal,
// let path = path.unwrap().path(); Some(&adjustment)
// let name: &str = path.file_stem().unwrap().to_str().unwrap(); );
//
// let file = File::open(&path) slider.set_draw_value(false);
// .expect("Couldn't open audio file");
// slider.connect_value_changed(move |scale| {
// let source = rodio::Decoder::new( let volume = scale.get_value();
// BufReader::new(file)
// ); if volume == 0. {
// sink.pause();
// if source.is_err() { } else {
// error_popup(&format!( sink.play();
// "Couldn't parse file {}. \n{}.", sink.set_volume(volume as f32);
// path.to_str().unwrap(), }
// source.err().unwrap() });
// ));
// continue; column_sliders.add(&slider);
// } }
//
// let source = source.unwrap().repeat_infinite(); window.show_all();
// }
// let sink = Sink::new(&device);
// sink.append(source); fn main() {
// sink.pause(); let application = gtk::Application::new(
// Some("dev.tinybird.max.lull"),
// let row = gtk::Box::new(Orientation::Horizontal, SPACING); Default::default()
// row.set_homogeneous(true); ).expect("Initialization failed...");
//
// let label = gtk::Label::new(Some(name)); application.connect_activate(|app| {
// row.add(&label); build_ui(app);
// });
// let adjustment = gtk::Adjustment::new(
// 0.0, application.run(&args().collect::<Vec<_>>());
// 0.0, }
// 1.0,
// 0.0,
// 0.0,
// 0.0
// );
//
// let slider = gtk::Scale::new(
// Orientation::Horizontal,
// Some(&adjustment)
// );
//
// slider.set_draw_value(false);
//
// slider.connect_value_changed(move |scale| {
// let volume = scale.get_value();
//
// if volume == 0. {
// 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();
// }