From 87f1b56eacbe26c65557b2c353eedbc4a26f6a9d Mon Sep 17 00:00:00 2001 From: Dukantic Date: Tue, 8 Jul 2025 22:37:28 +0200 Subject: [PATCH] add point + doc -> readme --- README.md | 17 +++++++++++++++++ src/main.rs | 7 ++++++- src/music.rs | 14 ++++++++++---- src/polygon_draw.rs | 4 ++-- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0f3f052..7716b9c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,21 @@ # Polymusic +## Instalation +>Install Rust and Cargo +>https://www.rust-lang.org/tools/install + +``` +cargo run +``` + +## Files + +The `saves` folder contains all the saves, these are files that are not made to be edited outside of this software. +The `assets` folder contains all the sounds you can play. You can add more. +### Compatible Files +- MP3 +- OGG Vorbis +- FLAC +- WAV diff --git a/src/main.rs b/src/main.rs index d8ab1bf..9b32a99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,6 +58,7 @@ enum Message { SetMusicLength, LengthChange(String), ChangeDelta(f32), + AddPoint, } struct MyApp { @@ -171,6 +172,9 @@ impl MyApp { self.update(Message::TogglePaused); } } + Message::AddPoint => { + self.music.add_Point(self.current_delta); + } } } @@ -312,7 +316,8 @@ impl MyApp { delta_to_string(self.current_delta), delta_to_string(self.music.length) )) - .size(20.0) + .size(20.0), + button("Add Point").on_press(Message::AddPoint) ] .spacing(20), column![ diff --git a/src/music.rs b/src/music.rs index 80b2c0a..97793de 100644 --- a/src/music.rs +++ b/src/music.rs @@ -52,10 +52,7 @@ impl Music { pub fn default() -> Music { Music { - poly_frame: vec![ - (0.0, PolygonFrame::default()), - (10.0, PolygonFrame::default()), - ], + poly_frame: vec![(0.0, PolygonFrame::default())], nb_sec_for_rev: 1.0, file_name: "Default Name".to_string(), length: 60.0, @@ -116,6 +113,15 @@ impl Music { //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ADD/REMOVE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + pub fn add_Point(&mut self, delta: f32) { + let pos = self + .poly_frame + .binary_search_by(|(d, _)| d.partial_cmp(&delta).unwrap()) + .unwrap_or_else(|e| e); + self.poly_frame + .insert(pos, (delta, self.current_frame(delta).clone())); + } + pub fn add_polygon(&mut self, delta: f32, polygon_name: String) { let current_frame = self.find_poly_frame(delta); let poly = string_to_polygon(polygon_name); diff --git a/src/polygon_draw.rs b/src/polygon_draw.rs index 83cd3c0..2932fed 100644 --- a/src/polygon_draw.rs +++ b/src/polygon_draw.rs @@ -23,7 +23,7 @@ impl RotationExt for Vector { ) } } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Clone)] pub struct PolygonFrame { pub teta: f32, pub polygons: Vec, @@ -118,7 +118,7 @@ impl canvas::Program for PolygonFrame { } } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct Polygon { pub global_teta: f32, pub points_teta: Vec,