/* Copyright (c) 2023 Bad Diode Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. */ // TODO: A list of features I would like to get to implement in the near future. // // High priority: // + Higher resolution clock to allow for microtiming and more accurate tempo. // + Look back again at the emulator issues... (I give up) // + Sync via MIDI with the Analogue cables. // + Fix bank switching behaviour (bug) // + Add more sync options // + When switching sync, play status acts wonky (bug) // + Channel params should show if there are some already on all triggers and // modify only the selected parameter, not all of them. // + Channel params (ALL) editing should only copy the value under the cursor. // - Fix scale being active for noise channel (makes no sense) // - Should scale mode be toggleable? // - Save scale on the bank // - Hold L/R retriggers at short intervals? // - Allow using B + dpad to nudge trigs. This will potentially mean switching // to key release to enable trigs. // - Fix any bugs we currently have // - Add an envelope to ch3, would need to work with a timer in order to make // it work I think (Can reuse the 96bpq sequencer timer for this). // - Add clipboard sharing between banks. // - Make sure transposing a sequence past the keyboard limit doesn't affect // the sequence and can be reversed. // - Study saving overhauls for bootleg cartridges. // // Low priority: // // UI tweaks. // - Add custom user themes // - Animations for cursor movement/current step highlight. (A fade out maybe?) // // Quality of life improvements. // - When not on play mode, adjusting a note or a parameter triggers the sound. // This could get annoying, so maybe it should be a configuration option to // enable it? // - Undo/Redo. // // Advanced // - Add tap tempo for BPM. // - Allow "marking" several trigs to be able to copy/paste them and/or adjust // their parameters. // - Per trig LFO? How would we go about this? There is at least one empty slot // in all channels. LFO amount? LFO speed? Would need a dedicated page for // configuring LFOs #include "gba/gba.h" #include "renderer_m0.c" #include "globals.c" #include "assets.c" #include "patterns.c" #include "settings.c" #include "dsound.c" #include "scale.c" #include "sequencer.c" #define PROF_ENABLE 0 #include "profiling.c" void render_sequencer(void) { if (redraw_trigs) { PROF(draw_triggers(), draw_trigs_cycles); redraw_trigs = false; } if (redraw_channels) { PROF(draw_channels(), draw_btn_cycles); redraw_channels = false; } if (redraw_pattern_buttons) { PROF(draw_pattern_buttons(), draw_btn_cycles); redraw_pattern_buttons = false; } if (redraw_bank_buttons) { PROF(draw_bank_buttons(), draw_btn_cycles); redraw_bank_buttons = false; } if (redraw_bpm) { PROF(draw_bpm(), draw_btn_cycles); redraw_bpm = false; } if (redraw_play_pause) { PROF(draw_play(), draw_btn_cycles); PROF(draw_stop(), draw_btn_cycles); PROF(draw_settings(), draw_btn_cycles); redraw_play_pause = false; } if (redraw_scale) { PROF(draw_scale(), draw_btn_cycles); redraw_scale = false; } if (redraw_params) { PROF(draw_parameters(), draw_param_cycles); redraw_params = false; } if (input_handler == handle_pattern_selection || input_handler == handle_pattern_chain) { draw_pattern_chain(); } draw_notif_bar(); PROF(draw_piano_notes(), draw_piano_cycles); PROF(draw_cursors(), draw_cursor_cycles); } void render_settings(void) { size_t x0 = 8; size_t x1 = x0 + 64; size_t y0 = 6; // Header. txt_drawf("SETTINGS", x0, y0, COL_FG) draw_wrench(SCREEN_WIDTH - 32, y0, COL_FG); y0 = 16; draw_filled_rect(x0, y0 - 1, SCREEN_WIDTH - 9, y0, COL_FG); y0 = 20; // Globals. txt_drawf("GLOBAL", x0, y0, COL_FG); draw_line(x0, y0 + 9, SCREEN_WIDTH - 9, y0 + 9, COL_FG); y0 += 17; draw_rect(x0, y0, x1, y0 + 10, COL_FG); txt_drawf("MUTE", x0 + 2, y0 + 1, COL_FG); txt_drawf("%s", x1 + 8, y0 + 1, COL_FG, toggle_settings_str[settings.global_mute]); y0 += 17; draw_rect(x0, y0, x1, y0 + 10, COL_FG); txt_drawf("BPM", x0 + 2, y0 + 1, COL_FG); txt_drawf("%s", x1 + 8, y0 + 1, COL_FG, toggle_settings_str[settings.global_bpm]); y0 += 17; txt_drawf("GENERAL", x0, y0, COL_FG); draw_line(x0, y0 + 9, SCREEN_WIDTH - 9, y0 + 9, COL_FG); y0 += 17; draw_rect(x0, y0, x1, y0 + 10, COL_FG); txt_drawf("AUTO-SAVE", x0 + 2, y0 + 1, COL_FG); txt_drawf("%s", x1 + 8, y0 + 1, COL_FG, toggle_settings_str[settings.auto_save]); y0 += 17; draw_rect(x0, y0, x1, y0 + 10, COL_FG); txt_drawf("SYNC", x0 + 2, y0 + 1, COL_FG); txt_drawf("%s", x1 + 8, y0 + 1, COL_FG, sync_setting_str[settings.sync]); y0 += 17; draw_rect(x0, y0, x1, y0 + 10, COL_FG); txt_drawf("THEME", x0 + 2, y0 + 1, COL_FG); txt_drawf("%s", x1 + 8, y0 + 1, COL_FG, theme_setting_str[settings.theme]); y0 += 17; draw_rect(x0, y0, x1, y0 + 10, COL_FG); txt_drawf("HELP", x0 + 2, y0 + 1, COL_FG); txt_drawf("%s", x1 + 8, y0 + 1, COL_FG, toggle_settings_str[settings.help]); PROF(draw_settings_cursor(), draw_cursor_cycles); } void render(void) { if (clear_screen) { PROF(screen_fill(COL_BG), clear_cycles); clear_screen = false; } switch (scene) { case SCENE_SETTINGS: { render_settings(); } break; case SCENE_SEQUENCER: { render_sequencer(); } break; } // DEBUG: Ensuring the saved data don't exceed SRAM size (32k). // txt_drawf("SIZE: %lu", 0, 0, COL_ACC_1, sizeof(Metadata) + sizeof(patterns) * 6 + sizeof(chain) * 6); } void handle_input(void) { switch (scene) { case SCENE_SETTINGS: { handle_settings_input(); } break; case SCENE_SEQUENCER: { handle_sequencer_input(); } break; } } void update(void) { if (next_scene != scene) { scene = next_scene; clear_screen = true; redraw_trigs = true; redraw_channels = true; redraw_pattern_buttons = true; redraw_bank_buttons = true; redraw_bpm = true; redraw_play_pause = true; redraw_params = true; redraw_scale = true; } last_trig_loc = trig_selection_loc; last_channel_loc = channel_selection_loc; last_pattern_loc = pattern_selection_loc; last_right_col_loc = right_col_selection_loc; if (update_bpm) { if (settings.global_bpm) { set_time(settings.bpm); } else { set_time(patterns[current_pattern].bpm); } update_bpm = false; } if (audio_sync_click) { play_click(); } if (notif.time > 0) { notif.time--; } rng_state++; } int main(void) { // Adjust system wait times. SYSTEM_WAIT = SYSTEM_WAIT_CARTRIDGE; // Initialize renderer. renderer_init(); // Register interrupts. irq_init(); irs_set(IRQ_VBLANK, sound_vsync); // Initialize sequencer. sequencer_init(); txt_spacing(6); // Main loop. while (true) { poll_keys(); bios_vblank_wait(); PROF_SHOW(); FRAME_START(); PROF(flip_buffer(), flip_cycles); PROF(update(), update_cycles); PROF(handle_input(), input_cycles); PROF(render(), render_cycles); FRAME_END(); } return 0; }