Skip to content

Commit 001ef35

Browse files
Refactored to make adding menus easier and improve readability
1 parent e04f10e commit 001ef35

File tree

1 file changed

+70
-127
lines changed

1 file changed

+70
-127
lines changed

src/reaper_osara.cpp

Lines changed: 70 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,16 @@ bool isFreeItemPositioningEnabled(MediaTrack* track) {
646646
return *(bool*)GetSetMediaTrackInfo(track, "B_FREEMODE", nullptr);
647647
}
648648

649+
bool doesAnySelectedTrackHaveItems () {
650+
int trackCount = CountTracks(nullptr);
651+
for (int i = 0; i < trackCount; ++i) {
652+
MediaTrack* tr = GetTrack(nullptr, i);
653+
if (isTrackSelected(tr) && CountTrackMediaItems(tr) > 0)
654+
return true;
655+
}
656+
return false;
657+
}
658+
649659
const char* automationModeAsString(int mode) {
650660
// this works for track automation mode and global automation override.
651661
switch (mode) {
@@ -5621,156 +5631,89 @@ void cmdReportAndEditScrubSegmentOffsets(Command* command) {
56215631
Main_OnCommand(43632, 0); // Scrub: Prompt to edit looped-segment scrub range
56225632
}
56235633

5634+
// Helper for adding a menu item
5635+
static void AddMenuItem(HMENU menu, int position, const char* label, UINT id, bool enabled = true) {
5636+
MENUITEMINFO info = {};
5637+
info.cbSize = sizeof(MENUITEMINFO);
5638+
info.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
5639+
info.fType = MFT_STRING;
5640+
info.dwTypeData = (char*)translate(label);
5641+
info.cch = strlen(info.dwTypeData);
5642+
info.wID = id;
5643+
info.fState = enabled ? MFS_ENABLED : MFS_DISABLED;
5644+
InsertMenuItem(menu, position, true, &info);
5645+
}
5646+
5647+
// Helper for creating a submenu (returns the submenu handle)
5648+
static HMENU AddSubMenu(HMENU parent, int position, const char* label, bool enabled = true) {
5649+
MENUITEMINFO info = {};
5650+
info.cbSize = sizeof(MENUITEMINFO);
5651+
info.fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_STATE;
5652+
info.fType = MFT_STRING;
5653+
info.dwTypeData = (char*)translate(label);
5654+
info.cch = strlen(info.dwTypeData);
5655+
info.hSubMenu = CreatePopupMenu();
5656+
info.fState = enabled ? MFS_ENABLED : MFS_DISABLED;
5657+
InsertMenuItem(parent, position, true, &info);
5658+
return info.hSubMenu;
5659+
}
5660+
56245661
void cmdShowPeakAndLoudnessMenu(Command* command) {
56255662
double startTS, endTS;
56265663
GetSet_LoopTimeRange(false, false, &startTS, &endTS, false);
5664+
int countTracks = CountTracks(nullptr);
56275665
int selTracks = CountSelectedTracks2(nullptr, true);
5666+
int itemCount = CountMediaItems(nullptr);
56285667
int selItems = CountSelectedMediaItems(nullptr);
5668+
bool selTracksHaveItems = doesAnySelectedTrackHaveItems();
56295669
HMENU menu = CreatePopupMenu();
5630-
MENUITEMINFO itemInfo;
5631-
itemInfo.cbSize = sizeof(MENUITEMINFO);
56325670
// Master submenu
5633-
itemInfo.fMask = MIIM_TYPE | MIIM_SUBMENU;
5634-
HMENU subMenu = CreatePopupMenu();
5635-
itemInfo.hSubMenu = subMenu;
5636-
itemInfo.fType = MFT_STRING;
5671+
bool nothingToDryRun = (startTS == endTS) && (countTracks == 0 || itemCount == 0);
56375672
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5638-
itemInfo.dwTypeData = (char*)translate("Master");
5639-
itemInfo.cch = strlen(itemInfo.dwTypeData);
5640-
InsertMenuItem(menu, 0, true, &itemInfo);
5641-
// Master -> Master mix (ID 1)
5642-
itemInfo.fMask = MIIM_TYPE | MIIM_ID;
5643-
itemInfo.fType = MFT_STRING;
5644-
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5645-
itemInfo.dwTypeData = (char*)translate("Master mix");
5646-
itemInfo.cch = strlen(itemInfo.dwTypeData);
5647-
itemInfo.wID = 1;
5648-
InsertMenuItem(subMenu, 0, true, &itemInfo);
5649-
// Master -> Time selection (ID 2)
5650-
itemInfo.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
5651-
itemInfo.fType = MFT_STRING;
5652-
if (startTS == endTS) {
5653-
itemInfo.fState = MFS_DISABLED;
5654-
} else {
5655-
itemInfo.fState = MFS_ENABLED;
5673+
HMENU masterSub = AddSubMenu(menu, 0, "Master", !nothingToDryRun);
5674+
if (!nothingToDryRun) {
5675+
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5676+
AddMenuItem(masterSub, 0, "Master mix", 1, itemCount != 0);
5677+
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5678+
AddMenuItem(masterSub, 1, "Time &selection", 2, startTS != endTS);
56565679
}
5657-
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5658-
itemInfo.dwTypeData = (char*)translate("Time &selection");
5659-
itemInfo.cch = strlen(itemInfo.dwTypeData);
5660-
itemInfo.wID = 2;
5661-
InsertMenuItem(subMenu, 1, true, &itemInfo);
56625680
// Tracks submenu
5663-
itemInfo.fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_STATE;
5664-
subMenu = CreatePopupMenu();
5665-
itemInfo.hSubMenu = subMenu;
5666-
itemInfo.fType = MFT_STRING;
56675681
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5668-
itemInfo.dwTypeData = (char*)translate("Tracks");
5669-
itemInfo.cch = strlen(itemInfo.dwTypeData);
5670-
if(selTracks > 0) itemInfo.fState = MFS_ENABLED;
5671-
else itemInfo.fState = MFS_DISABLED;
5672-
InsertMenuItem(menu, 1, true, &itemInfo);
5682+
HMENU tracksSub = AddSubMenu(menu, 1, "Tracks", selTracks > 0);
56735683
if (selTracks > 0) {
5674-
// Tracks -> Selected tracks (ID 3)
5675-
itemInfo.fMask = MIIM_TYPE | MIIM_ID;
5676-
itemInfo.fType = MFT_STRING;
56775684
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5678-
itemInfo.dwTypeData = (char*)translate("Selected &tracks");
5679-
itemInfo.cch = strlen(itemInfo.dwTypeData);
5680-
itemInfo.wID = 3;
5681-
InsertMenuItem(subMenu, 0, true, &itemInfo);
5682-
// Tracks -> Time selection (ID 4)
5683-
itemInfo.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
5684-
itemInfo.fType = MFT_STRING;
5685-
if (startTS == endTS) {
5686-
itemInfo.fState = MFS_DISABLED;
5687-
} else {
5688-
itemInfo.fState = MFS_ENABLED;
5689-
}
5685+
AddMenuItem(tracksSub, 0, "Selected &tracks", 3, selTracksHaveItems);
56905686
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5691-
itemInfo.dwTypeData = (char*)translate("Time &selection");
5692-
itemInfo.cch = strlen(itemInfo.dwTypeData);
5693-
itemInfo.wID = 4;
5694-
InsertMenuItem(subMenu, 1, true, &itemInfo);
5695-
// Tracks -> Selected tracks mono summed (ID 5)
5696-
itemInfo.fMask = MIIM_TYPE | MIIM_ID;
5697-
itemInfo.fType = MFT_STRING;
5687+
AddMenuItem(tracksSub, 1, "Time &selection", 4, startTS != endTS);
56985688
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5699-
itemInfo.dwTypeData = (char*)translate("&Mono summed selected tracks");
5700-
itemInfo.cch = strlen(itemInfo.dwTypeData);
5701-
itemInfo.wID = 5;
5702-
InsertMenuItem(subMenu, 2, true, &itemInfo);
5703-
// Tracks -> Mono summed time selection (ID 6)
5704-
itemInfo.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
5705-
itemInfo.fType = MFT_STRING;
5706-
if (startTS == endTS) {
5707-
itemInfo.fState = MFS_DISABLED;
5708-
} else {
5709-
itemInfo.fState = MFS_ENABLED;
5710-
}
5689+
AddMenuItem(tracksSub, 2, "&Mono summed selected tracks", 5, selTracksHaveItems);
57115690
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5712-
itemInfo.dwTypeData = (char*)translate("Time &selection");
5713-
itemInfo.cch = strlen(itemInfo.dwTypeData);
5714-
itemInfo.wID = 6;
5715-
InsertMenuItem(subMenu, 3, true, &itemInfo);
5691+
AddMenuItem(tracksSub, 3, "Mono summed time selection", 6, startTS != endTS);
57165692
}
57175693
// Items submenu
5718-
itemInfo.fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_STATE;
5719-
subMenu = CreatePopupMenu();
5720-
itemInfo.hSubMenu = subMenu;
5721-
itemInfo.fType = MFT_STRING;
57225694
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5723-
itemInfo.dwTypeData = (char*)translate("Items");
5724-
itemInfo.cch = strlen(itemInfo.dwTypeData);
5725-
if(selItems > 0) itemInfo.fState = MFS_ENABLED;
5726-
else itemInfo.fState = MFS_DISABLED;
5727-
InsertMenuItem(menu, 2, true, &itemInfo);
5695+
HMENU itemsSub = AddSubMenu(menu, 2, "Items", selItems > 0);
57285696
if (selItems > 0) {
5729-
// Items -> Selected items (ID 7)
5730-
itemInfo.fMask = MIIM_TYPE | MIIM_ID;
5731-
itemInfo.fType = MFT_STRING;
57325697
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5733-
itemInfo.dwTypeData = (char*)translate("Selected &items");
5734-
itemInfo.cch = strlen(itemInfo.dwTypeData);
5735-
itemInfo.wID = 7;
5736-
InsertMenuItem(subMenu, 0, true, &itemInfo);
5737-
// Items -> Include track/take FX and settings (ID 8)
5738-
itemInfo.fMask = MIIM_TYPE | MIIM_ID;
5739-
itemInfo.fType = MFT_STRING;
5698+
AddMenuItem(itemsSub, 0, "Selected &items", 7);
57405699
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5741-
itemInfo.dwTypeData = (char*)translate("Include track/take &FX and settings");
5742-
itemInfo.cch = strlen(itemInfo.dwTypeData);
5743-
itemInfo.wID = 8;
5744-
InsertMenuItem(subMenu, 1, true, &itemInfo);
5745-
}
5746-
int id = TrackPopupMenu(menu, TPM_NONOTIFY | TPM_RETURNCMD, 0, 0, 0,
5747-
mainHwnd, nullptr);
5748-
switch(id) {
5700+
AddMenuItem(itemsSub, 1, "Include track/take &FX and settings", 8);
5701+
}
5702+
// Translators: An entry in OSARA's context menu for analyzing loudness statistics.
5703+
AddMenuItem(menu, 3, "Dry run project using the most recent render settings", 9);
5704+
// Displaying and handling result
5705+
int id = TrackPopupMenu(menu, TPM_NONOTIFY | TPM_RETURNCMD, 0, 0, 0, mainHwnd, nullptr);
5706+
switch (id) {
57495707
case 0: return; // canceled
5750-
case 1:
5751-
Main_OnCommand(42440, 0); // Calculate loudness of master mix via dry run render
5752-
break;
5753-
case 2:
5754-
Main_OnCommand(42441, 0); // Calculate loudness of master mix within time selection via dry run render
5755-
break;
5756-
case 3:
5757-
Main_OnCommand(42438, 0); // Calculate loudness of selected tracks via dry run render
5758-
break;
5759-
case 4:
5760-
Main_OnCommand(42439, 0); // Calculate loudness of selected tracks within time selection via dry run render
5761-
break;
5762-
case 5:
5763-
Main_OnCommand(42447, 0); // Calculate mono loudness of selected tracks via dry run render
5764-
break;
5765-
case 6:
5766-
Main_OnCommand(42448, 0); // Calculate mono loudness of selected tracks within time selection via dry run render
5767-
break;
5768-
case 7:
5769-
Main_OnCommand(42468, 0); // Calculate loudness of selected items via dry run render
5770-
break;
5771-
case 8:
5772-
Main_OnCommand(42437, 0); // Calculate loudness of selected items, including take and track FX and settings, via dry run render
5773-
break;
5708+
case 1:Main_OnCommand(42440, 0); break; // Master mix
5709+
case 2: Main_OnCommand(42441, 0); break; // Master mix within time selection
5710+
case 3: Main_OnCommand(42438, 0); break; // Selected tracks
5711+
case 4: Main_OnCommand(42439, 0); break; // Selected tracks within time selection
5712+
case 5: Main_OnCommand(42447, 0); break; // Mono selected tracks
5713+
case 6: Main_OnCommand(42448, 0); break; // Mono selected tracks within time selection
5714+
case 7: Main_OnCommand(42468, 0); break; // Selected items
5715+
case 8: Main_OnCommand(42437, 0); break; // Selected items with FX
5716+
case 9: Main_OnCommand(43349, 0); break; // Dry run project using the most recent render settings
57745717
}
57755718
}
57765719

0 commit comments

Comments
 (0)