diff --git a/share/scripts/_stereo_to_mono.lua b/share/scripts/_stereo_to_mono.lua index 20bfb7c5b2..2455a03c7d 100644 --- a/share/scripts/_stereo_to_mono.lua +++ b/share/scripts/_stereo_to_mono.lua @@ -42,7 +42,7 @@ function factory (params) return function () local plc = 1 for nr in rv[1]:iter () do local pl = newtracks:table()[plc]:playlist() - pl:add_region (nr, r:position(), 1, false, 0, 0, false) + pl:add_region (nr, r:position(), 1, false) plc = plc + 1 end end diff --git a/share/scripts/bounce_replace.lua b/share/scripts/bounce_replace.lua index 5e7baa6b1b..73a2eece4f 100644 --- a/share/scripts/bounce_replace.lua +++ b/share/scripts/bounce_replace.lua @@ -39,7 +39,7 @@ function factory (params) return function () playlist:to_stateful ():clear_changes () -- bounce the region with processing - local region = track:bounce_range (r:position (), r:position() + r:length (), ARDOUR.InterThreadInfo (), track:main_outs (), false, ""); + local region = track:bounce_range (r:position ():samples(), (r:position() + r:length ()):samples(), ARDOUR.InterThreadInfo (), track:main_outs (), false, ""); -- remove old region.. playlist:remove_region (r); diff --git a/share/scripts/collapse_playlists.lua b/share/scripts/collapse_playlists.lua index a49b1ecd61..fde8b3cc74 100644 --- a/share/scripts/collapse_playlists.lua +++ b/share/scripts/collapse_playlists.lua @@ -40,7 +40,7 @@ function factory (params) return function () -- for each region of the playlist for r in p:region_list():iter() do -- add it to the current playlist - playlist:add_region (r, r:position(), 1, false, 0, 0, false) + playlist:add_region (r, r:position(), 1, false) end end end diff --git a/share/scripts/rubberband_swing.lua b/share/scripts/rubberband_swing.lua index c69c622f75..b2a646ea81 100644 --- a/share/scripts/rubberband_swing.lua +++ b/share/scripts/rubberband_swing.lua @@ -138,7 +138,7 @@ function factory () return function () local playlist = track:playlist () playlist:to_stateful ():clear_changes () -- prepare undo playlist:remove_region (r) - playlist:add_region (nar, r:position (), 1, false, 0, 0, false) + 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 diff --git a/share/scripts/s_set_region_fades.lua b/share/scripts/s_set_region_fades.lua index 04d94a6eb9..e0fe9a0e80 100644 --- a/share/scripts/s_set_region_fades.lua +++ b/share/scripts/s_set_region_fades.lua @@ -26,8 +26,8 @@ function factory () return function () -- fade in/out for 500 msec, or half the region-length, whatever is shorter local fadelen = .5 * sr - if fadelen > r:length () / 2 then - fadelen = r:length () / 2 + if fadelen > r:length ():samples () / 2 then + fadelen = r:length ():samples () / 2 end -- https://manual.ardour.org/lua-scripting/class_reference/#ARDOUR.FadeShape diff --git a/share/scripts/s_tempo_map.lua b/share/scripts/s_tempo_map.lua index 012065be37..9f88857c5c 100644 --- a/share/scripts/s_tempo_map.lua +++ b/share/scripts/s_tempo_map.lua @@ -3,14 +3,15 @@ ardour { ["type"] = "Snippet", name = "tempo map examples" } function factory () return function () -- query BPM at 00:00:10:00 - local tp = Temporal.timepos_t.from_superclock (Temporal.superclock_ticks_per_second () * Session:nominal_sample_rate () * 10) - local tm = Temporal.TempoMap.use () - print (tm:tempo_at (tp):quarter_notes_per_minute ()) + local tp = Temporal.timepos_t (Session:nominal_sample_rate () * 10) + local tm = Temporal.TempoMap.read () + print (tm:quarters_per_minute_at (tp)) + tm = nil -- set initial tempo to 140, ramp to 120 over the first 4/4 bar, then continue at BPM 80 - Temporal.TempoMap.fetch_writable () - local tm = Temporal.TempoMap.use () - tm:set_tempo (Temporal.Tempo (140, 120, 4), Temporal.timepos_t ()) + local tm = Temporal.TempoMap.fetch_writable () + tm:set_tempo (Temporal.Tempo (140, 120, 4), Temporal.timepos_t (0)) + tm:set_tempo (Temporal.Tempo (120, 80, 4), Temporal.timepos_t.from_ticks (Temporal.ticks_per_beat * 4)) tm:set_tempo (Temporal.Tempo (80, 80, 4), Temporal.timepos_t.from_ticks (Temporal.ticks_per_beat * 4)) Temporal.TempoMap.update (tm) tm = nil diff --git a/share/scripts/tomsloop.lua b/share/scripts/tomsloop.lua index 78123635c6..82806a9dd9 100644 --- a/share/scripts/tomsloop.lua +++ b/share/scripts/tomsloop.lua @@ -242,8 +242,8 @@ function factory (params) return function () playlist:to_stateful ():clear_changes () -- do the actual work - local region = track:bounce_range (loop:start (), loop:_end (), itt, proc, false, "") - playlist:add_region (region, playhead, n_paste, false, 0, 0, false) + local region = track:bounce_range (loop:start ():samples(), loop:_end ():samples(), itt, proc, false, "") + playlist:add_region (region, Temporal.timepos_t (playhead), n_paste, false) n_regions_created = n_regions_created + 1 @@ -258,7 +258,7 @@ function factory (params) return function () --advance playhead so it's just after the newly added regions if n_regions_created > 0 then - Session:request_locate (playhead + loop:length() * n_paste, false, ARDOUR.LocateTransportDisposition.MustStop, ARDOUR.TransportRequestSource.TRS_UI) + Session:request_locate (playhead + loop:length():samples() * n_paste, false, ARDOUR.LocateTransportDisposition.MustStop, ARDOUR.TransportRequestSource.TRS_UI) end -- all done, commit the combined Undo Operation diff --git a/share/scripts/vamp_audio_to_midi.lua b/share/scripts/vamp_audio_to_midi.lua index ece305dfe2..ed3f779efc 100644 --- a/share/scripts/vamp_audio_to_midi.lua +++ b/share/scripts/vamp_audio_to_midi.lua @@ -16,7 +16,7 @@ The plugin works best at 44.1KHz input sample rate, and is tuned for piano and g function factory () return function () local sel = Editor:get_selection () local sr = Session:nominal_sample_rate () - local tm = Session:tempo_map () + local tm = Temporal.TempoMap.read () local vamp = ARDOUR.LuaAPI.Vamp ("libardourvampplugins:qm-transcription", sr) local midi_region = nil local audio_regions = {} @@ -25,18 +25,19 @@ function factory () return function () local max_pos = 0 local cur_pos = 0 for r in sel.regions:regionlist ():iter () do - if r:to_midiregion():isnil() then - local st = r:position() - local ln = r:length() - local et = st + ln + local ar = r:to_audioregion() + if not ar:isnil() then + local st = r:position():samples() + local ln = r:length():samples() + local et = st + ln; if st < start_time then start_time = st end if et > end_time then end_time = et end - table.insert(audio_regions, r) - max_pos = max_pos + r:to_readable ():readable_length () + table.insert(audio_regions, ar) + max_pos = max_pos + ar:to_readable ():readable_length () else midi_region = r:to_midiregion() end @@ -51,8 +52,8 @@ function factory () return function () return end - midi_region:set_initial_position(start_time) - midi_region:set_length(end_time - start_time, 0) + midi_region:set_initial_position (Temporal.timepos_t (start_time)) + midi_region:set_length (Temporal.timecnt_t (end_time - start_time)) local pdialog = LuaDialog.ProgressWindow ("Audio to MIDI", true) function progress (_, pos) @@ -61,7 +62,7 @@ function factory () return function () for i,ar in pairs(audio_regions) do local a_off = ar:position () - local b_off = midi_region:quarter_note () - midi_region:start_beats () + local b_off = tm:quarters_at (midi_region:position ()); vamp:analyze (ar:to_readable (), 0, progress) @@ -77,15 +78,16 @@ function factory () return function () local mm = midi_region:midi_source(0):model() local midi_command = mm:new_note_diff_command ("Audio2Midi") for f in fl:iter () do - local ft = Vamp.RealTime.realTime2Frame (f.timestamp, sr) - local fd = Vamp.RealTime.realTime2Frame (f.duration, sr) + local ft = Temporal.timecnt_t (Vamp.RealTime.realTime2Frame (f.timestamp, sr)) + local fd = Temporal.timecnt_t (Vamp.RealTime.realTime2Frame (f.duration, sr)) local fn = f.values:at (0) - local bs = tm:exact_qn_at_sample (a_off + ft, 0) - local be = tm:exact_qn_at_sample (a_off + ft + fd, 0) + local bs = tm:quarters_at (a_off + ft, 0) + local be = tm:quarters_at (a_off + ft + fd, 0) + print ("N", bs, be, fn + 1) - local pos = Evoral.Beats (bs - b_off) - local len = Evoral.Beats (be - bs) + local pos = bs - b_off + local len = be - bs local note = ARDOUR.LuaAPI.new_noteptr (1, pos, len, fn + 1, 0x7f) midi_command:add (note) end