Skip to content

Commit f35a011

Browse files
committed
refactor: consolidate constants and fix compilation issues
- Move constants from core/constants.rs to src/constants.rs - Fix glam::const_vec3! macro usage (replaced with Vec3::new) - Fix type mismatch in pointer.rs (Z_OFFSET.z vs Z_OFFSET) - Remove unused imports and dead code - Update tests and documentation accordingly
1 parent 2d176f2 commit f35a011

File tree

9 files changed

+18
-125
lines changed

9 files changed

+18
-125
lines changed

README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Geno-1 : Generative Music Visualizer (Rust + WebGPU + WebAudio)
1+
# Geno-1: Generative Music Visualizer (Rust + WebGPU + WebAudio)
22

33
[![CI](https://github.com/rgilks/geno-1/actions/workflows/ci.yml/badge.svg)](https://github.com/rgilks/geno-1/actions/workflows/ci.yml)
44

55
<div align="center">
6-
<img src="/docs/screenshot.png" alt="rgou Screenshot" width="626" />
6+
<img src="/docs/screenshot.png" alt="geno-1 Screenshot" width="626" />
77
<br />
88
<a href='https://ko-fi.com/N4N31DPNUS' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi2.png?v=6' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
99
<hr />
@@ -17,7 +17,7 @@
1717
- Mouse-driven FX: corner-based saturation (clean ↔ fizz) and opposite-corner delay emphasis; visuals have inertial swirl motion and click ripples
1818
- Note-driven visuals use attack/release smoothing for organic response (no abrupt jumps)
1919
- Start overlay to initialize audio (Click Start; canvas-click fallback)
20-
- Keyboard: A..F (root), 1..7 (mode), R (new sequence), T (random key+mode), Space (pause/resume), ArrowLeft/Right (tempo), ArrowUp/Down (volume), Enter (fullscreen)
20+
- Keyboard: A..G (root), 1..7 (mode), R (new sequence), T (random key+mode), Space (pause/resume), ArrowLeft/Right (tempo), ArrowUp/Down (volume), Enter (fullscreen)
2121
- Starts at a lower default volume; use ArrowUp to raise or ArrowDown to lower
2222
- Dynamic hint shows current BPM, paused, and muted state
2323
- Rich visuals: voice-reactive wave displacement, ambient waves background, post bloom/tonemap/vignette; optional analyser-driven spectrum dots
@@ -53,8 +53,10 @@ Additional scripts:
5353

5454
Quick controls (browser):
5555

56-
- A..F: root • 1..7: mode • R: new seq • T: random key+mode • Space: pause/resume • ArrowLeft/Right: tempo • ArrowUp/Down: volume • Enter: fullscreen
56+
- Click Start to initialize audio (canvas click also works)
5757
- Click canvas: play a note; mouse position affects sound
58+
- Keys: A..G (root), 1..7 (mode), R (new sequence), T (random key+mode), Space (pause/resume), ArrowLeft/Right (tempo), ArrowUp/Down (volume), Enter (fullscreen)
59+
- Mouse position maps to master saturation and delay; moving the pointer leaves a “water-like” trailing swirl in visuals
5860

5961
### Pre-commit Check
6062

@@ -97,13 +99,6 @@ This repo is configured to deploy via Cloudflare Workers; cache-control headers
9799

98100
- The build generates `pkg/env.js` with a `version` derived from the current git commit (short SHA, with CI env fallbacks). `index.html` appends `?v=<version>` to the dynamic import of `app_web.js` to ensure deterministic cache busting across deploys.
99101

100-
Controls in browser:
101-
102-
- Click Start to initialize audio (canvas click also works)
103-
- Click canvas: play a note; mouse position affects sound
104-
- Keys: A..F (root), 1..7 (mode), R (new sequence), T (random key+mode), Space (pause/resume), ArrowLeft/Right (tempo), ArrowUp/Down (volume), Enter (fullscreen)
105-
- Mouse position maps to master saturation and delay; moving the pointer leaves a “water-like” trailing swirl in visuals
106-
107102
Headless test:
108103

109104
- `npm run ci` builds, serves, and runs a Puppeteer test locally
@@ -117,8 +112,6 @@ Headless test:
117112
- Workflow file: `.github/workflows/ci.yml`
118113
- CI tolerates missing WebGPU in headless by skipping engine-coupled assertions
119114

120-
<!-- Desktop run instructions removed -->
121-
122115
### Live Demo
123116

124117
- Use the hosted app: [`https://geno-1.tre.systems/`](https://geno-1.tre.systems/)

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "geno-1",
33
"version": "1.0.0",
44
"description": "Web (WASM): uses `wasm-pack` to build and a static `index.html` to run",
5-
"main": "index.js",
65
"scripts": {
76
"build": "wasm-pack build --target web --out-dir pkg --out-name app_web --release && node scripts/gen-env.js && rm -rf dist && mkdir -p dist/pkg && cp pkg/app_web.js dist/pkg/ && cp pkg/app_web_bg.wasm dist/pkg/ && cp pkg/env.js dist/pkg/env.js && cp index.html dist/index.html && cp favicon.svg dist/favicon.svg",
87
"dev": "wrangler dev --local --persist-to .wrangler/state --live-reload",

src/constants.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
///
33
/// These constants express intended behavior (e.g., time constants, clamp
44
/// limits) and keep magic numbers out of the code, improving readability.
5+
use glam::Vec3;
6+
57
// Exponential decay rate for internal pulse energy
68
pub const PULSE_ENERGY_DECAY_PER_SEC: f32 = 1.6;
79

@@ -62,6 +64,12 @@ pub const LEVEL_SPAN: f32 = 0.45;
6264
// Z distance used by both picking and audio listener alignment.
6365
pub const CAMERA_Z: f32 = 6.0;
6466

67+
// Voice interaction
68+
pub const PICK_SPHERE_RADIUS: f32 = 0.5;
69+
pub const SPREAD: Vec3 = glam::Vec3::new(3.0, 3.0, 3.0);
70+
pub const Z_OFFSET: Vec3 = glam::Vec3::new(0.0, 0.0, -1.5);
71+
pub const ENGINE_DRAG_MAX_RADIUS: f32 = 1.0;
72+
6573
// Post-processing defaults
6674
pub const BLOOM_STRENGTH: f32 = 0.9;
6775
pub const BLOOM_THRESHOLD: f32 = 0.6;

src/core/constants.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/core/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
pub mod constants;
21
pub mod music;
32

4-
pub use constants::*;
53
pub use music::*;
64

75
// Shaders bundled as string constants

src/events/pointer.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::audio;
2-
use crate::constants::CAMERA_Z;
3-
use crate::core::{
4-
midi_to_hz, MusicEngine, ENGINE_DRAG_MAX_RADIUS, PICK_SPHERE_RADIUS, SPREAD, Z_OFFSET,
5-
};
2+
use crate::constants::{CAMERA_Z, ENGINE_DRAG_MAX_RADIUS, PICK_SPHERE_RADIUS, SPREAD, Z_OFFSET};
3+
use crate::core::{midi_to_hz, MusicEngine};
64
use crate::input;
75
use crate::render;
86
use std::cell::RefCell;
@@ -114,7 +112,7 @@ fn wire_pointerdown(w: &InputWiring) {
114112
let mut ds = w.drag_state.borrow_mut();
115113
ds.active = true;
116114
ds.voice = i;
117-
ds.plane_z_world = w.engine.borrow().voices[i].position.z * SPREAD + Z_OFFSET.z;
115+
ds.plane_z_world = w.engine.borrow().voices[i].position.z * SPREAD.z + Z_OFFSET.z;
118116
log::info!("[mouse] begin drag on voice {}", i);
119117
}
120118
w.mouse_state.borrow_mut().down = true;

src/lib.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use wasm_bindgen::prelude::*;
99
use wasm_bindgen::JsCast;
1010
use wasm_bindgen_futures::spawn_local;
1111
use web_sys as web;
12-
// (DeviceExt no longer needed; legacy vertex buffers removed)
1312

1413
mod audio;
1514
mod camera;
@@ -21,9 +20,7 @@ mod frame;
2120
mod input;
2221
mod overlay;
2322
mod render;
24-
// ui module removed; overlay is controlled directly from here
2523

26-
// Rendering/picking shared constants live in `constants.rs`
2724
fn wire_canvas_resize(canvas: &web::HtmlCanvasElement) {
2825
dom::sync_canvas_backing_size(canvas);
2926
let canvas_resize = canvas.clone();
@@ -119,16 +116,6 @@ fn wire_overlay_buttons(audio_ctx: &web::AudioContext, paused: &Rc<RefCell<bool>
119116
});
120117
}
121118
}
122-
// noisy helper remnants removed
123-
124-
// analyser creation moved to audio::create_analyser
125-
126-
// global keydown moved to events.rs
127-
128-
// Create a GainNode with an initial value; logs on failure and returns None
129-
// create_gain moved to audio.rs
130-
131-
// (use overlay::hide instead of local helper)
132119

133120
#[wasm_bindgen(start)]
134121
pub fn start() -> Result<(), JsValue> {
@@ -296,5 +283,3 @@ async fn init() -> anyhow::Result<()> {
296283

297284
Ok(())
298285
}
299-
300-
// (local GpuState definition removed; use `render::GpuState` exclusively)

tests/constants_tests.rs

Lines changed: 0 additions & 77 deletions
This file was deleted.

wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name = "geno-visualizer"
1+
name = "geno-1"
22
compatibility_date = "2024-08-06"
33
compatibility_flags = ["nodejs_compat"]
44
main = "worker.js"

0 commit comments

Comments
 (0)