Cycling74 / min-api

High-level C++-language application programming interface for Max
MIT License
57 stars 23 forks source link

added set_long, set_float and set_atoms methods to min::instance class #199

Open benediktadams opened 1 year ago

benediktadams commented 1 year ago

I added these 3 setters, because I'm currently working on an external that exposes as parameter to Ableton Live via the getvalueof/setvalueof interface. To set attributes on this exposed parameter, i have to edit attributes on the object using

max::object_attr_setlong, max::object_attr_setfloat and max::object_attr_setvalueof

so I wrapped those in the same place where object_attr_setchar and object_attr_setsym are wrapped. I'm not sure if there's a better way to overload the existing set functions for a more consistent call style, but when I tried just overloading them everything became ambigous obviously.

Here's a simplified snippet from my code where I use these new functions on a min::box that exposes the getvalueof/setvalueof interface:

    min::box box;
    MyParamWrapper paramProp;

    box.set ("parameter_enable", 1);
    box.set ("presentation", 1);
    box.set ("_parameter_initial_enable", 1);
    box.set_long ("_parameter_type", getMaxParameterType () ); 
    box.set_float ("_parameter_initial", paramProp.getInitialValue ());       

    const auto paramId = paramProp.getName ().toRawUTF8();
    const auto displayName = paramProp.getDisplayName ().toRawUTF8();
    const auto range = paramProp.getRange ();

    box.set ("_parameter_longname", displayName);
    box.set ("_parameter_shortname", displayName);
    box.set_long ("_parameter_steps", paramProp.getNumSteps ());
    box.set ("_parameter_unitstyle", 9 /*custom*/);
    box.set ("_parameter_units", paramProp.getUnit ().toRawUTF8());

    box.set ("_parameter_invisible", paramProp.hasYumMetaData () ? 0 : 1);

    if (paramProp.isEnum ())
    {
        min::atoms enumAtoms;
        for (auto enumVal : paramProp.getEnumValues ())
            enumAtoms.push_back (min::atom { enumVal.toRawUTF8() });
        box.set_atoms ("_parameter_range", enumAtoms);
    }
    else
    {
        box.set_atoms ("_parameter_range", min::atoms { min::atom { range.getStart () }, min::atom { range.getEnd () } });
    }