Example #1
0
gboolean fxchain_process_cmd(struct cbox_command_target *ct, struct cbox_command_target *fb, struct cbox_osc_command *cmd, GError **error)
{
    struct fxchain_module *m = (struct fxchain_module *)ct->user_data;
    const char *subcommand = NULL;
    int index = 0;
    
    //EFFECT_PARAM("/module_count", "i", stages, int, , 1, 12) else
    if (!strcmp(cmd->command, "/status") && !strcmp(cmd->arg_types, ""))
    {
        if (!cbox_check_fb_channel(fb, cmd->command, error))
            return FALSE;
        for (uint32_t i = 0; i < m->module_count; i++)
        {
            gboolean res = FALSE;
            if (m->modules[i])
                res = cbox_execute_on(fb, NULL, "/module", "ss", error, m->modules[i]->engine_name, m->modules[i]->instance_name);
            else
                res = cbox_execute_on(fb, NULL, "/module", "ss", error, "", "");
            if (!res)
                return FALSE;
            res = cbox_execute_on(fb, NULL, "/bypass", "ii", error, i + 1, m->modules[i] ? m->modules[i]->bypass : 0);
        }
        return CBOX_OBJECT_DEFAULT_STATUS(&m->module, fb, error);
    }
    else if (cbox_parse_path_part_int(cmd, "/module/", &subcommand, &index, 1, m->module_count, error))
    {
        if (!subcommand)
            return FALSE;
        return cbox_module_slot_process_cmd(&m->modules[index - 1], fb, cmd, subcommand, CBOX_GET_DOCUMENT(&m->module), m->module.rt, m->module.engine, error);
    }
    else if (!strcmp(cmd->command, "/insert") && !strcmp(cmd->arg_types, "i"))
    {
        int pos = CBOX_ARG_I(cmd, 0) - 1;
        struct cbox_module **new_modules = malloc((m->module_count + 1) * sizeof(struct cbox_module *));
        memcpy(new_modules, m->modules, pos * sizeof(struct cbox_module *));
        new_modules[pos] = NULL;
        memcpy(new_modules + pos + 1, m->modules + pos, (m->module_count - pos) * sizeof(struct cbox_module *));
        void *old_modules = cbox_rt_swap_pointers_and_update_count(m->module.rt, (void **)&m->modules, new_modules, &m->module_count, m->module_count + 1);
        free(old_modules);
        return TRUE;
    }
    else if (!strcmp(cmd->command, "/delete") && !strcmp(cmd->arg_types, "i"))
    {
        int pos = CBOX_ARG_I(cmd, 0) - 1;
        struct cbox_module **new_modules = malloc((m->module_count + 1) * sizeof(struct cbox_module *));
        memcpy(new_modules, m->modules, pos * sizeof(struct cbox_module *));
        memcpy(new_modules + pos, m->modules + pos + 1, (m->module_count - pos - 1) * sizeof(struct cbox_module *));
        struct cbox_module *deleted_module = m->modules[pos];
        void *old_modules = cbox_rt_swap_pointers_and_update_count(m->module.rt, (void **)&m->modules, new_modules, &m->module_count, m->module_count - 1);
        free(old_modules);
        if (deleted_module)
            CBOX_DELETE(deleted_module);
        return TRUE;
    }
    else if (!strcmp(cmd->command, "/move") && !strcmp(cmd->arg_types, "ii"))
    {
        int oldpos = CBOX_ARG_I(cmd, 0) - 1;
        int newpos = CBOX_ARG_I(cmd, 1) - 1;
        fxchain_move(m, oldpos, newpos);
    }
    else
        return cbox_object_default_process_cmd(ct, fb, cmd, error);
    return TRUE;
}
Example #2
0
gboolean cbox_instrument_process_cmd(struct cbox_command_target *ct, struct cbox_command_target *fb, struct cbox_osc_command *cmd, GError **error)
{
    struct cbox_instrument *instr = ct->user_data;
    const char *subcommand = NULL;
    int index = 0;
    int aux_offset = instr->module->aux_offset / 2;
    if (!strcmp(cmd->command, "/status") && !strcmp(cmd->arg_types, ""))
    {
        if (!cbox_check_fb_channel(fb, cmd->command, error))
            return FALSE;
        if (!cbox_execute_on(fb, NULL, "/engine", "s", error, instr->module->engine_name))
            return FALSE;
        if (!cbox_execute_on(fb, NULL, "/aux_offset", "i", error, instr->module->aux_offset / 2 + 1))
            return FALSE;
        if (!cbox_execute_on(fb, NULL, "/outputs", "i", error, instr->module->outputs / 2))
            return FALSE;
        return CBOX_OBJECT_DEFAULT_STATUS(instr, fb, error);
    }
    else if (cbox_parse_path_part_int(cmd, "/output/", &subcommand, &index, 1, aux_offset, error))
    {
        if (!subcommand)
            return FALSE;
        if (index < 1 || index > 1 + instr->module->aux_offset)
        {
            g_set_error(error, CBOX_MODULE_ERROR, CBOX_MODULE_ERROR_FAILED, "Invalid position %d (valid are 1..%d)", index, instr->module->aux_offset);
            return FALSE;
        }
        return cbox_instrument_output_process_cmd(instr, &instr->outputs[index - 1], fb, cmd, subcommand, error);
    }
    else if (cbox_parse_path_part_int(cmd, "/aux/", &subcommand, &index, 1, instr->aux_output_count, error))
    {
        if (!subcommand)
            return FALSE;
        int acount = 1 + instr->module->outputs - instr->module->aux_offset;
        if (index < 1 || index > acount)
        {
            g_set_error(error, CBOX_MODULE_ERROR, CBOX_MODULE_ERROR_FAILED, "Invalid position %d (valid are 1..%d)", index, acount);
            return FALSE;
        }
        return cbox_instrument_aux_process_cmd(instr, &instr->outputs[aux_offset + index - 1], index - 1, fb, cmd, subcommand, error);
    }
    else
    if (!strncmp(cmd->command, "/engine/",8))
    {
        if (!instr->module->cmd_target.process_cmd)
        {
            g_set_error(error, CBOX_MODULE_ERROR, CBOX_MODULE_ERROR_FAILED, "The engine %s has no command target defined", instr->module->engine_name);
            return FALSE;
        }
        return cbox_execute_sub(&instr->module->cmd_target, fb, cmd, cmd->command + 7, error);
    }
    else if (!strcmp(cmd->command, "/move_to") && !strcmp(cmd->arg_types, "si"))
    {
        struct cbox_scene *new_scene = (struct cbox_scene *)CBOX_ARG_O(cmd, 0, instr->scene, cbox_scene, error);
        if (!new_scene)
            return FALSE;
        int dstpos = CBOX_ARG_I(cmd, 1) - 1;
        
        if (dstpos < 0 || dstpos > new_scene->layer_count)
        {
            g_set_error(error, CBOX_MODULE_ERROR, CBOX_MODULE_ERROR_FAILED, "Invalid position %d (valid are 1..%d or 0 for append)", dstpos + 1, 1 + new_scene->layer_count);
            return FALSE;
        }
        
        return cbox_scene_move_instrument_to(instr->scene, instr, new_scene, dstpos, error);
    }
    else
        return cbox_object_default_process_cmd(ct, fb, cmd, error);
}