Help with M4L Javascript and get_selected_notes [solved]

Learn about building and using Max for Live devices.
Post Reply
autodidactic
Posts: 71
Joined: Sun Jul 22, 2007 4:12 am

Help with M4L Javascript and get_selected_notes [solved]

Post by autodidactic » Sat Jul 21, 2012 4:44 pm

I also posted this on the Cycling ,74 forums but thought I should post this here as well.

I'm trying to retrieve all the midi note information from a specific clip on a specific track. I've managed to get data returned but what I am assuming is the pitch info doesn't match what's being played in the clip. The code is below:

Code: Select all

function myfunction(trk, slot){
var api = new LiveAPI(function(result){
this.call('select_all_notes');
var notes = this.call('get_selected_notes','pitch'); //adding the pitch argument seems to make no difference
/*
SHOULD RETURN:
count [int] is the number of note lines to follow.
pitch [int] is the MIDI note number, 0...127, 60 is C3.
time [double] is the note start time in beats of absolute clip time.
duration [double] is the note length in beats.
velocity [int] is the note velocity, 1 ... 127.
muted [bool] is 1 if the note is deactivated.
*/
post(notes);

}, "live_set tracks "+trk+" clip_slots "+slot+" clip");
}
The output I get looks like this: "notes, 312, note, 46,13.12,0.12,76,0,note,48,13,0.12,73,0,note,48...etc"

Based on the docs the first two values tell me the "count" or total number of notes in the clip. and then there is a "note" followed by 5 values. I am assuming that as per the docs, the values should be pitch, time, duration,velocity,muted in that order. However as I stated before, the pitches listed do not match what is being played and in this set I put together there is only one midi clip. Am I reading this wrong? or is there something wrong with how I'm calling the function?

Furthermore, according to the docs, arguments can be added to "get_selected_notes" so if I wanted only the pitch values I could add the "pitch" argument to "get_selected_notes". When I tried to add the pitch argument in javascript it still returns everything though. What am I doing wrong?
Last edited by autodidactic on Sat Jul 21, 2012 7:53 pm, edited 1 time in total.

autodidactic
Posts: 71
Joined: Sun Jul 22, 2007 4:12 am

Re: Help with M4L Javascript and get_selected_notes

Post by autodidactic » Sat Jul 21, 2012 6:54 pm

Dammit. You're absolutely correct! I filtered the data in js and took a second look. It turns out that "get_selected_notes" returns all the notes in ascending pitch order. So it would list all the E3s and then the E4s and so on. So that makes sense now. I have to sort the list by start time manually. Thanks for the eureka moment!

Post Reply