manual

64 WaveLab Concepts
Scripting window contexts
It is important to note that certain scripting commands are only available in the Audio File
Workspace and others only in the Audio Montage Workspace. Others are "global", meaning
you can use them in either Workspace. To begin exploring the WaveLab Scripting Language
in more detail see the WaveLab Scripting Language.
A basic scripting example
Below is a basic scripting example which uses some WaveLab scripting functions to perform
some simple operations on an Audio File in the Audio File Workspace. The script first displays
information about the Audio File, fades in the start and fades out the end of the file, and then
adds ten markers at 1 second intervals. Examine it line by line and read the comments for
each operation to see how it works.
/* To run this script:
- open an Audio File that is at least 10 seconds long
- open the Log window via the Utilities menu
- copy and paste this script into the Script window
- choose Functions > Execute Script */
//clear the log window
logWindow.clear();
//show some information about the active wave file in the log window
logWindow.printInfo("This wave file has " + activeWave.size() + " samples");
logWindow.printInfo("Its sample rate is " + activeWave.sampleRate());
logWindow.printInfo("It has " +activeWave.numChannels() + " channels");
//Work out how long the file is in seconds and round to a whole number
var lengthSecs = activeWave.size() / activeWave.sampleRate();
logWindow.printInfo("This wave file is " + lengthSecs + " seconds long");
//Select the first 10 seconds of the file
activeWave.select(0, 10 * activeWave.sampleRate());
//Trim the file to 10 seconds
activeWave.trim();
//select the first two seconds of the file and fade it in
activeWave.select(0, 2 * activeWave.sampleRate()); //sample rate multiplied by tw
o = 2 seconds
activeWave.fadeIn(linear);
//select the last two seconds of the file and fade it out
activeWave.select(activeWave.size() - (2 * activeWave.sampleRate()), activeWave.s
ize());
activeWave.fadeOut(linear);
//loop through 10 times and add a marker each second
for (i = 1; i <= 10; i++)
{
//work out next cursor time
var nextCursorPosition = i * activeWave.sampleRate();
//set cursor position forwards by a second
activeWave.setCursorPosition(nextCursorPosition);
//add a generic marker at the next cursor position and give it a name and comme
nt
WaveLab 7