shithub: pt2-clone

Download patch

ref: e02816128d18dbb46544ec84709257ff5c87265e
parent: 6b2df7a57294c528efc25765d7069407e9bdd4e8
author: Olav Sørensen <[email protected]>
date: Thu Mar 17 08:13:07 EDT 2022

Fixed CTRL+T (Swap Channel) bugs

CTRL+T (Swap Channel) didn't refresh the pattern data view, nor did it update the "song is modified" state.

--- a/src/pt2_header.h
+++ b/src/pt2_header.h
@@ -14,7 +14,7 @@
 #include "pt2_unicode.h"
 #include "pt2_palette.h"
 
-#define PROG_VER_STR "1.42"
+#define PROG_VER_STR "1.43"
 
 #ifdef _WIN32
 #define DIR_DELIMITER '\\'
--- a/src/pt2_keyboard.c
+++ b/src/pt2_keyboard.c
@@ -3469,11 +3469,27 @@
 	}
 }
 
+static void swapChannel(uint8_t srcCh, uint8_t dstCh)
+{
+	if (srcCh == dstCh)
+		return;
+
+	for (int32_t i = 0; i < MOD_ROWS; i++)
+	{
+		note_t *noteSrc = &song->patterns[song->currPattern][(i * AMIGA_VOICES) + dstCh];
+		note_t noteTmp = song->patterns[song->currPattern][(i * AMIGA_VOICES) + srcCh];
+
+		song->patterns[song->currPattern][(i * AMIGA_VOICES) + srcCh] = *noteSrc;
+		*noteSrc = noteTmp;
+	}
+
+	updateWindowTitle(MOD_IS_MODIFIED);
+	ui.updatePatternData = true;
+}
+
 bool handleGeneralModes(SDL_Keycode keycode, SDL_Scancode scancode)
 {
 	int8_t rawKey;
-	int16_t i;
-	note_t *noteSrc, noteTmp;
 
 	// SAMPLER SCREEN (volume box)
 	if (ui.samplerVolBoxShown && !ui.editTextFlag && scancode == SDL_SCANCODE_ESCAPE)
@@ -3747,15 +3763,7 @@
 
 			case SDL_SCANCODE_1:
 			{
-				for (i = 0; i < MOD_ROWS; i++)
-				{
-					noteSrc = &song->patterns[song->currPattern][(i * AMIGA_VOICES) + cursor.channel];
-					noteTmp = song->patterns[song->currPattern][i * AMIGA_VOICES];
-
-					song->patterns[song->currPattern][i * AMIGA_VOICES] = *noteSrc;
-					*noteSrc = noteTmp;
-				}
-
+				swapChannel(0, cursor.channel);
 				editor.swapChannelFlag = false;
 
 				pointerSetPreviousMode();
@@ -3765,15 +3773,7 @@
 
 			case SDL_SCANCODE_2:
 			{
-				for (i = 0; i < MOD_ROWS; i++)
-				{
-					noteSrc = &song->patterns[song->currPattern][(i * AMIGA_VOICES) + cursor.channel];
-					noteTmp = song->patterns[song->currPattern][(i * AMIGA_VOICES) + 1];
-
-					song->patterns[song->currPattern][(i * AMIGA_VOICES) + 1] = *noteSrc;
-					*noteSrc = noteTmp;
-				}
-
+				swapChannel(1, cursor.channel);
 				editor.swapChannelFlag = false;
 
 				pointerSetPreviousMode();
@@ -3783,15 +3783,7 @@
 
 			case SDL_SCANCODE_3:
 			{
-				for (i = 0; i < MOD_ROWS; i++)
-				{
-					noteSrc = &song->patterns[song->currPattern][(i * AMIGA_VOICES) + cursor.channel];
-					noteTmp = song->patterns[song->currPattern][(i * AMIGA_VOICES) + 2];
-
-					song->patterns[song->currPattern][(i * AMIGA_VOICES) + 2] = *noteSrc;
-					*noteSrc = noteTmp;
-				}
-
+				swapChannel(2, cursor.channel);
 				editor.swapChannelFlag = false;
 
 				pointerSetPreviousMode();
@@ -3801,15 +3793,7 @@
 
 			case SDL_SCANCODE_4:
 			{
-				for (i = 0; i < MOD_ROWS; i++)
-				{
-					noteSrc = &song->patterns[song->currPattern][(i * AMIGA_VOICES) + cursor.channel];
-					noteTmp = song->patterns[song->currPattern][(i * AMIGA_VOICES) + 3];
-
-					song->patterns[song->currPattern][(i * AMIGA_VOICES) + 3] = *noteSrc;
-					*noteSrc = noteTmp;
-				}
-
+				swapChannel(3, cursor.channel);
 				editor.swapChannelFlag = false;
 
 				pointerSetPreviousMode();