|
1 | 1 | #![cfg(target_arch = "wasm32")] |
2 | 2 | use app_core::{ |
3 | | - z_offset_vec3, EngineParams, MusicEngine, VoiceConfig, Waveform, BASE_SCALE, |
| 3 | + midi_to_hz, z_offset_vec3, EngineParams, MusicEngine, VoiceConfig, Waveform, BASE_SCALE, |
4 | 4 | C_MAJOR_PENTATONIC, DEFAULT_VOICE_COLORS, DEFAULT_VOICE_POSITIONS, ENGINE_DRAG_MAX_RADIUS, |
5 | | - PICK_SPHERE_RADIUS, SCALE_PULSE_MULTIPLIER, SPREAD, midi_to_hz, |
| 5 | + PICK_SPHERE_RADIUS, SCALE_PULSE_MULTIPLIER, SPREAD, |
6 | 6 | }; |
7 | 7 | use glam::{Mat4, Vec2, Vec3, Vec4}; |
8 | 8 | use instant::Instant; |
@@ -912,28 +912,49 @@ async fn init() -> anyhow::Result<()> { |
912 | 912 | for (i, v) in eng.voices.iter().enumerate() { |
913 | 913 | let vx = (v.position.x / 3.0).clamp(-1.0, 1.0) * 0.5 + 0.5; |
914 | 914 | let dx = (uvx - vx).abs(); |
915 | | - if dx < best_dx { best_dx = dx; best_i = i; } |
| 915 | + if dx < best_dx { |
| 916 | + best_dx = dx; |
| 917 | + best_i = i; |
| 918 | + } |
916 | 919 | } |
917 | 920 | drop(eng); |
918 | 921 | if let Ok(src) = web::OscillatorNode::new(&audio_ctx_click) { |
919 | 922 | match engine_m.borrow().configs[best_i].waveform { |
920 | | - Waveform::Sine => src.set_type(web::OscillatorType::Sine), |
921 | | - Waveform::Square => src.set_type(web::OscillatorType::Square), |
922 | | - Waveform::Saw => src.set_type(web::OscillatorType::Sawtooth), |
923 | | - Waveform::Triangle => src.set_type(web::OscillatorType::Triangle), |
| 923 | + Waveform::Sine => { |
| 924 | + src.set_type(web::OscillatorType::Sine) |
| 925 | + } |
| 926 | + Waveform::Square => { |
| 927 | + src.set_type(web::OscillatorType::Square) |
| 928 | + } |
| 929 | + Waveform::Saw => { |
| 930 | + src.set_type(web::OscillatorType::Sawtooth) |
| 931 | + } |
| 932 | + Waveform::Triangle => { |
| 933 | + src.set_type(web::OscillatorType::Triangle) |
| 934 | + } |
924 | 935 | } |
925 | 936 | src.frequency().set_value(freq); |
926 | 937 | if let Ok(g) = web::GainNode::new(&audio_ctx_click) { |
927 | 938 | g.gain().set_value(0.0); |
928 | 939 | let now = audio_ctx_click.current_time(); |
929 | 940 | let t0 = now + 0.005; |
930 | 941 | let dur = 0.35 + 0.25 * (1.0 - uvy as f64); |
931 | | - let _ = g.gain().linear_ramp_to_value_at_time(vel, t0 + 0.02); |
932 | | - let _ = g.gain().linear_ramp_to_value_at_time(0.0, t0 + dur); |
| 942 | + let _ = g |
| 943 | + .gain() |
| 944 | + .linear_ramp_to_value_at_time(vel, t0 + 0.02); |
| 945 | + let _ = g |
| 946 | + .gain() |
| 947 | + .linear_ramp_to_value_at_time(0.0, t0 + dur); |
933 | 948 | let _ = src.connect_with_audio_node(&g); |
934 | | - let _ = g.connect_with_audio_node(&voice_gains_click[best_i]); |
935 | | - let _ = g.connect_with_audio_node(&delay_sends_click[best_i]); |
936 | | - let _ = g.connect_with_audio_node(&reverb_sends_click[best_i]); |
| 949 | + let _ = g.connect_with_audio_node( |
| 950 | + &voice_gains_click[best_i], |
| 951 | + ); |
| 952 | + let _ = g.connect_with_audio_node( |
| 953 | + &delay_sends_click[best_i], |
| 954 | + ); |
| 955 | + let _ = g.connect_with_audio_node( |
| 956 | + &reverb_sends_click[best_i], |
| 957 | + ); |
937 | 958 | let _ = src.start_with_when(t0); |
938 | 959 | let _ = src.stop_with_when(t0 + dur + 0.05); |
939 | 960 | } |
|
0 commit comments