Parsing shortcuts.xml for QWERTY shortcuts cheat sheet
Happy New Year everyone,
I'm trying to generate a keyboard layout with shortcuts, as described here:
https://musescore.org/en/node/92431
I'm parsing shortcuts.xml, but I'm not entirely clear as to the conventions used in the XML.
1. Most fields within SC sections are <seq> with text contents, but some are <std>, with numerical contents - what's that all about?
2. As far as I can tell, some actions have multiple definitions, i.e. different keypresses/combos all produce the same result. This appears to be defined in different ways:
- multiple <seq> sections
(e.g.<SC>
<key>delete-measures</key>
<seq>Ctrl+Del</seq>
<seq>Ctrl+Backspace</seq>
</SC>)
- multiple combos separated by commas
( <SC>
<key>add-8vb</key>
<seq>Ctrl+Y,Ctrl+O,Ctrl+B</seq>
</SC> )
What does this mean? Surely that is Redo, Open, Append bar?
Can anyone clarify the difference in these definitions, if there is one?
3. Similarly, some combos have multiple different actions, presumably depending on context. Is there any convention about how that is defined?
I'm beginning to suspect that the shortcuts.xml does not actually define the shortcuts themselves, but is itself rendered depending on settings elsewhere. Could that be right? In fact, now I look at it in preferences, the whole list seems a bit wrong.
In short - is shortcuts.xml valid, and, if so, how does it work?
Ian
Comments
1. I *think" the "std" entries in the file mean, MuseScore uses whatever the operating system uses by default for that specific command. I think the numbers are based on this:
http://doc.qt.io/qt-4.8/qkeysequence.html#StandardKey-enum
I'm kind of guessing on that, but it's a somewhat educated guess :-)
2. When you see keys separated by commas, that means the shortcut consists of entering that sequence *in order*. That is, to add an 8vb, you press Ctrl+Y followed by Ctrl+O followed by Ctrl+B (or just hold Ctrl while typing "YOB").
3. Yes, there are different modes to allow the same shortcut to act differently depending on context. The modes are things like Note Input, Edit, Lyrics, etc. The current mode is displayed in the lower right of the status bar while using MuseScore. To understand which commands are active in which modes, see the code here:
https://github.com/musescore/MuseScore/blob/master/mscore/shortcut.cpp#…
You can override these shortcuts via Preferences, but the lsit of shortcuts in shrotcuts.xml does set the defaults as far as I know. What are you seeing that "seems a bit wrong"?
In reply to 1. I *think" the "std" by Marc Sabatella
Thanks for the response Marc,
1. Right-oh, I'm sure I can use that.
2. I thought it might be that but I couldn't get MS to recognise it as a sequence, i.e. it seemed to be splitting into redo, open, append bar (hence my belief that it might be a bit wrong). It's working now of course :-).
3. Ah, that code will be very useful, thanks. I was hoping that the shortcuts.xml file itself might contain a clue as to which shortcuts are valid in which context, but this will have to suffice. In the first instance I can just omit that information from the map. That clearly contains labels in US English - how are other languages and dialects handled?
More than just setting the defaults, shortcuts.xml appears to reflect any changes (e.g. I just assigned Y to "trill", and it has appeared in the xml file).
The goal, of course, is to have a script so that any user can generate their own (perhaps customised) layout map from shortcuts.xml and a description of their keyboard layout without needing the source code, but I guess I can take the information in shortcut.cpp (and language files) and incorporate it.
Much to think about,
Cheers
In reply to Thanks for the response by fizzybrain
2 & 3 may be related: the 8vb command is only active in certan modes. And you have to have selected something first.
Something to keep in mind: it isn't just a *shortcut* that is either active or not depending on mode - it's the command itself. That is, a given command is either active in a given mode or it is not. If it is, then the shortcut is active and so is the menu and possibly other means of activating that command (OSC remote control, for example). If a given command is *not* active in a given mode, then it isn't active by shortcut, menu, or OSC. And this is as it should be. If it doesn't make sense for a command to be available in a given mode, then it wouldn't much sense to only disable the shrotcut but still have the command accessible via menu or OSC.
I'm not sure what specifically you are asking about regarding languages, but in generally, translations are provided separately. I believe they are loaded at run time, but I have no idea how feasible it would be access them programmatically for this purpose.
In reply to 2 & 3 may be related: the 8vb by Marc Sabatella
Thanks Marc, those thoughts about commands all make sense.
Regarding languages, I was hoping that the language files might easily be parsed to get the labels (similar to the labels in shortcuts.cpp). Some software has language files in plain text, but MS seems to use .qm files, which are compiled and harder to handle. I'm guessing that the source text/xml/whatever files might be available somewhere on github, but I haven't looked yet. I believe there is also some third-party reader which might de-compile .qm into XML.
Ironically enough, the RSI which inspired me to make this shortcut chart so that I can use the keyboard more and the mouse less has got worse (probably due to my coding experiments thus far) and rather slowed me down in my efforts. I might just print out a differently-ordered list and leave it at that for a bit.
Cheers