Skip to content

Commit

Permalink
Color Shema Config
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Feb 1, 2021
1 parent d168645 commit e770196
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
24 changes: 24 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Default)]
pub struct ColorShema {
pub base: (u8, u8, u8),
pub dark: (u8, u8, u8),
}

#[derive(Serialize, Deserialize)]
pub struct Config {
#[serde(default = "default_speed_multiplier")]
Expand All @@ -9,7 +15,11 @@ pub struct Config {
pub playback_offset: f32,

#[serde(default = "default_play_along")]
#[serde(skip_serializing)]
pub play_along: bool,

#[serde(default = "default_color_shema")]
pub color_shema: Vec<ColorShema>,
}

impl Config {
Expand All @@ -31,6 +41,7 @@ impl Config {
speed_multiplier: default_speed_multiplier(),
playback_offset: default_playback_offset(),
play_along: default_play_along(),
color_shema: default_color_shema(),
})
}
}
Expand All @@ -55,3 +66,16 @@ fn default_playback_offset() -> f32 {
fn default_play_along() -> bool {
false
}

fn default_color_shema() -> Vec<ColorShema> {
vec![
ColorShema {
base: (93, 188, 255),
dark: (48, 124, 255),
},
ColorShema {
base: (210, 89, 222),
dark: (125, 69, 134),
},
]
}
20 changes: 6 additions & 14 deletions src/scene/playing_scene/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,21 @@ impl PianoKeyboard {
}
}

let colors: [[Color; 2]; 2] = [
[
Color::from_rgba8(93, 188, 255, 1.0),
Color::from_rgba8(48, 124, 255, 1.0),
],
[
Color::from_rgba8(210, 89, 222, 1.0),
Color::from_rgba8(125, 69, 134, 1.0),
],
];
let color_shema = &target.state.config.color_shema;

let white_keys = white_keys.into_iter().map(|note| {
let color = colors[note.1 % 2];
let color = &color_shema[note.1 % color_shema.len()];
if note.0 {
color[0]
color.base.into()
} else {
Color::new(1.0, 1.0, 1.0, 1.0)
}
});

let black_keys = black_keys.into_iter().map(|note| {
let color = colors[note.1 % 2];
let color = &color_shema[note.1 % color_shema.len()];
if note.0 {
color[1]
color.dark.into()
} else {
Color::new(0.1, 0.1, 0.1, 1.0)
}
Expand Down
26 changes: 4 additions & 22 deletions src/scene/playing_scene/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,11 @@ impl Notes {
let key = &keys[note.note as usize - 21];
let ar = window_w / window_h;

// let colors: [[[f32; 3]; 2]; 2] = [
// [
// [146.0 / 255.0, 255.0 / 255.0, 48.0 / 255.0],
// [87.0 / 255.0, 183.0 / 255.0, 12.0 / 255.0],
// ],
// [
// [118.0 / 255.0, 166.0 / 255.0, 211.0 / 255.0],
// [54.0 / 255.0, 109.0 / 255.0, 173.0 / 255.0],
// ],
// ];
let colors: [[Color; 2]; 2] = [
[
Color::from_rgba8(93, 188, 255, 1.0),
Color::from_rgba8(48, 124, 255, 1.0),
],
[
Color::from_rgba8(210, 89, 222, 1.0),
Color::from_rgba8(125, 69, 134, 1.0),
],
];
let color_shema = &target.state.config.color_shema;

let color = colors[note.track_id % 2];
let color = if key.is_black { color[1] } else { color[0] };
let color = &color_shema[note.track_id % color_shema.len()];
let color = if key.is_black { color.dark } else { color.base };
let color: Color = color.into();

let h = if note.duration >= 0.1 {
note.duration
Expand Down
6 changes: 6 additions & 0 deletions src/wgpu_jumpstart/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ impl Color {
]
}
}

impl From<(u8, u8, u8)> for Color {
fn from(f: (u8, u8, u8)) -> Self {
Self::from_rgba8(f.0, f.1, f.2, 1.0)
}
}

0 comments on commit e770196

Please sign in to comment.