This is the easiest way for me....and it works fine. You just bang the matrixctl every count (whatever the resolution is) and make sure to filter out the stuff that doesn't need to be sent to the LP. I hopefully will have time this week to get all of my monome stuff posted somewhere, but for the meantime, here is the script.
Its been a while since I did all this, so I don't know what pitfalls to tell you to beware of. Basically, it autodetects the first Launchpad instance, and if you feed it (x-coord, y-coord, color) in the first inlet, it will update the launchpad. The second and third inlets are for the top and side rows, the selects the control surface (prolly don't use this, as its unnecessary) and the fifth is to rebuild the api in case things get mucked up somehow. If things don't go right, send a (1) in this inlet.
The outlets give about the same for the first three (key presses), the fourth sends out the active LP mode (i.e. Grid, User1, User2, or Mixer) and the fifth is to let you know when the API has loaded (I can't remember how well this last one works, but I never seem to have issues).
If you haven't worked with js before, its pretty simple: copy the code, create a new object in max (call it [js lpd.js], but without the brackets), then double click on it. It will open a text editor. Paste the contents of the code below into the textedit window, then save it with the filename "lpd.js" somewhere in your max search path. I put all mine into: /Applications/Max5.13/Cycling'74/jsui-library, but I think as long as its in the search path you are in good shape. G'Luck
Code: Select all
autowatch = 1
inlets = 5;
outlets = 5;
setinletassist(0, "grid input");
setinletassist(1, "control input");
setinletassist(2, "mode input");
setinletassist(3, "control surface assignment");
setinletassist(4, "rebuild api");
setoutletassist(0, "grid output");
setoutletassist(1, "control output");
setoutletassist(2, "mode output");
setoutletassist(3, "active mode");
setoutletassist(4, "api load state");
cs = "0"
is_loaded="0"
var check = new Task(check_on_api);
check.interval = 2000;
function check_on_api()
{
post("check_on_api cs: ", cs, "\n");
post ("is_loaded", is_loaded, "\n");
if (is_loaded="0")
{
if (cs>"6")
{
cs="0";
}
api = new LiveAPI(this.patcher, "control_surfaces", cs);
post("control_surfaces id is: ", api.id, "\n");
post("control_surfaces type is :", api.type, "\n");
if (api.type!=("Launchpad"))
{
cs=(cs=++cs);
post("control_surface is not loaded yet, next check control_surfaces: ", cs, "\n");
outlet(4, 0);
}
else
{
post("control_surface has now loaded\n");
is_loaded="1";
post ("is_loaded", is_loaded, "\n");
check.cancel();
assign_api();
}
}
}
function assign_api()
{
controls=new Array;
modes=new Array;
grid=new LiveAPI(this.patcher, cb_grid, "control_surfaces", cs, "controls", 1);
grid.property = "value";
var makecontrols=0;
for (makecontrols=0;makecontrols<=7;makecontrols++)
{
var controlid=(makecontrols+67);
controls[makecontrols]=new LiveAPI(this.patcher, cb_controls, "control_surfaces", cs, "controls", (controlid));
controls[makecontrols].property = "value";
}
var makemodes=0;
for (makemodes=0;makemodes<=7;makemodes++)
{
var modeid=(makemodes+75);
modes[makemodes]=new LiveAPI(this.patcher, cb_modes, "control_surfaces", cs, "controls", (modeid));
modes[makemodes].property = "value";
}
active_mode=new LiveAPI(this.patcher, cb_active_mode, "control_surfaces", cs, "components", 0);
active_mode.property = "mode_index";
post("done_building_control_array \n");
outlet(4, 1);
}
function list(b, v, c)
{
if (inlet==0)
{
//post("receive grid: ", b, v, c, "\n");
grid.call("send_value", b, v, c);
}
else if(inlet==1)
{
var b=(b);
//post("receive controls: ", b, v, "\n");
controls[b].call("send_value", v);
}
else if(inlet==2)
{
//post("receive mode: ", b, v,"\n");
modes[b].call("send_value", v);
}
else if(inlet==3)
{
cs=(b);
post("control_surface_number :", b, "\n");
assign_api();
}
else if(inlet==4)
{
if (b==("1"));
{
post("control_surface initialize\n");
assign_api();
}
}
}
function cb_grid(args)
{
var val=(args);
if (val[0]==("value"))
{
if (val[1]!==("bang"))
{
//post("send grid", args[2], args[3], args[1], "\n");
outlet(0, args[2], args[3], args[1]);
}
}
}
function cb_controls(args)
{
var val=(args);
if (val[0]==("value"))
{
if (val[1]!==("bang"))
{
var id1=(parseInt(this.path.slice(28)))-67;
//post("send control", id1, val[1], "\n");
outlet(1, id1, val[1]);
}
}
}
function cb_modes(args)
{
var val=(args);
if (val[0]==("value"))
{
if (val[1]!==("bang"))
{
var id1=(parseInt(this.path.slice(28)))-75;
//post("send mode ", id1, val[1], "\n");
outlet(2, id1, val[1]);
}
}
}
function cb_active_mode(args)
{
if(args[1]>0&&args[1]<3)
{
post("active_mode ", args[1], "\n");
outlet(3, args[1]);
}
else
{
post("active_mode 0 \n");
outlet(3, 0);
}
}
function loadbang()
{
check.repeat();
}