From a7bcf5e9cd6884d010b5cec0146293a0515242fc Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 28 Jan 2026 00:41:07 +0100 Subject: 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. --- src/main.cc | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/main.cc') 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(); } -- cgit v1.2.3