Skip to content

Commit 9bc1ce0

Browse files
authored
Fix broken menu items in the Extensions -> OSARA menu on Mac. (issue #1218, PR #1219)
In #1180, OSARA started registering all commands shortly after startup instead of immediately on startup. This was done to enable interception of SWS commands. Unfortunately, this broke items in the OSARA menu on Mac. Presumably, the menu hook gets called slightly earlier on Mac, before our commands get registered, and so our menu items can't be associated with the correct command. To fix this, we now register OSARA's commands immediately on startup, but we continue to register other commands that we want to intercept slightly later. Developers should note that OSARA's own commands are now listed in the OSARA_COMMANDS array, not the COMMANDS array.
1 parent de958da commit 9bc1ce0

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

Diff for: src/reaper_osara.cpp

+29-22
Original file line numberDiff line numberDiff line change
@@ -5295,8 +5295,8 @@ void cmdJumpToTime(Command* command) {
52955295

52965296
#define DEFACCEL {0, 0, 0}
52975297

5298+
// REAPER or extension commands that we want to intercept.
52985299
Command COMMANDS[] = {
5299-
// Commands we want to intercept.
53005300
{MAIN_SECTION, {{0, 0, 40285}, nullptr}, nullptr, cmdGoToNextTrack}, // Track: Go to next track
53015301
{MAIN_SECTION, {{0, 0, 40286}, nullptr}, nullptr, cmdGoToPrevTrack}, // Track: Go to previous track
53025302
{MAIN_SECTION, {{0, 0, 40287}, nullptr}, nullptr, cmdGoToNextTrackKeepSel}, // Track: Go to next track (leaving other tracks selected)
@@ -5432,7 +5432,10 @@ Command COMMANDS[] = {
54325432
{MIDI_EVENT_LIST_SECTION, {{ 0, 0, 40762}, nullptr}, nullptr, cmdMidiFilterWindow}, // Filter: Show/hide filter window...
54335433
{MIDI_EVENT_LIST_SECTION, {{ 0, 0, 40471}, nullptr}, nullptr, cmdMidiFilterWindow}, // Filter: Enable/disable event filter and show/hide filter window...
54345434
#endif
5435-
// Our own commands.
5435+
};
5436+
5437+
// Our own commands.
5438+
Command OSARA_COMMANDS[] = {
54365439
{MAIN_SECTION, {DEFACCEL, _t("OSARA: Move to next item (leaving other items selected)")}, "OSARA_NEXTITEMKEEPSEL", cmdMoveToNextItemKeepSel},
54375440
{MAIN_SECTION, {DEFACCEL, _t("OSARA: Move to previous item (leaving other items selected)")}, "OSARA_PREVITEMKEEPSEL", cmdMoveToPrevItemKeepSel},
54385441
{MAIN_SECTION, {DEFACCEL, _t("OSARA: View properties for current media item/take/automation item (depending on focus)")}, "OSARA_PROPERTIES", cmdPropertiesFocus},
@@ -5526,8 +5529,8 @@ Command COMMANDS[] = {
55265529
#endif
55275530
{ MIDI_EVENT_LIST_SECTION, {DEFACCEL, _t("OSARA: Mute next message from OSARA")}, "OSARA_ML_MUTENEXTMESSAGE", cmdMuteNextMessage},
55285531
{ MEDIA_EXPLORER_SECTION, {DEFACCEL, _t("OSARA: Mute next message from OSARA")}, "OSARA_MX_MUTENEXTMESSAGE", cmdMuteNextMessage},
5529-
{0, {}, nullptr, nullptr},
55305532
};
5533+
55315534
map<pair<int, int>, Command*> commandsMap;
55325535

55335536
/*** Initialisation, termination and inner workings. */
@@ -5743,31 +5746,19 @@ void delayedInit() {
57435746
NF_GetSWSTrackNotes = (decltype(NF_GetSWSTrackNotes))plugin_getapi(
57445747
"NF_GetSWSTrackNotes");
57455748

5746-
for (int i = 0; COMMANDS[i].execute; ++i) {
5747-
if (COMMANDS[i].id && COMMANDS[i].gaccel.desc) {
5748-
// This is our own command.
5749-
if (COMMANDS[i].section == MAIN_SECTION) {
5750-
COMMANDS[i].gaccel.accel.cmd = plugin_register("command_id", (void*)COMMANDS[i].id);
5751-
COMMANDS[i].gaccel.desc = translate(COMMANDS[i].gaccel.desc);
5752-
plugin_register("gaccel", &COMMANDS[i].gaccel);
5753-
} else {
5754-
custom_action_register_t action;
5755-
action.uniqueSectionId = COMMANDS[i].section;
5756-
action.idStr = COMMANDS[i].id;
5757-
action.name = translate(COMMANDS[i].gaccel.desc);
5758-
COMMANDS[i].gaccel.accel.cmd = plugin_register("custom_action", &action);
5759-
}
5760-
} else if (COMMANDS[i].id) {
5749+
for (Command& command: COMMANDS) {
5750+
if (command.id) {
57615751
// This command is provided by an extension.
5762-
COMMANDS[i].gaccel.accel.cmd = NamedCommandLookup(COMMANDS[i].id);
5763-
KbdSectionInfo* section = SectionFromUniqueID(COMMANDS[i].section);
5764-
if (!kbd_getTextFromCmd(COMMANDS[i].gaccel.accel.cmd, section)[0]) {
5752+
command.gaccel.accel.cmd = NamedCommandLookup(command.id);
5753+
KbdSectionInfo* section = SectionFromUniqueID(command.section);
5754+
if (!kbd_getTextFromCmd(command.gaccel.accel.cmd, section)[0]) {
57655755
// This action hasn't been registered by an extension. The extension
57665756
// probably isn't installed.
57675757
continue;
57685758
}
57695759
}
5770-
commandsMap.insert(make_pair(make_pair(COMMANDS[i].section, COMMANDS[i].gaccel.accel.cmd), &COMMANDS[i]));
5760+
commandsMap.insert(make_pair(make_pair(command.section,
5761+
command.gaccel.accel.cmd), &command));
57715762
}
57725763

57735764
KbdSectionInfo* section = SectionFromUniqueID(MAIN_SECTION);
@@ -6007,6 +5998,22 @@ REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(REAPER_PLUGIN_HINSTANCE hI
60075998
}
60085999
}
60096000

6001+
for (Command& command: OSARA_COMMANDS) {
6002+
if (command.section == MAIN_SECTION) {
6003+
command.gaccel.accel.cmd = rec->Register("command_id", (void*)command.id);
6004+
command.gaccel.desc = translate(command.gaccel.desc);
6005+
rec->Register("gaccel", &command.gaccel);
6006+
} else {
6007+
custom_action_register_t action;
6008+
action.uniqueSectionId = command.section;
6009+
action.idStr = command.id;
6010+
action.name = translate(command.gaccel.desc);
6011+
command.gaccel.accel.cmd = rec->Register("custom_action", &action);
6012+
}
6013+
commandsMap.insert(make_pair(make_pair(command.section,
6014+
command.gaccel.accel.cmd), &command));
6015+
}
6016+
60106017
registerSettingCommands();
60116018
// hookcommand can only handle actions for the main section, so we need hookcommand2.
60126019
// According to SWS, hookcommand2 must be registered before hookcommand.

0 commit comments

Comments
 (0)