The CKSP Syntax
The cksp
syntax introduces a dialect of vanilla ksp
that incorporates syntax elements from Python
, TypeScript
, and Lua
, allowing for the use of more advanced programming abstractions and modularity when developing Kontakt instruments. This can improve both the readability and maintainability of the code.
In the following sections, we will explore the syntax of cksp
in detail. The sections are focussed on the specific features and do not explain the individual transformations or lowerings that cksp
performs to convert the code into valid vanilla ksp
. I might add those in the future, but for now, you can find descriptions on some of the transformations in our paper Retrofitting a Virtual Instrument DSL with Programming Abstractions.
The new syntax features that cksp
brings in addition to those of vanilla ksp
or sublime ksp
have grown considerably, so here is a brief overview of the most important ones. Each feature is linked to a more detailed explanation in the Syntax section.
-
Scopes and Local Variables
In addition to global variables in the
on init
callback,cksp
allows for lexical scoping where you can define local variables anywhere, with them only being valid within their scope. This allows the use of variables with the same name in different scopes without conflicts. Scopes and Local Variables
-
Custom Data Structures
With
cksp
, you can create custom data structures that contain methods applicable to the data structure. Additionally, operators can be overloaded to support custom types. Custom Data Structures
-
Typed Functions with Return Values
You can now define functions with return values and types to improve the readability and maintainability of your code. Using return statements, you can control the flow of execution and return values to the caller. Typed Functions
-
Easy Array Iteration with for-each Loops
Iterating over certain Dimensions Iterating over Lists of Strings With
cksp
, you can iterate over arrays with a simple loop. Usingpairs
you can iterate over array elements, dimensions in multidimensional arrays, ranges, or even lists of strings. For-Each Loops
-
Ternary Expressions
With
cksp
, you can use ternary expressions to simplify conditional assignments and improve code readability. Ternary Expressions