Skip to content

Commit

Permalink
Fix sample jamming not working if the pattern editor was hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
8bitbubsy committed May 11, 2024
1 parent f7f05c3 commit ad66110
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
31 changes: 20 additions & 11 deletions src/ft2_edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ static bool testNoteKeys(SDL_Scancode scancode)
const int8_t noteNum = scancodeKeyToNote(scancode);
if (noteNum == NOTE_OFF)
{
bool editmode = ui.patternEditorShown && (playMode == PLAYMODE_EDIT);

// inserts "note off" if editing song
if (playMode == PLAYMODE_EDIT || playMode == PLAYMODE_RECPATT || playMode == PLAYMODE_RECSONG)
if (editmode || playMode == PLAYMODE_RECPATT || playMode == PLAYMODE_RECSONG)
{
pauseMusic();
const volatile uint16_t curPattern = editor.editPattern;
Expand Down Expand Up @@ -88,20 +90,21 @@ static bool testEditKeys(SDL_Scancode scancode, SDL_Keycode keycode)
{
int8_t i;

bool editmode = ui.patternEditorShown && (playMode == PLAYMODE_EDIT);

if (cursor.object == CURSOR_NOTE)
{
// the edit cursor is at the note slot

if (testNoteKeys(scancode))
{
keyb.keyRepeat = (playMode == PLAYMODE_EDIT); // repeat keys only if in edit mode
keyb.keyRepeat = editmode; // repeat keys only if in edit mode
return true; // we jammed an instrument
}

return false; // no note key pressed, test other keys
}

if (playMode != PLAYMODE_EDIT && playMode != PLAYMODE_RECSONG && playMode != PLAYMODE_RECPATT)
if (!editmode && playMode != PLAYMODE_RECSONG && playMode != PLAYMODE_RECPATT)
return false; // we're not editing, test other keys

// convert key to slot data
Expand Down Expand Up @@ -348,7 +351,7 @@ void recordNote(uint8_t noteNum, int8_t vol) // directly ported from the origina
tick = 0;
}

bool editmode = (playMode == PLAYMODE_EDIT);
bool editmode = ui.patternEditorShown && (playMode == PLAYMODE_EDIT);
bool recmode = (playMode == PLAYMODE_RECSONG) || (playMode == PLAYMODE_RECPATT);

if (noteNum == NOTE_OFF)
Expand Down Expand Up @@ -564,7 +567,8 @@ bool handleEditKeys(SDL_Keycode keycode, SDL_Scancode scancode)
// special case for delete - manipulate note data
if (keycode == SDLK_DELETE)
{
if (playMode != PLAYMODE_EDIT && playMode != PLAYMODE_RECSONG && playMode != PLAYMODE_RECPATT)
bool editmode = ui.patternEditorShown && (playMode == PLAYMODE_EDIT);
if (!editmode && playMode != PLAYMODE_RECSONG && playMode != PLAYMODE_RECPATT)
return false; // we're not editing, test other keys

pauseMusic();
Expand Down Expand Up @@ -663,7 +667,8 @@ void writeFromMacroSlot(uint8_t slot)
int16_t row = editor.row;
resumeMusic();

if (playMode != PLAYMODE_EDIT && playMode != PLAYMODE_RECSONG && playMode != PLAYMODE_RECPATT)
bool editmode = ui.patternEditorShown && (playMode == PLAYMODE_EDIT);
if (!editmode && playMode != PLAYMODE_RECSONG && playMode != PLAYMODE_RECPATT)
return;

if (!allocatePattern(curPattern))
Expand Down Expand Up @@ -707,7 +712,8 @@ void insertPatternNote(void)
int16_t row = editor.row;
resumeMusic();

if (playMode != PLAYMODE_EDIT && playMode != PLAYMODE_RECPATT && playMode != PLAYMODE_RECSONG)
bool editmode = ui.patternEditorShown && (playMode == PLAYMODE_EDIT);
if (!editmode && playMode != PLAYMODE_RECPATT && playMode != PLAYMODE_RECSONG)
return;

note_t *p = pattern[curPattern];
Expand Down Expand Up @@ -737,7 +743,8 @@ void insertPatternLine(void)
int16_t row = editor.row;
resumeMusic();

if (playMode != PLAYMODE_EDIT && playMode != PLAYMODE_RECPATT && playMode != PLAYMODE_RECSONG)
bool editmode = ui.patternEditorShown && (playMode == PLAYMODE_EDIT);
if (!editmode && playMode != PLAYMODE_RECPATT && playMode != PLAYMODE_RECSONG)
return;

setPatternLen(curPattern, patternNumRows[curPattern] + config.recTrueInsert); // config.recTrueInsert is 0 or 1
Expand Down Expand Up @@ -772,7 +779,8 @@ void deletePatternNote(void)
int16_t row = editor.row;
resumeMusic();

if (playMode != PLAYMODE_EDIT && playMode != PLAYMODE_RECPATT && playMode != PLAYMODE_RECSONG)
bool editmode = ui.patternEditorShown && (playMode == PLAYMODE_EDIT);
if (!editmode && playMode != PLAYMODE_RECPATT && playMode != PLAYMODE_RECSONG)
return;

const int16_t numRows = patternNumRows[curPattern];
Expand Down Expand Up @@ -813,7 +821,8 @@ void deletePatternLine(void)
int16_t row = editor.row;
resumeMusic();

if (playMode != PLAYMODE_EDIT && playMode != PLAYMODE_RECPATT && playMode != PLAYMODE_RECSONG)
bool editmode = ui.patternEditorShown && (playMode == PLAYMODE_EDIT);
if (!editmode && playMode != PLAYMODE_RECPATT && playMode != PLAYMODE_RECSONG)
return;

const int16_t numRows = patternNumRows[curPattern];
Expand Down
2 changes: 1 addition & 1 deletion src/ft2_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#endif
#include "ft2_replayer.h"

#define PROG_VER_STR "1.83"
#define PROG_VER_STR "1.84"

// do NOT change these! It will only mess things up...

Expand Down
4 changes: 2 additions & 2 deletions src/ft2_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void keyUpHandler(SDL_Scancode scancode, SDL_Keycode keycode)
return;
}

if (ui.patternEditorShown && cursor.object == CURSOR_NOTE && !keyb.keyModifierDown)
if (cursor.object == CURSOR_NOTE && !keyb.keyModifierDown)
testNoteKeysRelease(scancode);

if (scancode == SDL_SCANCODE_KP_PLUS)
Expand Down Expand Up @@ -157,7 +157,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode, bool keyWasRepea
if (scancode == SDL_SCANCODE_KP_PLUS)
keyb.numPadPlusPressed = true;

if (ui.patternEditorShown && handleEditKeys(keycode, scancode))
if (handleEditKeys(keycode, scancode))
return;

if (keyb.keyModifierDown && checkModifiedKeys(keycode))
Expand Down

0 comments on commit ad66110

Please sign in to comment.