Giter Club home page Giter Club logo

maxmsp-es6-nodejs-babel-workflow's Introduction

maxmsp-es6-nodejs-babel-workflow

This repository may help you if:

  • you like writing complex JS scripts for Max/MSP
  • you would like to debug and run scripts into a more convenient environment (Node.js)
  • you would like to use the cool ES6 syntax (with Babel)
  • ... and you don't know how to do it.

The problem

Including Max/MSP scripts into regular Node.js files is problematic because of...

... Max js object properties which can be seen as undeclared variables:

autowatch = 1;
inlets = 0;
outlets = 2;

... messages which have to be called to debug scripts:

function bang()
{
    outlet(0, 'blip & blop');
}

... methods defined in the global Max Javascript context which do not exist in Node.js:

post('Coucou');

The concept

First, we need to export messages in scripts so as to call them outside with the CommonJS modules syntax:

// script.js
function bang()
{
    outlet(0, 'blip & blop');
}
exports.bang = bang;

// main.js
const s = require('./script.js);
s.bang();

However, Max may throw a: Javascript ReferenceError: exports is not defined, line XXX. Let's just wrap the exports into a `try/catch (which is a very unelegant way to deal with these probleme, but I don't care):

try {
  exports.bang = bang;
} catch (e) {
}

Then, we need to define a main playground file in which scripts will be included and executed, and which define useful Max global stuff:

// playground.js
global.post = message => process.stdout.write(message);
global.outlet = (...args) => process.stdout.write('OUTLET', args.map(JSON.stringify).join(' --> ').substring(0, 69) + '...');

import {bang} from './src/my-script';
bang();

You can provide your own implementation for post (the way things appear in the console) and outlet (a side effect which help you to debug the output of your scripts).

The process

Have a look on package.json, three NPM tasks are defined:

  • npm run play: transpile the code and launch your playground file to debug and run your scripts in a terminal (see playground.js).
  • npm run build: take all your scripts and transpile them to ES5 so as to use them in Max/MSP. In this a repository are given an example script (src/my-script.js) as well as an example dependency (src/my-lib.js). You can specify the directory in which the transpiled files appear (babel src -d ./<YOUR OUTPUT DIRECTORY>). Your scripts must be available to your Max/MSP environment.
  • npm run clean: erase all js files generated by a previous build task.

Nota bene: Babel plugin transform-remove-strict-mode (declared in .babelrc) prevents Babel to add "use strict" at the beginning of transpiled scripts.

Max/MSP patch with js

maxmsp-es6-nodejs-babel-workflow's People

Contributors

amleth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

aceslowman

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.