ft2-clone

Fasttracker 2 clone
Log | Files | Refs | README | LICENSE

commit 4c361537432bc90685552363aa2bcc025184b452
parent b9a2fce1c9260d118a7ff8664f873a3cd5919fd0
Author: Olav Sørensen <olav.sorensen@live.no>
Date:   Sat, 21 Mar 2020 15:14:08 +0100

Fix Smp. Ed. bug with Repeat/Replen. numbers on non-looping samples

Also do some other minor tweaks.

Diffstat:
Msrc/ft2_header.h | 2+-
Msrc/ft2_module_loader.c | 40++++++++++++++++++++++++----------------
Msrc/ft2_sample_ed.c | 27+++++++++++++--------------
3 files changed, 38 insertions(+), 31 deletions(-)

diff --git a/src/ft2_header.h b/src/ft2_header.h @@ -12,7 +12,7 @@ #endif #include "ft2_replayer.h" -#define PROG_VER_STR "1.13" +#define PROG_VER_STR "1.14" // do NOT change these! It will only mess things up... diff --git a/src/ft2_module_loader.c b/src/ft2_module_loader.c @@ -642,7 +642,7 @@ static bool loadMusicMOD(FILE *f, uint32_t fileLength, bool fromExternalThread) memcpy(s->name, songTmp.instrName[1+a], 22); if (modFormat == FORMAT_HMNT) // finetune in "His Master's NoiseTracker" is different - h_MOD31.instr[a].fine = (uint8_t)((-h_MOD31.instr[a].fine & 0x1F) / 2); // one more bit of precision, + inverted + h_MOD31.instr[a].fine = (uint8_t)((-h_MOD31.instr[a].fine & 0x1F) >> 1); // one more bit of precision, + inverted if (modFormat != FORMAT_STK) s->fine = 8 * ((2 * ((h_MOD31.instr[a].fine & 0xF) ^ 8)) - 16); @@ -661,13 +661,13 @@ static bool loadMusicMOD(FILE *f, uint32_t fileLength, bool fromExternalThread) // in The Ultimate SoundTracker, sample loop start is in bytes, not words if (mightBeSTK) - s->repS /= 2; + s->repS >>= 1; // fix for poorly converted STK (< v2.5) -> PT/NT modules (FIXME: Worth keeping or not?) if (!mightBeSTK && s->repL > 2 && s->repS+s->repL > s->len) { - if ((s->repS/2) + s->repL <= s->len) - s->repS /= 2; + if ((s->repS>>1)+s->repL <= s->len) + s->repS >>= 1; } // fix overflown loop @@ -704,6 +704,13 @@ static bool loadMusicMOD(FILE *f, uint32_t fileLength, bool fromExternalThread) memset(&s->pek[bytesRead], 0, bytesToClear); } + // clear repL and repS on non-looping samples... + if ((s->typ & 3) == 0) + { + s->repL = 0; + s->repS = 0; + } + fixSample(s); } @@ -957,7 +964,7 @@ static bool loadMusicSTM(FILE *f, uint32_t fileLength, bool fromExternalThread) if (s->repS+s->repL > s->len) s->repL = s->len - s->repS; - s->typ = 1; + s->typ = 1; // enable loop } else { @@ -1019,12 +1026,14 @@ static bool loadMusicSTM(FILE *f, uint32_t fileLength, bool fromExternalThread) if (len > 0) { tmp8 = ton->eff; - if (tmp8 >= len/256) + + int32_t newLen = len >> 8; + if (tmp8 >= newLen) { - if (len/256 < 1) + if (newLen < 1) tmp8 = 0; else - tmp8 = (uint8_t)((len/256) - 1); + tmp8 = (uint8_t)(newLen - 1); } } @@ -1187,8 +1196,8 @@ static bool loadMusicS3M(FILE *f, uint32_t dataLength, bool fromExternalThread) memcpy(songTmp.name, h_S3M.name, 20); songTmp.name[20] = '\0'; - ap = h_S3M.antPatt; - ai = h_S3M.antInstr; + ap = h_S3M.antPatt; + ai = h_S3M.antInstr; ver = h_S3M.ver; k = 31; @@ -1445,11 +1454,11 @@ static bool loadMusicS3M(FILE *f, uint32_t dataLength, bool fromExternalThread) } break; - case 21: // U (fine vibrato, doesn't exist in FT2, convert to normal vibrato) + case 21: // U (fine vibrato, doesn't exist in FT2, do a poor conversion to normal vibrato) { if ((ton.eff & 0x0F) != 0) { - ton.eff = (ton.eff & 0xF0) | (((ton.eff & 15) + 1) / 4); // divide depth by 4 + ton.eff = (ton.eff & 0xF0) | (((ton.eff & 15) + 1) >> 2); // divide depth by 4 if ((ton.eff & 0x0F) == 0) // depth too low, remove effect { illegalUxx = true; @@ -2183,7 +2192,6 @@ static bool loadInstrHeader(FILE *f, uint16_t i) if ((uint16_t)ins->envPP[j][0] > 32767) ins->envPP[j][0] = 32767; if ((uint16_t)ins->envVP[j][1] > 64) ins->envVP[j][1] = 64; if ((uint16_t)ins->envPP[j][1] > 63) ins->envPP[j][1] = 63; - } } @@ -2304,9 +2312,9 @@ static bool loadInstrSample(FILE *f, uint16_t i) { s->typ &= ~32; // remove stereo flag - s->len /= 2; - s->repL /= 2; - s->repS /= 2; + s->len >>= 1; + s->repL >>= 1; + s->repS >>= 1; newPtr = (int8_t *)realloc(s->origPek, s->len + LOOP_FIX_LEN); if (newPtr != NULL) diff --git a/src/ft2_sample_ed.c b/src/ft2_sample_ed.c @@ -351,7 +351,7 @@ static void updateViewSize(void) else dPos2ScrMul = (double)SAMPLE_AREA_WIDTH / smpEd_ViewSize; - dScr2SmpPosMul = smpEd_ViewSize / (double)SAMPLE_AREA_WIDTH; + dScr2SmpPosMul = smpEd_ViewSize * (1.0 / SAMPLE_AREA_WIDTH); } static void updateScrPos(void) @@ -417,18 +417,23 @@ static void fixRepeatGadgets(void) { int32_t repS, repE; sampleTyp *s; + bool showLoopPins = true; s = getCurSample(); - if (s == NULL || s->len <= 0 || s->pek == NULL || (s->typ & 3) == 0) + if (s == NULL || s->len <= 0 || s->pek == NULL || (s->typ & 3) == 0 || !editor.ui.sampleEditorShown) + showLoopPins = false; + + if (editor.ui.sampleEditorShown) + { + // draw Repeat/Replen. numbers + hexOutBg(536, 375, PAL_FORGRND, PAL_DESKTOP, curSmpRepS, 8); + hexOutBg(536, 387, PAL_FORGRND, PAL_DESKTOP, curSmpRepL, 8); + } + + if (!showLoopPins) { hideSprite(SPRITE_LEFT_LOOP_PIN); hideSprite(SPRITE_RIGHT_LOOP_PIN); - - if (editor.ui.sampleEditorShown) - { - hexOutBg(536, 375, PAL_FORGRND, PAL_DESKTOP, 0, 8); - hexOutBg(536, 387, PAL_FORGRND, PAL_DESKTOP, 0, 8); - } return; } @@ -455,12 +460,6 @@ static void fixRepeatGadgets(void) { hideSprite(SPRITE_RIGHT_LOOP_PIN); } - - if (editor.ui.sampleEditorShown) - { - hexOutBg(536, 375, PAL_FORGRND, PAL_DESKTOP, curSmpRepS, 8); - hexOutBg(536, 387, PAL_FORGRND, PAL_DESKTOP, curSmpRepL, 8); - } } static void fixSampleDrag(void)