Wouldn't it be nice to have an assistant in your studio? Someone who could take care of repetitive tasks for you? Someone who would know enough computer programming to write handy utilities, new commands, customized effects, and other features to add to your favorite sequencer, software sampler, or music-notation program?
Well, lurking beneath the surface of many computer applications is just such an assistant, and it's called scripting. A script is a specialized computer language that lets you take control of a program in new ways. In this article, I'll give some examples of how you can use scripting with a software sampler, a music-notation program, and a sequencer. But first, a few general words about this useful application.
FIG. 1A: Figure 1a shows a short piece of notation before applying FinaleScript to change its size, check playback of ties, be sure the clarinet part is transposed, and correct the spacing.
Scripts, like other computer languages, typically have commands that perform certain functions, variables that users can define, and built-in (predetermined) variables that report information from the application and its data. A built-in variable might give the current tempo of your sequencer, or the MIDI channel, pitch, and Velocity values of a note that has just been pressed on a keyboard controller.
MakeMusic Finale notation software, for example, contains a scripting language called FinaleScript, which was introduced in Finale 2004 and is supported by all subsequent versions. FinaleScript includes a powerful batch-processing tool that lets you create a series of commands that run automatically one after another. These commands could be used to modify all the files in a folder or subfolder.
To illustrate, imagine that you have ten files of short pieces for clarinet and piano. You'd like to change the size of the staves, make a final check of the ties to be sure they play back properly, be sure that the clarinet is transposed rather than in concert pitch, and fix any notes that are improperly spaced. While you could do all these tasks manually for each separate file, creating a script makes the task less tedious and ensures that you don't accidentally skip one step of the process on one of the files or make some other small mistake.
For the FinaleScript code that will accomplish the above tasks on all files in a selected folder, see the sidebar “Script Examples,” example A. (The scripts in this article are also available at www.emusician.com. See Web Clip 1 for example A.) Fig. 1 shows the score before and after the script is run.
To run the above script, click on the New Script icon from the FinaleScript plug-in dialog box (Ctrl + Alt + Q) to launch an editor window and paste or type the script into that window. Then click on the Save And Close button. Next, click on the Choose Batch Folder icon and select the folder containing all the files you want to process, run the script by clicking on the Play icon, and relax while your automated assistant does the work! Because you've saved your script, it will now appear alongside the included scripts whenever you launch the FinaleScript Palette.
FinaleScript is fairly easy to learn — it's really just an automated, text-based approach to running program commands that are already familiar to Finale users. Running it can be a real time-saver, especially for batch processing multiple files.
FIG. 1B: The score after the script has been applied.
Native Instruments' Kontakt sampler first included script-reading and -creation features with version 2, and its Kontakt Player 2 and later can also read (but not create) scripts. In addition to computer language features, the Kontakt Script Processor (KSP) lets you easily create user interface elements such as knobs, selectors, and sliders.
To get a feel for how KSP works, see Fig. 2 or Web Clip 2. Both show the script that produces the following result: whenever you release a note on the keyboard, the script will trigger a second note that's a fifth or an octave above the original note. The script includes a selector interface element to allow the user to choose the preferred interval. To use this script, run Kontakt and then load up a sound to work with (I used an Electric Piano in this example, as shown in Fig. 2). Click on the Wrench icon to get into Edit mode, then click on the Script Editor tab. Next, type in the script shown in Fig. 2 (or copy and paste it from Web Clip 2) and name it EM KSP Note Release. Notice in Fig. 2 that there are four additional empty slots you can use to add up to four more scripts. A detailed explanation of the script, shown in example B in “Script Examples,” is as follows:
The declare ui_menu command creates the menu-selector object and gives it a variable name of “interval.” A dollar sign precedes all variables in KSP and indicates their function. (Note that user-defined variables can be upper- or lowercase, while built-in variables, such as those shown in the next-to-last line of example B, are always uppercase.) The two add_menu_item commands create the text that will appear onscreen. The add_menu_item has three parameters: the first identifies the ui_menu you're referring to, the second provides the text (shown in quotes) that you want to appear, and the third is the number that the menu item returns when that item is selected. The numbers chosen here (7 and 12) are those of semitones in a fifth and in an octave.
The three middle lines at the top of example B are enclosed in the on init/end on block of code. The on init code is known as a callback, and it runs once when the script is first loaded and initialized.
Next, create a block of code that will run every time a note is released. Here, I used a callback block called on release. For the code, see the last three lines of example B in “Script Examples,” or see Web Clip 2.
When a note is released, the on release/end on block is run. The variables $EVENT_NOTE and $EVENT_VELOCITY are two of many built-in variables that you can use in a KSP script. They represent the MIDI Note Number and the MIDI Velocity (0-127) of the note that is released. The value of the selected interval is determined by the selector user-interface object. So if “fifth” is selected, the variable $interval returns the value of 7, and then adds that value to the original note from $EVENT_NOTE. In other words, if middle C (MIDI 60) were played, play_note will play 60 + 7, or 67, which is the G above middle C.
The play_note function takes four parameters: note number, Velocity, sample offset, and duration (in microseconds). So the script is playing the note that is a fifth above the note released, at the same Velocity as the original note (assuming “fifth” has been selected), with no sample offset, and lasting for one-tenth of a second (100,000 microseconds).
CAL on Call
Cakewalk Sonar also has excellent scripting support. Its language is called CAL (Cakewalk Application Language), and its scripts can work on a recorded sequence or in live performance. CAL is the most complex of the three scripting languages covered here, and there isn't much information about it within the Sonar documentation. Fortunately, there are several third-party books and Web sites that provide a fair amount of information.
CAL allows you to scan the MIDI data in your sequence and manipulate it in various ways. For example, one of the included CAL scripts will harmonize each note in a sequence with a major triad (there are scripts for other chord types as well). You'll also find an unquantize script that offsets the start time of each note by a random amount, a script that splits a track into as many as 15 other tracks according to the channel of each MIDI event, and a script that thins various kinds of controller data. The best way to learn CAL is to find a sample script that is close to what you want, and then edit it.
Note that the Run CAL menu item is hidden in the default menu layout of Sonar 6 and 7. To access Run CAL, open the Process menu and mouse over the gray bar at the bottom. You'll find a few dozen CAL scripts under the ProcessRun CAL menu once it is enabled.
Scripts can save you huge amounts of time and can provide you with new features that didn't come with your software. Check out your music software and see if it has a scripting language available. If so, give it a try; you might find a new assistant to improve your work flow or discover new sounds that you didn't think your favorite program could produce.
Composer Peter Hamlin teaches music at Middlebury College and performs in the electronic-music improv band Data Stream.
Script Example A (in FinaleScript):
batch process folder
resize pages to 75%
execute menu item uncheck “Document/Display in Concert Pitch“
execute menu item “Utilities/Note Spacing/Apply Note Spacing to Current Part/Score“
Script Example B (in KSP script):
declare ui_menu $interval
add_menu_item ($interval, “fifth“, 7)
add_menu_item ($interval, “octave“, 12)
play_note($EVENT_NOTE+$interval, $EVENT_VELOCITY, 0, 100000)