Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: Neothesia web #42

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"neothesia-cli",
"neothesia-core",
"neothesia-pipelines",
"neothesia-web",
"midi-file",
"midi-io",
]
Expand Down
2 changes: 1 addition & 1 deletion midi-file/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ authors = ["Poly <[email protected]>"]
edition = "2021"

[dependencies]
midly = "0.5"
midly = { version = "0.5", default-features = false, features = ["std"] }
6 changes: 5 additions & 1 deletion midi-file/src/midi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ impl Midi {
Err(_) => return Err(String::from("Could Not Open File")),
};

let smf = match Smf::parse(&data) {
Self::new_from_bytes(&data)
}

pub fn new_from_bytes(data: &[u8]) -> Result<Self, String> {
let smf = match Smf::parse(data) {
Ok(smf) => smf,
Err(_) => return Err(String::from("Midi Parsing Error (midly lib)")),
};
Expand Down
6 changes: 6 additions & 0 deletions neothesia-core/src/utils/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ pub fn default_sf2() -> Option<PathBuf> {

#[cfg(target_os = "macos")]
return bundled_resource_path("default", "sf2").map(PathBuf::from);

#[cfg(target_family = "wasm")]
return None;
}

pub fn settings_ron() -> Option<PathBuf> {
Expand All @@ -59,6 +62,9 @@ pub fn settings_ron() -> Option<PathBuf> {

#[cfg(target_os = "macos")]
return bundled_resource_path("settings", "ron").map(PathBuf::from);

#[cfg(target_family = "wasm")]
return None;
}

#[cfg(target_os = "macos")]
Expand Down
14 changes: 11 additions & 3 deletions neothesia-pipelines/src/waterfall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'a> WaterfallPipeline {
let shader = gpu
.device
.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("RectanglePipeline::shader"),
label: Some("waterfall::shader"),
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!(
"./shader.wgsl"
))),
Expand All @@ -41,7 +41,7 @@ impl<'a> WaterfallPipeline {
let render_pipeline_layout =
&gpu.device
.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None,
label: Some("waterfall::pipeline"),
bind_group_layouts: &[
&transform_uniform.bind_group_layout,
&time_uniform.bind_group_layout,
Expand Down Expand Up @@ -106,10 +106,18 @@ impl<'a> WaterfallPipeline {
#[derive(Clone, Copy, Pod, Zeroable)]
struct TimeUniform {
time: f32,
_pad1: f32,
_pad2: f32,
_pad3: f32,
}

impl Default for TimeUniform {
fn default() -> Self {
Self { time: 0.0 }
Self {
time: 0.0,
_pad1: 0.0,
_pad2: 0.0,
_pad3: 0.0,
}
}
}
3 changes: 3 additions & 0 deletions neothesia-pipelines/src/waterfall/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ struct ViewUniform {

struct TimeUniform {
time: f32,
_pad1: f32,
_pad2: f32,
_pad3: f32,
}

@group(0) @binding(0)
Expand Down
1 change: 1 addition & 0 deletions neothesia-web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
25 changes: 25 additions & 0 deletions neothesia-web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "neothesia-web"
version = "0.1.0"
edition = "2021"

[dependencies]
neothesia-core = { workspace = true }
wgpu = { workspace = true, features = ["webgl"] }
wgpu-jumpstart = { workspace = true }

winit = { version = "0.28.2" }
env_logger = { workspace = true }
pollster = "0.3.0"
console_log = "1.0.0"
web-sys = "0.3.61"
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4.34"
console_error_panic_hook = "0.1.7"

midi-file = { workspace = true }
piano-math = { workspace = true }
log = { workspace = true }
instant = "0.1.12"

getrandom = { version = "0.2", features = ["js"] }
4 changes: 4 additions & 0 deletions neothesia-web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Run
```
trunk serve --open
```
35 changes: 35 additions & 0 deletions neothesia-web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Trunk | Vanilla | web-sys</title>

<base data-trunk-public-url />

<style>
html {
background-color: black;
height: 100%;

margin: 0;
padding: 0;
}

body {
margin: 0;
padding: 0;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>

<body>
<link data-trunk rel="rust" href="Cargo.toml" data-wasm-opt="z" data-bin="neothesia-web" />
</body>

</html>
Loading