Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Feature Requests

Reply
 
Thread Tools Display Modes
Old 11-10-2020, 06:49 AM   #1
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default API: GetShortcutCode/EnumShortcutCode for keymap-switching-scripts

I was thinking about this for a long time and I think I have fiddled out, how to make setting shortcuts programmeable.

For that there are already a number of functions present in the C++-API:
DeleteActionShortcut
GetActionShortcutDesc
DoActionShortcutDialog
CountActionShortcuts

which can be used in conjunction with StuffMIDIMessage to set new shortcuts.
Means: I use DoActionShortcutDialog, sent the keyboard/midi-shortcut via StuffMIDIMessage and click the OK-button.

But there is one last function missing: a function that returns the code of actually set shortcuts.

In the kb.ini, shortcuts are represented using two numbers in the KEY-entries. The same goes, when I sent a shortcut via StuffMIDIMessage, where the first two bytes signal the actual shortcut.
Now, if I want to set shortcuts, I would love to know, if a certain shortcut is already set.
Especially if I want to delete the old binding of a shortcut before setting it to a new action to avoid the "shortcut already set"-dialog.
I could try to make this with GetActionShortcutDesc, but I fear, that the description returns the shortcut localized, means: german keymap -> german description.
So what I need is something, that is more "internationalized".
And these are actually the two numbers in the KEY-entries as well as the first two bytes in StuffMIDIMessage.

So: I would like to propose a function, that returns the kb.ini-KEY-numbers as well as the StuffMIDIMessage-bytes associated with the shortcut.

Code:
integer kbini_1, integer kbini_2, integer smidim_1, integer smidim_2 =  reaper.GetShortcutCode(integer commandid, integer shortcut_idx)
The first ones return the two kb.ini-related KEY-numbers, while the second two the two integer that could be used for StuffMIDIMessage. (I found in my research, that the numbers in the KEY-entries seem to differ from their StuffMIDIMessage-counterparts, that's why I think both are needed...)

In addition to that, it would be nice to have a function for enumerating all existing shortcuts for their codes:

Code:
string shortcut_desc = reaper.EnumShortcutCode_KBini(integer code1, integer code2)

string shortcut_desc = reaper.EnumShortcutCode_StuffMIDIMEssage(integer code1, integer code2)
and for reverse-lookup, to which action a certain shortcut-code is already associated(without the need of parsing the kb.ini for that)

Code:
integer command_id, integer shortcut_idx = reaper.ReverseLookupShortcutCode(integer code1, integer code2)


The reason I'm asking it for is, that it would allow having things like switchable keyboard-layouts for different usecases.
So I could have a script, that displays the keymap to the user and by clicking on a key, you can bind an action selected in the actionlist(the actionlist does it the other way round).

And if you store multiple of them, you could switch between them via script, which is a feature that had been asked numerous times in the past.
The EnumShortcutCode-functions would also allow to localize the keyboard-names. So in english keymaps, it would return "Ctrl", while on german keymaps, it would return "Strg".
So displaying localised keynames in such a keymap-script would be easy to do.

This would be a huge leap forward in terms of workflow-management for many users, if we could write something like that(no matter if it's as script or maybe even in SWS).
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...

Last edited by Meo-Ada Mespotine; 11-10-2020 at 06:55 AM.
Meo-Ada Mespotine is offline   Reply With Quote
Old 11-13-2020, 04:01 PM   #2
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,031
Default

Anything which improves key-mapping, midi-mapping and their management, via exprot/import via .txt/.csv files is great.
TonE is offline   Reply With Quote
Old 11-13-2020, 05:34 PM   #3
juan_r
Human being with feelings
 
juan_r's Avatar
 
Join Date: Oct 2019
Posts: 1,075
Default

+1

I'm not a scripter, though I do dabble a bit. I've been looking for a way to reset only selected keyboard shortcuts to their default values. It seems to me that the functions proposed by Mespotine could help build such a selective restore.
juan_r is offline   Reply With Quote
Old 12-23-2020, 05:16 PM   #4
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

I like the idea of managing shortcuts via scripts.

While we're waiting the requested function, I have exposed the ones that you listed in the js_ReaScriptAPI extension:
DeleteActionShortcut
GetActionShortcutDesc
DoActionShortcutDialog
CountActionShortcuts
juliansader is offline   Reply With Quote
Old 12-23-2020, 05:40 PM   #5
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Awesome! Thnx, Julian
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 12-24-2020, 07:04 PM   #6
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

+1 +1 +1 +1


Also Thanks Julian :O awesome

Last edited by daniellumertz; 12-24-2020 at 07:10 PM.
daniellumertz is offline   Reply With Quote
Old 12-25-2020, 09:27 PM   #7
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Have checked on it further but my idea doesn't work within defer-scripts.

https://forum.cockos.com/showpost.ph...postcount=1457

So I'm proposing a function called SetActionShortcut:

Code:
boolean = SetActionShortcut(integer section, integer commandid, integer shortcutidx, integer value1, integer value2, integer MIDICC, integer Scope)

integer section - the section of the action
integer commandid - the command-id of the action
integer shortcutidx - the id of the shortcut to add/replace
integer value1 - the first value in the kb.ini-KEY-entry
integer value2 - the second value in the kb.ini-KEY-entry
integer MIDICC - MIDI-CC dropdownlist(0-3); &1024=Soft takeover
integer Scope - the scope (0-2) as in the scope-dropdownlist
with which I can set shortcuts, by passing to it the values used by the KEY-entries in reaper-kb.ini

I have fully working functions for creating these values in my Ultraschall-API, so the only thing left missing is the SetActionShortcut-function.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...

Last edited by Meo-Ada Mespotine; 12-25-2020 at 09:38 PM.
Meo-Ada Mespotine is offline   Reply With Quote
Old 12-25-2020, 10:02 PM   #8
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

an SetActionShortCut would be great indeed !
daniellumertz is offline   Reply With Quote
Old 12-25-2020, 10:12 PM   #9
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Yes. And I could code all kinds of functions to translate keycodes from one concept to the one for shortcuts.

For instance, the gfx.getkey-codes or even VKeys(the latter has been asked for by Amagalma), could be possible that way.

And as the values for value1 and value2 represent the ones in KEY-entries, parsing ReaperKeyMap-files to set them via script would be easy to do as well.

Would probably be a matter of days to include all of them in Ultraschall-API.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 01-27-2021, 03:41 PM   #10
vonglan
Human being with feelings
 
Join Date: Oct 2019
Location: Lübeck, Germany
Posts: 47
Default

Yes, I would also be VERY interested in an API function to set/change shortcuts via script.

Like mentioned in various threads before, this would allow to swap sets of keyboard shortcuts (or MIDI CC) bindings for actions.

For example, I could reuse my trusty old AKAI APC20 and write scripts that allow me to change with one of its buttons, whether its faders control Volume or Pan of the first 8 Reaper tracks.

(Doing this for FX VSTs with a JSFX script is already possible. I just implemented this to be able to switch the CC destinations for the 4 knobs of Midiplus X3 keyboard to different parameter groups, like Osc1-3, Mixer, Filter, Amp+Filt Envelope.)
vonglan is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:25 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.