static bool init_effect_buffers(Device_states* dstates, const Device_node* node) { rassert(dstates != NULL); rassert(node != NULL); const Device* node_device = Device_node_get_device(node); if (node_device == NULL) return true; Device_thread_state* node_ts = Device_states_get_thread_state(dstates, 0, Device_get_id(node_device)); if (Device_thread_state_get_node_state(node_ts) > DEVICE_NODE_STATE_NEW) { rassert(Device_thread_state_get_node_state(node_ts) != DEVICE_NODE_STATE_REACHED); return true; } Device_thread_state_set_node_state(node_ts, DEVICE_NODE_STATE_REACHED); if (Device_node_get_type(node) == DEVICE_NODE_TYPE_AU) { const Audio_unit* au = Device_node_get_au_mut(node); if (au == NULL) { Device_thread_state_set_node_state(node_ts, DEVICE_NODE_STATE_VISITED); return true; } const Connections* au_conns = Audio_unit_get_connections(au); if (au_conns != NULL) { if (!Device_states_prepare(dstates, au_conns)) return false; } } for (int port = 0; port < KQT_DEVICE_PORTS_MAX; ++port) { const Connection* edge = Device_node_get_received(node, port); while (edge != NULL) { if (Device_node_get_device(edge->node) == NULL) { edge = edge->next; continue; } if (!init_effect_buffers(dstates, edge->node)) return false; edge = edge->next; } } Device_thread_state_set_node_state(node_ts, DEVICE_NODE_STATE_VISITED); return true; }
static bool Handle_update_connections(Handle* handle) { rassert(handle != NULL); Module* module = Handle_get_module(handle); const Connections* conns = Module_get_connections(module); if (conns == NULL) return true; Device_states* dstates = Player_get_device_states(handle->player); if (!Device_states_prepare(dstates, conns)) { Handle_set_error(handle, ERROR_MEMORY, "Couldn't allocate memory for connections"); return false; } return true; }