From 76c0f42ecbfe73d8cedbb611338e7b29d2abe9af Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 27 Sep 2022 18:58:53 +0200 Subject: [PATCH] Second round of Lua script API updates --- share/scripts/_dump_midiregion.lua | 4 ++-- ...faders_to_trims.lua => _faders_to_trims.lua} | 0 share/scripts/_find_nonzero_sample.lua | 8 ++++---- share/scripts/_hook_test.lua | 6 +++--- share/scripts/_insert_region_gaps.lua | 13 ++++--------- share/scripts/_osc_hook_example.lua | 6 +++--- share/scripts/_region_transients.lua | 10 ++++------ share/scripts/_split_benchmark.lua | 2 +- share/scripts/_stereo_to_mono.lua | 8 +++++++- share/scripts/bounce_replace.lua | 10 ++-------- share/scripts/collapse_playlists.lua | 11 ++--------- share/scripts/jump_to_marker.lua | 2 +- share/scripts/lfo_automation.lua | 14 ++++++++------ share/scripts/midi_cc_to_automation.lua | 6 +----- share/scripts/rubberband_swing.lua | 10 ++-------- share/scripts/s_fader_automation.lua | 6 +++--- share/scripts/s_plugin_automation.lua | 6 +++--- share/scripts/s_region_gain.lua | 17 +++++------------ share/scripts/s_region_gain_curve.lua | 2 +- share/scripts/s_selection.lua | 11 ++++++++--- share/scripts/split_all_markers.lua | 13 +++---------- share/scripts/stop_at_marker.lua | 10 +++++----- share/scripts/tomsloop.lua | 13 ++++--------- 23 files changed, 76 insertions(+), 112 deletions(-) rename share/scripts/{faders_to_trims.lua => _faders_to_trims.lua} (100%) diff --git a/share/scripts/_dump_midiregion.lua b/share/scripts/_dump_midiregion.lua index 0c62a56479..90f5712262 100644 --- a/share/scripts/_dump_midiregion.lua +++ b/share/scripts/_dump_midiregion.lua @@ -2,15 +2,15 @@ ardour { ["type"] = "Snippet", name = "Dump MIDI Region" } function factory () return function () local sel = Editor:get_selection () + local tm = Temporal.TempoMap.read () for r in sel.regions:regionlist ():iter () do local mr = r:to_midiregion () if mr:isnil () then goto next end print (r:name (), "Pos:", r:position (), "Start:", r:start ()) - local bfc = ARDOUR.BeatsSamplesConverter (Session:tempo_map (), r:position ()) local nl = ARDOUR.LuaAPI.note_list (mr:model ()) for n in nl:iter () do - print (" Note @", bfc:to (n:time ()), + print (" Note @", n:time (), tm:sample_at_beats (n:time ()), ARDOUR.ParameterDescriptor.midi_note_name (n:note ()), "Vel:", n:velocity ()) end diff --git a/share/scripts/faders_to_trims.lua b/share/scripts/_faders_to_trims.lua similarity index 100% rename from share/scripts/faders_to_trims.lua rename to share/scripts/_faders_to_trims.lua diff --git a/share/scripts/_find_nonzero_sample.lua b/share/scripts/_find_nonzero_sample.lua index 485199b1fc..782f570e9d 100644 --- a/share/scripts/_find_nonzero_sample.lua +++ b/share/scripts/_find_nonzero_sample.lua @@ -19,14 +19,14 @@ function factory () return function () -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection for r in sel.regions:regionlist ():iter () do -- test if it's an audio region - if r:to_audioregion ():isnil () then + local ar = r:to_audioregion() + if ar:isnil () then goto next end -- to read the Region data, we use the Readable interface of the Region -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Readable - local a = r.to_audioregion() - local rd = a:to_readable () + local rd = ar:to_readable () local n_samples = rd:readable_length () local n_channels = rd:n_channels () @@ -59,7 +59,7 @@ function factory () return function () end if (nonzeropos >= 0) then - msg = msg .. string.format("%s: %d\n", r:name (), nonzeropos + r:position()) + msg = msg .. string.format("%s: %d\n", r:name (), nonzeropos + r:position():samples ()) else msg = msg .. "Region: '%s' is silent\n" end diff --git a/share/scripts/_hook_test.lua b/share/scripts/_hook_test.lua index eccdbeb74d..e63bf64591 100644 --- a/share/scripts/_hook_test.lua +++ b/share/scripts/_hook_test.lua @@ -31,10 +31,10 @@ function factory (params) file = io.open ("/tmp/test" ,"a") io.output (file) for region in rl:iter() do - io.write (string.format ("Region: '%s' pos-changed: %s, length-changed: %s\n", + io.write (string.format ("Region: '%s' length@pos-changed: %s Start-changed: %s\n", region:name (), - tostring (pch:containsSamplePos (ARDOUR.Properties.Position)), - tostring (pch:containsSamplePos (ARDOUR.Properties.Length)) + tostring (pch:containsTimeCnt (ARDOUR.Properties.Length)), + tostring (pch:containsTimePos (ARDOUR.Properties.Start)) )) end io.close (file) diff --git a/share/scripts/_insert_region_gaps.lua b/share/scripts/_insert_region_gaps.lua index 3a7f5ed8e9..ebdb9728c0 100644 --- a/share/scripts/_insert_region_gaps.lua +++ b/share/scripts/_insert_region_gaps.lua @@ -21,7 +21,6 @@ function factory () return function () local sel = Editor:get_selection () -- get current selection - local add_undo = false -- keep track of changes Session:begin_reversible_command ("Insert Gaps") -- iterate over all selected tracks @@ -40,23 +39,19 @@ function factory () return function () region:to_stateful ():clear_changes () -- move region - region:set_position (region:position() + offset, 0) + region:set_position (region:position() + Temporal.timecnt_t (offset)) offset = offset + Session:nominal_sample_rate () * gap -- create a diff of the performed work, add it to the session's undo stack -- and check if it is not empty - if not Session:add_stateful_diff_command (region:to_statefuldestructible ()):empty () then - add_undo = true - end + Session:add_stateful_diff_command (region:to_statefuldestructible ()) end ::continue:: end -- all done, commit the combined Undo Operation - if add_undo then - -- the 'nil' Command here mean to use the collected diffs added above + if not Session:abort_empty_reversible_command () then Session:commit_reversible_command (nil) - else - Session:abort_reversible_command () end + end end diff --git a/share/scripts/_osc_hook_example.lua b/share/scripts/_osc_hook_example.lua index b5fa6cc4f2..347602b603 100644 --- a/share/scripts/_osc_hook_example.lua +++ b/share/scripts/_osc_hook_example.lua @@ -45,9 +45,9 @@ function factory (params) for region in rl:iter() do tx:send ("/region_property_changed", "sTTiii", region:name (), - (pch:containsSamplePos (ARDOUR.Properties.Start)), - (pch:containsSamplePos (ARDOUR.Properties.Length)), - region:position (), region:start (), region:length ()) + (pch:containsTimePos (ARDOUR.Properties.Start)), + (pch:containsTimeCnt (ARDOUR.Properties.Length)), + region:position ():samples(), region:start ():samples(), region:length ():samples()) end end end diff --git a/share/scripts/_region_transients.lua b/share/scripts/_region_transients.lua index de42992dd1..d70433f051 100644 --- a/share/scripts/_region_transients.lua +++ b/share/scripts/_region_transients.lua @@ -3,13 +3,11 @@ ardour { ["type"] = "Snippet", name = "Region Transient List" } function factory () return function () local sel = Editor:get_selection () for r in sel.regions:regionlist ():iter () do - local region_pos = r:position() - local region_off = r:start() - print (r:name(), r:position(), r:start()) - local trans = r:transients() + local ref = r:position() - r:start() + print (r:name(), r:position(), r:start(), r:position():samples(), r:start():samples()) + local trans = r:transients() -- list of samplepos_t for t in trans:iter() do - -- print absolute timeline position of transients - print (t + region_pos - region_off) + print (ref + Temporal.timecnt_t(t), ref:samples () + t) end print ("----") end diff --git a/share/scripts/_split_benchmark.lua b/share/scripts/_split_benchmark.lua index 8ed64e43f2..b3f3b7d54b 100644 --- a/share/scripts/_split_benchmark.lua +++ b/share/scripts/_split_benchmark.lua @@ -15,7 +15,7 @@ function factory (params) return function () local playlist = route:to_track():playlist () playlist:to_stateful ():clear_changes () for region in playlist:regions_at (pos):iter () do - playlist:split_region (region, ARDOUR.MusicSample (pos, 0)) + playlist:split_region (region, Temporal.timepos_t (pos)) end if not Session:add_stateful_diff_command (playlist:to_statefuldestructible ()):empty () then add_undo = true diff --git a/share/scripts/_stereo_to_mono.lua b/share/scripts/_stereo_to_mono.lua index 2455a03c7d..9313e5de63 100644 --- a/share/scripts/_stereo_to_mono.lua +++ b/share/scripts/_stereo_to_mono.lua @@ -11,6 +11,12 @@ function factory (params) return function () -- (regions, tracks, ranges, markers, automation, midi-notes etc) local sel = Editor:get_selection () + -- default track output channel count (= master bus input count) + local n_chan_out = 2 + if not Session:master_out():isnil() then + n_chan_out = Session:master_out():n_inputs ():n_audio () + end + -- for each track.. for t in sel.tracks:routelist ():iter () do local track = t:to_track () @@ -30,7 +36,7 @@ function factory (params) return function () if channels ~= 2 then goto next end -- create 2 new tracks (using the name of the original track)( - local newtracks = Session:new_audio_track (2, 2, nil, 2, t:name(), ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal, true) + local newtracks = Session:new_audio_track (1, n_chan_out, nil, 2, t:name(), ARDOUR.PresentationInfo.max_order, ARDOUR.TrackMode.Normal, true) assert (newtracks:size() == 2) for r in playlist:region_list ():iter () do diff --git a/share/scripts/bounce_replace.lua b/share/scripts/bounce_replace.lua index 73a2eece4f..6db9792670 100644 --- a/share/scripts/bounce_replace.lua +++ b/share/scripts/bounce_replace.lua @@ -24,7 +24,6 @@ function factory (params) return function () -- prepare undo operation Session:begin_reversible_command ("Bounce+Replace Regions") - local add_undo = false -- keep track if something has changed -- Iterate over Regions part of the selection -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection @@ -48,17 +47,12 @@ function factory (params) return function () -- create a diff of the performed work, add it to the session's undo stack -- and check if it is not empty - if not Session:add_stateful_diff_command (playlist:to_statefuldestructible ()):empty () then - add_undo = true - end + Session:add_stateful_diff_command (playlist:to_statefuldestructible ()) end -- all done, commit the combined Undo Operation - if add_undo then - -- the 'nil' Command here mean to use the collected diffs added above + if not Session:abort_empty_reversible_command () then Session:commit_reversible_command (nil) - else - Session:abort_reversible_command () end end end diff --git a/share/scripts/collapse_playlists.lua b/share/scripts/collapse_playlists.lua index fde8b3cc74..4a24d55cf1 100644 --- a/share/scripts/collapse_playlists.lua +++ b/share/scripts/collapse_playlists.lua @@ -12,7 +12,6 @@ function factory (params) return function () -- prepare undo operation -- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Session Session:begin_reversible_command ("Collapse Playlists") - local add_undo = false -- keep track if something has changed -- Track/Bus Selection -- iterate over all Editor-GUI selected tracks -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:TrackSelection @@ -46,19 +45,13 @@ function factory (params) return function () end -- collect undo data - if not Session:add_stateful_diff_command (playlist:to_statefuldestructible()):empty() then - -- is something has changed, we need to save it at the end. - add_undo = true - end + Session:add_stateful_diff_command (playlist:to_statefuldestructible()) ::continue:: end -- all done, commit the combined Undo Operation - if add_undo then - -- the 'nil' Command here mean to use the collected diffs added above + if not Session:abort_empty_reversible_command () then Session:commit_reversible_command (nil) - else - Session:abort_reversible_command () end end end diff --git a/share/scripts/jump_to_marker.lua b/share/scripts/jump_to_marker.lua index 0fa4259bae..811b3dedef 100644 --- a/share/scripts/jump_to_marker.lua +++ b/share/scripts/jump_to_marker.lua @@ -27,7 +27,7 @@ function factory () return function () for l in Session:locations():list():iter() do if l:is_mark() and string.find (l:name(), "^" .. rv['marker'] .. ".*$") then - Session:request_locate (l:start (), false, ARDOUR.LocateTransportDisposition.RollIfAppropriate, ARDOUR.TransportRequestSource.TRS_UI) + Session:request_locate (l:start ():samples (), false, ARDOUR.LocateTransportDisposition.RollIfAppropriate, ARDOUR.TransportRequestSource.TRS_UI) if keep then goto restart end return end diff --git a/share/scripts/lfo_automation.lua b/share/scripts/lfo_automation.lua index fe181fd41c..f1ae8245c2 100644 --- a/share/scripts/lfo_automation.lua +++ b/share/scripts/lfo_automation.lua @@ -134,20 +134,20 @@ function factory (unused_params) Session:begin_reversible_command("Add LFO automation to region") local before = al:get_state() -- save previous state (for undo) -- Clear events in target automation-list for the selected region. - al:clear(region:position() - region:start(), region:position() - region:start() + region:length()) + al:clear(region:position() - region:start(), region:position() + region:length() - region:start()) local values = lut[wave] local last = nil for i = 0, cycles - 1 do -- cycle length = region:length() / cycles - local cycle_start = region:position() - region:start() + i * region:length() / cycles - local offset = region:length() / cycles / (#values - 1) + local cycle_start = region:position() - region:start() + region:length():scale(Temporal.ratio(i, cycles)) + local offset = region:length():scale (Temporal.ratio (1, cycles * (#values - 1))) for k, v in pairs(values) do - local pos = cycle_start + (k - 1) * offset + local pos = cycle_start + offset:scale (Temporal.ratio (k - 1, 1)) if k == 1 and v ~= last then -- Move event one sample further. A larger offset might be needed to avoid unwanted effects. - pos = pos + 1 + pos = pos:increment () end if k > 1 or v ~= last then @@ -167,7 +167,9 @@ function factory (unused_params) -- Save undo Session:add_command(al:memento_command(before, al:get_state())) - Session:commit_reversible_command(nil) + if not Session:abort_empty_reversible_command () then + Session:commit_reversible_command (nil) + end region, al, lut = nil, nil, nil end diff --git a/share/scripts/midi_cc_to_automation.lua b/share/scripts/midi_cc_to_automation.lua index 2db9c41bdb..382d2f98b6 100644 --- a/share/scripts/midi_cc_to_automation.lua +++ b/share/scripts/midi_cc_to_automation.lua @@ -91,16 +91,12 @@ function factory () return function () if ec:isnil () then goto next end if ec:list ():events ():size () == 0 then goto next end - -- MIDI events are timestamped in "bar-beat" units, we need to convert those - -- using the tempo-map, relative to the region-start - local bfc = ARDOUR.BeatsSamplesConverter (Session:tempo_map (), r:start ()) - -- iterate over CC-events for av in ec:list ():events ():iter () do -- re-scale event to target range local val = pd.lower + (pd.upper - pd.lower) * av.value / 127 -- and add it to the target-parameter automation-list - al:add (r:position () - r:start () + bfc:to (av.when), val, false, true) + al:add (r:position () - r:start () + av.when, val, false, true) add_undo = true end ::next:: diff --git a/share/scripts/rubberband_swing.lua b/share/scripts/rubberband_swing.lua index b2a646ea81..a3d12dd799 100644 --- a/share/scripts/rubberband_swing.lua +++ b/share/scripts/rubberband_swing.lua @@ -46,7 +46,6 @@ function factory () return function () -- prepare undo operation Session:begin_reversible_command ("Rubberband Regions") - local add_undo = false -- keep track if something has changed -- for each selected region -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection @@ -141,9 +140,7 @@ function factory () return function () playlist:add_region (nar, r:position (), 1, false) -- create a diff of the performed work, add it to the session's undo stack -- and check if it is not empty - if not Session:add_stateful_diff_command (playlist:to_statefuldestructible ()):empty () then - add_undo = true - end + Session:add_stateful_diff_command (playlist:to_statefuldestructible ()) end ::next:: @@ -152,11 +149,8 @@ function factory () return function () ::out:: -- all done, commit the combined Undo Operation - if add_undo then - -- the 'nil' Command here mean to use the collected diffs added above + if not Session:abort_empty_reversible_command () then Session:commit_reversible_command (nil) - else - Session:abort_reversible_command () end end end diff --git a/share/scripts/s_fader_automation.lua b/share/scripts/s_fader_automation.lua index 307ab785b6..abb8b7e4e6 100644 --- a/share/scripts/s_fader_automation.lua +++ b/share/scripts/s_fader_automation.lua @@ -1,8 +1,8 @@ ardour { ["type"] = "Snippet", name = "Fader Automation" } function factory () return function () - local playhead = Session:transport_sample () - local samplerate = Session:nominal_sample_rate () + local playhead = Temporal.timepos_t (Session:transport_sample ()) + local samplerate = Temporal.timecnt_t (Session:nominal_sample_rate ()) -- get selected tracks rl = Editor:get_selection ().tracks:routelist () @@ -32,7 +32,7 @@ function factory () return function () for i=0,50 do -- use a sqrt fade-out (the shape is recognizable, and otherwise -- not be possible to achieve with existing ardour fade shapes) - al:add (playhead + i * samplerate / 50, + al:add (playhead + samplerate:scale (Temporal.ratio (i, 50)), g * (1 - math.sqrt (i / 50)), false, true) end diff --git a/share/scripts/s_plugin_automation.lua b/share/scripts/s_plugin_automation.lua index 2b04bae638..9bf5510139 100644 --- a/share/scripts/s_plugin_automation.lua +++ b/share/scripts/s_plugin_automation.lua @@ -2,8 +2,8 @@ ardour { ["type"] = "Snippet", name = "Plugin automation" } function factory () return function () -- query playhead position and session sample-rate - local playhead = Session:transport_sample () - local samplerate = Session:nominal_sample_rate () + local playhead = Temporal.timepos_t (Session:transport_sample ()) + local samplerate = Temporal.timecnt_t (Session:nominal_sample_rate ()) -- get Track/Bus with RID 3 local r = Session:get_remote_nth_route(3) @@ -30,7 +30,7 @@ function factory () return function () -- add new data points after the playhead 1 sec, min..max -- without guard-points, but with initial (..., false, true) for i=0,10 do - cl:add (playhead + i * samplerate / 10, + cl:add (playhead + samplerate:scale (Temporal.ratio (i, 10)), pd.lower + math.sqrt (i / 10) * (pd.upper - pd.lower), false, true) end diff --git a/share/scripts/s_region_gain.lua b/share/scripts/s_region_gain.lua index 35ab7c9210..53b9cbf7a4 100644 --- a/share/scripts/s_region_gain.lua +++ b/share/scripts/s_region_gain.lua @@ -11,20 +11,19 @@ function factory () return function () -- prepare undo operation Session:begin_reversible_command ("Lua Region Gain") - local add_undo = false -- keep track if something has changed -- iterate over selected regions -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:RegionSelection for r in sel.regions:regionlist ():iter () do -- test if it's an audio region - if r:to_audioregion ():isnil () then + local ar = r:to_audioregion () + if ar:isnil () then goto next end -- to read the Region data, we use the Readable interface of the Region -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:AudioReadable - local a = r.to_audioregion - local rd = a:to_readable () + local rd = ar:to_readable () local n_samples = rd:readable_length () local n_channels = rd:n_channels () @@ -64,20 +63,14 @@ function factory () return function () -- apply gain r:to_audioregion (): set_scale_amplitude (1 / peak) -- save changes (if any) to undo command - if not Session:add_stateful_diff_command (r:to_statefuldestructible ()):empty () then - add_undo = true - end + Session:add_stateful_diff_command (r:to_statefuldestructible ()) end ::next:: end - -- all done. now commit the combined undo operation - if add_undo then - -- the 'nil' command here means to use all collected diffs + if not Session:abort_empty_reversible_command () then Session:commit_reversible_command (nil) - else - Session:abort_reversible_command () end end end diff --git a/share/scripts/s_region_gain_curve.lua b/share/scripts/s_region_gain_curve.lua index 2a73303568..6ca44cd8eb 100644 --- a/share/scripts/s_region_gain_curve.lua +++ b/share/scripts/s_region_gain_curve.lua @@ -30,7 +30,7 @@ function factory () return function () -- add some new ones for i=0,50 do - al:add (i * r:length () / 50, + al:add (r:length ():scale (Temporal:ratio (i, 50)), 1 - math.sqrt (i / 50), false, true) end diff --git a/share/scripts/s_selection.lua b/share/scripts/s_selection.lua index b4f1eac2d5..c30d613d7d 100644 --- a/share/scripts/s_selection.lua +++ b/share/scripts/s_selection.lua @@ -11,8 +11,13 @@ function factory () return function () -- -- Range selection, total span of all ranges (0, 0 if no time range is selected) - if sel.time:start () < sel.time:end_sample () then - print ("Total Range:", sel.time:start (), sel.time:end_sample ()) + if sel.time:start_sample () < sel.time:end_sample () then + print ("Total Range:", sel.time:start_sample (), sel.time:end_sample ()) + end + + -- .. and the same in Temporal.timepos_t + if sel.time:start_time () < sel.time:end_time () then + print ("Total Range:", sel.time:start_time (), sel.time:end_time ()) end -- Range selection, individual ranges. @@ -50,7 +55,7 @@ function factory () return function () ---------------------------------------------------------- -- The total time extents of all selected regions and ranges - local ok, ext = Editor:get_selection_extents (0, 0) + local ok, ext = Editor:get_selection_extents (Temporal.timepos_t(0), Temporal.timepos_t(0)) if ok then print ("Selection Extents:", ext[1], ext[2]) else diff --git a/share/scripts/split_all_markers.lua b/share/scripts/split_all_markers.lua index 4af62a39c4..924dc6a40d 100644 --- a/share/scripts/split_all_markers.lua +++ b/share/scripts/split_all_markers.lua @@ -14,7 +14,6 @@ function factory (params) return function () -- prepare undo operation -- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Session Session:begin_reversible_command ("Auto Region Split") - local add_undo = false -- keep track if something has changed -- Track/Bus Selection -- iterate over all Editor-GUI selected tracks -- http://manual.ardour.org/lua-scripting/class_reference/#ArdourUI:TrackSelection @@ -40,7 +39,7 @@ function factory (params) return function () if l:is_mark() then -- get all regions on the given track's playlist (may be stacked) for reg in playlist:regions_at (l:start ()):iter () do - playlist:split_region (reg, ARDOUR.MusicSample (l:start(), 0)) + playlist:split_region (reg, l:start()) -- the above operation will invalidate the playlist's region list: -- split creates 2 new regions. -- @@ -51,20 +50,14 @@ function factory (params) return function () end -- collect undo data - if not Session:add_stateful_diff_command (playlist:to_statefuldestructible ()):empty () then - -- is something has changed, we need to save it at the end. - add_undo = true - end + Session:add_stateful_diff_command (playlist:to_statefuldestructible ()) ::continue:: end -- all done, commit the combined Undo Operation - if add_undo then - -- the 'nil' Command here mean to use the collected diffs added above + if not Session:abort_empty_reversible_command () then Session:commit_reversible_command (nil) - else - Session:abort_reversible_command () end end end diff --git a/share/scripts/stop_at_marker.lua b/share/scripts/stop_at_marker.lua index 8aac8ced7a..0c75a2aeb3 100644 --- a/share/scripts/stop_at_marker.lua +++ b/share/scripts/stop_at_marker.lua @@ -19,10 +19,10 @@ function factory () -- find first marker after the current playhead position, ignore loop + punch ranges -- (this only works when rolling forward, to extend this example see -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:Locations ) - -- - local m = loc:first_mark_after (pos, false) + local t = Temporal.timepos_t (pos) + local m = loc:first_mark_after (t, false) - if (m == -1) then + if (m == Temporal.timepos_t.max (t:time_domain())) then -- no marker was found return end @@ -40,10 +40,10 @@ function factory () -- -- So even though "pos + n_samples" is barely reached, -- we need to stop at "m" in the cycle that crosses or ends at "m". - if (pos + n_samples >= m) then + if (pos + n_samples >= m:samples ()) then -- asking to locate to "m" ensures that playback continues at "m" -- and the same marker will not be taken into account. - Session:request_locate (m, false, ARDOUR.LocateTransportDisposition.MustStop, ARDOUR.TransportRequestSource.TRS_Engine) + Session:request_locate (m:samples (), false, ARDOUR.LocateTransportDisposition.MustStop, ARDOUR.TransportRequestSource.TRS_Engine) end end end diff --git a/share/scripts/tomsloop.lua b/share/scripts/tomsloop.lua index 82806a9dd9..594d50bd13 100644 --- a/share/scripts/tomsloop.lua +++ b/share/scripts/tomsloop.lua @@ -174,7 +174,7 @@ function factory (params) return function () goto errorout end assert (loop:start () < loop:_end ()) - if loop:_end () > playhead then + if loop:_end ():samples () > playhead then -- print_help(); print ("Error: The Playhead (paste point) needs to be after the loop.") LuaDialog.Message ("Tom's Loop", "Error: The Playhead (paste point) needs to be after the loop.", LuaDialog.MessageType.Error, LuaDialog.ButtonType.Close):run () @@ -249,9 +249,7 @@ function factory (params) return function () -- create a diff of the performed work, add it to the session's undo stack -- and check if it is not empty - if not Session:add_stateful_diff_command (playlist:to_statefuldestructible ()):empty () then - add_undo = true - end + Session:add_stateful_diff_command (playlist:to_statefuldestructible ()) ::continue:: end -- for all routes @@ -262,14 +260,11 @@ function factory (params) return function () end -- all done, commit the combined Undo Operation - if add_undo then - -- the 'nil' Command here mean to use the collected diffs added above + if not Session:abort_empty_reversible_command () then Session:commit_reversible_command (nil) - else - Session:abort_reversible_command () end - print ("bounced " .. n_regions_created .. " regions from loop range (" .. loop:length() .. " samples) to playhead @ sample # " .. playhead) + print ("bounced " .. n_regions_created .. " regions from loop range (" .. loop:length():samples() .. " samples) to playhead @ sample # " .. playhead) ::errorout:: end -- end of anonymous action script function end -- end of script factory