Skip to content

getKeys for dictionaries #222

Open
Open
@thomas-risse

Description

@thomas-risse

Would it be possible to include the getKeys method of the max API for dictionaries to the min API ? If not, would it be possible to ad a function returning the underlying max dictionary ?

I can't figure out how to get the underlyning max dictionary from the dict class, as the only casting functions casts the object to a max::t_object*.

Thanks a lot !

Activity

isabelgk

isabelgk commented on Feb 27, 2025

@isabelgk
Contributor

This is a reasonable request! In the meantime, you can simply cast the max::t_object* to a max::t_dictionary* when using with the C-based API. (This is a general pattern you would see in the Max SDK where t_object acts kind of like a base class. A struct that has a t_object as the first member, like t_dictionary, is passed around as the more general t_object* pointer.) You can see in the min-api that the max::t_object* operator is returning what is indeed an underlying max::t_dictionary* just as a max::t_object* pointer.

janmech

janmech commented on Mar 21, 2025

@janmech

Wanted to make a pull request, but I didn't manage.

adding this code to c74_min_dictionary.h will add two new methods:

dict.entrycount()
dict.keys()

to get the entry count and a the keys respectively.

 /// Get number of entries of dictionary
    long entrycount() {
        return (long)max::dictionary_getentrycount(m_instance);
    }
    
    /// Returns a vector of symbols with dictionary keys
    std::vector<symbol> keys() {
        std::vector<symbol>k;
        max::t_symbol    **keys = NULL;
        long        numkeys = 0;
        long        I;
        
        max::dictionary_getkeys(m_instance, &numkeys, &keys);
        for(i=0; i<numkeys; i++){
            k.push_back(symbol(keys[i]));
        }
        if(keys) {
            max::dictionary_freekeys(m_instance, numkeys, keys);
        }
        return k;
    }

update: pull request created: Cycling74/min-api#202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @janmech@isabelgk@thomas-risse

        Issue actions

          getKeys for dictionaries · Issue #222 · Cycling74/min-devkit