| 429 | |
| 430 | |
| 431 | static void Engine_updateConnected(Engine* that) { |
| 432 | // Find disconnected ports |
| 433 | std::set<Input*> disconnectedInputs; |
| 434 | std::set<Output*> disconnectedOutputs; |
| 435 | for (Module* module : that->internal->modules) { |
| 436 | for (Input& input : module->inputs) { |
| 437 | disconnectedInputs.insert(&input); |
| 438 | } |
| 439 | for (Output& output : module->outputs) { |
| 440 | disconnectedOutputs.insert(&output); |
| 441 | } |
| 442 | } |
| 443 | for (TerminalModule* terminalModule : that->internal->terminalModules) { |
| 444 | for (Input& input : terminalModule->inputs) { |
| 445 | disconnectedInputs.insert(&input); |
| 446 | } |
| 447 | for (Output& output : terminalModule->outputs) { |
| 448 | disconnectedOutputs.insert(&output); |
| 449 | } |
| 450 | } |
| 451 | for (Cable* cable : that->internal->cables) { |
| 452 | // Connect input |
| 453 | Input& input = cable->inputModule->inputs[cable->inputId]; |
| 454 | auto inputIt = disconnectedInputs.find(&input); |
| 455 | if (inputIt != disconnectedInputs.end()) |
| 456 | disconnectedInputs.erase(inputIt); |
| 457 | Port_setConnected(&input); |
| 458 | // Connect output |
| 459 | Output& output = cable->outputModule->outputs[cable->outputId]; |
| 460 | auto outputIt = disconnectedOutputs.find(&output); |
| 461 | if (outputIt != disconnectedOutputs.end()) |
| 462 | disconnectedOutputs.erase(outputIt); |
| 463 | Port_setConnected(&output); |
| 464 | } |
| 465 | // Disconnect ports that have no cable |
| 466 | for (Input* input : disconnectedInputs) { |
| 467 | Port_setDisconnected(input); |
| 468 | } |
| 469 | for (Output* output : disconnectedOutputs) { |
| 470 | Port_setDisconnected(output); |
| 471 | DISTRHO_SAFE_ASSERT(output->cables.empty()); |
| 472 | } |
| 473 | // Order the modules according to their connections |
| 474 | Engine_orderModules(that); |
| 475 | } |
| 476 | |
| 477 | |
| 478 | static void Engine_refreshParamHandleCache(Engine* that) { |
no test coverage detected