• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Automation Blocks - Modifying Audio Channels and Laying Tracks into Timeline

Participant ,
Apr 08, 2024 Apr 08, 2024

Copy link to clipboard

Copied

Hi There,

 

I have a script that does the following...

For all selected project items:
-Modify Audio Channels from Stereo to Dual Mono (some of the selected won't be stereo)

-Lay project items into specific tracks on a sequence dependent on file names.

 

I have it working, with some flaws...

-It lays project items into the sequence before modifying the audio channels, and then overwrites them on the sequence after modifying audio channels

-If there are no project items with audio channels that need modifying, it still lays the project items in the correct sequence tracks, but gives me an error:
"Cannot set property audioChannelsType (line 4)"

 

The ultimate result is the script does what I want. But I feel like it's bad practice. 
Can you tell me how to modify the script to:

-lay project items in sequence tracks only once, after modifying

-Understand that if no project items need audio channel modification, that's ok

 

Also, you'll see from the attached script that I repeat the if-do multiple times, just to run the same script. Is there away to combine all those if-do statements into one?

TOPICS
SDK

Views

785

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 09, 2024 Apr 09, 2024

Here is simplified example showing what happens if you nest loops inside each other:Screenshot 2024-04-09 at 13.28.34.png

 

On the right side you can see the console output of the "write to console" blocks. And as you can see, the first "write to console" message is executed 3 times (once for each iteration of the outer loop) and the second "write to console" message is executed 9 times, namely 3 times for each run of the outer loop.

Votes

Translate

Translate
Community Expert ,
Apr 09, 2024 Apr 09, 2024

Copy link to clipboard

Copied

Hi Sam,

here is a revised version of your code:

Screenshot 2024-04-09 at 13.13.14.png

You can search for multiple strings at once using the search in text block which is like a more powerful version of the basic  find in text block with more options. In particular it offers a "Regular Expression" option, which allows you to search for complex patterns.

 

The more important change is that I eliminated the second green "for each item" block, which you nested inside the first one. Say the outer green block is executed three times (if you have three project items selected) and you nest a second copy of the same block inside of it, then everything inside the nested block is executed nine times (3 times for each time the outer loop is executed). That means, you inserted each clip not only once, but three times - and in the first round of insertions all three clips where insertet, but only for the first one the audio channels have been changed already.

Code is attached.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2024 Apr 09, 2024

Copy link to clipboard

Copied

Here is simplified example showing what happens if you nest loops inside each other:Screenshot 2024-04-09 at 13.28.34.png

 

On the right side you can see the console output of the "write to console" blocks. And as you can see, the first "write to console" message is executed 3 times (once for each iteration of the outer loop) and the second "write to console" message is executed 9 times, namely 3 times for each run of the outer loop.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 09, 2024 Apr 09, 2024

Copy link to clipboard

Copied

Thank you! Find in Text is going to help me a lot going forward. It's the kind of simplication I was hoping for.

 

The only issue with your modified script is IF there are NO selected clips that need audio channel mapping, the script doesn't lay everything into the timeline. This use-case will happen often, as we will only need to remap our audio channels once, but this bunch if clips will get cut into multiple sequences

 

Adding back that nested green block actually fixes that issue. But, as you said, is a very inefficient way to do it and does show an error in the console.

How would I go about running part two of the script, irrespective of the outcome of part one?

In general, is there a simple way to attach two independant scripts together into one script and choose the order in which they run?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 10, 2024 Apr 10, 2024

Copy link to clipboard

Copied

Ok, the issue there seems to be that you have some clips selected which have no audio at all and then when the script tries to set the audio channels, it stops the execution with an error (and hence does not do any of the subsequent commands.

Attached you find a new version of the script. The only change I did was in the execute code block. The entire code is now wrapped into a try-catch statement, which ensures that if an error happens during the code execution the script just ignores the error and continues:

 

try {
var mapping = myItem.getAudioChannelMapping;
if(mapping && mapping.audioChannelsType != 0){
mapping.audioChannelsType = 0;
mapping.audioClipsNumber = 2;
myItem.setAudioChannelMapping(mapping);
}
}
catch(err){}

 

Alternatively, you could also refine your if-statement and only execute the code block if both

- the string 2MX|2FX|... is found AND

- the clip has audio.

 

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 10, 2024 Apr 10, 2024

Copy link to clipboard

Copied

LATEST

That worked perfectly! Thank you!

If you're curious, it wasn't that some of the selected clips had no audio, it was in instances where there was no audio that needed to be re-mapped (in other words, nothing in 1 Track Stereo).


None the less, your modification worked perfectly!

 

With every bit of guidance you give me, I learn more and more about this program. I've written more scripts in the past few days than ever before. Thank you for an awesome product.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines