|
|
|
03-02-2021, 08:34 AM
|
#1
|
Human being with feelings
Join Date: Jan 2021
Location: Paris
Posts: 255
|
Rodilab_ Explode multichannel items to mono items in new tracks (without render)
[Edit 17/03/2020 - v1.0 in ReaPack]
Hi,
I made a new script for "Explode multichannel items to mono items in new tracks (without render)".
In order to preserve source media file metadata, and not render new mono files, this script copy/past item in new tracks and changes the "take channel mode".
New tracks keep same info values (color, volume, etc).
Last edited by Rodilab; 03-17-2021 at 01:04 AM.
|
|
|
03-02-2021, 10:09 AM
|
#2
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
Still better than the native action :P
I have a script pack for Explode Items Takes/Channels cause there can be some other consideration like exploding on child track, exploding on child tracks without create new tracks etc... but the basic logic is the same as you found (using copy items).
Your code seems quite ok too apart the lack of PreventUIRefresh :P
|
|
|
03-02-2021, 05:03 PM
|
#3
|
Human being with feelings
Join Date: Feb 2014
Posts: 240
|
Might be OK, but routing to new tracks instead of new media items should use less CPU.
|
|
|
03-03-2021, 02:05 AM
|
#4
|
Human being with feelings
Join Date: Jan 2021
Location: Paris
Posts: 255
|
Quote:
Originally Posted by X-Raym
Still better than the native action :P
I have a script pack for Explode Items Takes/Channels cause there can be some other consideration like exploding on child track, exploding on child tracks without create new tracks etc... but the basic logic is the same as you found (using copy items).
Your code seems quite ok too apart the lack of PreventUIRefresh :P
|
Thanks Raym
I will add a "PreventUIRefresh".
Code:
Might be OK, but routing to new tracks instead of new media items should use less CPU.
You're right, I did a test with 90 mono tracks. One exploded with my script, the other with the native script (so rendered in new mono audio files)
The difference : 5.5% to 4.5%
There is mostly a difference in disc playback : 60Mb/s to 15Mb/s
|
|
|
03-03-2021, 02:24 AM
|
#5
|
Human being with feelings
Join Date: Jan 2021
Location: Paris
Posts: 255
|
@Raym :
Like this for "PreventUIRefresh" and "UpdateArrange" ?
When do we actually need to add a "PreventUIRefresh" or a "UpdateArrange" ?
Code:
-- @description Explode multichannel items to mono items in new tracks (without render)
-- @author Rodilab
-- @version 0.1
-- @about
-- Explode multichannel selected items to mono items in new tracks (without render new source files).
-- This script changes the channel mode of the takes.
--
-- by Rodrigo Diaz (aka Rodilab)
local count = reaper.CountSelectedMediaItems(0)
if count > 0 then
reaper.PreventUIRefresh(1)
reaper.Undo_BeginBlock()
-- Save selected items in a list
local item_list={}
for i=0, count-1 do
item_list[i+1] = reaper.GetSelectedMediaItem(0,i)
end
local pevious_track = ""
local track_max_chan = 1
for i, item in ipairs(item_list) do
-- Get some track/item/take/source infos
local track = reaper.GetMediaItem_Track(item)
local track_id = reaper.GetMediaTrackInfo_Value(track,"IP_TRACKNUMBER")
local take = reaper.GetActiveTake(item)
local take_name = reaper.GetTakeName(take)
local take_chanmode = reaper.GetMediaItemTakeInfo_Value(take,"I_CHANMODE")
local source = reaper.GetMediaItemTake_Source(take)
local source_chan = reaper.GetMediaSourceNumChannels(source)
-- Find the real chan num of take
if source_chan > 1 and take_chanmode < 2 then
take_chan = source_chan
elseif source_chan > 1 and take_chanmode > 66 then
take_chan = 2
else
take_chan = 1
end
if take_chan > 1 then
-- Create new tracks if necessary
if track == previous_track then
if track_max_chan < take_chan then
for j=0, take_chan - track_max_chan - 1 do
reaper.InsertTrackAtIndex(track_id+track_max_chan+j,true)
local _,track_name = reaper.GetSetMediaTrackInfo_String(track,"P_NAME","",false)
local new_track = reaper.GetTrack(0,track_id+track_max_chan+j)
reaper.GetSetMediaTrackInfo_String(new_track,"P_NAME",track_name.." - "..(j+track_max_chan+1),true)
end
track_max_chan = take_chan
end
else
track_max_chan = take_chan
for j=0, take_chan - 1 do
reaper.InsertTrackAtIndex(track_id+j,true)
local _,track_name = reaper.GetSetMediaTrackInfo_String(track,"P_NAME","",false)
new_track = reaper.GetTrack(0,track_id+j)
reaper.GetSetMediaTrackInfo_String(new_track,"P_NAME",track_name.." - "..(j+1),true)
end
end
previous_track = track
track_id = reaper.GetMediaTrackInfo_Value(track,"IP_TRACKNUMBER")
reaper.Main_OnCommand(40769,0)-- Unselect all
reaper.SetMediaItemSelected(item,true)-- Select item
reaper.Main_OnCommand(40698,0)-- Copy item
reaper.Main_OnCommand(41173,0)-- Move cursor
reaper.SetOnlyTrackSelected(track)-- Select one track
for i=0, take_chan-1 do
reaper.Main_OnCommand(40285,0)-- Go to next track
reaper.Main_OnCommand(42398,0)-- Past item
reaper.Main_OnCommand(41173,0)-- Move cursor
-- Set take name
local new_item = reaper.GetSelectedMediaItem(0,0)
local new_take = reaper.GetActiveTake(new_item)
reaper.GetSetMediaItemTakeInfo_String(new_take,"P_NAME",take_name.." - "..i+1,true)
-- Change new take chanmode to mono (depend of parent take chanmode)
if take_chanmode == 0 then
reaper.SetMediaItemTakeInfo_Value(new_take,"I_CHANMODE",i+3)
elseif take_chanmode == 1 then
if i == 0 then
reaper.SetMediaItemTakeInfo_Value(new_take,"I_CHANMODE",4)
elseif i == 1 then
reaper.SetMediaItemTakeInfo_Value(new_take,"I_CHANMODE",3)
else
reaper.SetMediaItemTakeInfo_Value(new_take,"I_CHANMODE",i+3)
end
elseif take_chanmode > 66 then
reaper.SetMediaItemTakeInfo_Value(new_take,"I_CHANMODE",(take_chanmode-67)+i+3)
end
end
end
end
reaper.Undo_EndBlock("Explode multichannel items to mono items in new tracks (without render)",0)
reaper.PreventUIRefresh(-1)
reaper.UpdateArrange()
end
|
|
|
03-03-2021, 02:33 AM
|
#6
|
Human being with feelings
Join Date: Dec 2012
Posts: 13,334
|
Quote:
Originally Posted by Rodilab
@Raym :
Like this for "PreventUIRefresh" and "UpdateArrange" ?
When do we actually need to add a "PreventUIRefresh" or a "UpdateArrange" ?
|
I would like to know, too. I think the first one just stops refreshing the whole UI, while updating arrange is used when you change something in arrange, like splitting items or move them.
|
|
|
03-03-2021, 03:13 AM
|
#7
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
Seems good.
preventuirefresh if the scrpit will do lots of things which will change the UI but we didnt need to see until the end results.
UpdateArrange if something has changed in the arrange view at the end of the script cause not all reaper api fubctions actualy refresh arrange (to save CPU)
Also, have you tested your script for items with snap offset not at 0 ? :P
|
|
|
07-17-2023, 02:04 PM
|
#8
|
Human being with feelings
Join Date: Jun 2016
Posts: 267
|
Cool!
I came across this post because I was looking to have access to the entire source file after exploding takes to new tracks... and also not have to create to files for no reason.... and it seems this does it.
I wonder why this isn't the default behavior, since it's less destructive.
Anyway, I'll just sub out this action in the menu. Thanks again!
|
|
|
08-09-2023, 02:38 PM
|
#9
|
Human being with feelings
Join Date: Jun 2016
Posts: 267
|
Hey Rodilab, I love this script
One thing I'd like to change, if it's easy, is for the view to not change after running the script.
I'm no programmer, but is there a line of code you could suggest I try modifying?
Currently, after running this script, the Reaper session is scrolled all the way to the top. So if I'm at the bottom of a bunch of tracks, and I run the script, I then am forced to scroll down to where I was.
If it's too complicated, I'm happy as is -- just thought I'd ask if it were a simple amendment.
Thanks!
Pietro
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 01:10 PM.
|