New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS Increase Add ammount #120

Closed
derwentx opened this Issue Sep 3, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@derwentx
Copy link
Contributor

derwentx commented Sep 3, 2017

Hi,
According to the source code, the "increase add ammount" shortcut is bound to the "section symbol" key on macOS. I have a recent macbook pro which has a tilde key instead of a section symbol key. Normally you can input this symbol using "alt-6" however this doesn't work with Milkytracker.

I'd love to be able to use a shortcut to increase the add amount. Do you have any suggestions for a workaround?

Thanks.

@Deltafire

This comment has been minimized.

Copy link
Collaborator

Deltafire commented Sep 4, 2017

Looks like the new macbook keyboard has 1 less key than the older models :(

I was thinking of also mapping the `/~ key, but this is already mapped to note-off. Maybe the - key? It doesn't seem to be used for anything else.

@derwentx

This comment has been minimized.

Copy link
Contributor Author

derwentx commented Sep 6, 2017

Sort of :P
I did some more research and it looks like there are 2 main Apple keyboards.
ANSI / US:
US Keyboard
ISO / EN International:
UK Keyboard
But the Milkytracker bindings are based on an archaic german layout, hence all the weird names for the keys like SC_SMALLERGREATER
German Keyboard

So it would be a good idea to make sure whatever mapping you come up with works with at least the two main keyboards.

Here's some notes I've taken on what exactly is mapped in src/tracker/PatternEditorControlKeyboard.cpp.

Action FT Key Modifier MT Key Modifier
CharBinding_Copy 'C' CTRL ALT
CharBinding_Copy VK_F4 ALT 'C' CTRL
CharBinding_Cut 'X' CTRL ALT 'X' CTRL
CharBinding_Cut VK_F3 ALT
CharBinding_Interpolate 'I' SHIFT 'X' CTRL
CharBinding_InvertMuting 'M' SHIFT CTRL 'X' CTRL
CharBinding_MuteChannel 'M' SHIFT 'M' SHIFT
CharBinding_Paste 'V' CTRL ALT 'V' CTRL
CharBinding_Paste VK_F5 ALT
CharBinding_Redo 'Y' CTRL ALT 'Y' CTRL
CharBinding_SelectAll 'A' CTRL ALT 'A' CTRL
CharBinding_TransparentPaste VK_F6 ALT 'V' SHIFT CTRL
CharBinding_Undo 'Z' CTRL ALT 'Z' CTRL
DownBinding_CopyPattern VK_F4 CTRL
DownBinding_CopyTrack VK_F4 SHIFT
DownBinding_CutPattern VK_F3 CTRL
DownBinding_CutTrack VK_F3 SHIFT
DownBinding_DeleteEffect VK_DELETE ALT VK_DELETE ALT
DownBinding_DeleteLine VK_BACK SHIFT VK_BACK SHIFT
DownBinding_DeleteNote VK_DELETE 0
DownBinding_DeleteNoteSlot VK_BACK 0 VK_BACK 0
DownBinding_DeleteNoteVolumeAndEffect VK_DELETE SHIFT VK_DELETE SHIFT
DownBinding_DeleteVolumeAndEffect VK_DELETE CTRL VK_DELETE CTRL
DownBinding_DOWN VK_DOWN 0xFFFF VK_DOWN 0xFFFF
DownBinding_END VK_END 0xFFFF VK_END 0xFFFF
DownBinding_HOME VK_HOME 0xFFFF VK_HOME 0xFFFF
DownBinding_InsDecSelection SC_SS CTRL SC_SS CTRL
DownBinding_InsDecTrack SC_SS SHIFT CTRL SC_SS SHIFT CTRL
DownBinding_InsertLine VK_INSERT SHIFT VK_INSERT SHIFT
DownBinding_InsertNote VK_INSERT 0 VK_INSERT 0
DownBinding_InsIncSelection SC_TICK CTRL SC_TICK CTRL
DownBinding_InsIncTrack SC_TICK SHIFT CTRL SC_TICK SHIFT CTRL
DownBinding_LEFT VK_LEFT 0xFFFF VK_LEFT 0xFFFF
DownBinding_NEXT VK_NEXT 0xFFFF VK_NEXT 0xFFFF
DownBinding_NextChannel VK_TAB 0 VK_TAB 0
DownBinding_NextChannel VK_TAB ALT VK_TAB SHIFT
DownBinding_PastePattern VK_F5 CTRL
DownBinding_PasteTrack VK_F5 SHIFT
DownBinding_PreviousChannel VK_TAB SHIFT VK_TAB ALT
DownBinding_PreviousChannel VK_TAB SHIFT ALT VK_TAB SHIFT ALT
DownBinding_PRIOR VK_PRIOR 0xFFFF VK_PRIOR 0xFFFF
DownBinding_ReadMacro0 SC_0 ALT SHIFT
DownBinding_ReadMacro1 SC_1 ALT SHIFT
DownBinding_ReadMacro2 SC_2 ALT SHIFT
DownBinding_ReadMacro3 SC_3 ALT SHIFT
DownBinding_ReadMacro4 SC_4 ALT SHIFT
DownBinding_ReadMacro5 SC_5 ALT SHIFT
DownBinding_ReadMacro6 SC_6 ALT SHIFT
DownBinding_ReadMacro7 SC_7 ALT SHIFT
DownBinding_ReadMacro8 SC_8 ALT SHIFT
DownBinding_ReadMacro9 SC_9 ALT SHIFT
DownBinding_RIGHT VK_RIGHT 0xFFFF VK_RIGHT 0xFFFF
DownBinding_SC_A SC_A ALT
DownBinding_SC_D SC_D ALT
DownBinding_SC_DecreaseRowInsertAdd SC_WTF SHIFT
DownBinding_SC_E SC_E ALT
DownBinding_SC_F SC_F ALT
DownBinding_SC_G SC_G ALT
DownBinding_SC_H SC_H ALT
DownBinding_SC_I SC_I ALT
DownBinding_SC_IncreaseRowInsertAdd SC_WTF 0
DownBinding_SC_J SC_J ALT
DownBinding_SC_K SC_K ALT
DownBinding_SC_Q SC_Q ALT
DownBinding_SC_R SC_R ALT
DownBinding_SC_S SC_S ALT
DownBinding_SC_T SC_T ALT
DownBinding_SC_U SC_U ALT
DownBinding_SC_W SC_W ALT
DownBinding_SC_Z SC_Z ALT
DownBinding_TransparentPastePattern VK_F6 CTRL
DownBinding_TransparentPasteTrack VK_F6 SHIFT
DownBinding_UP VK_UP 0xFFFF VK_UP 0xFFFF
DownBinding_WriteMacro0 SC_0 ALT
DownBinding_WriteMacro1 SC_1 ALT
DownBinding_WriteMacro2 SC_2 ALT
DownBinding_WriteMacro3 SC_3 ALT
DownBinding_WriteMacro4 SC_4 ALT
DownBinding_WriteMacro5 SC_5 ALT
DownBinding_WriteMacro6 SC_6 ALT
DownBinding_WriteMacro7 SC_7 ALT
DownBinding_WriteMacro8 SC_8 ALT
DownBinding_WriteMacro9 SC_9 ALT

And here are the interesting parts of the code that maps Cocoa events to the Scancodes that MilkyTracker uses:


// ---------------------------------------------------------
//  Converts Cocoa Event keycode to MilkyTracker VirtualKey
// ---------------------------------------------------------
+ (pp_uint16)toVK:(unsigned short) keyCode
{
	switch (keyCode)
	{
                // ...
		// Numeric keypad
		case kVK_ANSI_KeypadEquals:		return VK_DIVIDE;	// See numpad Mac key mappings
		case kVK_ANSI_KeypadDivide:		return VK_MULTIPLY; // in MilkyTracker docs to understand
		case kVK_ANSI_KeypadMultiply:	return VK_SUBTRACT; // why this looks messed up... :)
		case kVK_ANSI_KeypadMinus:		return VK_ADD;
		case kVK_ANSI_KeypadPlus:		return VK_SEPARATOR;
		case kVK_ANSI_KeypadEnter:		return VK_DECIMAL;

		// Modifier keys
		case kVK_Command:		return VK_CONTROL;
		case kVK_Option:		return VK_ALT;
		case kVK_RightCommand:	return VK_RMENU;	// MilkyTracker uses VK_RMENU for Play Pattern
		case kVK_RightOption:	return VK_RCONTROL; // and VK_RCONTROL for Play Song

		case kVK_Shift:
		case kVK_RightShift:	return VK_SHIFT;

		case kVK_CapsLock:		return VK_CAPITAL;

		case kVK_ForwardDelete:	return VK_DELETE;
		case kVK_Delete:		return VK_BACK;

		case kVK_LeftArrow:		return VK_LEFT;
		case kVK_RightArrow:	return VK_RIGHT;
		case kVK_DownArrow:		return VK_DOWN;
		case kVK_UpArrow:		return VK_UP;

		case kVK_PageUp:		return VK_PRIOR;
		case kVK_PageDown:		return VK_NEXT;
		case kVK_Home:			return VK_HOME;
		case kVK_End:			return VK_END;

		// Function keys
		case kVK_F13:			return VK_INSERT;

		default:				return VK_UNDEFINED;
	}
}

// -------------------------------------------------------
//  Converts Cocoa Event keycode to MilkyTracker Scancode
// -------------------------------------------------------
+ (pp_uint16)toSC:(unsigned short) keyCode
{
	switch (keyCode)
	{
		// Letters
		case kVK_ANSI_Y:	return SC_Z; // MilkyTracker scancodes are based on German
		case kVK_ANSI_Z:	return SC_Y; // keyboard layout; so Y <-> Z swap is correct here.

		// Special characters
		case kVK_ANSI_Minus:		return SC_SS;
		case kVK_ANSI_Equal:		return SC_TICK;
		case kVK_ANSI_LeftBracket:	return SC_UE;
		case kVK_ANSI_RightBracket:	return SC_PLUS;

		case kVK_ANSI_Semicolon:	return SC_OE;
		case kVK_ANSI_Quote:		return SC_AE;
		case kVK_ANSI_Backslash:	return SC_SHARP;

		case kVK_ANSI_Grave:		return SC_SMALLERGREATER;
		case kVK_ANSI_Comma:		return SC_COMMA;
		case kVK_ANSI_Period:		return SC_PERIOD;
		case kVK_ANSI_Slash:		return SC_MINUS;
		case kVK_ISO_Section:		return; SC_WTF; // WTF is actually a Section sign

		// Modifiers
		case kVK_CapsLock:			return SC_CAPSLOCK;

		default:					return 0;
	}
}

Some notes:

  • My keyboard is ANSI / US so there is actually no way for me to hit the SC_WTF scancode without using Karibiner to remap the keyboard as ISO.
  • Minus and equal are already mapped to SC_SS and SC_TICK which do "increase / decrease instrument in selection / track" depending on modifiers.
    • cmd-shift-+/- increases / decreases the instrument value for the track when using my internal keyboard
    • cmd-+/- increases / decreases the instruments value for the selection when using my internal keyboard.
    • Unfortunately when using my external keyboard, I get some odd behaviour. Even though, according to a key codes utility, I'm pressing the exact same keys, cmd-minus does some kind of macro where it sets the note volume to -1 and adds a newline. Not sure what how this works but it's probably my keyboard.

So, in theory if you just mapped alt-+/- to DownBinding_SC_IncreaseRowInsertAdd / DownBinding_SC_DecreaseRowInsertAdd then this should make the bindings work on all modern keyboards :)

I've tested this out, and it works! (but only in note edit mode)

Here are the modifications I made to test it out:
line 75:

	// Alternate binding for eventKeyDownBinding_SC_IncreaseRowInsertAdd
	// for modern ANSI keyboards without section symbol key
    scanCodeBindingsMilkyTracker->addBinding(SC_SS, KeyModifierALT, &PatternEditorControl::eventKeyDownBinding_SC_DecreaseRowInsertAdd);
	scanCodeBindingsMilkyTracker->addBinding(SC_TICK, KeyModifierALT, &PatternEditorControl::eventKeyDownBinding_SC_IncreaseRowInsertAdd);

line 186:

	// Alternate binding for eventKeyDownBinding_SC_IncreaseRowInsertAdd
	// for modern ANSI keyboards without section symbol key
	scanCodeBindingsFastTracker->addBinding(SC_SS, KeyModifierALT, &PatternEditorControl::eventKeyDownBinding_SC_DecreaseRowInsertAdd);
	scanCodeBindingsFastTracker->addBinding(SC_TICK, KeyModifierALT, &PatternEditorControl::eventKeyDownBinding_SC_IncreaseRowInsertAdd);

I'll submit a PR now. Thanks!

@Deltafire

This comment has been minimized.

Copy link
Collaborator

Deltafire commented Sep 6, 2017

Nice research! Some sort of user definable keyboard mappings would be the ultimate goal (as part of issue #30), but a lot of work involved for that.

Deltafire added a commit that referenced this issue Sep 9, 2017

@Deltafire Deltafire closed this Sep 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment