diff --git a/src/samples/ghhb_game.h b/src/samples/ghhb_game.h index 7fca2b0..030970a 100644 --- a/src/samples/ghhb_game.h +++ b/src/samples/ghhb_game.h @@ -16,7 +16,9 @@ namespace { constexpr int LANE_COUNT = 12; constexpr int OCTAVE_COUNT = 3; -constexpr int OCTAVE_OFFSET = 48; +constexpr int MIDI_LANE_MIN = 48; +constexpr int MIDI_LANE_MAX = 83; +constexpr int MIDI_LANE_COUNT = MIDI_LANE_MAX - MIDI_LANE_MIN + 1; constexpr int MAX_GAMEPADS = 4; constexpr int MAX_INSTRUMENT_TYPES = MAX_GAMEPADS; constexpr float RECEPTOR_HEIGHT = 150.0f; @@ -26,7 +28,7 @@ constexpr float SCROLL_PX_PER_SEC = 350.0f; constexpr float LEAD_OFFSET_SECONDS = 3.0f; constexpr float GLYPH_HEIGHT_FRACTION_OF_LANE = 0.5f; constexpr float MIN_SUSTAIN_FALLBACK_SEC = 0.05f; -constexpr float MIN_GLYPH_DURATION_SEC = 0.05f; +constexpr float MIN_GLYPH_DURATION_SEC = 0.1f; const int GAMEPAD_BUTTONS[LANE_COUNT] = { GAMEPAD_BUTTON_LEFT_FACE_LEFT, // Left @@ -87,7 +89,8 @@ const float INSTRUMENT_VOLUME[MAX_INSTRUMENT_TYPES] = { 0.6f }; -const char* const INSTRUMENT_LANE_WAV[MAX_INSTRUMENT_TYPES][LANE_COUNT * OCTAVE_COUNT] { +/* Index i = MIDI note (48 + i); notes outside [48, 83] are not rendered. */ +const char* const INSTRUMENT_LANE_WAV[MAX_INSTRUMENT_TYPES][MIDI_LANE_COUNT] { { // Instrument 0 - Synth "assets/sounds/snes_synth/snes_synth_048.wav", "assets/sounds/snes_synth/snes_synth_049.wav", "assets/sounds/snes_synth/snes_synth_050.wav", "assets/sounds/snes_synth/snes_synth_051.wav", @@ -242,7 +245,7 @@ std::vector chart_from_song(const Song& song, int track_override) std::vector> timed_notes; for (const Note& note : track.notes) { - if (note.midi >= 0 && note.midi <= 127) + if (note.midi >= MIDI_LANE_MIN && note.midi <= MIDI_LANE_MAX) timed_notes.push_back({note.ticks, ¬e}); } std::sort(timed_notes.begin(), timed_notes.end(), @@ -258,11 +261,9 @@ std::vector chart_from_song(const Song& song, int track_override) const Note& note = *pair.second; float time_sec = note.ticks / ticks_per_sec; // This is now the BOTTOM time float duration_sec = note.duration_ticks / ticks_per_sec; - int lane = note.midi % LANE_COUNT; - int offset = 0; - if (note.midi >= OCTAVE_OFFSET) - offset = OCTAVE_OFFSET; - int octave = (note.midi - offset) % (LANE_COUNT * OCTAVE_COUNT); + int wav_index = note.midi - MIDI_LANE_MIN; + int lane = wav_index % LANE_COUNT; + int octave = wav_index; int instrument_slot = note_index % MAX_INSTRUMENT_TYPES; // Log original glyph timing (time is bottom, time + duration is top) @@ -356,8 +357,8 @@ public: float lane_width = 0.0f; float screen_width = 0.0f; float screen_height = 0.0f; - Sound note_sounds[MAX_INSTRUMENT_TYPES][LANE_COUNT * OCTAVE_COUNT] = {{0}}; - bool note_sounds_loaded[MAX_INSTRUMENT_TYPES][LANE_COUNT * OCTAVE_COUNT] = {{false}}; + Sound note_sounds[MAX_INSTRUMENT_TYPES][MIDI_LANE_COUNT] = {{0}}; + bool note_sounds_loaded[MAX_INSTRUMENT_TYPES][MIDI_LANE_COUNT] = {{false}}; std::deque note_sounds_playing[LANE_COUNT][MAX_INSTRUMENT_TYPES]; static constexpr float PRESS_FLASH_DURATION = 0.12f; float press_flash_timer[LANE_COUNT] = {0}; @@ -424,7 +425,7 @@ public: } for (int slot = 0; slot < MAX_INSTRUMENT_TYPES; slot++) { - for (int lane = 0; lane < LANE_COUNT * OCTAVE_COUNT; lane++) + for (int lane = 0; lane < MIDI_LANE_COUNT; lane++) { if (note_sounds_loaded[slot][lane]) { @@ -445,7 +446,7 @@ public: update_layout(); for (int slot = 0; slot < MAX_INSTRUMENT_TYPES; slot++) { - for (int lane = 0; lane < LANE_COUNT * OCTAVE_COUNT; lane++) + for (int lane = 0; lane < MIDI_LANE_COUNT; lane++) { const char* path = INSTRUMENT_LANE_WAV[slot][lane]; if (FileExists(path)) diff --git a/src/samples/instrument_select.h b/src/samples/instrument_select.h index b270ce2..dd0a341 100644 --- a/src/samples/instrument_select.h +++ b/src/samples/instrument_select.h @@ -32,9 +32,9 @@ public: static constexpr const char* INSTRUMENT_IMAGE_PATHS[MAX_INSTRUMENT_TYPES] = { "assets/instruments/guitar.png", - "assets/instruments/piano.png", - "assets/instruments/violin.png", "assets/instruments/sax.png", + "assets/instruments/violin.png", + "assets/instruments/piano.png", }; std::array instrument_owner = {-1, -1, -1, -1}; diff --git a/src/samples/title_screen.h b/src/samples/title_screen.h index e69dd8e..8c9a9f0 100644 --- a/src/samples/title_screen.h +++ b/src/samples/title_screen.h @@ -15,11 +15,14 @@ public: void update(float delta_time) override { - // Trigger scene change on Enter key or gamepad start button. - if (IsKeyPressed(KEY_ENTER) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_MIDDLE_RIGHT)) + bool start = IsKeyPressed(KEY_ENTER); + for (int gp = 0; gp < 4; gp++) { - game->go_to_scene("song_select"); + if (IsGamepadAvailable(gp) && IsGamepadButtonPressed(gp, GAMEPAD_BUTTON_MIDDLE_RIGHT)) + start = true; } + if (start) + game->go_to_scene("song_select"); } void draw() override