Skip to content
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

Add project and take markers action #1133

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
29 changes: 17 additions & 12 deletions config/mac/reaper-kb.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ACT 1 32060 "53b7b74114d130409a9fd4d31c97ebe4" "Custom: Select and quantize note
ACT 1 32061 "4a1c1a073e300c4cb987bb7b787bd065" "Custom: Move edit cursor to end of file" 40037 _OSARA_FOCUSMIDIEVENT
ACT 1 32061 "9752206b806c41488273e8bf51d94c48" "Custom: move edit cursor to start of file" 40036 _OSARA_FOCUSMIDIEVENT
SCR 4 0 RS1cbf05b0c4f875518496f34a5ce45adefe05cb67 "Custom: Default_6.0_theme_adjuster.lua" Cockos/Default_6.0_theme_adjuster.lua
SCR 4 0 RS6c2efb3f983d062c88752f161da4cbbd6ab222e9 "Custom: Default_7.0_theme_adjuster.lua" Cockos/Default_7.0_theme_adjuster.lua
SCR 4 0 RS1ee9bb229dabffe151848d7efa3c10f748e1a1cf "Custom: lyrics.lua" Cockos/lyrics.lua
SCR 4 32060 RS7d3c_1ee9bb229dabffe151848d7efa3c10f748e1a1cf "Custom: lyrics.lua" Cockos/lyrics.lua
KEY 0 63 0 0 # Main : ? : DISABLED DEFAULT
Expand Down Expand Up @@ -299,6 +300,8 @@ KEY 17 85 41997 0 # Main : Opt+U : Track: Move tracks to subproject
KEY 13 73 42082 0 # Main : Cmd+Shift+I : Envelope: Insert automation item
KEY 5 73 42235 0 # Main : Shift+I : Track: View routing and I/O for master track
KEY 9 114 42348 0 # Main : Cmd+F3 : Reset all MIDI control surface devices
KEY 8 58 42393 0 # Main : Cmd+: : Item: Set cursor to previous take marker in selected items
KEY 8 34 42394 0 # Main : Cmd+" : Item: Set cursor to next take marker in selected items
KEY 5 117 42455 0 # Main : Shift+F6 : OVERRIDE DEFAULT : FX: Toggle delta solo for last focused FX
KEY 13 78 42460 0 # Main : Cmd+Shift+N : OVERRIDE DEFAULT : Item properties: Normalize items (peak/RMS/LUFS)...
KEY 21 117 42467 0 # Main : Opt+Shift+F6 : FX: Clear delta solo for all project FX
Expand All @@ -321,6 +324,8 @@ KEY 37 81 _FNG_QUANTIZE_TO_GRID 0 # Main : Shift+Control+Q : SWS/FNG: Quantize
KEY 24 45 _FNG_RATE_101 0 # Main : Cmd+Opt+- : SWS/FNG: Time compress selected items (fine)
KEY 24 61 _FNG_RATE_1_101 0 # Main : Cmd+Opt+= : SWS/FNG: Time stretch selected items (fine)
KEY 9 112 _OSARA_ABOUT 0 # Main : Cmd+F1 : OVERRIDE DEFAULT : OSARA: About
KEY 5 77 _OSARA_ADDEDITPROJTAKEMARKER 0 # Main : Shift+M : OVERRIDE DEFAULT : OSARA: Add/edit project or take marker at cursor (depending on focus)
KEY 1 77 _OSARA_ADDPROJTAKEMARKER 0 # Main : M : OVERRIDE DEFAULT : OSARA: Add project or take marker at cursor (depending on focus)
KEY 9 123 _OSARA_CONFIG 0 # Main : Cmd+F12 : OSARA: Configuration
KEY 0 16 _OSARA_CONTEXTMENU1 0 # Main : k!16 : OSARA: Show first context menu (depending on focus)
KEY 33 49 _OSARA_CONTEXTMENU1 0 # Main : Control+1 : OSARA: Show first context menu (depending on focus)
Expand Down Expand Up @@ -492,27 +497,27 @@ KEY 5 80 40183 32060 # MIDI Editor : Shift+P : Edit: Move notes left one grid
KEY 1 80 40184 32060 # MIDI Editor : P : Edit: Move notes right one grid unit
KEY 17 32805 40185 32060 # MIDI Editor : Opt+Left : OVERRIDE DEFAULT : Edit: Move edit cursor left one pixel
KEY 17 32807 40186 32060 # MIDI Editor : Opt+Right : OVERRIDE DEFAULT : Edit: Move edit cursor right one pixel
KEY 1 48 40189 32060 # MIDI Editor : 0 : Grid: Set to 1/48 (1/32 triplet)
KEY 32 41 40189 32060 # MIDI Editor : Control+) : Grid: Set to 1/48 (1/32 triplet)
KEY 8 41 40189 32060 # MIDI Editor : Cmd+) : Grid: Set to 1/48 (1/32 triplet)
KEY 1 48 40189 32060 # MIDI Editor : 0 : Grid: Set to 1/48 (1/32 note triplet)
KEY 32 41 40189 32060 # MIDI Editor : Control+) : Grid: Set to 1/48 (1/32 note triplet)
KEY 8 41 40189 32060 # MIDI Editor : Cmd+) : Grid: Set to 1/48 (1/32 note triplet)
KEY 1 51 40190 32060 # MIDI Editor : 3 : Grid: Set to 1/32
KEY 13 51 40190 32060 # MIDI Editor : Cmd+Shift+3 : Grid: Set to 1/32
KEY 32 35 40190 32060 # MIDI Editor : Control+# : Grid: Set to 1/32
KEY 1 55 40191 32060 # MIDI Editor : 7 : Grid: Set to 1/24 (1/16 triplet)
KEY 13 55 40191 32060 # MIDI Editor : Cmd+Shift+7 : Grid: Set to 1/24 (1/16 triplet)
KEY 32 38 40191 32060 # MIDI Editor : Control+& : Grid: Set to 1/24 (1/16 triplet)
KEY 1 55 40191 32060 # MIDI Editor : 7 : Grid: Set to 1/24 (1/16 note triplet)
KEY 13 55 40191 32060 # MIDI Editor : Cmd+Shift+7 : Grid: Set to 1/24 (1/16 note triplet)
KEY 32 38 40191 32060 # MIDI Editor : Control+& : Grid: Set to 1/24 (1/16 note triplet)
KEY 1 54 40192 32060 # MIDI Editor : 6 : Grid: Set to 1/16
KEY 13 54 40192 32060 # MIDI Editor : Cmd+Shift+6 : Grid: Set to 1/16
KEY 32 94 40192 32060 # MIDI Editor : Control+^ : Grid: Set to 1/16
KEY 1 57 40193 32060 # MIDI Editor : 9 : Grid: Set to 1/12 (1/8 triplet)
KEY 13 57 40193 32060 # MIDI Editor : Cmd+Shift+9 : Grid: Set to 1/12 (1/8 triplet)
KEY 32 40 40193 32060 # MIDI Editor : Control+( : Grid: Set to 1/12 (1/8 triplet)
KEY 1 57 40193 32060 # MIDI Editor : 9 : Grid: Set to 1/12 (1/8 note triplet)
KEY 13 57 40193 32060 # MIDI Editor : Cmd+Shift+9 : Grid: Set to 1/12 (1/8 note triplet)
KEY 32 40 40193 32060 # MIDI Editor : Control+( : Grid: Set to 1/12 (1/8 note triplet)
KEY 1 56 40197 32060 # MIDI Editor : 8 : Grid: Set to 1/8
KEY 13 56 40197 32060 # MIDI Editor : Cmd+Shift+8 : Grid: Set to 1/8
KEY 32 42 40197 32060 # MIDI Editor : Control+* : Grid: Set to 1/8
KEY 1 53 40199 32060 # MIDI Editor : 5 : Grid: Set to 1/6 (1/4 triplet)
KEY 13 53 40199 32060 # MIDI Editor : Cmd+Shift+5 : Grid: Set to 1/6 (1/4 triplet)
KEY 32 37 40199 32060 # MIDI Editor : Control+% : Grid: Set to 1/6 (1/4 triplet)
KEY 1 53 40199 32060 # MIDI Editor : 5 : Grid: Set to 1/6 (1/4 note triplet)
KEY 13 53 40199 32060 # MIDI Editor : Cmd+Shift+5 : Grid: Set to 1/6 (1/4 note triplet)
KEY 32 37 40199 32060 # MIDI Editor : Control+% : Grid: Set to 1/6 (1/4 note triplet)
KEY 1 52 40201 32060 # MIDI Editor : 4 : Grid: Set to 1/4
KEY 13 52 40201 32060 # MIDI Editor : Cmd+Shift+4 : Grid: Set to 1/4
KEY 32 36 40201 32060 # MIDI Editor : Control+$ : Grid: Set to 1/4
Expand Down
4 changes: 4 additions & 0 deletions config/windows/reaper-kb.ini
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ KEY 17 85 41997 0 # Main : Alt+U : Track: Move tracks to subproject
KEY 13 73 42082 0 # Main : Ctrl+Shift+I : Envelope: Insert automation item
KEY 5 73 42235 0 # Main : Shift+I : Track: View routing and I/O for master track
KEY 9 114 42348 0 # Main : Ctrl+F3 : Reset all MIDI control surface devices
KEY 13 186 42393 0 # Main : Ctrl+Shift+; : Item: Set cursor to previous take marker in selected items
KEY 13 222 42394 0 # Main : Ctrl+Shift+# : Item: Set cursor to next take marker in selected items
KEY 5 117 42455 0 # Main : Shift+F6 : OVERRIDE DEFAULT : FX: Toggle delta solo for last focused FX
KEY 13 78 42460 0 # Main : Ctrl+Shift+N : OVERRIDE DEFAULT : Item properties: Normalize items (peak/RMS/LUFS)...
KEY 21 117 42467 0 # Main : Alt+Shift+F6 : FX: Clear delta solo for all project FX
Expand Down Expand Up @@ -312,6 +314,8 @@ KEY 13 81 _FNG_QUANTIZE_TO_GRID 0 # Main : Ctrl+Shift+Q : SWS/FNG: Quantize it
KEY 25 189 _FNG_RATE_101 0 # Main : Ctrl+Alt+- : SWS/FNG: Time compress selected items (fine)
KEY 25 187 _FNG_RATE_1_101 0 # Main : Ctrl+Alt+= : SWS/FNG: Time stretch selected items (fine)
KEY 9 112 _OSARA_ABOUT 0 # Main : Ctrl+F1 : OVERRIDE DEFAULT : OSARA: About
KEY 5 77 _OSARA_ADDEDITPROJTAKEMARKER 0 # Main : Shift+M : OVERRIDE DEFAULT : OSARA: Add/edit project or take marker at cursor (depending on focus)
KEY 1 77 _OSARA_ADDPROJTAKEMARKER 0 # Main : M : OVERRIDE DEFAULT : OSARA: Add project or take marker at cursor (depending on focus)
KEY 9 123 _OSARA_CONFIG 0 # Main : Ctrl+F12 : OSARA: Configuration
KEY 13 74 _OSARA_CURSORPOS 0 # Main : Ctrl+Shift+J : OSARA: Report edit/play cursor position, transport state and nearest markers and regions
KEY 25 74 _OSARA_CYCLEENVELOPEPOINTSHAPE 0 # Main : Ctrl+Alt+J : OSARA: Cycle shape of selected envelope points
Expand Down
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ SWS/FNG: Time stretch selected items (fine): Control+Alt+=
- FX: Show/hide track envelope for last touched FX parameter: Control+Alt+L

#### Markers and Regions
- OSARA: Add project or take marker at cursor (depending on focus): M
- OSARA: Add/edit project or take marker at cursor (depending on focus): Shift+M
- Markers: Go to previous marker/project start: ;
- Markers: Go to next marker/project end: '
- Item: Set cursor to previous take marker in selected items: Control+Shift+;
- Item: Set cursor to next take marker in selected items: Control+Shift+'
- Markers: Go to marker 01: 1
- Markers: Go to marker 02: 2
- Markers: Go to marker 03: 3
Expand All @@ -220,7 +224,6 @@ SWS/FNG: Time stretch selected items (fine): Control+Alt+=
- Markers: Go to marker 08: 8
- Markers: Go to marker 09: 9
- Markers: Go to marker 10: 0
- Markers: Insert marker at current position: M
- Regions: Go to region 01 after current region finishes playing (smooth seek): Alt+1
- Regions: Go to region 02 after current region finishes playing (smooth seek): Alt+2
- Regions: Go to region 03 after current region finishes playing (smooth seek): Alt+3
Expand Down Expand Up @@ -876,8 +879,6 @@ This list is worth referencing when making your own key map additions, assigning
- Item: Nudge items volume +1dB
- Item: Nudge items volume -1dB
- Item: remove stretch marker at current position
- Item: Set cursor to next take marker in selected items
- Item: Set cursor to previous take marker in selected items
- Item: Delete take marker at cursor
- Item: Delete all take markers
- Markers: Delete time signature marker near cursor
Expand Down
43 changes: 42 additions & 1 deletion src/reaper_osara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4793,8 +4793,33 @@ void cmdInsertMarker(Command* command) {
Main_OnCommand(command->gaccel.accel.cmd, 0);
return;
}
if(CountSelectedMediaItems(0)>0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are no selected items, this means we will never pass the command to REAPER. Practically, this should be fine, since REAPER will probably do nothing in the case of 0 selected items. However, when intercepting commands, I do think we should always pass them to REAPER, on the very slight chance that REAPER does something we don't expect, either now or in future. Otherwise, the action will just do nothing, even if it would have done something without OSARA installed.

You could either:

  1. Check if the item count is 0, call Main_OnCommand and return; or
  2. Don't check at all and rely on the fact that 0 items means the loops will do nothing.

vector<int> preMarkers(CountSelectedMediaItems(nullptr));
for(int i = 0; i < preMarkers.size(); ++ i) {
MediaItem* item = GetSelectedMediaItem(nullptr, i);
MediaItem_Take* take = GetActiveTake(item);
preMarkers[i] = GetNumTakeMarkers(take);
}
Main_OnCommand(42390, 0); // Item: Quick add take marker at play position or edit cursor
int addedMarkers = 0;
for(int i = 0; i < preMarkers.size(); ++ i) {
MediaItem* item = GetSelectedMediaItem(nullptr, i);
MediaItem_Take* take = GetActiveTake(item);
if (preMarkers[i] < GetNumTakeMarkers(take)) {
++ addedMarkers;
}
}
if (addedMarkers == 0) {
return; // not inserted
} else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for an else block if you always return in the if above it. This also simplifies things by avoiding a level of nesting.

// Translators: Reported when using REAPER's quick add take marker action. If more than one take marker is inserted, [] will be replaced with the number of markers. E.G. "2 take markers inserted".
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[] should be {}

Suggested change
// Translators: Reported when using REAPER's quick add take marker action. If more than one take marker is inserted, [] will be replaced with the number of markers. E.G. "2 take markers inserted".
// Translators: Reported when using REAPER's quick add take marker action. If more than one take marker is inserted, {} will be replaced with the number of markers. E.G. "2 take markers inserted".

outputMessage(format(
translate_plural("take marker inserted", "{} take markers inserted", addedMarkers), addedMarkers));
return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for a return if it's the last thing in the function and the function returns nothing.

Suggested change
return;

}
}
int count = CountProjectMarkers(nullptr, nullptr, nullptr);
Main_OnCommand(command->gaccel.accel.cmd, 0);
Main_OnCommand(40157, 0);
if (CountProjectMarkers(nullptr, nullptr, nullptr) == count) {
return; // Not inserted.
}
Expand All @@ -4810,6 +4835,20 @@ void cmdInsertMarker(Command* command) {
outputMessage(format(translate("marker {} inserted"), number));
}

void cmdInsertOrEditMarker(Command* command) {
double start, end;
GetSet_LoopTimeRange(false, true, &start, &end, false);
if (start != end && CountSelectedMediaItems(nullptr)>0) {
Main_OnCommand(43181, 0); // Item: Add/edit take marker at time selection
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The action is called "OSARA: Add project or take marker at cursor (depending on focus)". It doesn't mention time selection. Should it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Urgh, just realised that I renamed the wrong action. Time selection is only relevant when using the add/edit one. Another commit coming up shortly.

return;
} else if(CountSelectedMediaItems(nullptr) > 0) {
Main_OnCommand(42385, 0); // Item: Add/edit take marker at play position or edit cursor
} else {
Main_OnCommand(40171, 0); // Markers: Insert and/or edit marker at current position
return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary return.

Suggested change
return;

}
}

void cmdInsertRegion(Command* command) {
if (!shouldReportTimeMovement()) {
Main_OnCommand(command->gaccel.accel.cmd, 0);
Expand Down Expand Up @@ -5252,6 +5291,8 @@ Command COMMANDS[] = {
{MAIN_SECTION, {DEFACCEL, _t("OSARA: Check for update")}, "OSARA_UPDATE", cmdCheckForUpdate},
{MAIN_SECTION, {DEFACCEL, _t("OSARA: Open online documentation")}, "OSARA_OPENDOC", cmdOpenDoc},
{MAIN_SECTION, {DEFACCEL, _t("OSARA: Report tempo and time signature at play cursor; press twice to add/edit tempo markers")}, "OSARA_MANAGETEMPOTIMESIGMARKERS", cmdManageTempoTimeSigMarkers},
{MAIN_SECTION, {DEFACCEL, _t("OSARA: Add project or take marker at cursor (depending on focus)")}, "OSARA_ADDPROJTAKEMARKER", cmdInsertMarker},
{MAIN_SECTION, {DEFACCEL, _t("OSARA: Add/edit project or take marker at cursor (depending on focus)")}, "OSARA_ADDEDITPROJTAKEMARKER", cmdInsertOrEditMarker},
{MIDI_EDITOR_SECTION, {DEFACCEL, _t("OSARA: Enable noncontiguous selection/toggle selection of current chord/note")}, "OSARA_MIDITOGGLESEL", cmdMidiToggleSelection},
{MIDI_EDITOR_SECTION, {DEFACCEL, _t("OSARA: Move to next chord")}, "OSARA_NEXTCHORD", cmdMidiMoveToNextChord},
{MIDI_EDITOR_SECTION, {DEFACCEL, _t("OSARA: Move to previous chord")}, "OSARA_PREVCHORD", cmdMidiMoveToPreviousChord},
Expand Down