Forums > Javascript

Correct JS syntax for M4L API Clip class "replace_selected_notes" series?


W
February 22, 2010 | 7:21 am

Hi! Could anybody show me the proper JS syntax used to call the M4L API Clip class "replace_selected_notes" series?

call replace_selected notes
call notes 2
call note 60 0.0 0.5 100 0
call note 62 0.6 0.5 100 0
call done

I’m a tad confused due to there not being a "note" property for the
Clip class.

Any help would be greatly appreciated!!

W.


February 23, 2010 | 12:46 am

watchClip = new LiveAPI(this.patcher, null, "live_set tracks 0 clip_slots 0 clip");
watchClip.call("replace_selected_notes");
watchClip.call("notes", 1);
watchClip.call("note 60 0.0 0.5 100 0"); //see note below
watchClip.call("done");

the point at which i say see note is the sticky part. i hand over an array instead of a string, but i am being lazy and secretive.

MAKE SURE you keep a decimal point in those 2 numbers that have decimal points.



W
February 23, 2010 | 4:29 am

that’s what I thought, yet I am getting 2 errors;

1.Clip has no attribute "note 60 0.0 0.5 100 0"
2.wrong note count

any idea as to why?

W.


February 23, 2010 | 3:20 pm

yes.

it can’t be a string. you must pass an array. (i was not sure of this, but now i am. i went with an array because i already had the note as an array, so it was just happy coincidence for me.)

and the parts that they say have to be doubles HAVE to be doubles. they MUST have decimal points.

it just doesn’t count any note message it doesn’t think is correct.


February 23, 2010 | 3:22 pm

noteArray = ['note', 60, 0.0, 0.5, 100, 0];

watchClip = new LiveAPI(this.patcher, null, "live_set tracks 0 clip_slots 0 clip");
watchClip.call("replace_selected_notes");
watchClip.call("notes", 1);
watchClip.call(noteArray);
watchClip.call("done");


February 23, 2010 | 3:24 pm

eventually, i will post my whole solution in the form of the patch i am working on, but i hope this helped you.



W
February 24, 2010 | 2:09 am

Yeah absolutely.Thanks. I tried passing an array minus the note portion. Thanks for the clarification!!

W



W
February 24, 2010 | 7:17 am

When passing a float value of 0.0 as a parameter in the call, it is converted into an integer and then the compiler throws an "Invalid Syntax" Error due to the appropriate positions in the array not being floats. This only happens when 0.0 is used, 0.5 for instance, is recognized as a float!

The 0.0 in the call message comes up in the Max window as 0 !

Could this be a bug?
Has anybody else experienced this?


February 24, 2010 | 1:11 pm

it isn’t quite a bug. it IS frustrating. javascript is ‘dynamic,’ so it interprets what a var is supposed to be and can usually figure it out correctly. but not in this case. i think the reason is that js is handing the number back to a less dynamically typed language.

and it would happen any time one of those numbers i s a whole number. any time. so annoying.

in any case, make 2 number objects from the 2 indexes and use toFixed. and then you are fine.


March 7, 2010 | 1:55 am

http://docs.monome.org/doku.php?id=app:gs.clipstep

and now i can stop being secretive!


Viewing 10 posts - 1 through 10 (of 10 total)