diff options
| author | skal <pascal.massimino@gmail.com> | 2026-01-28 00:41:07 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-01-28 00:41:07 +0100 |
| commit | a7bcf5e9cd6884d010b5cec0146293a0515242fc (patch) | |
| tree | bcc07dd93e19c7b429363c8cac1e9866762f6e6e /src/main.cc | |
| parent | 9dcf94ab01269311b4e5d39be23c95560904c626 (diff) | |
feat: Implement fullscreen, keyboard controls, and pulsating heptagon
This commit fulfills tasks 1 and 2, and adds a synchronized visual effect.
- **Fullscreen Mode**: Added '--fullscreen' command-line argument and dynamic toggling via 'F' key.
- **Keyboard Controls**: Implemented 'Esc' to exit and 'F' to toggle fullscreen in 'src/platform.cc'.
- **Synchronized Visuals**: Added a pulsating heptagon effect in 'src/gpu/gpu.cc' and 'src/gpu/shader.wgsl' that scales and changes color based on the real-time audio peak from the synth.
- **Refactor**: Abstracted platform-specific WebGPU surface creation into 'src/platform.cc' to keep 'src/gpu/gpu.cc' cross-platform.
- **Build System**: Corrected 'CMakeLists.txt' to properly link 'wgpu-native' and platform frameworks, and updated 'project_init.sh' to build the submodule.
- **Documentation**: Updated 'HOWTO.md' and 'PROJECT_CONTEXT.md' with new features and decisions.
Diffstat (limited to 'src/main.cc')
| -rw-r--r-- | src/main.cc | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/main.cc b/src/main.cc index 56d755c..315fa10 100644 --- a/src/main.cc +++ b/src/main.cc @@ -26,15 +26,23 @@ void generate_tone(float *buffer, float freq) { } } -int main() { - platform_init(); +int main(int argc, char **argv) { + bool fullscreen_enabled = false; + for (int i = 1; i < argc; ++i) { + if (strcmp(argv[i], "--fullscreen") == 0) { + fullscreen_enabled = true; + break; + } + } + + platform_init_window(fullscreen_enabled); gpu_init(platform_get_window()); audio_init(); generate_tone(g_spec_buffer_a, 440.0f); // A4 - generate_tone(g_spec_buffer_b, 880.0f); // A5 + generate_tone(g_spec_buffer_b, 0.0f); // A5 - Spectrogram spec = {g_spec_buffer_a, g_spec_buffer_b, SPEC_FRAMES}; + const Spectrogram spec = {g_spec_buffer_a, g_spec_buffer_b, SPEC_FRAMES}; int tone_id = synth_register_spectrogram(&spec); double last_beat_time = 0.0; @@ -45,21 +53,22 @@ int main() { double current_time = platform_get_time(); if (current_time - last_beat_time > SECONDS_PER_BEAT) { - synth_trigger_voice(tone_id, 0.5f, 0.0f); + const float pan = (beat_count & 1) ? -.8 : .8; + synth_trigger_voice(tone_id, 0.8f, pan); last_beat_time = current_time; beat_count++; - if (beat_count == 8) { + if (beat_count % 4 == 0) { // Time to update the sound! float *back_buffer = synth_begin_update(tone_id); if (back_buffer) { - generate_tone(back_buffer, 220.0f); // A3 + generate_tone(back_buffer, (beat_count % 8) == 4 ? 220.0f : 480.f); // A3 synth_commit_update(tone_id); } - } + } } - gpu_draw(); + gpu_draw(synth_get_output_peak()); audio_update(); } |
