Merge branch 'master' of mx.cogentleman.com:cogentleman/guitarHeroButBetter

This commit is contained in:
Joseph DiMaria 2026-01-31 17:44:48 -08:00
commit 6a4c712f96
3 changed files with 22 additions and 18 deletions

View File

@ -16,7 +16,9 @@ namespace
{ {
constexpr int LANE_COUNT = 12; constexpr int LANE_COUNT = 12;
constexpr int OCTAVE_COUNT = 3; 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_GAMEPADS = 4;
constexpr int MAX_INSTRUMENT_TYPES = MAX_GAMEPADS; constexpr int MAX_INSTRUMENT_TYPES = MAX_GAMEPADS;
constexpr float RECEPTOR_HEIGHT = 150.0f; 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 LEAD_OFFSET_SECONDS = 3.0f;
constexpr float GLYPH_HEIGHT_FRACTION_OF_LANE = 0.5f; constexpr float GLYPH_HEIGHT_FRACTION_OF_LANE = 0.5f;
constexpr float MIN_SUSTAIN_FALLBACK_SEC = 0.05f; 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] = { const int GAMEPAD_BUTTONS[LANE_COUNT] = {
GAMEPAD_BUTTON_LEFT_FACE_LEFT, // Left GAMEPAD_BUTTON_LEFT_FACE_LEFT, // Left
@ -87,7 +89,8 @@ const float INSTRUMENT_VOLUME[MAX_INSTRUMENT_TYPES] = {
0.6f 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 { // 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_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", "assets/sounds/snes_synth/snes_synth_050.wav", "assets/sounds/snes_synth/snes_synth_051.wav",
@ -242,7 +245,7 @@ std::vector<Glyph> chart_from_song(const Song& song, int track_override)
std::vector<std::pair<int, const Note*>> timed_notes; std::vector<std::pair<int, const Note*>> timed_notes;
for (const Note& note : track.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, &note}); timed_notes.push_back({note.ticks, &note});
} }
std::sort(timed_notes.begin(), timed_notes.end(), std::sort(timed_notes.begin(), timed_notes.end(),
@ -258,11 +261,9 @@ std::vector<Glyph> chart_from_song(const Song& song, int track_override)
const Note& note = *pair.second; const Note& note = *pair.second;
float time_sec = note.ticks / ticks_per_sec; // This is now the BOTTOM time float time_sec = note.ticks / ticks_per_sec; // This is now the BOTTOM time
float duration_sec = note.duration_ticks / ticks_per_sec; float duration_sec = note.duration_ticks / ticks_per_sec;
int lane = note.midi % LANE_COUNT; int wav_index = note.midi - MIDI_LANE_MIN;
int offset = 0; int lane = wav_index % LANE_COUNT;
if (note.midi >= OCTAVE_OFFSET) int octave = wav_index;
offset = OCTAVE_OFFSET;
int octave = (note.midi - offset) % (LANE_COUNT * OCTAVE_COUNT);
int instrument_slot = note_index % MAX_INSTRUMENT_TYPES; int instrument_slot = note_index % MAX_INSTRUMENT_TYPES;
// Log original glyph timing (time is bottom, time + duration is top) // Log original glyph timing (time is bottom, time + duration is top)
@ -356,8 +357,8 @@ public:
float lane_width = 0.0f; float lane_width = 0.0f;
float screen_width = 0.0f; float screen_width = 0.0f;
float screen_height = 0.0f; float screen_height = 0.0f;
Sound note_sounds[MAX_INSTRUMENT_TYPES][LANE_COUNT * OCTAVE_COUNT] = {{0}}; Sound note_sounds[MAX_INSTRUMENT_TYPES][MIDI_LANE_COUNT] = {{0}};
bool note_sounds_loaded[MAX_INSTRUMENT_TYPES][LANE_COUNT * OCTAVE_COUNT] = {{false}}; bool note_sounds_loaded[MAX_INSTRUMENT_TYPES][MIDI_LANE_COUNT] = {{false}};
std::deque<Sound> note_sounds_playing[LANE_COUNT][MAX_INSTRUMENT_TYPES]; std::deque<Sound> note_sounds_playing[LANE_COUNT][MAX_INSTRUMENT_TYPES];
static constexpr float PRESS_FLASH_DURATION = 0.12f; static constexpr float PRESS_FLASH_DURATION = 0.12f;
float press_flash_timer[LANE_COUNT] = {0}; float press_flash_timer[LANE_COUNT] = {0};
@ -424,7 +425,7 @@ public:
} }
for (int slot = 0; slot < MAX_INSTRUMENT_TYPES; slot++) 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]) if (note_sounds_loaded[slot][lane])
{ {
@ -445,7 +446,7 @@ public:
update_layout(); update_layout();
for (int slot = 0; slot < MAX_INSTRUMENT_TYPES; slot++) 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]; const char* path = INSTRUMENT_LANE_WAV[slot][lane];
if (FileExists(path)) if (FileExists(path))

View File

@ -32,9 +32,9 @@ public:
static constexpr const char* INSTRUMENT_IMAGE_PATHS[MAX_INSTRUMENT_TYPES] = { static constexpr const char* INSTRUMENT_IMAGE_PATHS[MAX_INSTRUMENT_TYPES] = {
"assets/instruments/guitar.png", "assets/instruments/guitar.png",
"assets/instruments/piano.png",
"assets/instruments/violin.png",
"assets/instruments/sax.png", "assets/instruments/sax.png",
"assets/instruments/violin.png",
"assets/instruments/piano.png",
}; };
std::array<int, MAX_INSTRUMENT_TYPES> instrument_owner = {-1, -1, -1, -1}; std::array<int, MAX_INSTRUMENT_TYPES> instrument_owner = {-1, -1, -1, -1};

View File

@ -15,11 +15,14 @@ public:
void update(float delta_time) override void update(float delta_time) override
{ {
// Trigger scene change on Enter key or gamepad start button. bool start = IsKeyPressed(KEY_ENTER);
if (IsKeyPressed(KEY_ENTER) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_MIDDLE_RIGHT)) 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 void draw() override