Exemple #1
0
int lo_coerce(lo_type type_to, lo_arg * to, lo_type type_from,
              lo_arg * from)
{
    if (type_to == type_from) {
        memcpy(to, from, lo_arg_size(type_from, from));

        return 1;
    }

    if (lo_is_string_type(type_to) && lo_is_string_type(type_from)) {
        strcpy((char *) to, (char *) from);

        return 1;
    }

    if (lo_is_numerical_type(type_to) && lo_is_numerical_type(type_from)) {
        switch (type_to) {
        case LO_INT32:
            to->i = (uint32_t) lo_hires_val(type_from, from);
            break;

        case LO_INT64:
            to->i64 = (uint64_t) lo_hires_val(type_from, from);
            break;

        case LO_FLOAT:
            to->f = (float) lo_hires_val(type_from, from);
            break;

        case LO_DOUBLE:
            to->d = (double) lo_hires_val(type_from, from);
            break;

        default:
            fprintf(stderr, "liblo: bad coercion: %c -> %c\n", type_from,
                    type_to);
            return 0;
        }
        return 1;
    }

    return 0;
}
Exemple #2
0
static int lo_can_coerce(char a, char b)
{
    return ((a == b) ||
           (lo_is_numerical_type(a) && lo_is_numerical_type(b)) ||
           (lo_is_string_type(a) && lo_is_string_type (b)));
}
int wxSpinTreeCtrl_liblo_callback(const char *path, const char *types, lo_arg **argv, int argc, void * WXUNUSED(data), void *user_data)
{
    // DEBUG PRINT:

    printf("wxSpinTreeCtrl got spin message: %s", path);
    for (int i=0; i<argc; i++) {
        printf(" ");
        lo_arg_pp((lo_type) types[i], argv[i]);
    }
    printf("\n");


    if (!argc)
    {
        std::cout << "ERROR: got message for " << path << " without any method or arguments" << std::endl;
        return 1;
    }

    // check that the treeCtrl was provided as user_data
    wxSpinTreeCtrl *treeCtrl = (wxSpinTreeCtrl*) user_data;
    if (! treeCtrl)
        return 1;


    // WARNING: this callback will match ANY path, so we must manually check
    // if it is within the SPIN namespace, and if it matches the sceneID:
    // TODO: replace this with node/scene callbacks!!!
    /*
    std::string spinToken, sceneString, nodeString;
    std::istringstream pathstream(path);
    pathstream.get(); // ignore leading slash
    getline(pathstream, spinToken, '/');
    getline(pathstream, sceneString, '/');
    getline(pathstream, nodeString, '/');

    if ((spinToken!="SPIN") || !spin::wildcardMatch(sceneString.c_str(), spin::spinApp::Instance().getSceneID().c_str()) )
    {
        std::cout << "Warning: wxSpinTreeCtrl is ignoring message: " << path << std::endl;
        return 1;
    }
     */
    // get the method (argv[0]):
    std::string theMethod;
    if (lo_is_string_type((lo_type) types[0]))
    {
        theMethod = std::string((char *) argv[0]);
    }
    else
        return 0;

    // SCENE MESSAGES:
    if (1)//(nodeString.empty())
    {
        if ((theMethod=="nodeList") && (argc>2))
        {
            for (int i = 2; i < argc; ++i)
            {
                if (strcmp((char*) argv[i], "NULL") != 0) treeCtrl->addNode((char*) argv[i]);
            }
        }
        else if ((theMethod=="createNode") && (argc==3))
        {
            treeCtrl->addNode((char*) argv[1]);
        }
        else if ((theMethod=="deleteNode") && (argc==2))
        {
            treeCtrl->removeNode((char*) argv[1]);
        }
        else if (theMethod=="refresh")
        {
            treeCtrl->Refresh();
        }
        else if (theMethod=="clear")
        {
            treeCtrl->Refresh();
            treeCtrl->SelectNode(NULL);
        }
        else if ((theMethod=="parentChange") && (argc==3))
        {
            //std::cout << "got parentChange for node " << (char*)argv[1] << ". New parent: " << (char*)argv[2] << std::endl;
            //treeCtrl->removeNode((char*) argv[1]);
            //treeCtrl->addNode((char*) argv[1]);
            treeCtrl->addNode((char*)argv[1]);

        }
    }
/*
    // NODE MESSAGES:
    else
    {
        if ((theMethod=="setParent") && (argc==2))
        {
            treeCtrl->removeNode(nodeString.c_str());
            treeCtrl->addNode(nodeString.c_str());
        }
    }
*/
    return 1;
}