tinyrand -> rand
This commit is contained in:
Generated
+1
-7
@@ -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"
|
||||
|
||||
+1
-1
@@ -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"
|
||||
rand = "0.9.2"
|
||||
|
||||
+8
-11
@@ -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<Mutex<StdRand>>
|
||||
pub color: Color32
|
||||
}
|
||||
|
||||
impl Grid {
|
||||
pub fn new(id: Id, rand: Arc<Mutex<StdRand>>) -> 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<R: Rand, T: DerefMut<Target=R>>(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::<color::Srgb>([angle, 100.0, 50.0]);
|
||||
Color32::from_rgb(
|
||||
(rgb[0] * 255.0) as u8,
|
||||
@@ -131,7 +128,7 @@ impl Showable<f32> for Grid {
|
||||
};
|
||||
|
||||
if ui.button("Color").clicked() {
|
||||
self.color = Self::random_color(self.rand.lock().unwrap());
|
||||
self.color = Self::random_color();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+1
-1
@@ -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| {
|
||||
|
||||
+2
-5
@@ -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<Mutex<StdRand>>) -> 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
|
||||
}
|
||||
|
||||
+1
-9
@@ -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<String>,
|
||||
|
||||
/// A random number generator
|
||||
pub rand: Arc<Mutex<StdRand>>,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user