Skip to content

Commit

Permalink
working tests, update comparison script
Browse files Browse the repository at this point in the history
  • Loading branch information
myrrc committed Jan 29, 2025
1 parent fc8fc80 commit 68e4327
Show file tree
Hide file tree
Showing 6 changed files with 392 additions and 19 deletions.
18 changes: 9 additions & 9 deletions internal/custom_actions/custom_actions.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local utils = require "custom_actions.utils"
local actions = {}
-- TODO rename to movement.lua

function actions.projectStart() reaper.SetEditCurPos(0, true, false) end

Expand Down Expand Up @@ -41,7 +42,8 @@ function actions.prevItemStart()
for j = 0, reaper.GetTrackNumMediaItems(track) - 1 do
local item = reaper.GetTrackMediaItem(track, j)
local pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
if pos >= cur then goto next_track elseif pos > start then start = pos end
if pos + reaper.GetMediaItemInfo_Value(item, "D_LENGTH") >= cur then goto next_track end
if pos > start then start = pos end
end
::next_track::
end
Expand Down Expand Up @@ -143,15 +145,13 @@ end

function actions.trackWithNumber()
local ok, num = reaper.GetUserInputs("Match Forward", 1, "Track Number", "")
if not ok or type(num) ~= 'number' then return end
if not ok or type(num) ~= 'number' or num < 1 then return end
local track = reaper.GetTrack(0, num - 1)
if track then reaper.SetOnlyTrackSelected(track) end
end

function actions.firstTrackWithItem()
local num = reaper.GetNumTracks()
if num == 0 then return end
for i = 0, num - 1 do
for i = 0, reaper.GetNumTracks() - 1 do
local track = reaper.GetTrack(0, i)
if reaper.GetTrackNumMediaItems(track) > 0 then
return reaper.SetOnlyTrackSelected(track)
Expand All @@ -172,10 +172,10 @@ end

function actions.innerItem()
local item_positions = utils.getItemPositionsOnSelectedTracks()
local current_position = reaper.GetCursorPosition()
local cur = reaper.GetCursorPosition()
for i = #item_positions, 1, -1 do
local item = item_positions[i]
if item.left <= current_position and item.right >= current_position then
if item.left <= cur and item.right >= cur then
return reaper.GetSet_LoopTimeRange(true, false, item.left, item.right, false)
end
end
Expand Down Expand Up @@ -214,8 +214,8 @@ local function getUserGridDivisionInput()
if not ok then return end
local division = str:match("[0-9.]+")
local fraction = str:match("/([0-9.]+)")
if division and fraction then return division / fraction end
if division then return division end
if division and fraction and fraction ~= 0 then return division / fraction end
if division and not fraction then return division end
reaper.MB("Could not parse specified grid division " .. str, "Error", 0)
return nil
end
Expand Down
13 changes: 7 additions & 6 deletions internal/custom_actions/utils.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local utils = {}
-- TODO rename to movement_utils.lua

local function mergeItemPositionsLists(item_positions_list)
local merged_list = {}
Expand Down Expand Up @@ -141,12 +142,12 @@ function utils.setCurrentTrack(index)
end

function utils.getSelectedTrackIndices()
local selected_tracks = utils.getSelectedTracks()
local selected_track_indices = {}
for i,track in ipairs(selected_tracks) do
selected_track_indices[i] = reaper.GetMediaTrackInfo_Value(track, "IP_TRACKNUMBER") - 1
end
return selected_track_indices
local idxs = {}
for i = 0, reaper.CountSelectedTracks() - 1 do
idxs[i + 1] = reaper.GetMediaTrackInfo_Value(
reaper.GetSelectedTrack(0, i), "IP_TRACKNUMBER") - 1
end
return idxs
end

return utils
1 change: 1 addition & 0 deletions internal/library/marks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local state_interface = require('state_machine.state_interface')
local reaper_utils = require('custom_actions.utils')
local log = require('utils.log')
local format = require('utils.format')
-- TODO rename to internal/marks.lua

local marks = {}

Expand Down
5 changes: 5 additions & 0 deletions tests/compare
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ ignored_keys = Path("ignored_keys").read_text().split()
# skip project declaration
for left, right in zip(left_file.split("\n")[1:], right_file.split("\n")[1:]):
left, right = left.strip(), right.strip()
if left.startswith("MARKER") and right.startswith("MARKER"): # marker id
left, right = left[:left.find("{")], right[:right.find("{")]
if left == right or any(map(lambda x: left.startswith(x), ignored_keys)):
continue
# binary state may differ slightly
if len(left) == len(right) and sum(x != y for x, y in zip(left, right)) < 5:
continue
print(f"< {left}\n> {right}")
out = 1

Expand Down
Loading

0 comments on commit 68e4327

Please sign in to comment.