default_value attribute missing.

    Mar 31 2013 | 10:37 am
    using javascript, how do I detect whether a LiveAPI device parameter has a default_value property or not? although the LOM docs do not mention it, parameters are not guaranteed to have such a value.
    (Related rant: I would really like it if Max for Live used the normal javascript error handling. you know, if you have an error it would be nice to be able to use try/catch to handle it, rather than have an mysterious error pop up in the Max window which you cannot detect from javascript, leaving you to guess.)
    To see this, load the attached ableton project. Now, open the Max window of the single M4L device in track 1, after the operator. You should see the following messages: >'DeviceParameter' object has no attribute 'default_value' > default value 0.00
    Since some object DO have a default value of 0.00, this leaves me with no way to detect this situation.

    • Apr 05 2013 | 10:27 pm
      I found a workaround for this one. in fact, if the parameter in question has no default value attribute, then the value returned is 5e-324 (that is, a very small denormal float). However, if there IS a default value attribute, then you get back an array, [0.0].
      Testing for a number to see if I have a return value is an undocumented feature, but it works for now, until the capricious gods of Cycling74 take it away. YMMV.
      example code, where the LiveAPI object is called "paramApi":
      // This attribute is not guaranteed to exist, but how you detect that it is missing is non obvious
      // An error is dumped to the Max window, but there is no way to trap it,
      // However, the value that is returned in that case is the float 5e-324.
      // but if the value DOES exist, you get an array containing the float.
      defaultValue = paramApi.get("default_value");
      if (typeof defaultValue === "object") {
      	defaultValue = defaultValue[0];
      } else {
      	defaultValue = null;
      	post("If you just got an error saying "jsliveapi: 'DeviceParameter' object has no attribute 'default_value'" then everything is OK.n");
    • Apr 05 2013 | 11:34 pm
      (Note that this doesn't get rid of the Max window error message)
    • Jul 09 2017 | 9:39 am
      has there been an update on this topic? i've come across it several times and there doesn't seem to be a solution...