Skip to content

Commit

Permalink
first schema of DoMiK
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderARodin committed Jan 9, 2024
1 parent 5935f50 commit ae19c8b
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/base_domik_view.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const VERS: &str = "v0.0.3";
const VERS: &str = "v0.1.0";


//use crate::raadbg::log;

//use crate::synth_wrapper::SynthWrapper;
//use crate::midi_lib::MidiMessage;

use crate::domik_ui_elements::*;



Expand All @@ -28,6 +29,9 @@ impl BaseDomikView {
pub fn updateUI(&mut self, ui: &mut egui::Ui) {
ui.label( format!("DoMiK {}", VERS) );
ui.separator();
for lvl in -7..=5 {
ui.add(dom_lvl( -lvl ));
}
}
}

152 changes: 152 additions & 0 deletions src/domik_ui_elements/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@







// // // // // // // //
// Basic test element
// // // // // // // //
pub fn dom_lvl(lvl: i8) -> impl egui::Widget + 'static {
move |ui: &mut egui::Ui| dom_lvl_responder(ui, lvl)
}

fn dom_lvl_responder( ui: &mut egui::Ui, lvl: i8 ) -> egui::Response {
let clr = lvl2color(lvl);
let de_oct_lvl = de_oct_lvl( lvl );

let desired_size = ui.spacing().interact_size.y * 2. * egui::vec2(2.5, 1.);
let (rect, mut response) = ui.allocate_exact_size(desired_size, egui::Sense::click());
if response.clicked() {
// do something
response.mark_changed();
}
//response.widget_info(|| egui::WidgetInfo::selected(typ, selected, label));
if ui.is_rect_visible(rect) {
let visuals = ui.style().interact_selectable(&response, true );
let rect = rect.expand(visuals.expansion);
let radius = 0.1 * rect.height();
let points: Vec<egui::Pos2> = match de_oct_lvl {
-3 | -1 | 2 | 4 | 6 => {
vec![
egui::Pos2::new( rect.left(), rect.bottom() ),
egui::Pos2::new( rect.right(), rect.bottom() ),
egui::Pos2::new( rect.left()+0.5*rect.width(), rect.top() )
]
},
-4 | -2 | 1 | 3 | 5 => {
vec![
egui::Pos2::new( rect.right(), rect.top() ),
egui::Pos2::new( rect.left(), rect.top() ),
egui::Pos2::new( rect.left()+0.5*rect.width(), rect.bottom() )
]
},
_ => {
vec![
egui::Pos2::new( rect.left(), rect.bottom() ),
egui::Pos2::new( rect.right(), rect.bottom() ),
egui::Pos2::new( rect.right(), rect.top() ),
egui::Pos2::new( rect.left(), rect.top() )
]
},
};

let poly = egui::Shape::convex_polygon(points, clr, visuals.bg_stroke );
ui.painter().add( poly );
}
response
}


// // // // // // // //
// UTILs
// // // // // // // //
fn de_oct_lvl( lvl: i8 ) -> i8 {
let clear_lvl = lvl % 12;
if clear_lvl < -5 {
return clear_lvl + 12
}
if clear_lvl > 7 {
return clear_lvl - 12
}
clear_lvl
}
fn lvl2color( lvl: i8 ) -> egui::Color32 {
let de_oct = de_oct_lvl( lvl );
match de_oct {
7 |
-5 => egui::Color32::from_rgb( 173,255, 47 ),
6 => egui::Color32::from_rgb( 255, 36, 0 ),
5 => egui::Color32::from_rgb( 46,232,187 ),
4 => egui::Color32::from_rgb( 255,165, 0 ),
3 => egui::Color32::from_rgb( 0, 0,255 ),
2 => egui::Color32::from_rgb( 253,233, 16 ),
1 => egui::Color32::from_rgb( 127, 0,127 ),
0 => egui::Color32::from_rgb( 86,127, 24 ),
-1 => egui::Color32::from_rgb( 204, 0, 0 ),
-2 => egui::Color32::from_rgb( 128,166,255 ),
-3 => egui::Color32::from_rgb( 217,204, 0 ),
-4 => egui::Color32::from_rgb( 127, 0,255 ),
_ => {
egui::Color32::from_rgb( 222,222,222 )
}
}
}




// // // // // // // //
// TESTS
// // // // // // // //

#[cfg(test)]
mod domik_utils{
use super::*;

#[test]
fn should_not_change() {
for lvl in -5..=7 {
//println!("test:lvl:{} -> {}", lvl, de_oct_lvl(lvl) );
let de_oct = de_oct_lvl(lvl);
assert!( lvl == de_oct, "should not be changed" );
}
}
#[test]
fn should_change_oct_up() {
for lvl in -5..=6 {
let shifted = lvl - 12;
let de_oct = de_oct_lvl(shifted);
//println!("test:lvl:{} -> {}", shifted, de_oct );
assert!( lvl == de_oct, "should be an octave rised" );
}
}
#[test]
fn should_change_oct_down() {
for lvl in -4..=7 {
let shifted = lvl + 12;
let de_oct = de_oct_lvl(shifted);
//println!("test:lvl:{} -> {}", shifted, de_oct );
assert!( lvl == de_oct, "should be an octave skiped" );
}
}
#[test]
fn should_change_2oct_up() {
for lvl in -5..=6 {
let shifted = lvl - 24;
let de_oct = de_oct_lvl(shifted);
//println!("test:lvl:{} -> {}", shifted, de_oct );
assert!( lvl == de_oct, "should be a two octave rised" );
}
}
#[test]
fn should_change_2oct_down() {
for lvl in -4..=7 {
let shifted = lvl + 24;
let de_oct = de_oct_lvl(shifted);
//println!("test:lvl:{} -> {}", shifted, de_oct );
assert!( lvl == de_oct, "should be a two octave skiped" );
}
}
}
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ mod root_app;

mod player_to_audio;

//mod midi_lib;
//mod midi_sequencer;
//mod synths;
use root_app::RootApp;

mod domik_ui_elements;
mod base_domik_view;
mod test_view;

Expand Down

0 comments on commit ae19c8b

Please sign in to comment.