Control Max with a Midi Controller using Javascript – Evolution UC-33e

Max can be connected to hardware midi devices by configuring midi control objects to exchange data with hardware like the UC-33e.

For this implementation the [ctlin] object is used:
Left outlet = midi device CC controller value
Middle outlet = midi device CC controller number

This CC data is channelled to the JavaScript API via message boxes, processed and sent to other patcher objects.

Workflow:

  1. Midi data sent to max
  2. JavaScript processes data
  3. Data passed back

JavaScript concatenation and iteration logic sends one message to multiple objects with different variable names.

Getting Midi data from Evolution UC-33e controller

The uc-33_midicontrol.pat fully implements connection between Max 5 and the Evolution UC-33 controller.


Usage:
Place both [uc-33_midicontrol.maxpat] and [js uc-33.js] into the Max 5 directory and open the patcher.

Moving sliders and knobs controls UI objects and posts CC control names and values in the stderror.
Data is posted in the Max stderror. Data posts are created in the [js uc-33.js] object (using ‘post()’ method).


Implentation:

  1. [ctlin] controls midi input data and parses into two streams: CC number and CC value
  2. Data pairs are sent to message boxes [value $1] and [number $1]
  3. CC data messages are processed in JavaScript in [js] object
  4. Data sent to the patcher UI objects

Javascript file: js uc-33.js
inlets= 2;
outlets =2;

// automatically lock ctlin/out to UC-33 midi controller
var p = this.patcher;
var ctlNum;
var ctlValue;

var controller;

//executes first because [number] is on the right
function number(val)
{
    if(arguments.length)
        {
            ctlNum = arguments[0];            //get the cc number of control
            controller = p.getnamed ("midictl" + ctlNum); //prepend cc number
                                            //'controller' is named patcher UI dial
            if (ctlNum >19 && ctlNum <28 || ctlNum == 116)
            {
                post("control: "+ "SLIDER_" + "midictl" + ctlNum);
                post();  
            }
            else
            {
                post("control:"+ "KNOB_" + "midictl" + ctlNum);
                post();
            }
        }
}

//Executes second because on the left
//sends val to controller defined in [number(val)]
function value(val)
{
    if(arguments.length)
        {
            ctlValue = arguments[0];        //get the cc control value    
            
            controller.message(ctlValue)    //send value to 'controller' dial
       
            post("value: " + ctlValue);
            post();
        }
}
Max Patcher: uc-33_midicontrol.maxpat

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: