From 15a92927e7671a090199fb60f192de2298c22663 Mon Sep 17 00:00:00 2001 From: skal Date: Mon, 2 Feb 2026 23:44:14 +0100 Subject: update the melody a bit --- src/main.cc | 77 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) (limited to 'src/main.cc') diff --git a/src/main.cc b/src/main.cc index 55bb4a0..97732da 100644 --- a/src/main.cc +++ b/src/main.cc @@ -107,10 +107,9 @@ int main(int argc, char** argv) { synth_init(); tracker_init(); - // Register drum assets (if still needed, can be moved to tracker samples) - // int kick_id = register_spec_asset(AssetId::ASSET_KICK_1); - // int snare_id = register_spec_asset(AssetId::ASSET_SNARE_1); - // int hihat_id = register_spec_asset(AssetId::ASSET_HIHAT_1); + int kick_id = register_spec_asset(AssetId::ASSET_KICK_1); + int snare_id = register_spec_asset(AssetId::ASSET_SNARE_1); + int hihat_id = register_spec_asset(AssetId::ASSET_HIHAT_1); // Still keep the dynamic tone for bass (can be integrated into tracker too) const float* g_spec_buffer_a = generate_tone(nullptr, 110.0f); // A2 @@ -122,43 +121,43 @@ int main(int argc, char** argv) { // int melody_id = generate_melody(); // synth_trigger_voice(melody_id, 0.6f, 0.0f); - // double last_beat_time = 0.0; - // int beat_count = 0; + double last_beat_time = 0.0; + int beat_count = 0; auto update_game_logic = [&](double t) { - // if (t - last_beat_time > SECONDS_PER_BEAT / 2.0) { // 8th notes - // last_beat_time = t; // Sync to t - - // const int step = beat_count % 16; - - // // Kick on 1, 9, 11, 14... - // if (step == 0 || step == 8 || step == 10 || step == 13) { - // synth_trigger_voice(kick_id, 1.0f, 0.0f); - // } - - // // Snare on 4, 12 - // if (step == 4 || step == 12) { - // synth_trigger_voice(snare_id, 0.8f, step & 8 ? -1.0f : 1.0f); - // } - - // // Hihat on every offbeat - // if (step % 2 == 1) { - // synth_trigger_voice(hihat_id, 0.5f, 0.3f); - // } - - // // Bass pattern - // if (step % 4 == 0) { - // float* back_buffer = synth_begin_update(bass_id); - // if (back_buffer) { - // float bass_freq = (step < 8) ? 110.0f : 164.82f; // A3 then E3 - // generate_tone(back_buffer, bass_freq); - // synth_commit_update(bass_id); - // } - // synth_trigger_voice(bass_id, 0.9f, 1.2f); - // } - - // ++beat_count; - // } + if (t - last_beat_time > (60.0f / g_tracker_score.bpm) / 2.0) { // 8th notes + last_beat_time = t; // Sync to t + + const int step = beat_count % 16; + + // Kick on 1, 9, 11, 14... + if (step == 0 || step == 8 || step == 10 || step == 13) { + synth_trigger_voice(kick_id, 0.6f, 0.0f); + } + + // Snare on 4, 12 + if (step == 4 || step == 12) { + synth_trigger_voice(snare_id, 0.48f, step & 8 ? -1.0f : 1.0f); + } + + // Hihat on every offbeat + if (step % 2 == 1) { + synth_trigger_voice(hihat_id, 0.3f, 0.3f); + } + + // Bass pattern + if (step % 4 == 0) { + float* back_buffer = synth_begin_update(bass_id); + if (back_buffer) { + float bass_freq = (step < 8) ? 110.0f : 164.82f; // A3 then E3 + generate_tone(back_buffer, bass_freq); + synth_commit_update(bass_id); + } + synth_trigger_voice(bass_id, 0.9f, 1.2f); + } + + ++beat_count; + } tracker_update((float)t); }; -- cgit v1.2.3