Skip to content

Commit

Permalink
Fixes #99, and improves Keyboard MODONLY impl
Browse files Browse the repository at this point in the history
  • Loading branch information
bazz1tv committed Jun 30, 2020
1 parent a11b53c commit cde906b
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 21 deletions.
46 changes: 46 additions & 0 deletions pc/shared/kbd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "kbd.h"

bool MODONLY(const Uint16 &mod, const Uint16 k)
{
enum {
CTRL=0,
SHIFT,
ALT,
GUI,
MOD_END
};
// iteration of each left/right modifier key group
Uint16 modLR[4] = {
KMOD_CTRL,
KMOD_SHIFT,
KMOD_ALT,
KMOD_GUI
};

bool match = true;

// for each modifier key group L/R pair
for (int i=0; i < MOD_END; i++)
{
if (k & modLR[i]) // if we're supposed to be checking for ANY of these pair
{
// if the keys pressed do not reflect the keys checked for
// (applies to any specified L / R / LR mod key combo)
if ( ! ( (mod & modLR[i]) & (k & modLR[i]) ) )
{
match = false;
break;
}
}
else // if we're not supposed to be checking for this pair
{
if (mod & modLR[i]) // make sure this pair's keys are not held
{
match = false;
break;
}
}
}

return match;
}
6 changes: 3 additions & 3 deletions pc/shared/kbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* held, and to check if any modifier is held, respectively:
*
* Examples:
* check if only the CTRL modifier (left or right) is held:
* if (MODONLY(mod, KMOD_CTRL))
* check for CTRL + SHIFT:
* if (MODONLY(mod, KMOD_CTRL | KMOD_SHIFT))
*
*
*
* */
#define MODONLY(mod, k) ( (mod) & (k) && !( (mod) & ~(k) ) )
bool MODONLY(const Uint16 &mod, const Uint16 k);
#define MOD_ANY(mod) (mod & (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_GUI))
6 changes: 4 additions & 2 deletions pc/tracker/Instruments.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "platform.h"
#include "kbd.h"
#include "tracker/Instruments.h"
#include "shared/Colors.h"
#include "shared/sdl_userevents.h"
Expand Down Expand Up @@ -620,13 +622,13 @@ int Instrument_Panel::event_handler(const SDL_Event &ev)
switch(scancode)
{
case SDLK_UP:
if (mod & KMOD_SHIFT && !(mod & KMOD_CTRL))
if (MODONLY(mod, KMOD_SHIFT))
{
dec_currow();
}
break;
case SDLK_DOWN:
if (mod & KMOD_SHIFT && !(mod & KMOD_CTRL))
if (MODONLY(mod, KMOD_SHIFT))
{
inc_currow();
}
Expand Down
21 changes: 9 additions & 12 deletions pc/tracker/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,31 +750,31 @@ int PatSeqPanel::event_handler(const SDL_Event &ev)
switch(scancode)
{
case SDLK_UP:
if (MODONLY(mod, KMOD_CTRL))
if (MODONLY(mod, CMD_CTRL_KEY))
{
dec_currow();
}
break;
case SDLK_DOWN:
if (MODONLY(mod, KMOD_CTRL))
if (MODONLY(mod, CMD_CTRL_KEY))
{
inc_currow();
}
break;
case SDLK_LEFT:
if (MODONLY(mod, KMOD_CTRL))
if (MODONLY(mod, CMD_CTRL_KEY))
decpat(this);
break;
case SDLK_RIGHT:
if (MODONLY(mod, KMOD_CTRL))
if (MODONLY(mod, CMD_CTRL_KEY))
incpat(this);
break;
case SDLK_F9:
if (MODONLY(mod, KMOD_CTRL))
if (MODONLY(mod, CMD_CTRL_KEY))
clear(this);
break;
case SDLK_F10:
if (MODONLY(mod, KMOD_CTRL))
if (MODONLY(mod, CMD_CTRL_KEY))
{
//insert_pattern();
PatternMeta *p = get_current_pattern_meta(this);
Expand All @@ -795,11 +795,11 @@ int PatSeqPanel::event_handler(const SDL_Event &ev)
}
break;
case SDLK_F11:
if (MODONLY(mod, KMOD_CTRL))
if (MODONLY(mod, CMD_CTRL_KEY))
clone_seq_common(this);
break;
case SDLK_F12:
if (MODONLY(mod, KMOD_CTRL))
if (MODONLY(mod, CMD_CTRL_KEY))
clone(this);
break;

Expand Down Expand Up @@ -1865,7 +1865,7 @@ void PatternEditorPanel::events_kb_universal(const int scancode, const int mod)
switch(scancode)
{
case SDLK_w:
if (MODONLY(mod, KMOD_CTRL))
if (MODONLY(mod, CMD_CTRL_KEY))
pattern_wrap = !pattern_wrap;
break;
case SDLK_PAGEUP:
Expand Down Expand Up @@ -1954,9 +1954,6 @@ void PatternEditorPanel::events_kb_universal(const int scancode, const int mod)
}
}

#define MODONLY(mod, k) ( (mod) & (k) && !( (mod) & ~(k) ) )
#define MOD_ANY(mod) (mod & (KMOD_CTRL | KMOD_SHIFT | KMOD_ALT | KMOD_GUI))

void PatternEditorPanel::piano_kb(const int scancode, const int mod)
{
if (MOD_ANY(mod))
Expand Down
9 changes: 7 additions & 2 deletions pc/tracker/Samples.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include "platform.h"
#include "kbd.h"

#include "Samples.h"
#include "Instruments.h"
#include "shared/Colors.h"
Expand All @@ -9,6 +12,8 @@
#include "globals.h" // for ::mouse
#include "PanelCommon.h"



const int Sample_Panel::NUM_ROWS;
#define SAMPLE_NAME_GUI_CHAR_WIDTH 22

Expand Down Expand Up @@ -568,14 +573,14 @@ int Sample_Panel::event_handler(const SDL_Event &ev)
switch(scancode)
{
case SDLK_UP:
if (mod & KMOD_SHIFT && (mod & KMOD_CTRL))
if (MODONLY(mod, KMOD_SHIFT | CMD_CTRL_KEY))
{
dec_currow();
return ROW_UPDATED;
}
break;
case SDLK_DOWN:
if (mod & KMOD_SHIFT && (mod & KMOD_CTRL))
if (MODONLY(mod, KMOD_SHIFT | CMD_CTRL_KEY))
{
inc_currow();
return ROW_UPDATED;
Expand Down
4 changes: 2 additions & 2 deletions pc/tracker/Tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,11 @@ void Tracker::handle_events()
switch (scancode)
{
case SDLK_LEFT:
if ((mod & KMOD_SHIFT) && (mod & KMOD_CTRL))
if ( MODONLY(mod, KMOD_SHIFT | CMD_CTRL_KEY) )
mousecursors->prev();
break;
case SDLK_RIGHT:
if ((mod & KMOD_SHIFT) && (mod & KMOD_CTRL))
if ( MODONLY(mod, KMOD_SHIFT | CMD_CTRL_KEY) )
mousecursors->next();
break;
case SDLK_RETURN:
Expand Down

0 comments on commit cde906b

Please sign in to comment.