js: device parameter units? appointed device listener?

Learn about building and using Max for Live devices.
amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

js: device parameter units? appointed device listener?

Post by amounra93 » Sun Mar 07, 2010 8:29 am

I'm creating a js script to deal with all the features I like using from the Remote25SL (but think I can do better myself) in anticipation of the iPad's release. I have been using a Max Standalone in conjunction with the Remote Script, but this is troublesome, and I will want to customize things when I get my hands on the new iPad. I've come across a few problems.

"live_set appointed_device" cannot currently be selected for callbacks. I've made a workaround using a task on a 500ms timer, but that obviously can't be the most efficient way. Is there a chance this property is available for callbacks in a newer beta version, or can I expect it in some future version? The method (workaround) I'm using is very awkward, and is bound to be wasting cycles.

Also, is there currently any way to get device parameter unit values? Like, for instance, 1.6 db or 25%? I've been looking around and haven't found anything, but hopefully I missed something. It seems like something that should be available through the API, since my Novation is able to access them. This is something I've gotten very used to and don't want to live without.....

Other than this (unit names), it appears that I've been able to implement every feature of the RM25SL's Remote Script through a js. The nice thing about this is that one can assign any MIDI controller to the faders and buttons in the M4L plugin through Live's MIDI assignment (read:Nocturn) and have the same functionality as the RM25. Groovy :) Almost finished, if anyone is interested I'll publish it.

cheers
Last edited by amounra93 on Wed Mar 24, 2010 12:36 am, edited 1 time in total.
http://www.aumhaa.com for Monomod and other m4l goodies.

ST8
Posts: 259
Joined: Mon Jan 26, 2009 12:55 pm

Re: device parameter units? appointed device listener?

Post by ST8 » Mon Mar 08, 2010 1:25 pm

Try tracking the currently selected track and the selected device on that track, should give the same information but it should be watchable.

You want Song.view.selected_track and Track.View.selected_device

I cant see anything in the api that returns the units of the current parameter, only the name, min and max

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: device parameter units? appointed device listener?

Post by amounra93 » Mon Mar 08, 2010 8:44 pm

Good idea, I thought of selected track, then getting the first device, but didn't notice "selected device" for some reason. The nice thing about appointed device, though, is that it is lockable.

I think I'm just going to build a list of all the devices in the set and make them selectable via menus tied to buttons. But I wanted to duplicate the functionality of the RM25SL as closely as possible, just for grins if nothing else. Plus, the "blue hand" method of selection is kind of nice.

Thanks for the response ST8. I think I remember trying to implement all of this via the PythonLiveOSC script at some point, and Icouldn't get unit names that way, either.

Also, I am getting some inconsistencies in values sent via the API matching up to the values displayed in the Live Device window. That is kinda weird..... e.g. Autofilter freq==6.7khz in device window, but API is sending 116.1328...anyone know what that is about?
http://www.aumhaa.com for Monomod and other m4l goodies.

zalo
Posts: 999
Joined: Sat Jun 27, 2009 9:10 pm

Re: device parameter units? appointed device listener?

Post by zalo » Mon Mar 08, 2010 10:32 pm

amounra93 wrote:Also, I am getting some inconsistencies in values sent via the API matching up to the values displayed in the Live Device window. That is kinda weird..... e.g. Autofilter freq==6.7khz in device window, but API is sending 116.1328...anyone know what that is about?
what is the min and max values for autofilter freq? i could be that it is taking the log scale of autofilter and converting it to a linear representation of it on a scale of 128.

im away from my live at the moment

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: device parameter units? appointed device listener?

Post by amounra93 » Tue Mar 09, 2010 1:17 am

Nope, don't think so....I'm using a scale equation to get a value from 0.0 to 1.0 which gives me the number I want to go to a fader/knob:

device_parameter[number+device_offset].set("value",( ( (device_parameter[number+device_offset].max-device_parameter[number+device_offset].min) * (value) ) +device_parameter[number+device_offset].min));
}

However the raw value that is sent via value is 20 to 135 (when it should be 26 to 19900)....there is some kind of weird math going on, but I'm not sure what it is....lo val is 20, (but device window says 26.0Hz) and high val is 135 (but device window says 19.9khz).

wierd....

:edit:

actually, that's the scale for input....the one for callbacks is reversed, but its pointless to post it without the rest of the code.
Last edited by amounra93 on Tue Mar 09, 2010 9:04 am, edited 2 times in total.
http://www.aumhaa.com for Monomod and other m4l goodies.

zalo
Posts: 999
Joined: Sat Jun 27, 2009 9:10 pm

Re: device parameter units? appointed device listener?

Post by zalo » Tue Mar 09, 2010 4:01 am

amounra93 wrote:Nope, don't think so....I'm using a scale equation to get a value from 0.0 to 1.0 which gives me the number I want to go to a fader/knob:

device_parameter[number+device_offset].set("value",( ( (device_parameter[number+device_offset].max-device_parameter[number+device_offset].min) * (value) ) +device_parameter[number+device_offset].min));
}

However the raw value that is sent via value is 26hz to 19.9khz....there is some kind of weird math going on, but I'm not sure what it is....lo val is 20, (but device window says 26.0Hz) and high val is 135 (but device window says 19.9khz).

wierd....
there is also the object [scale]

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: device parameter units? appointed device listener?

Post by amounra93 » Tue Mar 09, 2010 6:29 am

thanks zalo....

trying to keep everything js. But I may change this later...I was curious if it would take any longer to do everything in javascript. As long as it lives there, I can assign a function and call it whenever I want from within the js.

I wonder if there is some sort of scale function built into js that I don't know about??
http://www.aumhaa.com for Monomod and other m4l goodies.

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: device parameter units? appointed device listener?

Post by amounra93 » Wed Mar 10, 2010 12:21 am

hehe....after 12 hours of thinking about algebra and relearning what I knew so well in highschool, I have become painfully aware of the PITA of creating a correct scale object (especially in js).

All praise the Max [scale] object!!! Yes, I will be using it, I think.
http://www.aumhaa.com for Monomod and other m4l goodies.

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: device parameter units? appointed device listener?

Post by amounra93 » Wed Mar 10, 2010 8:22 pm

Soooo...not so stoked on scale within Max anymore. Should work fine, but I'm having all sorts of problems with "fromsymbol" and "tosymbol" and strangly formatted floats (if you "toFixed()" a float in js, it sends it out of the js object formatted like "00.783" or whatever, which doesn't work within Max).

So I did a little more thinking and asking and came up with an easy solution which will work for any number less than 1,000,000. I shouldn't think I'd need to scale anything more than that, but if so, its easy to increase its capacity by changing a part of the arguments.

Code: Select all

function scale(x,a,b,c,d)
{
    var in_dif=((Math.max((a+1000000),(b+1000000)))-(Math.min((a+1000000),(b+1000000))));
    var in_val=((Math.max((a+1000000),(x+1000000)))-(Math.min((a+1000000),(x+1000000))));
    var out_dif=((Math.max((c+1000000),(d+1000000)))-(Math.min((c+1000000),(d+1000000))));
    var out_min=(c+1000000);
    return(((out_min+(((in_val)/(in_dif))*(out_dif)-1000000)).toFixed(3)));
}
Script is almost done, can't wait to get my iPad! preorders on the 12th!
http://www.aumhaa.com for Monomod and other m4l goodies.

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: device parameter units? appointed device listener?

Post by amounra93 » Wed Mar 17, 2010 6:30 am

So, for anyone curious, there is a way to get the unit types as well as all the parameter values for a given device by using "live_set tracks n devices n" and then calling "get parameters". This would have saved me so much time lol. Good to know, though.
http://www.aumhaa.com for Monomod and other m4l goodies.

zalo
Posts: 999
Joined: Sat Jun 27, 2009 9:10 pm

Re: device parameter units? appointed device listener?

Post by zalo » Wed Mar 17, 2010 7:17 am

amounra93 wrote:So, for anyone curious, there is a way to get the unit types as well as all the parameter values for a given device by using "live_set tracks n devices n" and then calling "get parameters". This would have saved me so much time lol. Good to know, though.
for some reason i thought you had tried this, sorry i didnt mention this earlier

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: device parameter units? appointed device listener?

Post by amounra93 » Wed Mar 24, 2010 12:20 am

So, I'm not liking js right now.

Problem: when passing a value from the API to an Array, callbacks assigned to "property=name" like "live_set tracks 0" seem to pass a string (which is manipulable in js, and can be converted easily enough to ascii for sending out to a control surface lcd: the real purpose here). However, when making calls like "arrayblah[blah].get("name")", where arrayblah[blah] is a LiveAPI object assigned to the same "live_set tracks 0", the returned value is apparently a tuple, which can't be manipulated.

Am I misunderstanding something? I've tried casting to a string etc. nothing works.

So, two possibilities that will help me out here:

Is there any way to convert a tuple that's arrived from the API into a manipulable string in js? I know python can do this, but I can't find any way with js.

Is there a way to get a listing of all the track names at once, as with device parameter values (as I mentioned above)....I really only need device parameter values anyway, as I found a workaround for the track names.

Shot in the dark, hopefully someone is listening that knows wtf I'm talking about.
http://www.aumhaa.com for Monomod and other m4l goodies.

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: js: device parameter units? appointed device listener?

Post by amounra93 » Wed Mar 24, 2010 3:20 am

LMAO!

Figured it out. Ridiculous. tostring() didn't work. Check this out:

Code: Select all

autowatch=1

function testit()
{
    test=new LiveAPI(this.patcher, callback, "live_set", "tracks", 1, "devices", 1, "parameters", 0)
    test.property="value";
    var newtest = test.get("name");
    post(newtest);
    post(to_ascii(newtest));
    
}

function callback(args)
{
    post("test:", args, "\n");
}

function to_ascii(str)
{
    var code = str.split("");
    for (var i = 0; i < 9; i++)
    {
        if(!code[i])
        {
            code[i]=(32);
        }
        else
        {
            code[i] = code[i].charCodeAt(0);
            if(code[i]>127)
            {
                code[i]=(32)
            }
        }        
    }
    return code;
}
Doesn't work. It should....

But do this and it works fine.

Code: Select all

function testit()
{
    test=new LiveAPI(this.patcher, callback, "live_set", "tracks", 1, "devices", 1, "parameters", 0)
    test.property="value";
    var newtest = test.get("name")+"";
    post(newtest);
    post(to_ascii(newtest));
    
}
Anybody know what's going on here? I mean, I understand why it is working, but why didn't it work with tostring, or slice, or any of the other methods I tried?

I'm prolly talking to myself lol....
http://www.aumhaa.com for Monomod and other m4l goodies.

amounra93
Posts: 432
Joined: Sat Jan 24, 2009 8:16 pm
Location: Arcata, CA
Contact:

Re: js: device parameter units? appointed device listener?

Post by amounra93 » Thu Mar 25, 2010 10:39 pm

I'm still trying to find a way to get individual parameter values encoded as actual units. I've found a way to get the raw information, but its not delineated for inidividual parameter #'s for a device.

Code: Select all

<pre><code>
----------begin_max5_patcher----------
483.3ocyUFriaCBDF9r8SAxmcs.6jTmdqU8RjZeBpVshfmMgVavBHaS6p8cu
vXmDusNqSqh1sGL1LL.+ymGFdHNJYsdOXSHui7ERTzCwQQnofgn99QIM78hZ
tEcKQAeWu9qIocC4f8NzbqQpbGrp10n24pAGNEZu0VtSrUp1bqADttsLmkQS
IrYyCuJJvNkYTxM8SQVgKteCeCK+vpemV4T7F.G58FIul7Acc0vgsxehCynY
zSZRpNHIVv1iwwglzKLva.qkuA9iHeC3HsbiWPNvXGGArdqclb+nE5h+jjig
5Xzgh.ghuJywNKNCcXWQ5jeEoiOr1Rpk2C2Z8bxY3huYITREbuT.9utl7ZAl
MMaIBp4KeNdU9JiqybJJ.pL+.gP5ZlH0cLKGSg5AyYNlM++XvDxkFGKEmEKo
8OSm271YHcXOGcJdkqAIzMMvo5rGwymW8wUj6L5Fxm7f5utLbQWgFLzKKwuW
N..gsQnq0lNuoYEoglYgVeCabVsXBVQV430RwQuLaVO85+DvxlFr3D8YOpe+
RNjBA6Ok1V8Ni3PxS+4AxosuBrNoh6jZ0.eBWMMvosxpJPMD4MxpVs+9wdMP
tYze8WpjB05mTSyeQkT4EnnhWTEUbgLh8OpHemGi+EPlrQhv
-----------end_max5_patcher-----------
</code></pre>
This will get you a list of the pertinent information. BUT. There is no way to sort it so that the appropriate portion of the list gets to the right controller strip. If I could somehow call this same information on a per parameter basis....this would solve a lot of problems. Anyone? I've tried everything I can think of, and nothing is working. Presumably this is just a hook that hasn't been inserted yet, but if there is some way, I'd be grateful to know it. Even if the data received from the call was separated onto different lines it would be usable. But as it stands, this information is just useless, as there are variable items for each element of the list, and they aren't parseable when they are received this way. (give the patch a try, you will see what I mean).
http://www.aumhaa.com for Monomod and other m4l goodies.

pukunui
Posts: 405
Joined: Thu Jan 29, 2009 10:26 pm
Location: Los Angeles

Re: js: device parameter units? appointed device listener?

Post by pukunui » Thu Mar 25, 2010 11:02 pm

I have to admit I'm not entirely sure what it is that you're trying to do.

But,

Here is a patch I made in the early days of testing which maybe does nothing to help this thread at all.


<pre><code>
----------begin_max5_patcher----------
1978.3oc0bkzaiaCE9ryuBAgdzMf6Tr25x0hdnGGTDHayjnNVRFRxoyBl+6k
KxJd7XKQYSwnfAicDsR3ie7s7w26I+06VDup7Sx53neI5CQKV706V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