From 70e085b8dff0c0608ea68d07fa25eb216ec89a9c Mon Sep 17 00:00:00 2001 From: Bazz Date: Sun, 8 Nov 2020 22:14:29 -0500 Subject: [PATCH] [bug] Fixes #153 Fixes Loading older version song files, where a long instrument or sample name would overflow the panel --- pc/tracker/Instrument_Panel.cpp | 3 --- pc/tracker/Instruments.cpp | 4 ++++ pc/tracker/Instruments.h | 2 ++ pc/tracker/Sample_Panel.cpp | 3 +-- pc/tracker/Samples.cpp | 5 +++++ pc/tracker/Samples.h | 2 ++ 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pc/tracker/Instrument_Panel.cpp b/pc/tracker/Instrument_Panel.cpp index d4a8b7d9..1f521001 100644 --- a/pc/tracker/Instrument_Panel.cpp +++ b/pc/tracker/Instrument_Panel.cpp @@ -19,9 +19,6 @@ const int Instrument_Panel::NUM_ROWS; -// Shortened the length for new GUI layout (v0.2.1) -#define INSTR_NAME_GUI_CHAR_WIDTH (22 - 3) - // Little helper #define min(x, y) ((x) <= (y) ? (x) : (y)) diff --git a/pc/tracker/Instruments.cpp b/pc/tracker/Instruments.cpp index d9a67020..ae45320f 100644 --- a/pc/tracker/Instruments.cpp +++ b/pc/tracker/Instruments.cpp @@ -233,6 +233,10 @@ size_t InstrumentChunkLoader::load(SDL_RWops *file, size_t chunksize) DEBUGLOG("\tSubChunkID::name\n"); assert(idx_loaded); size_t bytesread = ChunkLoader::read_str_from_file2(file, instruments[idx].name, subchunksize, INSTR_NAME_MAXLEN); + + // Truncate the sample name for the GUI's shorter length + instruments[idx].name[INSTR_NAME_GUI_CHAR_WIDTH - 1] = 0; + subchunksize -= bytesread; maxread += bytesread; } diff --git a/pc/tracker/Instruments.h b/pc/tracker/Instruments.h index 8d969e32..be940366 100644 --- a/pc/tracker/Instruments.h +++ b/pc/tracker/Instruments.h @@ -7,6 +7,8 @@ * increased */ #define NUM_INSTR 0x40 #define INSTR_NAME_MAXLEN 22 +// Shortened the length for new GUI layout (v0.2.1) +#define INSTR_NAME_GUI_CHAR_WIDTH (22 - 3) #define APU_MAXVOL 0x7f // TODO : take out meta info from Instrument into a InstrumentMeta diff --git a/pc/tracker/Sample_Panel.cpp b/pc/tracker/Sample_Panel.cpp index 672b1e04..5f2946ec 100644 --- a/pc/tracker/Sample_Panel.cpp +++ b/pc/tracker/Sample_Panel.cpp @@ -13,8 +13,6 @@ #include "Tracker.h" const int Sample_Panel::NUM_ROWS; -// Shortened the length for new GUI layout (v0.2.1) -#define SAMPLE_NAME_GUI_CHAR_WIDTH (22 - 3) // Little helper #define min(x, y) ((x) <= (y) ? (x) : (y)) @@ -90,6 +88,7 @@ void Sample_Panel::set_coords(int x, int y) * tracker (core), these strings should automatically update after a * redraw */ sample_names[i].str = samples[i].name; + sample_names[i].strsize = min(SAMPLE_NAME_MAXLEN, SAMPLE_NAME_GUI_CHAR_WIDTH); sample_names[i].rect = sample_indices[i].rect; /* Base this rect off of the index rect */ sample_names[i].rect.x += 3 * CHAR_WIDTH; diff --git a/pc/tracker/Samples.cpp b/pc/tracker/Samples.cpp index 56a93300..17919909 100644 --- a/pc/tracker/Samples.cpp +++ b/pc/tracker/Samples.cpp @@ -193,6 +193,11 @@ size_t SampleChunkLoader::load(SDL_RWops *file, size_t chunksize) DEBUGLOG("\tSubChunkID::name\n"); assert(idx_loaded); size_t bytesread = ChunkLoader::read_str_from_file2(file, samples[idx].name, subchunksize, SAMPLE_NAME_MAXLEN); + + // Truncate the sample name for the GUI's shorter length + // Shenanigans from 11/8/2020 Twitch Stream. Ariel: if {song ends=true, then noIt’sNotThisSongNeverEnds; song ends = false;} + samples[idx].name[SAMPLE_NAME_GUI_CHAR_WIDTH - 1] = 0; + subchunksize -= bytesread; maxread += bytesread; } diff --git a/pc/tracker/Samples.h b/pc/tracker/Samples.h index b6c4288b..d8539fc0 100644 --- a/pc/tracker/Samples.h +++ b/pc/tracker/Samples.h @@ -9,6 +9,8 @@ * increased */ #define NUM_SAMPLES 0x100 #define SAMPLE_NAME_MAXLEN 22 +// Shortened the length for new GUI layout (v0.2.1) +#define SAMPLE_NAME_GUI_CHAR_WIDTH (22 - 3) struct Sample {