Skip to content

Commit

Permalink
[bug] Fixes #153
Browse files Browse the repository at this point in the history
Fixes Loading older version song files, where a long instrument or
sample name would overflow the panel
  • Loading branch information
bazz1tv committed Mar 15, 2021
1 parent 2c3068c commit 70e085b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 5 deletions.
3 changes: 0 additions & 3 deletions pc/tracker/Instrument_Panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
4 changes: 4 additions & 0 deletions pc/tracker/Instruments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions pc/tracker/Instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pc/tracker/Sample_Panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions pc/tracker/Samples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions pc/tracker/Samples.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 70e085b

Please sign in to comment.