13
0

First round of Lua script API updates

This commit is contained in:
Robin Gareus 2022-09-27 05:06:13 +02:00
parent 395bf4a650
commit 30a92894fc
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
8 changed files with 34 additions and 31 deletions

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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