2021-12-11 11:44:43 -05:00
|
|
|
ardour { ["type"] = "Snippet", name = "tempo map examples" }
|
|
|
|
|
|
|
|
function factory () return function ()
|
|
|
|
|
|
|
|
-- query BPM at 00:00:10:00
|
2022-09-26 23:06:13 -04:00
|
|
|
local tp = Temporal.timepos_t (Session:nominal_sample_rate () * 10)
|
|
|
|
local tm = Temporal.TempoMap.read ()
|
|
|
|
print (tm:quarters_per_minute_at (tp))
|
|
|
|
tm = nil
|
2021-12-11 11:44:43 -05:00
|
|
|
|
|
|
|
-- set initial tempo to 140, ramp to 120 over the first 4/4 bar, then continue at BPM 80
|
2023-04-07 17:33:13 -04:00
|
|
|
local tm = Temporal.TempoMap.write_copy ()
|
2022-09-26 23:06:13 -04:00
|
|
|
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))
|
2021-12-11 11:44:43 -05:00
|
|
|
tm:set_tempo (Temporal.Tempo (80, 80, 4), Temporal.timepos_t.from_ticks (Temporal.ticks_per_beat * 4))
|
2022-10-23 17:21:08 -04:00
|
|
|
Session:begin_reversible_command ("Change Tempo Map")
|
2021-12-11 11:44:43 -05:00
|
|
|
Temporal.TempoMap.update (tm)
|
2022-10-23 17:21:08 -04:00
|
|
|
if not Session:abort_empty_reversible_command () then
|
|
|
|
Session:commit_reversible_command (nil)
|
|
|
|
end
|
2021-12-11 11:44:43 -05:00
|
|
|
tm = nil
|
|
|
|
|
|
|
|
-- Abort Edit example
|
2023-04-07 17:33:13 -04:00
|
|
|
-- after every call to Temporal.TempoMap.write_copy ()
|
2021-12-11 11:44:43 -05:00
|
|
|
-- there must be a matching call to
|
|
|
|
-- Temporal.TempoMap.update() or Temporal.TempoMap.abort_update()
|
2023-04-07 17:33:13 -04:00
|
|
|
Temporal.TempoMap.write_copy()
|
2021-12-11 11:44:43 -05:00
|
|
|
Temporal.TempoMap.abort_update()
|
|
|
|
|
2023-07-11 17:01:09 -04:00
|
|
|
-- get grid -- currently only available in debug-builds
|
|
|
|
-- Temporal.superclock_ticks_per_second = 282240000
|
|
|
|
tm = Temporal.TempoMap.read ()
|
2023-07-14 17:48:05 -04:00
|
|
|
local grid = tm:grid (Temporal.TempoMapPoints(), 0, Temporal.superclock_ticks_per_second (), 0, 1)
|
2023-07-11 17:01:09 -04:00
|
|
|
for t in grid[1]:iter () do
|
|
|
|
-- each t is-a TempoMapPoint
|
|
|
|
local metric = t:to_tempometric ()
|
|
|
|
local tempo_point = metric:tempo ()
|
|
|
|
local meter_point = metric:meter()
|
|
|
|
print (t:time(), tempo_point:to_tempo():quarter_notes_per_minute(), meter_point:note_value())
|
|
|
|
end
|
|
|
|
tm = nil
|
|
|
|
|
2021-12-11 11:44:43 -05:00
|
|
|
end end
|