diff --git a/Cargo.lock b/Cargo.lock index ebc1317..2434d86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3193,10 +3193,10 @@ version = "0.1.0" dependencies = [ "color", "eframe", + "rand", "rfd", "rodio", "serde", - "tinyrand", "tokio", "toml", ] @@ -3289,12 +3289,6 @@ dependencies = [ "strict-num", ] -[[package]] -name = "tinyrand" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ffaad2263779579369d45f65cad0647c860893d27e4543cdcc1e428d07da2c" - [[package]] name = "tinystr" version = "0.8.1" diff --git a/Cargo.toml b/Cargo.toml index 4e7a366..2421e3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,4 @@ toml = "0.9.7" serde = { version = "1.0.227", features = ["derive"] } rfd = "0.15.4" color = "0.3.2" -tinyrand = "0.5.0" \ No newline at end of file +rand = "0.9.2" diff --git a/src/grid.rs b/src/grid.rs index fe814cc..f5ccc71 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -1,9 +1,8 @@ use color::ColorSpace; -use std::ops::{DerefMut, RangeInclusive}; -use std::sync::{Arc, Mutex}; +use std::ops::RangeInclusive; use eframe::egui; use eframe::egui::{Color32, Context, Id, PointerButton, Pos2, Rangef, Sense, Ui, Vec2}; -use tinyrand::{Rand, StdRand}; +use rand::Rng; use crate::gui::Showable; use crate::scale::Scale; use crate::tenori::LOOP_LENGTH; @@ -19,13 +18,12 @@ pub struct Grid { pub open: bool, pub timbre: Timbre, pub timbre_open: bool, - pub color: Color32, - pub rand: Arc> + pub color: Color32 } impl Grid { - pub fn new(id: Id, rand: Arc>) -> Self { - let color = Self::random_color(rand.lock().unwrap()); + pub fn new(id: Id) -> Self { + let color = Self::random_color(); Self { volume: 1.0, @@ -35,14 +33,13 @@ impl Grid { name: "New Track".to_string(), timbre: Timbre::default(), timbre_open: false, - rand, color, id } } - fn random_color>(mut rand: T) -> Color32 { - let angle = (rand.next_lim_u32(72) * 5) as f32; + fn random_color() -> Color32 { + let angle = (rand::rng().random_range(0..72) * 5) as f32; let rgb = color::Hsl::convert::([angle, 100.0, 50.0]); Color32::from_rgb( (rgb[0] * 255.0) as u8, @@ -131,7 +128,7 @@ impl Showable for Grid { }; if ui.button("Color").clicked() { - self.color = Self::random_color(self.rand.lock().unwrap()); + self.color = Self::random_color(); } }); diff --git a/src/gui.rs b/src/gui.rs index 29e91ff..9da684b 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -35,7 +35,7 @@ impl Tenori { if ui.button("Add track").clicked() { let id = self.window_id(); - self.grids.push(Grid::new(id, self.rand.clone())); + self.grids.push(Grid::new(id)); } ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { diff --git a/src/saveload.rs b/src/saveload.rs index b69d9e7..bc08cb1 100644 --- a/src/saveload.rs +++ b/src/saveload.rs @@ -1,7 +1,5 @@ -use std::sync::{Arc, Mutex}; use eframe::egui::{Color32, Id}; use serde::{Deserialize, Serialize}; -use tinyrand::StdRand; use crate::grid::Grid; use crate::scale::Scale; use crate::tenori::Tenori; @@ -24,7 +22,7 @@ impl From<&Tenori> for PersistedTenori { impl PersistedTenori { pub fn apply_to(self, tenori: &mut Tenori) { - tenori.grids = self.grids.into_iter().map(|g| g.into_grid(tenori.window_id(), tenori.rand.clone())).collect(); + tenori.grids = self.grids.into_iter().map(|g| g.into_grid(tenori.window_id())).collect(); tenori.tempo = self.tempo; tenori.playing = false; // Start paused tenori.timer = 0.0; // Start at the beginning of the loop @@ -56,7 +54,7 @@ impl From<&Grid> for PersistedGrid { } impl PersistedGrid { - pub fn into_grid(self, id: Id, rand: Arc>) -> Grid { + pub fn into_grid(self, id: Id) -> Grid { let notes: Vec<_> = self.notes.chars().map(|c| c == '1').collect(); Grid { volume: self.volume, @@ -66,7 +64,6 @@ impl PersistedGrid { open: true, timbre_open: false, color: Color32::from_rgb(self.color.0, self.color.1, self.color.2), - rand, notes, id } diff --git a/src/tenori.rs b/src/tenori.rs index f3a5398..f74a3e0 100644 --- a/src/tenori.rs +++ b/src/tenori.rs @@ -1,7 +1,5 @@ -use std::sync::{Arc, Mutex}; -use std::time::{Instant, SystemTime, UNIX_EPOCH}; +use std::time::Instant; use rodio::OutputStream; -use tinyrand::{Seeded, StdRand}; use crate::grid::Grid; use crate::dialog::Dialog; use crate::noise::Note; @@ -36,9 +34,6 @@ pub struct Tenori { /// If present, we can save to this file without asking the /// user to select a file first. pub default_filename: Option, - - /// A random number generator - pub rand: Arc>, } impl Default for Tenori { @@ -46,8 +41,6 @@ impl Default for Tenori { let output_stream = rodio::OutputStreamBuilder::open_default_stream() .expect("Open audio output stream"); - let rand = StdRand::seed(SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()); - Self { tempo: 90, timer: 0.0, @@ -57,7 +50,6 @@ impl Default for Tenori { window_counter: 0, dialogs: vec![], default_filename: None, - rand: Arc::new(Mutex::new(rand)), output_stream } }