static gboolean cbox_instrument_aux_process_cmd(struct cbox_instrument *instr, struct cbox_instrument_output *output, int id, struct cbox_command_target *fb, struct cbox_osc_command *cmd, const char *subcmd, GError **error) { if (!strcmp(subcmd, "/status") && !strcmp(cmd->arg_types, "")) { if (!cbox_check_fb_channel(fb, cmd->command, error)) return FALSE; if (!(cbox_execute_on(fb, NULL, "/gain_linear", "f", error, output->gain) && cbox_execute_on(fb, NULL, "/gain", "f", error, gain2dB_simple(output->gain)) && cbox_execute_on(fb, NULL, "/bus", "s", error, instr->aux_output_names[id] ? instr->aux_output_names[id] : ""))) return FALSE; return cbox_module_slot_process_cmd(&output->insert, fb, cmd, subcmd, CBOX_GET_DOCUMENT(instr->scene), instr->scene->rt, instr->scene->engine, error); } else if (!strcmp(subcmd, "/bus") && !strcmp(cmd->arg_types, "s")) { struct cbox_scene *scene = instr->scene; if (!CBOX_ARG_S(cmd, 0)) { struct cbox_aux_bus *old_bus = cbox_rt_swap_pointers(instr->module->rt, (void **)&instr->aux_outputs[id], NULL); if (old_bus) cbox_aux_bus_unref(old_bus); return TRUE; } for (int i = 0; i < scene->aux_bus_count; i++) { if (!scene->aux_buses[i]) continue; if (!strcmp(scene->aux_buses[i]->name, CBOX_ARG_S(cmd, 0))) { g_free(instr->aux_output_names[id]); instr->aux_output_names[id] = g_strdup(scene->aux_buses[i]->name); cbox_aux_bus_ref(scene->aux_buses[i]); struct cbox_aux_bus *old_bus = cbox_rt_swap_pointers(instr->module->rt, (void **)&instr->aux_outputs[id], scene->aux_buses[i]); if (old_bus) cbox_aux_bus_unref(old_bus); return TRUE; } } g_set_error(error, CBOX_MODULE_ERROR, CBOX_MODULE_ERROR_FAILED, "Unknown aux bus: %s", CBOX_ARG_S(cmd, 0)); return FALSE; } else if (!strcmp(subcmd, "/output") && !strcmp(cmd->arg_types, "i")) // not supported { cbox_set_command_error(error, cmd); return FALSE; } else // otherwise, treat just like an command on normal (non-aux) output return cbox_instrument_output_process_cmd(instr, output, fb, cmd, subcmd, error); }
void fxchain_move(struct fxchain_module *m, unsigned int oldpos, unsigned int newpos) { if (oldpos == newpos) return; struct cbox_module **modules = malloc(sizeof(struct cbox_module *) * m->module_count); for (uint32_t i = 0; i < m->module_count; i++) { int s; if (i == newpos) s = oldpos; else { if (oldpos < newpos) s = (i < oldpos || i > newpos) ? i : i + 1; else s = (i < newpos || i > oldpos) ? i : i - 1; } modules[i] = m->modules[s]; } free(cbox_rt_swap_pointers(m->module.rt, (void **)&m->modules, modules)); }
void cbox_module_swap_pointers_and_free(struct cbox_module *sm, void **pptr, void *value) { free(cbox_rt_swap_pointers(sm->rt, pptr, value)); }
gboolean cbox_module_slot_process_cmd(struct cbox_module **psm, struct cbox_command_target *fb, struct cbox_osc_command *cmd, const char *subcmd, struct cbox_document *doc, struct cbox_rt *rt, struct cbox_engine *engine, GError **error) { struct cbox_module *sm = *psm; if (!strcmp(subcmd, "/status") && !strcmp(cmd->arg_types, "")) { if (!cbox_check_fb_channel(fb, cmd->command, error)) return FALSE; if (!(cbox_execute_on(fb, NULL, "/insert_engine", "s", error, sm ? sm->engine_name : "") && cbox_execute_on(fb, NULL, "/insert_preset", "s", error, sm ? sm->instance_name : "") && cbox_execute_on(fb, NULL, "/bypass", "i", error, sm ? sm->bypass : 0))) return FALSE; return TRUE; } if (!strcmp(subcmd, "/insert_preset") && !strcmp(cmd->arg_types, "s")) { struct cbox_module *effect = cbox_module_new_from_fx_preset(CBOX_ARG_S(cmd, 0), doc, rt, engine, error); if (!effect) return FALSE; cbox_rt_swap_pointers(rt, (void **)psm, effect); return TRUE; } if (!strcmp(subcmd, "/insert_engine") && !strcmp(cmd->arg_types, "s")) { struct cbox_module *effect = NULL; if (*CBOX_ARG_S(cmd, 0)) { struct cbox_module_manifest *manifest = cbox_module_manifest_get_by_name(CBOX_ARG_S(cmd, 0)); if (!manifest) { g_set_error(error, CBOX_MODULE_ERROR, CBOX_MODULE_ERROR_FAILED, "No effect engine '%s'", CBOX_ARG_S(cmd, 0)); return FALSE; } effect = cbox_module_manifest_create_module(manifest, NULL, doc, rt, engine, "unnamed", error); if (!effect) return FALSE; } cbox_rt_swap_pointers(rt, (void **)psm, effect); return TRUE; } if (!sm) { g_set_error(error, CBOX_MODULE_ERROR, CBOX_MODULE_ERROR_FAILED, "No engine on module in path '%s'", cmd->command); return FALSE; } if (!strncmp(subcmd, "/engine/", 8)) { if (!sm->cmd_target.process_cmd) { g_set_error(error, CBOX_MODULE_ERROR, CBOX_MODULE_ERROR_FAILED, "The engine %s has no command target defined", sm->engine_name); return FALSE; } return cbox_execute_sub(&sm->cmd_target, fb, cmd, subcmd + 7, error); } if (!strcmp(subcmd, "/set_bypass") && !strcmp(cmd->arg_types, "i")) { sm->bypass = CBOX_ARG_I(cmd, 0); return TRUE; } return cbox_object_default_process_cmd(&sm->cmd_target, fb, cmd, error); }