ruppel.io / Type Definitions for Logic Pro's Scripter


Type Definitions for Logic Pro's Scripter

Last edited February 24, 2024

Logic Pro's Scripter is a super powerful tool for manipulating MIDI, but the docs are... not great. TypeScript can fix that.

There are offical docs for Logic Pro's Scripter. I won't link to them here, not because the link will eventually 404, but because I find them intensely unhelpful. Add this to the fact that authoring scripts in the Scripter editor is downright painful. We can do better.

The goal: A scalable build process for Logic scripts.

Types help code scale. The TypeScript compiler can tell if you if your code suddenly no longer conforms to the type contracts you put in place. This is ideal for when you're revisiting a script you wrote months/years earlier. As a bonus, Once we have types in place, we can use typedoc to generate API documentation we can use instead of the offical docs.

As for portability, Scripter runs the version of JavaScriptCore on your system. Since I want to share my scripts with people who may be running older systems, I want to transpile my scripts as far down as possible. tsc is great at this.

Type Definitions

#

Because all of the Scripter types are globals, we can declare them as such:

declare function GetParameter(name: string): number

Similarly, we can define the ambient classes Logic uses for Events

declare class NoteOn {
  send(): void
  trace(): void
}

Once we have all of our types defined, here's what we can do:

Autocomplete
Autocomplete for all Event types
Type defs for parameters
Type definitions for plugin parameters

Usage in a project

#

The types described above have been published to npm: https://www.npmjs.com/package/logic-pro-types

Install typescript and logic-pro-types as devDependencies.

npm install typescript logic-pro-types --save-dev

Create a tsconfig.json with the following compiler options:

{
  "compilerOptions": {
    "outDir": "<where you want your scripts written out>",
    "target": "ES5",
    "skipLibCheck": true
  },
  "include": ["<your source files>"]
}

💡 It's important to target ES5 because Scripter looks specifically for var statements for global variables like PluginParameters. const and let won't work.

Finally, run tsc. It's helpful to put this in your package.json as a script.

{
  "scripts": {
    "build": "tsc"
  }
}
#