Logic Pro Scripter

Introduction to Scripter

Logic Pro X includes a very nice tool for the musician that loves music technology: Scripter, the MIDI programming script editor. This is a MIDI plugin that allows us to program new MIDI plugins by using JavaScript code.

Perhaps Scripter is the least understood plugin in Logic. The documentation is somewhat limited and you need some experience coding with JavaScript to push it to its limits. Anyway, it's worth it to give it a try and start working on it, as the possibilities are endless!


Fig. 1. Scripter main window.

But, what is it good for? Well in general, you can manipulate MIDI data in many flexible and powerful ways. For example, you can:
  • Change the pitch, volume, panning, etc. of certain notes.
  • Create new notes and play them back at different time intervals.
  • Create automatic Control Change (CC) messages or transform them.
  • Generate random notes or create notes based on probability (algorithmic music, this is your call!).
  • Filter, transform or delay MIDI events based on our rules.

With this tool, we can create things like:
  • A MIDI effect that emulates guitar strumming techniques.
  • An algorithm to create automatic melodies or rhythms.
  • Totally customized arpeggiators or harmonizers.
  • MIDI Sequencers or drum machines.
  • User interfaces with menus and sliders for our plugin.

Fig. 2. Scripter and the editing window.

As we see, we can create many interesting tools to unleash our musical creativity. It's important to mention that we can use Scripter right away, without writing a single line of code! Scripter comes with a variety of interesting presets that we can use immediately. Anyway, let's see how to start writing our own scripts or how to customize the presets according to our needs.

Let's begin with the basics: JavaScript

JavaScript (JS) is a programming language that was born along with the Web browsers. Regardless of that, it has become one of the most popular languages in recent years. Its applications reach areas like: the Internet of Things, mobile applications, virtual reality and of course, music.

This is because JS is a robust language, it's easy to learn and there's a huge community of developers around the world that use it. It's important to mention that JavaScript is not the same language as Java. The name looks similar but they are very different languages. Mozilla is the group that maintains and develops JS.

JS has a specific syntax that we should learn to write code. We will learn the most essential parts to keep our focus on what we want more: the music.

Functions

A function is a block of code that can be reused. Programming languages include basic functions and the programmer can create his own functions. In Logic, we have different functions that are defined in the Scripter API.

The simplest example of code in Scripter is a program that "resends" the MIDI data that it receives. Think of it as a virtual MIDI Thru. Here it is the code:

function HandleMIDI(event) {
    event.send();   //Resends the event that is received.
}


The word function is a keyword in JS. It indicates that we will use a function named HandleMIDI(). This function is part of the Scripter API and it will receive and process MIDI data. Then it will store it in the variable named event. This variable could be named in any other way if the programmer desires.

When the function HandleMIDI() is called (when the plugin runs), the instructions between the curly brackets will be executed one at a time, from top to bottom. In this example, there's only one instruction: event.send(). The text after the double slash (//) is known as a comment. It helps the programmer to understand the code. It's just for clarification purposes as it is ignored when the program runs. Although it's optional, it's recommended to use.

The command event.send() reads the data in the variable event and sends that data to the MIDI channel where the plugin is inserted in Logic. With this code, you can hear the notes played on that channel. Not a big deal, as it's the same effect as using no plugin at all! Each command or instruction ends with a semicolon.

Let's add another command to make our program more interesting:

function HandleMIDI(event) {
    event.send();
    event.trace();  //Prints the data in the editor console                
}


The command event.trace() prints a log in the Scripter console (lower part of the window). Here we can see the information inside the event variable.

Fig. 3. Scripter Console showing the MIDI data received.

In the image, we see that the console shows a list of MIDI messages received by the Scripter plugin. In this case, there are NoteOn and NoteOff messages, along with their parameters: channel, pitch, and velocity.

This code is very simple, but it is useful to understand the logic behind Scripter. Later we will see other more advanced commands to manipulate the MIDI data.




0 comments:

Publicar un comentario