2024-02-21 19:29:29 -05:00
ardour {
[ " type " ] = " EditorAction " ,
name = " Import ADM BWF File " ,
author = " Ardour Team " ,
2024-02-26 15:49:52 -05:00
description = [[Load dynamic meta-data from an ADM file, import audio channels to the timeline and copy fixed settings for export.]]
2024-02-21 19:29:29 -05:00
}
function factory ( ) return function ( )
function parse_bin_mode ( mode )
if mode == " Off " then return 1 end
if mode == " Near " then return 2 end
if mode == " Far " then return 3 end
return 0 -- "Undefined" ie "Mid"
end
2024-02-24 21:22:26 -05:00
function parse_zone ( zone )
if zone == " No Back " then return 1 end
if zone == " No Sides " then return 2 end
if zone == " Center Back " then return 3 end
if zone == " Screen Only " then return 4 end
if zone == " Surround Only " then return 5 end
return 0
end
function parse_ramp ( ramp )
if tonumber ( ramp ) == 0 then return 0 end
return 1
end
2024-02-26 18:27:43 -05:00
if 0 ~= os.execute ( " master_info -h " ) then
2024-03-11 10:14:44 -04:00
local md = LuaDialog.Message ( " Master Info Tool Missing " , " The 'master_info' tool from Dolby_Atmos_Storage_SIDK_v2.3.2/Tools/ needs to be in $PATH for ADM BWF meta-data import to work. " , LuaDialog.MessageType . Error , LuaDialog.ButtonType . Close )
2024-02-26 18:27:43 -05:00
print ( md : run ( ) )
return 1
end
2024-03-11 10:14:44 -04:00
local rv = LuaDialog.Dialog ( " Load ADM BWF File " ,
2024-02-21 19:29:29 -05:00
{
2024-03-11 10:14:44 -04:00
{ type = " file " , key = " file " , title = " Choose ADM BWF File " , path = " " } ,
2024-02-21 19:29:29 -05:00
} ) : run ( )
if ( not rv or not ARDOUR.LuaAPI . file_test ( rv [ ' file ' ] , ARDOUR.LuaAPI . FileTest.Exists ) ) then
return
end
2024-02-23 11:03:41 -05:00
-- place `Dolby_Atmos_Storage_SIDK_v2.3.2/Tools/linux/lin64_fpic/master_info` in $PATH
2024-02-26 18:27:43 -05:00
if 0 ~= os.execute ( " master_info -printMetadata \" " .. rv [ ' file ' ] .. " \" > /tmp/adm.info " ) then
local md = LuaDialog.Message ( " Master Info Tool Error " , " The 'master_info' tool failed to extract meta-data from \n ' " .. rv [ ' file ' ] .. " '. " , LuaDialog.MessageType . Error , LuaDialog.ButtonType . Close )
print ( md : run ( ) )
return 1
end
2024-02-21 19:29:29 -05:00
if Session : get_tracks ( ) : size ( ) == 0 then
print ( " Importing Files ... " )
Session : cfg ( ) : set_use_surround_master ( true )
Session : cfg ( ) : set_use_region_fades ( false )
local files = C.StringVector ( )
files : push_back ( rv [ ' file ' ] )
local pos = Temporal.timepos_t ( 0 )
Editor : do_import ( files ,
Editing.ImportDistinctChannels , Editing.ImportAsTrack , ARDOUR.SrcQuality . SrcBest ,
ARDOUR.MidiTrackNameSource . SMFTrackName , ARDOUR.MidiTempoMapDisposition . SMFTempoIgnore ,
pos , ARDOUR.PluginInfo ( ) , ARDOUR.Track ( ) , false )
print ( " Files Imported " )
end
local meta = { }
2024-02-23 16:22:50 -05:00
local chan_map = { }
2024-02-21 19:29:29 -05:00
local last_chan = 0
for line in io.lines ( ' /tmp/adm.info ' ) do
local rv , _ , chn = string.find ( line , " channel (%d+) descriptor " )
if rv then
last_chan = tonumber ( chn )
goto next
end
2024-02-23 16:22:50 -05:00
local rv , _ , idx = string.find ( line , " source channel index: (%d+) " )
2024-02-21 19:29:29 -05:00
if rv then
2024-02-23 16:22:50 -05:00
chan_map [ last_chan ] = tonumber ( idx )
2024-02-21 19:29:29 -05:00
goto next
end
2024-02-24 21:22:26 -05:00
local rv , _ , obj , tme , pan_ramp , pan_x , pan_y , pan_z , pan_snap , pan_eleven , pan_zone , pan_size , bin_mode = string.find ( line ,
" Metadata.* index: (%d+) offset: (%d+) .* ramp: (%d+) pos: %(([%d%.]+),([%d%.]+),([%d%.-]+)%) snap: (%d) elevation: (%d) zone: '([%a ]+)' size: %(([%d%.]+),.* binaural: '(%a+)' " )
2024-02-21 19:29:29 -05:00
if not rv then goto next end
if not meta [ obj ] then
2024-02-24 21:22:26 -05:00
meta [ obj ] = { x = { } , y = { } , z = { } , sz = { } , sn = { } , el = { } , rp = { } , zn = { } }
2024-02-21 19:29:29 -05:00
end
tme = tonumber ( tme )
meta [ obj ] [ ' x ' ] [ tme ] = tonumber ( pan_x )
meta [ obj ] [ ' y ' ] [ tme ] = tonumber ( pan_y )
meta [ obj ] [ ' z ' ] [ tme ] = tonumber ( pan_z )
meta [ obj ] [ ' sz ' ] [ tme ] = tonumber ( pan_size )
meta [ obj ] [ ' sn ' ] [ tme ] = tonumber ( pan_snap )
2024-02-24 21:22:26 -05:00
meta [ obj ] [ ' el ' ] [ tme ] = tonumber ( pan_eleven )
meta [ obj ] [ ' rp ' ] [ tme ] = parse_ramp ( pan_ramp )
meta [ obj ] [ ' zn ' ] [ tme ] = parse_zone ( pan_zone )
2024-02-21 19:29:29 -05:00
meta [ obj ] [ ' bin ' ] = bin_mode
:: next ::
end
print ( " Setting Metadata " )
2024-02-27 11:41:23 -05:00
2024-02-21 19:29:29 -05:00
for obj , d in pairs ( meta ) do
local r = Session : get_remote_nth_route ( obj )
if r : isnil ( ) then goto skip end
local s = r : surround_send ( )
if s : isnil ( ) then goto skip end
assert ( 1 == s : n_pannables ( ) )
local p = s : pannable ( 0 )
2024-02-27 11:41:23 -05:00
p.pan_pos_x : to_ctrl ( ) : list ( ) : set_interpolation ( Evoral.InterpolationStyle . Discrete )
p.pan_pos_y : to_ctrl ( ) : list ( ) : set_interpolation ( Evoral.InterpolationStyle . Discrete )
p.pan_pos_z : to_ctrl ( ) : list ( ) : set_interpolation ( Evoral.InterpolationStyle . Discrete )
p.pan_snap : to_ctrl ( ) : list ( ) : set_interpolation ( Evoral.InterpolationStyle . Discrete )
local thin = 0 -- 0.00001
2024-02-24 21:22:26 -05:00
ARDOUR.LuaAPI . set_automation_data ( p.pan_pos_x , d [ ' x ' ] , thin )
ARDOUR.LuaAPI . set_automation_data ( p.pan_pos_y , d [ ' y ' ] , thin )
ARDOUR.LuaAPI . set_automation_data ( p.pan_pos_z , d [ ' z ' ] , thin )
ARDOUR.LuaAPI . set_automation_data ( p.pan_size , d [ ' sz ' ] , thin )
ARDOUR.LuaAPI . set_automation_data ( p.pan_snap , d [ ' sn ' ] , thin )
ARDOUR.LuaAPI . set_automation_data ( p.sur_elevation_enable , d [ ' el ' ] , thin )
ARDOUR.LuaAPI . set_automation_data ( p.sur_zones , d [ ' zn ' ] , thin )
ARDOUR.LuaAPI . set_automation_data ( p.sur_ramp , d [ ' rp ' ] , thin )
2024-02-21 19:29:29 -05:00
p.binaural_render_mode : set_value ( parse_bin_mode ( d [ ' bin ' ] ) , PBD.GroupControlDisposition . NoGroup )
-- this changes all
p.pan_pos_x : set_automation_state ( ARDOUR.AutoState . Play )
:: skip ::
end
2024-02-23 16:22:50 -05:00
local imap = C.IntVector ( )
for k = 0 , 127 do
v = chan_map [ k ] or k
imap : add ( { v } )
end
Session : surround_master ( ) : surround_return ( ) : set_bed_mix ( true , rv [ ' file ' ] , imap : to_array ( ) )
2024-02-21 19:29:29 -05:00
print ( " OK " )
end end
2024-02-26 15:49:52 -05:00
function icon ( params ) return function ( ctx , width , height , fg )
local wh = math.min ( width , height )
ctx : set_source_rgba ( ARDOUR.LuaAPI . color_to_rgba ( fg ) )
ctx : arc ( 0.5 * width - wh * 0.3 , 0.5 * height , wh * .275 , - 0.5 * math.pi , 0.5 * math.pi )
ctx : close_path ( )
ctx : fill ( )
ctx : arc ( 0.5 * width + wh * 0.3 , 0.5 * height , wh * .275 , 0.5 * math.pi , 1.5 * math.pi )
ctx : close_path ( )
ctx : fill ( )
end end