Caught in infinite loop

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
RNIB
Macro Veteran
Posts: 193
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Caught in infinite loop

Post by RNIB » Wed Mar 16, 2016 12:22 pm

I keep getting caught in an infinite loop with a macro I'm working on and I can't work out what I'm doing wrong.

This is the code:

Code: Select all

//Ask if the magazine has multiple parts
Input>TotalParts,How Many Parts Does This Magazine Have?,1
//Single part
If>TotalParts=1
Let>INPUT_BROWSE=2
Input>AudioFolder,Please select the folder containing the audio files you wish to append.,
Let>PartNo=1
ELSE
//Multiple parts
Let>NumTimes=TotalParts+1
Let>loop=1
Repeat>loop
Let>INPUT_BROWSE=2
Input>AudioFolder%loop%,Please select the folder containing the audio files for Part %loop%.,
If>AudioFolder%loop%=""
Exit>0
EndIF
Until>loop=NumTimes
EndIF
Input>ProdNumber,Please Enter The Production Number?,150
Input>PubDate,Please Enter The Publication Date As YYMMDD?,
Input>ProducerName,Please Enter The Initials of The Audio Producer,
So what is supposed to happen is the user is asked how many parts a magazine has. If they answer say 2 then the macro asks them to locate the folder containing the files for Part 1 and then asks them to locate the folder for Part 2. At which point it then should continue with the rest of the script.

What I'm finding is that it keeps asking for folders for part 1, 2, 3, - infinity and even if I click on cancel or the X it just keeps going.

Is it because I'm using Nested IF's - not sure on what the correct way of working with them is.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Caught in infinite loop

Post by JRL » Wed Mar 16, 2016 1:05 pm

Code: Select all

//Ask if the magazine has multiple parts
Input>TotalParts,How Many Parts Does This Magazine Have?,1
//Single part
If>TotalParts=1
  Let>INPUT_BROWSE=2
  Input>AudioFolder,Please select the folder containing the audio files you wish to append.,
  Let>PartNo=1
ELSE
  //Multiple parts
  Let>NumTimes=TotalParts+1
  Let>loop=1
  Repeat>loop
    Let>INPUT_BROWSE=2
    //Input can't assign a variable name that contains the "loop" variable
    //You'll have to create that variable separately
    Input>AFloop,Please select the folder containing the audio files for Part %loop%.,
    Let>AudioFolder%loop%=AFLoop
    ////////////////////////////////////////////////
    //If> can't use a variable name that contains the "loop" variable 
    If>AFloop=""
      Exit>0
    EndIF
    //Need a "Loop" incrementer line otherwise you'll have an infinite loop
    Let>Loop=Loop+1
  Until>loop=NumTimes
EndIF
Input>ProdNumber,Please Enter The Production Number?,150
Input>PubDate,Please Enter The Publication Date As YYMMDD?,
Input>ProducerName,Please Enter The Initials of The Audio Producer,

RNIB
Macro Veteran
Posts: 193
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Caught in infinite loop

Post by RNIB » Wed Mar 16, 2016 2:51 pm

Aha!!

Thanks so much, you saved me from going bald(er). Didn't realise you couldn't use loop but it makes sense thinking about it :oops:

RNIB
Macro Veteran
Posts: 193
Joined: Thu Jan 10, 2008 10:25 am
Location: London, UK

Re: Caught in infinite loop

Post by RNIB » Wed Mar 16, 2016 4:14 pm

Ahh I think there is a problem

This is the start of the script

Code: Select all

//Ask if the magazine has multiple parts
Input>TotalParts,How Many Parts Does This Magazine Have?,1
//Single Part
If>TotalParts=1
Let>INPUT_BROWSE=2
Input>AudioFolder,Please select the folder containing the audio files you wish to append.,
If>AudioFolder=""
Exit>0
EndIF
Let>PartNo=1
ELSE
//Multiple Parts
Let>PartNo=TotalParts
Let>NumTimes=TotalParts+1
Let>loop=1
Repeat>loop
Let>INPUT_BROWSE=2
Input>AFLoop,Please select the folder containing the files for Part %loop%.,
Let>AudioFolder%loop%=AFLoop
If>AFLoop=""
Exit>0
EndIF
Let>Loop=Loop+1
Until>loop=NumTimes
ENDIF
//Continue with rest of data gathering
But then later I have this:

Code: Select all

//Locate to File Name Field
Press Alt
Send>n
Release Alt
Wait>1
IF>TotalParts=1
Send>%AudioFolder%
Else
Send>AudioFolder%loop%
EndIF
This bit needs to enter the full path of the folder containing the files for each part. So if there are two parts then, for part 1 it enters the path for the folder containing the files for Part 1 on the first pass and then enters the path for part 2 on the second pass.

It will probably help to explain what the macro does in full.

I need to join several files together in Adobe Audition and drop in markers and metadata and then save the result as a new file which is for an audio magazine. However sometimes the magazine will be in 1 part and other times it will be in 2, 3 or more parts. When there are multiple parts each new file needs to be created individually but odd numbered parts have have different metadata to even numbered parts.

So the basic overview is:
Collect information about the magazine
If there are more than 1 part, collect the paths to the files for both parts
Load files for the first part into Audition and join them together
Add relevant metadata depending on whether it is an odd or even part number
Save the file to a specified location
If there is more than one part, repeat the process but this time load files for part 2, 3 etc

This is my full code at the moment (a work in progress), I had this all working for single parts but now am trying to get it to automate multiple parts so some of the code towards the end hasn't been changed yet:

Code: Select all

//Ask if the magazine has multiple parts
Input>TotalParts,How Many Parts Does This Magazine Have?,1
//Single Part
If>TotalParts=1
Let>INPUT_BROWSE=2
Input>AudioFolder,Please select the folder containing the audio files you wish to append.,
If>AudioFolder=""
Exit>0
EndIF
Let>PartNo=1
ELSE
//Multiple Parts
Let>PartNo=TotalParts
Let>NumTimes=TotalParts+1
Let>loop=1
Repeat>loop
Let>INPUT_BROWSE=2
Input>AFLoop,Please select the folder containing the files for Part %loop%.,
Let>AudioFolder%loop%=AFLoop
If>AFLoop=""
Exit>0
EndIF
Let>Loop=Loop+1
Until>loop=NumTimes
ENDIF
//Continue with rest of data gathering
Input>ProdNumber,Please Enter The Production Number?,150
If>ProdNumber=""
Exit>0
EndIF
Input>PubDate,Please Enter The Publication Date As YYMMDD?,
If>PubDate=""
Exit>0
EndIF
Input>ProducerName,Please Enter The Initials of The Audio Producer,
If>ProducerName=""
Exit>0
EndIF
Input>SaveDrive,Please Select Where You Want The File Saved,
If>SaveDrive=""
Exit>0
EndIF
//Works out if the number of parts are odd or even
Let>x={%PartNo% mod 2}
SetFocus>Adobe Audition
Wait>1
//makes sure Audition is set to Edit view
Send>8
//Open Append
Press ALT
Send>f
Release ALT
Wait>1
Send>d
WaitWindowOpen>Open Append
Wait>2
//Locate to File Name Field
Press Alt
Send>n
Release Alt
Wait>1
IF>TotalParts=1
Send>%AudioFolder%
Else
Send>AudioFolder%loop%
EndIF
Wait>1
Press Enter
Wait>3
Press Shift
Press Tab*2
Release Shift
//select in reverse order
Wait>1
Press End
Press Shift
Press Home
Release Shift
Wait>1
//load audio
Press Enter
WaitWindowOpen>Adobe Audition - Untitled*
//This is where it needs to work out if it is an odd or even part number
IF>x=0
//For Even Parts
//Add CD Track
Press End
//open marker list
Press Alt
Send>8
Release Alt
Wait>1
MouseMoveRel>430,119
LClick
Press Tab
Press Right*2
Press Enter
Press Tab
Send>CD Track 01
Press Tab*4
Press Down
Press Home
Press Down*2
Press Enter
Press Tab*7
Send>r
Press Enter
//delete first track
Press Tab
Press Home
Press Tab
Press Right
Press Enter
Wait>1
MouseMoveRel>430,119
LClick
Wait>1
Press End
Press Up
Press Tab*7
Send>s
Press Enter
Wait>1
Press Alt
Send>8
ELSE
//For Odd Numbered Parts
//Add CD Track
Press End
//open marker list
Press Alt
Send>8
Release Alt
Wait>1
MouseMoveRel>430,119
LClick
Press Tab
Press Right*2
Press Enter
Press Tab
Send>CD Track 01
Press Tab*4
Press Down
Press Home
Press Down*2
Press Enter
Press Tab*7
Send>r
Press Enter
//delete first track
Press Tab
Press Home
Press Tab
Press Right
Press Enter
Wait>1
MouseMoveRel>430,119
LClick
Wait>1
Press Home
Press Tab*7
Send>s
Press Enter
Wait>1
Press Alt
Send>8
ENDIF
//save the file
Release Alt
Press Alt
Send>f
Release Alt
Send>e
Wait>2
Press Tab*5
Wait>1
Send>%SaveDrive%\%ProdNumber%_%PubDate%_%ProducerName%_%Part_No%.wav
Press Enter

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts