Unlimited royalty free music tracks, footage, graphics & courses! Unlimited asset downloads! From \$16.50/m

# An Introduction to Scripting in Logic X

One of the more unique and less understood of the new features within the Logic X upgrade from Logic 9 is the MIDI Scripter. Although it comes with a host of ready made scripts, one of its key features is the ability to write one's own plugin program from scratch.

In this tutorial I’ll get into the nuts and bolts of what exactly the Scripter is and go on to create a fairly basic, yet personalized MIDI delay plugin.

## The Scripter Explained

The Scripter is basically a plugin which runs on the JavaScript coding language. It is inserted pre-instrument in order to effect incoming MIDI and/or timing data. As such, it is unlike any other Logic plugin as it does not have an effect on audio at all.

Incoming information goes through the Scripter and only after passing through it does the information reach an inserted instrument which then creates an audio event.

The MIDI effects comes pre-stocked with a number of editable—the Scripter option—and non-editable pre-sets which are great jumping off points in order to explore the new capabilities. It is accessed by clicking on the top-most insert in an instrument channel—the MIDI FX slot.

The menu which pops up contains the un-editable stock MIDI effects along with the editable Scripter option which, in turn, contains a good number of editable tutorial script presets.

The interfaces alone of the non-editable programs are enough evidence to understand they are pretty sophisticated programs, yet they are all achievable with the right amount of JavaScript knowledge within Scripter—minus the clean interface.

A good example of this is the Arpeggiator. The stock Arpeggiator interface is very clean with a number of options, while selecting the Simple Arpeggiator pre-set of the Scripter itself reveals a stocky interface with far fewer options.

## Under The Hood

The Scripter comes in two sections. The top portion, the Code Editor, is where I will be writing the code while the bottom section, Interactive Console, gives me information such as errors, output values, about the code written above.

The Code Editor, once programmed, will look for incoming MIDI and/or timing data, from the Transport, manipulate it in some way and either output it as text to the Console or directly to the instantiated instrument's input.

In the upper left is the Run Script button which will evaluate the written code and is necessary to hit after any code updates in order for them to be integrated.

Additionally, Scripter comes equipped with an auto syntax error checking feature which will automatically highlight error lines as well as a syntax highlighting feature which distinguishes relevant keywords with color.

## Getting Started

Getting in-depth at a beginner level of JavaScript is really beyond the purview of a music tutorial, so I’ll jump into the delay I built/wrote and give a brief explanation as to what is going on with the particular lines or blocks of code.

For further information on JavaScript, Envato can—of course—be used as an invaluable tool. The Logic Effects Manual is also packed full of Scripter specific code and examples for further learning.

The code line function HandleMIDI(event) is the first line in this particular example and is the line that tells Scripter to look for a MIDI event and pass that information through the Scripter code.

The next line event.send(); tells the Scripter to pass the MIDI event through Scripter untouched. This will serve as the dry signal while the first line will serve as the wet/delay.

if (event instanceof Note)

event.sendAfterMilliseconds(delayTime);

This tells Scripter that an incoming note event needs to be sent after a specified delay time in milliseconds. The delayTime is a variable value determined by a slider that will be built later. This value can also be changed from delayTime to a specific numeric value if a non-variable delay time is desired (e.g. 100 in place of delayTime for a set 100 ms delay).

var delayTime;

var PluginParameters =

{name:'Delay Time', type:'lin', unit:'ms', 

minValue:0, maxValue:1200, defaultValue:1, numberOfSteps:120},

This block of code creates a fader for the Scripter interface and names its output delayTime for internal routing. In this instance the slider will be named Delay Time in the Scripter interface, it will be a linear fader, lin, and the output units will be milliseconds, ms. It will output a minimum of 0 ms, a maximum of 1200 and will have a resolution of 120 steps, or 10 milliseconds.

function ParameterChanged(param, value) 

var timeInMilliseconds = value;

if (param == 0) delayTime = timeInMilliseconds;

This block of code connects the slider ('0' indicates that it is the first fader of the plugin) and what it outputs internally to the initial delayTime value.

Essentially, if the slider is moved it is outputting a time in milliseconds and that time is sent to sendAfterMilliseconds(delayTime);.

## How It Sounds

I have set up the Scripter with the completed code, Logic's B3 Organ, a MIDI sequence and a Slate Compressor, just to make things sound a bit better.

As you can hear below, this delay is much different than a traditional audio delay in that there is no amplitude decay or other variations throughout the delay. It is simply sending the same MIDI signal twice at whatever slider value is selected. The only reason the delays sound slightly different is that they are sent at different times to the B3 which has an internal modulation effect.

In the below sound example, I have started with a 750 millisecond value—that sounds best to me with this particular example—and then slid up and back down through all of the possible parameters, landing on zero to show the dry loop.

### Outro

The Scripter and the above code opens up a realm of possibilities, both for coding and further processing. One could use this in front of a stale hi-hat pattern to intuitively and improvisationaly slide through a large number of unthought of patterns where certain hits are accented with automation.

One could also expand on the coding and in front of a pitched instrument create delayed chord progressions or chords where the note events do not happen simultaneously and have timing irregularities according to slider positions.

The Scripter, to my thinking, is likely Logic's answer to Max for Live and a novel one as Live can already be integrated into Logic since some years past. The ability to code ones own programs within a standalone DAW is a unique one and one I hope you can learn from and be inspired by.