Skip to content

Commit

Permalink
Introduce neothesia-core create
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Jun 4, 2023
1 parent a9eab20 commit 25f809a
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 136 deletions.
20 changes: 18 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"wgpu-jumpstart",
"neothesia",
"neothesia-cli",
"neothesia-core",
"neothesia-pipelines",
"midi-file",
"midi-io",
Expand All @@ -19,5 +20,6 @@ env_logger = "0.10"
futures = "0.3"
wgpu-jumpstart = { path = "./wgpu-jumpstart" }
neothesia = { path = "./neothesia", default-features = false }
neothesia-core = { path = "./neothesia-core" }
midi-file = { path = "./midi-file" }
piano-math = { path = "./piano-math" }
3 changes: 2 additions & 1 deletion neothesia-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ edition = "2021"
build-ffmpeg = ["mpeg_encoder/build"]

[dependencies]
neothesia = { workspace = true }
neothesia-core = { workspace = true }

midi-file = { workspace = true }
piano-math = { workspace = true }
wgpu-jumpstart = { workspace = true }
Expand Down
9 changes: 4 additions & 5 deletions neothesia-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::{default::Default, time::Duration};

use neothesia::{
use neothesia_core::{
config::Config,
render::{KeyboardRenderer, TextRenderer, WaterfallRenderer},
Gpu, TransformUniform, Uniform,
};
use wgpu_jumpstart::wgpu;
use wgpu_jumpstart::{wgpu, Gpu, TransformUniform, Uniform};

struct Recorder {
gpu: Gpu,
Expand Down Expand Up @@ -46,7 +45,7 @@ impl Recorder {
backends: wgpu_jumpstart::default_backends(),
..Default::default()
});
let gpu = neothesia::block_on(Gpu::new(&instance, None)).unwrap();
let gpu = futures::executor::block_on(Gpu::new(&instance, None)).unwrap();

let args: Vec<String> = std::env::args().collect();

Expand Down Expand Up @@ -237,7 +236,7 @@ fn main() {

{
let slice = output_buffer.slice(..);
neothesia::block_on(async {
futures::executor::block_on(async {
let (tx, rx) = futures::channel::oneshot::channel();

slice.map_async(wgpu::MapMode::Read, move |_| {
Expand Down
20 changes: 20 additions & 0 deletions neothesia-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "neothesia-core"
version = "0.1.0"
edition = "2021"

[dependencies]
log = { workspace = true }
ron = "0.8"
serde = { version = "1.0", features = ["serde_derive"] }

wgpu = { workspace = true }
wgpu_glyph = "0.20.0"
wgpu-jumpstart = { workspace = true }

neothesia-pipelines = { path = "../neothesia-pipelines" }
piano-math = { workspace = true }
midi-file = { workspace = true }

[target.'cfg(target_os = "macos")'.dependencies]
objc = "0.2"
1 change: 1 addition & 0 deletions neothesia-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This crate contains basic functionality needed to render the keyboard and notes waterfall, used both by cli renderer and app renderer.
12 changes: 2 additions & 10 deletions neothesia/src/config.rs → neothesia-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ use std::path::PathBuf;

use serde::{Deserialize, Serialize};

#[cfg(feature = "app")]
use crate::output_manager::OutputDescriptor;

#[derive(Serialize, Deserialize, Default)]
pub struct ColorSchema {
pub base: (u8, u8, u8),
Expand Down Expand Up @@ -72,13 +69,8 @@ impl Config {
})
}

#[cfg(feature = "app")]
pub fn set_output(&mut self, v: &OutputDescriptor) {
if let OutputDescriptor::DummyOutput = v {
self.output = None;
} else {
self.output = Some(v.to_string());
}
pub fn set_output(&mut self, output: Option<String>) {
self.output = output;
}

pub fn set_input<D: std::fmt::Display>(&mut self, v: Option<D>) {
Expand Down
7 changes: 7 additions & 0 deletions neothesia-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![allow(clippy::collapsible_match, clippy::single_match)]

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

pub mod config;
pub mod render;
pub mod utils;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
73 changes: 73 additions & 0 deletions neothesia-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
pub mod resources;

#[derive(Debug, Default, Clone, Copy)]
pub struct Point<T> {
pub x: T,
pub y: T,
}

impl<T> From<(T, T)> for Point<T> {
fn from((x, y): (T, T)) -> Self {
Self { x, y }
}
}

impl<T> From<Point<T>> for [T; 2] {
fn from(p: Point<T>) -> Self {
[p.x, p.y]
}
}

impl<T: Copy> From<&Point<T>> for [T; 2] {
fn from(p: &Point<T>) -> Self {
(*p).into()
}
}

impl<T> std::ops::Add for Point<T>
where
T: std::ops::Add<Output = T>,
{
type Output = Self;

fn add(self, rhs: Self) -> Self::Output {
Self {
x: self.x + rhs.x,
y: self.y + rhs.y,
}
}
}

impl<T> std::ops::AddAssign for Point<T>
where
T: std::ops::AddAssign,
{
fn add_assign(&mut self, rhs: Self) {
self.x += rhs.x;
self.y += rhs.y;
}
}

#[derive(Debug, Default, Clone, Copy)]
pub struct Size<T> {
pub w: T,
pub h: T,
}

impl<T> From<(T, T)> for Size<T> {
fn from((w, h): (T, T)) -> Self {
Self { w, h }
}
}

impl<T> From<Size<T>> for [T; 2] {
fn from(p: Size<T>) -> Self {
[p.w, p.h]
}
}

impl<T: Copy> From<&Size<T>> for [T; 2] {
fn from(p: &Size<T>) -> Self {
(*p).into()
}
}
File renamed without changes.
45 changes: 13 additions & 32 deletions neothesia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,7 @@ edition = "2021"
default-run = "neothesia"

[features]
default = ["app"]

app = [
"rfd",
"oxi-synth",
"iced_core",
"iced_runtime",
"iced_wgpu",
"iced_graphics",
"iced_style",
"iced_widget",
"midi-io",
"async-thread",
"winit",
]
default = ["oxi-synth"]

synth = []
fluid-synth = ["synth", "cpal", "fluidlite"]
Expand All @@ -40,38 +26,33 @@ wgpu = { workspace = true }
wgpu_glyph = "0.20.0"
wgpu-jumpstart = { workspace = true }

neothesia-core = { workspace = true }
neothesia-pipelines = { path = "../neothesia-pipelines" }
piano-math = { workspace = true }

# App Deps

winit = { version = "0.28.2", optional = true }
rfd = { version = "0.11.2", optional = true }
cpal = { version = "0.15.0", optional = true }
async-thread = { version = "0.1", optional = true }
winit = "0.28.2"
rfd = "0.11.2"
async-thread = "0.1"

cpal = { version = "0.15.0", optional = true }
fluidlite = { version = "0.2", features = ["builtin"], optional = true }
oxisynth = { version = "0.0.3", optional = true }

midi-file = { workspace = true }
midi-io = { path = "../midi-io", optional = true }
midi-io = { path = "../midi-io" }

iced_core = { git = "https://github.com/iced-rs/iced.git", rev = "b5f102c55835cf42427f9f8672634e81a5d724f6", optional = true }
iced_runtime = { git = "https://github.com/iced-rs/iced.git", rev = "b5f102c55835cf42427f9f8672634e81a5d724f6", optional = true }
iced_style = { git = "https://github.com/iced-rs/iced.git", rev = "b5f102c55835cf42427f9f8672634e81a5d724f6" }
iced_graphics = { git = "https://github.com/iced-rs/iced.git", rev = "b5f102c55835cf42427f9f8672634e81a5d724f6" }
iced_core = { git = "https://github.com/iced-rs/iced.git", rev = "b5f102c55835cf42427f9f8672634e81a5d724f6" }
iced_runtime = { git = "https://github.com/iced-rs/iced.git", rev = "b5f102c55835cf42427f9f8672634e81a5d724f6" }
iced_wgpu = { git = "https://github.com/iced-rs/iced.git", rev = "b5f102c55835cf42427f9f8672634e81a5d724f6", features = [
"image",
], optional = true }
iced_graphics = { git = "https://github.com/iced-rs/iced.git", rev = "b5f102c55835cf42427f9f8672634e81a5d724f6", optional = true }
iced_style = { git = "https://github.com/iced-rs/iced.git", rev = "b5f102c55835cf42427f9f8672634e81a5d724f6", optional = true }
iced_widget = { git = "https://github.com/iced-rs/iced.git", rev = "b5f102c55835cf42427f9f8672634e81a5d724f6", optional = true, features = [
] }
iced_widget = { git = "https://github.com/iced-rs/iced.git", rev = "b5f102c55835cf42427f9f8672634e81a5d724f6", features = [
"image",
] }

# Recorder Deps

[target.'cfg(target_os = "macos")'.dependencies]
objc = "0.2"

[[bin]]
name = "neothesia"
required-features = ["app"]
10 changes: 1 addition & 9 deletions neothesia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@
use futures::Future;
pub use wgpu_jumpstart::{Gpu, TransformUniform, Uniform};

pub mod config;
pub mod render;
use neothesia_core::{config, render};
pub mod utils;

#[cfg(feature = "app")]
pub mod iced_utils;
#[cfg(feature = "app")]
pub mod input_manager;
#[cfg(feature = "app")]
pub mod midi_event;
#[cfg(feature = "app")]
pub mod output_manager;
#[cfg(feature = "app")]
pub mod scene;
#[cfg(feature = "app")]
pub mod target;

#[cfg(feature = "app")]
#[derive(Debug)]
pub enum NeothesiaEvent {
MainMenu(crate::scene::menu_scene::Event),
Expand Down
2 changes: 0 additions & 2 deletions neothesia/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(feature = "app")]

use neothesia::{
midi_event::MidiEvent,
scene::{menu_scene, playing_scene, scene_manager, SceneType},
Expand Down
8 changes: 7 additions & 1 deletion neothesia/src/scene/menu_scene/iced_menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ impl Program for AppUi {
self.data.is_loading = false;
}
Message::SelectOutput(output) => {
target.config.set_output(&output);
target
.config
.set_output(if let OutputDescriptor::DummyOutput = output {
None
} else {
Some(output.to_string())
});
self.data.selected_output = Some(output);
}
Message::SelectInput(input) => {
Expand Down
Loading

0 comments on commit 25f809a

Please sign in to comment.