GLRepl

This year one of the few things I had the time to work on was this REPL for Cycling '74's Max software. Its basically a fully extensible REPL built using OpenGL and Typescript that you can use to control your max patches. At it's most basic, using the default configuration file, it's intended to be used to output messages, either all at once or a line at a time, so you can use [route] and [routepass] objects to direct those messages around your patches. This allows you to control Max patches in a flexible livecoding like fashion and makes it very easy to hack a livecoding interface into your existing patches without too much effort. It will also route any GLRepl specific command back to itself, which allows you to do things like read in text files directly from the REPL, alter the REPL's behaviour, normally controlled through max message, arguments and attributes, directly. With only a few extra objects you can create a livecoding environment which allows you to interact directly with the jit.world in which the REPL is rendered. You can see this in the GL EXAMPLE patch which you can find inside the GLRepl Overview, found in the Max Extra's menu.

However if you look beyond the default configuration you'll find a highly extensible framework which allows you to attach functions to individual keypresses, using either code

//Typescript signature is actually
//const functionOne = (k: number, ctx: {}) => {
const functionOne = (k, ctx) => {
    return `some message`;
};
glrepl.manager.kp.preloadFunction('doSomething', functionOne);

or config

{
    "bindings": [
        {
            "id": "pushSpace",
            "asciiCode": -2,
            "functions": [
                "doSomething"
            ]
        },
        {
             "id": "replaceLine-alt-p",
             "asciiCode": 960,
             "functions": [
                 "var pb = ctx.tb.pasteBinGet(); var startLine = ctx.c.line(); ctx.deleteLine(); if(ctx.c.line() < ctx.tb.length()-1){ctx.jumpLine(-1);ctx.jumpTo(1);} if(startLine === 0){ctx.jumpTo(0); ctx.newLine(); ctx.jumpTo(2); }else { ctx.newLine(); } for(var i = 0; i < pb.length; i++){for (var a = 0; a < pb[i].length; a++) {var char = pb[i].charCodeAt(a); ctx.keyPress(char)}}"
             ]
         }
    ]
}

transform input text before outputting it using formatters written in javascript,

// This example is in typescript for clarity, and user-repl.js needs
// to be in the type of archaic javascript that max understands but
// hopefully you get the idea.
// See examples/custom-formatter/user-repl.js for a full pure javascript
// implementation of a custom formatter.
//To create a lot of extensions for the repl it's recommended to look into 
// using typescript, transpiling and generating your user-repl.js file.

class UppercaseFormatter implements TextFormatter {
    id: string = "uppercase"
    format(strArr: Array<string>, ctx: {}): Array<string> {
        // Example implementation that returns all strings in uppercase
        return strArr.map(str => str.toUpperCase());
    }
}
glrepl.manager.preloadFormatter(new UppercaseFormatter);
// then include via repl json config: {"settings"{"textbuffer": {"formatters": ["uppercase"]}}}

playback text files a keypress at a time to build up application state, and loads more. If you do want to extend the REPL with code by writing text-formatters, programatically binding keys, or extending the core you should read the README.md file included in the package and on Github, as it will explain how you can get started with this in more depth than the included help and overview patches. Β If you develop any cool core features please do make a pull request on Github!Β 

You can download it now from the Max package manager in the app, or fromΒ my github. It's recommended that unless you're a developer you download it directly from the package manager. It's extremely flexible so I'm excited to see what people might do with it.

GLRepl package in the Max package manager
The GLRepl Package, as seen in the Max package manager

Full credit to Timo Hoogland for writing the th.gl.texteditor object (which is used in his fantastic Max livecoding environment Mercury) upon which this complete rewrite and extension in Typescript is based.