Midi Region creation via LUA

With 6, can I now create/copy or otherwise get an uncoupled copy of midi region into a new track? I can create the track happily, just cannot work out how to create the midi region.

Thanks.

Mike

try

local new_region = ARDOUR.RegionFactory.clone_region (region, true, true) 

That calls C++ RegionFactory::create (RegionPtr region, bool announce, bool fork) setting “fork = true” will return an unlinked new MIDI region. You should be able to add this to the playlist of a new MIDI track:

local pl = the_track:playlist()
pl:add_region (new_region, region:position(), 1, false, 0, 0, false) 

Many thanks - the flags was the problem - unsure why that works now but didn’t before. The docs I have don’t name the flags, FORK for example, where did you find that please?

Being self service is far easier if I know where to look. :slight_smile:

This one is tricky.

There are many different Region constructors, clone_region does not match the underlying C++ c’tor. I manually looked it up in the corresponding source files (libs/ardour/luabindings.cc and libs/ardour/ardour/region_factory.h).

A bigger issue however is that only about 15% of all methods are documented in the source (doxygen), so even if the connection (clone_region -> ::create) was made the parameters would not be documented.

Out of interest, what does ANNOUNCE flag do? Nearly all create methods have it…and defaulted to true in nearly every case.

Thanks,

Mike

The announce flag c(if true) auses a signal to be emitted that notifies others that the region has been created. It should generally be true. False is generally for locally-scoped and/or other private regions that are short-lived and not intended to be a part of the user’s timeline operations.

Many thanks both.

So daft question - I want to loop over user region selection (more than one) more than once. But when I add a track and region in the LUA script, the selection changes (in fact nothing is selected).

What would be your best method (is there a sneaky way I am not sure of due to being new to Lua and Lua in Ardour) to save the original regions selected so that I can come back to them at a later time.

Many thanks for all your help.

You should be able to just copy the regionlist:

local selection = Editor:get_selection()
local selected_regions = selection.regions:regionlist()

and later iterate over that list

for r in selected_regions:iter() do
  ...
end

Ok - no idea why that works now - chalk it up to experience.

So - New problem - and hopefully last problem for now. (Sorry for all the questions but I am learning quickly), I have the following which all works bar the very LAST line. Fails with

LuaException: [string "ardour {..."]:70: attempt to call a nil value (method 'model')

Code
67 local newRegion = ARDOUR.RegionFactory.clone_region(midi_region, true,true)
68 local playList = newTrack:playlist()
69 playList:add_region(newRegion, midi_region:position(), 1, false, 0, 0, false)
70 local newModel = newRegion:model()

Oddly this bit of code works…
Code
55 local model = midi_region:model()
56 local notes = ARDOUR.LuaAPI.note_list(model)

midi_region and newRegion are both userdata objects and appear valid.

Your help with this (hopefully) last hurdle will be greatly appreciated. Incidentally, what do you chaps use for a IDE for LUA - I am using Bluefish which is just a glorified text editor but it works.

Why is it that I always try just that ONE more thing after asking for help.

I had to cast the region to a midiregion and then it worked.

Still would like to know about your IDEs though :slight_smile:

EDIT

Ok - final problem - and - been at it 2 hours now - time to ask.

All regions being created properly, all notes being copied over. Overthing GOOD except I cannot remove notes. If you see on the far right, I set the midi_command, remove notes on a region by region basis (in an outer loop which also creates the track one at a time) and then ‘commits’ it. The regions appear correcty but as exact clones.

The process is roughly, Add track for note 34. Scan all regions selected one by one. If note 34 exists, clone region, then go through it and remove anything NOT note 34. Commit and move to the next region, and eventually next track and repeat. Everything appears to happen, even the “remove” does something without erroring, and the UNDO(s) are in the menu. Just the notes are not removed.

In the above image, only the top track existed to start with, with 3 different drum notes. When selecting that region, it made the 3 tracks in a group and put the regions in etc, I just need to bin the other notes in each track.

I am probably doing something in the wrong order etc.

As a VERY last question - can I ask the track via LUA to expand the view so that the contents fit. There is a menu command, just wondering if I can ping it at all.

Thanks.

Neither Robin nor myself (nor any other current and almost no previous Ardour contributors) use an “IDE”. Robin is a vi(m) user, and I use emacs. We have a build system that is platform and IDE independent. If people want to use an IDE, they are welcome to, but we are never to tie the build system or any other aspect of Ardour development to a particular tool (note that we already support multiple compilers, linkers and debuggers).

Was anybody able to assist with the above problem. I have the midi command in a loop, and it appears to remove the notes, but it just doesn’t do it physically. The notes remain.

Aside : If the region existed already, then the code above (in a cut down snippet form) works and removes the notes.

I have a feeling it is because I create the region as a clone and remove notes ‘immediately’. Do I have to ‘commit’ something or other.

Many thanks in advance!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.