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

W's icon

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.

Griotspeak's icon

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's icon

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.

Griotspeak's icon

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.

Griotspeak's icon

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");

Griotspeak's icon

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

W's icon

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

W

W's icon

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?

Griotspeak's icon

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.

Griotspeak's icon