shithub: ft2-clone

Download patch

ref: 4c361537432bc90685552363aa2bcc025184b452
parent: b9a2fce1c9260d118a7ff8664f873a3cd5919fd0
author: Olav Sørensen <olav.sorensen@live.no>
date: Sat Mar 21 11:14:35 EDT 2020

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

Also do some other minor tweaks.

--- 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...
 
--- a/src/ft2_module_loader.c
+++ b/src/ft2_module_loader.c
@@ -642,7 +642,7 @@
 			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 @@
 
 		// 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 @@
 			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 @@
 				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 @@
 						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 @@
 	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 @@
 							}
 							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 @@
 				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 @@
 			{
 				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)
--- a/src/ft2_sample_ed.c
+++ b/src/ft2_sample_ed.c
@@ -351,7 +351,7 @@
 	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 @@
 {
 	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;
 	}
 
@@ -454,12 +459,6 @@
 	else
 	{
 		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);
 	}
 }