Skip to content

Commit

Permalink
Make edit highest marker script work when only 1 marker
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyBars3k committed Oct 20, 2023
1 parent 326a26f commit 7918879
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions Utilities/MB_Edit project marker with highest index at position.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ reaper.Undo_BeginBlock()
reaper.PreventUIRefresh(1)

local _highest_marker_number, _marker_idx_to_edit, _first_marker_idx, _first_marker_name, _first_marker_color, _cursor_pos, _num_markers, _num_regions, _command_id__edit_marker_near_cursor

_highest_marker_number = -1
_marker_idx_to_edit = -1
_first_marker_idx = -1
Expand All @@ -18,31 +17,32 @@ for i = 0, _num_markers + _num_regions - 1 do
local retval, isrgn, pos, rgnend, name, markrgnindexnumber, color = reaper.EnumProjectMarkers(i)

if not isrgn and math.abs(pos - _cursor_pos) < 1e-5 then

if _first_marker_idx == -1 then
_first_marker_idx, _first_marker_name, _first_marker_color = i, name, color
end

if markrgnindexnumber > _highest_marker_number then
if markrgnindexnumber >= _highest_marker_number then
_highest_marker_number, _marker_idx_to_edit = markrgnindexnumber, i
end
end
end

if _marker_idx_to_edit ~= -1 and _first_marker_idx ~= -1 and _marker_idx_to_edit ~= _first_marker_idx then
local _, _, pos = reaper.EnumProjectMarkers(_first_marker_idx)

reaper.DeleteProjectMarkerByIndex(0, _first_marker_idx)
reaper.Main_OnCommand(_command_id__edit_marker_near_cursor, 0)
if _marker_idx_to_edit ~= -1 then
if _first_marker_idx ~= _marker_idx_to_edit then
local _, _, pos = reaper.EnumProjectMarkers(_first_marker_idx)
reaper.DeleteProjectMarkerByIndex(0, _first_marker_idx)
end

local new_idx, successful = reaper.AddProjectMarker(0, false, pos, 0, _first_marker_name, -1)
reaper.Main_OnCommand(_command_id__edit_marker_near_cursor, 0)

if successful then
reaper.SetProjectMarkerByIndex(0, new_idx, false, pos, 0, new_idx, _first_marker_color)
if _first_marker_idx ~= _marker_idx_to_edit then
local new_idx, successful = reaper.AddProjectMarker(0, false, pos, 0, _first_marker_name, -1)
if successful then
reaper.SetProjectMarkerByIndex(0, new_idx, false, pos, 0, new_idx, _first_marker_color)
end
end
end


reaper.UpdateTimeline()
reaper.PreventUIRefresh(-1)
reaper.Undo_EndBlock("MB_Edit project marker with highest index at position", -1)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- @description MB_Utilities: Various utility scripts for Reaper
-- @author MonkeyBars
-- @version 1.4.1
-- @changelog Prevent UI updates during edit highest marker script run
-- @version 1.4.2
-- @changelog Make edit highest marker script work when only 1 marker
-- @provides [main] .
-- [main] MB_Create new autoincremented folder and save project.lua
-- [main] MB_Create new pair of grouped tracks with MIDI & stereo audio routing to & from selected (virtual instrument) tracks.lua
Expand Down

0 comments on commit 7918879

Please sign in to comment.