| 1043 | |
| 1044 | |
| 1045 | void Engine::removeCable_NoLock(Cable* cable) { |
| 1046 | assert(cable); |
| 1047 | Input& input = cable->inputModule->inputs[cable->inputId]; |
| 1048 | Output& output = cable->outputModule->outputs[cable->outputId]; |
| 1049 | // Check that the cable is already added |
| 1050 | auto it = std::find(internal->cables.begin(), internal->cables.end(), cable); |
| 1051 | assert(it != internal->cables.end()); |
| 1052 | // Remove cable caches |
| 1053 | internal->cablesCache.erase(cable->id); |
| 1054 | // Remove cable |
| 1055 | internal->cables.erase(it); |
| 1056 | // Check if input/output is still connected to a cable |
| 1057 | bool inputIsConnected = false; |
| 1058 | bool outputIsConnected = false; |
| 1059 | for (Cable* cable2 : internal->cables) { |
| 1060 | if (cable2->inputModule == cable->inputModule && cable2->inputId == cable->inputId) { |
| 1061 | inputIsConnected = true; |
| 1062 | } |
| 1063 | if (cable2->outputModule == cable->outputModule && cable2->outputId == cable->outputId) { |
| 1064 | outputIsConnected = true; |
| 1065 | } |
| 1066 | } |
| 1067 | // Set input as disconnected if disconnected from all cables |
| 1068 | if (!inputIsConnected) { |
| 1069 | input.channels = 0; |
| 1070 | // Clear input values |
| 1071 | for (uint8_t c = 0; c < PORT_MAX_CHANNELS; c++) { |
| 1072 | input.setVoltage(0.f, c); |
| 1073 | } |
| 1074 | } |
| 1075 | // Set output as disconnected if disconnected from all cables |
| 1076 | if (!outputIsConnected) { |
| 1077 | output.channels = 0; |
| 1078 | // Don't clear output values |
| 1079 | } |
| 1080 | // Dispatch input port event |
| 1081 | if (!inputIsConnected) { |
| 1082 | Module::PortChangeEvent e; |
| 1083 | e.connecting = false; |
| 1084 | e.type = Port::INPUT; |
| 1085 | e.portId = cable->inputId; |
| 1086 | cable->inputModule->onPortChange(e); |
| 1087 | } |
| 1088 | // Dispatch output port event |
| 1089 | if (!outputIsConnected) { |
| 1090 | Module::PortChangeEvent e; |
| 1091 | e.connecting = false; |
| 1092 | e.type = Port::OUTPUT; |
| 1093 | e.portId = cable->outputId; |
| 1094 | cable->outputModule->onPortChange(e); |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | |
| 1099 | bool Engine::hasCable(Cable* cable) { |
nothing calls this directly
no test coverage detected