Fitting Audio Item to Tempo Map

Now if I import an audio item that’s has a bpm of 120 and the timeline has tempo changes can I fit the item to these changes, if the item has embedded tempo will it use that ?
There’s nothing in the properties to set the bpm.

In Ardour 5 and Ardour 6 (not yet released), there is no concept of automatically adjusting audio material to fit the tempo map.

You can manually use the timestretch tool to accomplish this, although it gets tedious if you are doing this over and over.

So could I do that with a script that would ask for the original tempo of the item then calculates the stretch percentage amount from the tempo changes ?

Probably not easily. I don’t believe the relevant tempo_map bindings are available in Ardour 5.x do to this with Lua.

More relevant are the split positions prior to stretching.
If you could get those then it would be easy to just use Ardour’s stretch-tool and snap-to-[beat]grid.

I found with the stretch tool it anchors at 0 and you can’t do a selection it has to be the whole file, I tried ctrl, alt etc… have I missed something or is that how it is ? if so see the RubberBand timemap method below.
So you have no way to get the tempo markers with the script ?
There’s no way to move to next tempo marker, copy the current tempo, insert a CDmarker with that tempo and use session.chapters.txt to get the map ?
The trouble with splitting the wav you get a glitch in the audio with a held note or vocal.
I have that issue with Reaper as it uses stretch markers.
The way I’m looking at is RubberBand command line that works perfect with no glitches and smooth tempo changes.

-M, --timemap Use file F as the source for key frame map
A map file consists of a series of lines each having two numbers separated
by a single space. These are source and target sample frame numbers for fixed
time points within the audio data, defining a varying stretch factor through
the audio. You must specify an overall stretch factor using e.g. -t as well.

EDIT: also can I send a command to the terminal or CMD with the script ?

Correct. Ardour’s Tempo Map is about to change significantly, breaking the API and would make scripts incompatible. So no Lua bindings exist yet.

Meanwhile you could probably grep Tempo markers from the .ardour XML file, and just use rubberband the commandline app.

that should do it thanks ! Now what about sending to the terminal or CMD the rubberband commands ?

Has it got os.execute ? Reaper has that and BR_Win32_ShellExecute, ExecProcess

local script_path = debug.getinfo(1, ‘S’).source:match[[^@?(.[/])[^/]$]] or “”
local command = ‘""’…script_path…‘sendmidi.exe" dev “Microsoft GS Wavetable Synth” pc 17 channel 1 on 60 90"’
os.execute(command)

  1. it doesn’t need to be the whole file … it does have to be the whole region (different concept)
  2. ardour uses rubberband internally. Any difference in the output will come most likely from the parameters given to the RB engine. There are several options available from the GUI that Ardour creates for this, but only a subset of the possible ones.
  3. no version of ardour under development or released provides any way to use RB’s “timemap” feature. This is planned, but it completely inaccessible at this time.

That works easy by just getting the samples from the TempoMap section in the xml
then calculate the the sample position for the bar/beat from the source file bpm changing it to the sample position in the tempo map.
The top is the original constant bpm of 120 the file under is the RB output fitting the tempo map.
Full Screen

1 Like

Nice! That is very cool! Have you published the script somewhere already?

I’ll add Lua bindings for librubberband, so that there’s no need to depend on external apps to do the stretching before 6.0.

Ardour already comes with the qm-barbeattracker VAMP plugin and a Lua API for VAMP to analyze a region.

I’m unsure what to do about exposing the TempoMap internals to Lua. There is an upcoming overhaul, currently scheduled for v7.0 (https://ardour.org/timing.html). I’ll see if can think of a nice way to add minimal bindings; worst case the scripts will have to be updated once libardour’s tempo-map API changes.

Then again stretchy-regions, locked to Music-Time, are also on the ToDo list. Although those is somewhat different from one-time mapping.

No I haven’t scripted anything yet, I just made the map.txt

0 0
176400 176400
441000‬ 420646
617400‬ 632326
3131100‬ 3146026
3351600 3386572

and command line

rubberband -D 76.23 -M map.txt Test-32-bars_Drums.wav Test-32-bars_Drums_output.wav

You would need to be able to fit an audio clip anywhere along the timeline also.
I’ll look at the VAMP API, and yes it would help having Lua for librubberband thanks.
Just trying to find a cross-platform GUI to send keystroke and access the menus like the script menu, just looking at tkbash

Ardour/git (nightly.ardour.org builds) now allow time-stretching from a Lua script. A key-frame map can be passed as Lua table, example included:

1 Like

What is the actual goal that you want to achieve?

Scripts can be assigned to toolbar buttons (Preferences > Appearance > Toolbar > Show script buttons).
Also Keyboard shortcuts can be assigned to scripts, too.

Pretty much everything in Ardour can be remote-controlled via OSC or from a control-surface via access action, to call Lua Action scripts: Editor/script-action-1-12

Thanks for that !
With the script buttons if you had them in a floating tabbed window with options to use numbers, names or icons as well as button/icon size and scaling of the window.
If I use GTK to create a GUI that can somehow access Edit > Lua Scripts > script name, it would work. I can create a circle of fifths or chords/scale/key in the GUI but to insert the chosen chord name as a marker at current bar I would need a way to access run the “insert chord from clipboard as marker.lua” that will copy the clipboard sent from the GUI. I’m just trying to find an easy way without having to compile it into Ardour.

I don’t want to rain on this parade, but I really, really think you’re heading in a direction that isn’t likely to be productive.

I get that many people (including you) don’t want to deal with the build process for Ardour, and want to do everything from a scripted/interpreted environment. They are used to the idea of proprietary (or even open source) software where you never hack on the “actual code” but do everything with the extension system.

However, this just isn’t something we’re aiming to support. If you can make it work, great! We’re just not likely to ever deal with the bits and pieces that will be needed to do development on Ardour in this way.

I intend to write an extremely powerful chord tool for Ardour. I plan to do all of that work in C++, as part of the program itself.

now allow time-stretching from a Lua script

Does this create a new region or is it on the fly?

Is it just time stretching or is pitch shifting included too?

Time stretch operations in Ardour are one of the few ‘destructive’ (In that it creates a new region on dick, not that it removes or changes the old data) operations. It will happen offline. Beyond that I haven’t looked at Robin’s script yet to be able to answer if it will pitch shift, I know the tool can choose to stretch with and without pitch shift, but it isn’t used to pitch shift on it’s own I do not believe.

   Seablade
1 Like

If I was younger and more enthusiastic man I would be right into it !
I would love to see ArTrak as a native feature but the only way I could do that is pay someone to develop it into Ardour as Ben @ Harrison suggested.

Not sure what needs adding,
you have given support to scripting for a reason as not many proprietary DAW’s have it.
You could of said why have scripting, it’s open source you can compile what you need yourself.
So I don’t know what way to go.
Maybe just use the Biab or RapidComposer VSTs

A new region (really a new source file) is created.
The premise is that you only do the operation once, but then play it back multiple times.

You can do both using rubberband’s API.

1 Like