Better routing
This commit is contained in:
parent
916965488c
commit
07e2fb4c5a
3 changed files with 99 additions and 27 deletions
|
|
@ -565,22 +565,38 @@ void WarpGraphModel::refreshFromClient() {
|
|||
QtNodes::PortIndex inPortIdx = 0;
|
||||
bool found = false;
|
||||
|
||||
bool outPortFound = false;
|
||||
bool inPortFound = false;
|
||||
|
||||
for (const auto &[qtId, nodeData] : m_nodes) {
|
||||
for (size_t i = 0; i < nodeData.outputPorts.size(); ++i) {
|
||||
if (nodeData.outputPorts[i].id.value == link.output_port.value) {
|
||||
outNodeIt = m_pwToQt.find(nodeData.info.id.value);
|
||||
outPortIdx = static_cast<QtNodes::PortIndex>(i);
|
||||
if (!outPortFound) {
|
||||
for (size_t i = 0; i < nodeData.outputPorts.size(); ++i) {
|
||||
if (nodeData.outputPorts[i].id.value ==
|
||||
link.output_port.value) {
|
||||
outNodeIt = m_pwToQt.find(nodeData.info.id.value);
|
||||
outPortIdx = static_cast<QtNodes::PortIndex>(i);
|
||||
outPortFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < nodeData.inputPorts.size(); ++i) {
|
||||
if (nodeData.inputPorts[i].id.value == link.input_port.value) {
|
||||
inNodeIt = m_pwToQt.find(nodeData.info.id.value);
|
||||
inPortIdx = static_cast<QtNodes::PortIndex>(i);
|
||||
if (!inPortFound) {
|
||||
for (size_t i = 0; i < nodeData.inputPorts.size(); ++i) {
|
||||
if (nodeData.inputPorts[i].id.value ==
|
||||
link.input_port.value) {
|
||||
inNodeIt = m_pwToQt.find(nodeData.info.id.value);
|
||||
inPortIdx = static_cast<QtNodes::PortIndex>(i);
|
||||
inPortFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (outPortFound && inPortFound)
|
||||
break;
|
||||
}
|
||||
|
||||
if (outNodeIt != m_pwToQt.end() && inNodeIt != m_pwToQt.end()) {
|
||||
if (outPortFound && inPortFound && outNodeIt != m_pwToQt.end() &&
|
||||
inNodeIt != m_pwToQt.end()) {
|
||||
found = true;
|
||||
}
|
||||
|
||||
|
|
@ -710,6 +726,8 @@ void WarpGraphModel::refreshFromClient() {
|
|||
Q_EMIT nodeVolumeChanged(qtId, previous, cached);
|
||||
}
|
||||
|
||||
recomputeConnectionChannels();
|
||||
|
||||
m_refreshing = false;
|
||||
if (sceneChanged) {
|
||||
Q_EMIT endBatchUpdate();
|
||||
|
|
@ -976,6 +994,40 @@ float WarpGraphModel::nodePeakLevel(QtNodes::NodeId nodeId) const {
|
|||
return it != m_peakLevels.end() ? it->second : 0.0f;
|
||||
}
|
||||
|
||||
void WarpGraphModel::recomputeConnectionChannels() {
|
||||
m_connectionChannels.clear();
|
||||
|
||||
std::unordered_map<QtNodes::NodeId, std::vector<QtNodes::ConnectionId>> byTarget;
|
||||
for (const auto &cId : m_connections)
|
||||
byTarget[cId.inNodeId].push_back(cId);
|
||||
|
||||
for (auto &[targetId, conns] : byTarget) {
|
||||
std::sort(conns.begin(), conns.end(),
|
||||
[this](const auto &a, const auto &b) {
|
||||
auto posA = m_positions.count(a.outNodeId)
|
||||
? m_positions.at(a.outNodeId).y()
|
||||
: 0.0;
|
||||
auto posB = m_positions.count(b.outNodeId)
|
||||
? m_positions.at(b.outNodeId).y()
|
||||
: 0.0;
|
||||
if (posA != posB)
|
||||
return posA < posB;
|
||||
return a.outPortIndex < b.outPortIndex;
|
||||
});
|
||||
|
||||
int count = static_cast<int>(conns.size());
|
||||
for (int i = 0; i < count; ++i)
|
||||
m_connectionChannels[conns[i]] = {i, count};
|
||||
}
|
||||
}
|
||||
|
||||
WarpGraphModel::ConnectionChannel
|
||||
WarpGraphModel::connectionChannel(QtNodes::ConnectionId cId) const {
|
||||
auto it = m_connectionChannels.find(cId);
|
||||
return it != m_connectionChannels.end() ? it->second
|
||||
: ConnectionChannel{0, 1};
|
||||
}
|
||||
|
||||
void WarpGraphModel::saveLayout(const QString &path) const {
|
||||
ViewState vs{};
|
||||
saveLayout(path, vs);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue