Skip to content

Commit 70e085b

Browse files
committed
[bug] Fixes #153
Fixes Loading older version song files, where a long instrument or sample name would overflow the panel
1 parent 2c3068c commit 70e085b

File tree

6 files changed

+14
-5
lines changed

6 files changed

+14
-5
lines changed

pc/tracker/Instrument_Panel.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
const int Instrument_Panel::NUM_ROWS;
2121

22-
// Shortened the length for new GUI layout (v0.2.1)
23-
#define INSTR_NAME_GUI_CHAR_WIDTH (22 - 3)
24-
2522
// Little helper
2623
#define min(x, y) ((x) <= (y) ? (x) : (y))
2724

pc/tracker/Instruments.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ size_t InstrumentChunkLoader::load(SDL_RWops *file, size_t chunksize)
233233
DEBUGLOG("\tSubChunkID::name\n");
234234
assert(idx_loaded);
235235
size_t bytesread = ChunkLoader::read_str_from_file2(file, instruments[idx].name, subchunksize, INSTR_NAME_MAXLEN);
236+
237+
// Truncate the sample name for the GUI's shorter length
238+
instruments[idx].name[INSTR_NAME_GUI_CHAR_WIDTH - 1] = 0;
239+
236240
subchunksize -= bytesread;
237241
maxread += bytesread;
238242
}

pc/tracker/Instruments.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* increased */
88
#define NUM_INSTR 0x40
99
#define INSTR_NAME_MAXLEN 22
10+
// Shortened the length for new GUI layout (v0.2.1)
11+
#define INSTR_NAME_GUI_CHAR_WIDTH (22 - 3)
1012
#define APU_MAXVOL 0x7f
1113

1214
// TODO : take out meta info from Instrument into a InstrumentMeta

pc/tracker/Sample_Panel.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include "Tracker.h"
1414

1515
const int Sample_Panel::NUM_ROWS;
16-
// Shortened the length for new GUI layout (v0.2.1)
17-
#define SAMPLE_NAME_GUI_CHAR_WIDTH (22 - 3)
1816

1917
// Little helper
2018
#define min(x, y) ((x) <= (y) ? (x) : (y))
@@ -90,6 +88,7 @@ void Sample_Panel::set_coords(int x, int y)
9088
* tracker (core), these strings should automatically update after a
9189
* redraw */
9290
sample_names[i].str = samples[i].name;
91+
9392
sample_names[i].strsize = min(SAMPLE_NAME_MAXLEN, SAMPLE_NAME_GUI_CHAR_WIDTH);
9493
sample_names[i].rect = sample_indices[i].rect; /* Base this rect off of the index rect */
9594
sample_names[i].rect.x += 3 * CHAR_WIDTH;

pc/tracker/Samples.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ size_t SampleChunkLoader::load(SDL_RWops *file, size_t chunksize)
193193
DEBUGLOG("\tSubChunkID::name\n");
194194
assert(idx_loaded);
195195
size_t bytesread = ChunkLoader::read_str_from_file2(file, samples[idx].name, subchunksize, SAMPLE_NAME_MAXLEN);
196+
197+
// Truncate the sample name for the GUI's shorter length
198+
// Shenanigans from 11/8/2020 Twitch Stream. Ariel: if {song ends=true, then noIt’sNotThisSongNeverEnds; song ends = false;}
199+
samples[idx].name[SAMPLE_NAME_GUI_CHAR_WIDTH - 1] = 0;
200+
196201
subchunksize -= bytesread;
197202
maxread += bytesread;
198203
}

pc/tracker/Samples.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* increased */
1010
#define NUM_SAMPLES 0x100
1111
#define SAMPLE_NAME_MAXLEN 22
12+
// Shortened the length for new GUI layout (v0.2.1)
13+
#define SAMPLE_NAME_GUI_CHAR_WIDTH (22 - 3)
1214

1315
struct Sample
1416
{

0 commit comments

Comments
 (0)