Skip to content

Commit

Permalink
Rename piano-math to piano-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Sep 18, 2024
1 parent 7fd912c commit 7a1ae20
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 42 deletions.
8 changes: 3 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
"piano-math",
"piano-layout",
"wgpu-jumpstart",
"neothesia",
"neothesia-cli",
Expand Down Expand Up @@ -30,7 +30,7 @@ neothesia-iced-widgets = { path = "./neothesia-iced-widgets" }

midi-file = { path = "./midi-file" }
midi-io = { path = "./midi-io" }
piano-math = { path = "./piano-math" }
piano-layout = { path = "./piano-layout" }
nuon = { path = "./nuon" }

profiling = "1.0"
Expand Down
1 change: 0 additions & 1 deletion neothesia-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ build-ffmpeg = ["mpeg_encoder/build"]
[dependencies]
neothesia-core.workspace = true
midi-file.workspace = true
piano-math.workspace = true
wgpu-jumpstart.workspace = true
env_logger.workspace = true
futures.workspace = true
Expand Down
9 changes: 5 additions & 4 deletions neothesia-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{default::Default, time::Duration};

use neothesia_core::{
config::Config,
piano_layout,
render::{GuidelineRenderer, KeyboardRenderer, QuadPipeline, TextRenderer, WaterfallRenderer},
};
use wgpu_jumpstart::{wgpu, Gpu, TransformUniform, Uniform};
Expand All @@ -26,13 +27,13 @@ struct Recorder {
fn get_layout(
width: f32,
height: f32,
range: piano_math::KeyboardRange,
) -> piano_math::KeyboardLayout {
range: piano_layout::KeyboardRange,
) -> piano_layout::KeyboardLayout {
let white_count = range.white_count();
let neutral_width = width / white_count as f32;
let neutral_height = height * 0.2;

piano_math::KeyboardLayout::from_range(neutral_width, neutral_height, range)
piano_layout::KeyboardLayout::from_range(neutral_width, neutral_height, range)
}

fn time_without_lead_in(playback: &midi_file::PlaybackState) -> f32 {
Expand Down Expand Up @@ -82,7 +83,7 @@ impl Recorder {
let keyboard_layout = get_layout(
width as f32,
height as f32,
piano_math::KeyboardRange::new(config.piano_range()),
piano_layout::KeyboardRange::new(config.piano_range()),
);

let mut keyboard = KeyboardRenderer::new(keyboard_layout.clone());
Expand Down
2 changes: 1 addition & 1 deletion neothesia-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bytemuck.workspace = true
wgpu.workspace = true
glyphon.workspace = true
wgpu-jumpstart.workspace = true
piano-math.workspace = true
piano-layout.workspace = true
midi-file.workspace = true
profiling.workspace = true
euclid.workspace = true
Expand Down
1 change: 1 addition & 0 deletions neothesia-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(clippy::collapsible_match, clippy::single_match)]

pub use piano_layout;
pub use wgpu_jumpstart::{Color, Gpu, TransformUniform, Uniform};

pub mod config;
Expand Down
6 changes: 3 additions & 3 deletions neothesia-core/src/render/guidelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
pub struct GuidelineRenderer {
pos: Point<f32>,

layout: piano_math::KeyboardLayout,
layout: piano_layout::KeyboardLayout,
vertical_guidelines: bool,
horizontal_guidelines: bool,

Expand All @@ -18,7 +18,7 @@ pub struct GuidelineRenderer {

impl GuidelineRenderer {
pub fn new(
layout: piano_math::KeyboardLayout,
layout: piano_layout::KeyboardLayout,
pos: Point<f32>,
vertical_guidelines: bool,
horizontal_guidelines: bool,
Expand All @@ -39,7 +39,7 @@ impl GuidelineRenderer {
self.cache.clear();
}

pub fn set_layout(&mut self, layout: piano_math::KeyboardLayout) {
pub fn set_layout(&mut self, layout: piano_layout::KeyboardLayout) {
self.layout = layout;
self.cache.clear();
}
Expand Down
4 changes: 2 additions & 2 deletions neothesia-core/src/render/keyboard/key_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ pub fn border_radius(w: f32, is_sharp: bool) -> f32 {
radius * kind_multiplier
}

pub fn to_quad(key: &piano_math::Key, color: Color, origin: Point<f32>) -> QuadInstance {
pub fn to_quad(key: &piano_layout::Key, color: Color, origin: Point<f32>) -> QuadInstance {
let position = [origin.x + key.x(), origin.y];

let mut size: Size<f32> = key.size().into();

if let piano_math::KeyKind::Neutral = key.kind() {
if let piano_layout::KeyKind::Neutral = key.kind() {
size.width -= 1.0;
}

Expand Down
10 changes: 5 additions & 5 deletions neothesia-core/src/render/keyboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
utils::Point,
};

use piano_math::range::KeyboardRange;
use piano_layout::range::KeyboardRange;

mod key_state;
pub use key_state::KeyState;
Expand All @@ -15,14 +15,14 @@ pub struct KeyboardRenderer {

key_states: Vec<KeyState>,

layout: piano_math::KeyboardLayout,
layout: piano_layout::KeyboardLayout,

cache: Vec<QuadInstance>,
text_cache: Vec<super::text::TextArea>,
}

impl KeyboardRenderer {
pub fn new(layout: piano_math::KeyboardLayout) -> Self {
pub fn new(layout: piano_layout::KeyboardLayout) -> Self {
let key_states: Vec<KeyState> = layout
.range
.iter()
Expand Down Expand Up @@ -73,11 +73,11 @@ impl KeyboardRenderer {
self.invalidate_cache();
}

pub fn layout(&self) -> &piano_math::KeyboardLayout {
pub fn layout(&self) -> &piano_layout::KeyboardLayout {
&self.layout
}

pub fn set_layout(&mut self, layout: piano_math::KeyboardLayout) {
pub fn set_layout(&mut self, layout: piano_layout::KeyboardLayout) {
self.layout = layout;
self.invalidate_cache();
}
Expand Down
4 changes: 2 additions & 2 deletions neothesia-core/src/render/waterfall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl WaterfallRenderer {
hidden_tracks: &[usize],
config: &Config,
transform_uniform: &Uniform<TransformUniform>,
layout: piano_math::KeyboardLayout,
layout: piano_layout::KeyboardLayout,
) -> Self {
let mut notes: Vec<_> = tracks
.iter()
Expand Down Expand Up @@ -52,7 +52,7 @@ impl WaterfallRenderer {
device: &wgpu::Device,
queue: &wgpu::Queue,
config: &Config,
layout: piano_math::KeyboardLayout,
layout: piano_layout::KeyboardLayout,
) {
let range_start = layout.range.start() as usize;

Expand Down
2 changes: 1 addition & 1 deletion neothesia-iced-widgets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ iced_core.workspace = true
iced_wgpu.workspace = true
iced_widget.workspace = true

piano-math = { workspace = true }
piano-layout = { workspace = true }
4 changes: 2 additions & 2 deletions neothesia-iced-widgets/src/piano_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ impl<M, R: iced_core::Renderer> Widget<M, Theme, R> for PianoRange {
) {
let bounds = layout.bounds();
renderer.with_translation(Vector::new(bounds.x, bounds.y), |renderer| {
let range = piano_math::KeyboardRange::new(self.0.clone());
let range = piano_layout::KeyboardRange::new(self.0.clone());

let white_count = range.white_count();
let neutral_width = bounds.width / white_count as f32;
let neutral_height = bounds.height;

let layout =
piano_math::KeyboardLayout::from_range(neutral_width, neutral_height, range);
piano_layout::KeyboardLayout::from_range(neutral_width, neutral_height, range);

let mut neutral = layout
.keys
Expand Down
1 change: 0 additions & 1 deletion neothesia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ wgpu.workspace = true
wgpu-jumpstart.workspace = true
neothesia-core.workspace = true
neothesia-iced-widgets.workspace = true
piano-math.workspace = true
midi-file.workspace = true
midi-io.workspace = true
nuon.workspace = true
Expand Down
15 changes: 8 additions & 7 deletions neothesia/src/scene/playing_scene/keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use midi_file::midly::MidiMessage;
use neothesia_core::{
piano_layout,
render::{QuadPipeline, TextRenderer},
utils::Point,
};
use piano_math::KeyboardRange;
use piano_layout::KeyboardRange;

use crate::{config::Config, context::Context, render::KeyboardRenderer, song::SongConfig};

Expand All @@ -15,21 +16,21 @@ pub struct Keyboard {
fn get_layout(
width: f32,
height: f32,
range: piano_math::KeyboardRange,
) -> piano_math::KeyboardLayout {
range: piano_layout::KeyboardRange,
) -> piano_layout::KeyboardLayout {
let white_count = range.white_count();
let neutral_width = width / white_count as f32;
let neutral_height = height * 0.2;

piano_math::KeyboardLayout::from_range(neutral_width, neutral_height, range)
piano_layout::KeyboardLayout::from_range(neutral_width, neutral_height, range)
}

impl Keyboard {
pub fn new(ctx: &Context, song_config: SongConfig) -> Self {
let layout = get_layout(
ctx.window_state.logical_size.width,
ctx.window_state.logical_size.height,
piano_math::KeyboardRange::new(ctx.config.piano_range()),
piano_layout::KeyboardRange::new(ctx.config.piano_range()),
);

let mut renderer = KeyboardRenderer::new(layout);
Expand All @@ -41,11 +42,11 @@ impl Keyboard {
}
}

pub fn layout(&self) -> &piano_math::KeyboardLayout {
pub fn layout(&self) -> &piano_layout::KeyboardLayout {
self.renderer.layout()
}

fn set_layout(&mut self, layout: piano_math::KeyboardLayout) {
fn set_layout(&mut self, layout: piano_layout::KeyboardLayout) {
self.renderer.set_layout(layout)
}

Expand Down
7 changes: 4 additions & 3 deletions neothesia/src/scene/playing_scene/midi_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
output_manager::OutputConnection,
song::{PlayerConfig, Song},
};
use neothesia_core::piano_layout;
use std::{
collections::{HashMap, HashSet},
time::{Duration, Instant},
Expand All @@ -20,7 +21,7 @@ impl MidiPlayer {
pub fn new(
output: OutputConnection,
song: Song,
user_keyboard_range: piano_math::KeyboardRange,
user_keyboard_range: piano_layout::KeyboardRange,
) -> Self {
let mut player = Self {
playback: midi_file::PlaybackState::new(
Expand Down Expand Up @@ -245,7 +246,7 @@ struct NotePress {

#[derive(Debug)]
pub struct PlayAlong {
user_keyboard_range: piano_math::KeyboardRange,
user_keyboard_range: piano_layout::KeyboardRange,

/// Notes required to proggres further in the song
required_notes: HashMap<NoteId, NotePress>,
Expand All @@ -259,7 +260,7 @@ pub struct PlayAlong {
}

impl PlayAlong {
fn new(user_keyboard_range: piano_math::KeyboardRange) -> Self {
fn new(user_keyboard_range: piano_layout::KeyboardRange) -> Self {
Self {
user_keyboard_range,
required_notes: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion piano-math/Cargo.toml → piano-layout/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[package]
name = "piano-math"
name = "piano-layout"
version = "0.1.0"
edition = "2021"
1 change: 1 addition & 0 deletions piano-layout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Piano layout calculations crate
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions piano-math/.gitignore

This file was deleted.

Empty file removed piano-math/README.md
Empty file.

0 comments on commit 7a1ae20

Please sign in to comment.