From 5d06b94ef7668ab73c0d60def2fe5a7ce7d5f626 Mon Sep 17 00:00:00 2001 From: Stephane Letz Date: Thu, 18 Apr 2013 15:44:21 +0200 Subject: [PATCH] Use port type information in JackDriver::SaveConnections and JackDriver::RestoreConnections. --- common/JackDriver.cpp | 71 +++++++++++++++++++++++----------------- common/JackDriver.h | 4 +-- common/JackNetDriver.cpp | 6 ++-- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/common/JackDriver.cpp b/common/JackDriver.cpp index bd03eb13..68e80af7 100644 --- a/common/JackDriver.cpp +++ b/common/JackDriver.cpp @@ -499,26 +499,28 @@ void JackDriver::SaveConnections(int alias) if (fCapturePortList[i] && (connections = fGraphManager->GetConnections(fCapturePortList[i])) != 0) { if (alias == 0) { for (int j = 0; connections[j]; j++) { - fConnections.push_back(make_pair(fGraphManager->GetPort(fCapturePortList[i])->GetName(), connections[j])); + JackPort* port_id = fGraphManager->GetPort(fCapturePortList[i]); + fConnections.push_back(make_pair(port_id->GetType(), make_pair(port_id->GetName(), connections[j]))); jack_info("Save connection: %s %s", fGraphManager->GetPort(fCapturePortList[i])->GetName(), connections[j]); } } else { int res1 = fGraphManager->GetPort(fCapturePortList[i])->GetAliases(aliases); string sub_name; if (res1 >= alias) { - sub_name = RemoveLast(aliases[alias-1]); + sub_name = aliases[alias-1]; } else { - sub_name = RemoveLast(fGraphManager->GetPort(fCapturePortList[i])->GetName()); + sub_name = fGraphManager->GetPort(fCapturePortList[i])->GetName(); } for (int j = 0; connections[j]; j++) { - int res2 = fGraphManager->GetPort(fGraphManager->GetPort(connections[j]))->GetAliases(system_aliases); + JackPort* port_id = fGraphManager->GetPort(fGraphManager->GetPort(connections[j])); + int res2 = port_id->GetAliases(system_aliases); string sub_system_name; if (res2 >= alias) { - sub_system_name = RemoveLast(system_aliases[alias-1]); + sub_system_name = system_aliases[alias-1]; } else { - sub_system_name = RemoveLast(connections[j]); + sub_system_name = connections[j]; } - fConnections.push_back(make_pair(sub_name, sub_system_name)); + fConnections.push_back(make_pair(port_id->GetType(), make_pair(sub_name, sub_system_name))); jack_info("Save connection: %s %s", sub_name.c_str(), sub_system_name.c_str()); } } @@ -530,26 +532,28 @@ void JackDriver::SaveConnections(int alias) if (fPlaybackPortList[i] && (connections = fGraphManager->GetConnections(fPlaybackPortList[i])) != 0) { if (alias == 0) { for (int j = 0; connections[j]; j++) { - fConnections.push_back(make_pair(fGraphManager->GetPort(fPlaybackPortList[i])->GetName(), connections[j])); + JackPort* port_id = fGraphManager->GetPort(fPlaybackPortList[i]); + fConnections.push_back(make_pair(port_id->GetType(), make_pair(port_id->GetName(), connections[j]))); jack_info("Save connection: %s %s", fGraphManager->GetPort(fPlaybackPortList[i])->GetName(), connections[j]); } } else { int res1 = fGraphManager->GetPort(fPlaybackPortList[i])->GetAliases(aliases); string sub_name; if (res1 >= alias) { - sub_name = RemoveLast(aliases[alias-1]); + sub_name = aliases[alias-1]; } else { - sub_name = RemoveLast(fGraphManager->GetPort(fPlaybackPortList[i])->GetName()); + sub_name = fGraphManager->GetPort(fPlaybackPortList[i])->GetName(); } for (int j = 0; connections[j]; j++) { - int res2 = fGraphManager->GetPort(fGraphManager->GetPort(connections[j]))->GetAliases(system_aliases); + JackPort* port_id = fGraphManager->GetPort(fGraphManager->GetPort(connections[j])); + int res2 = port_id->GetAliases(system_aliases); string sub_system_name; if (res2 >= alias) { - sub_system_name = RemoveLast(system_aliases[alias-1]); + sub_system_name = system_aliases[alias-1]; } else { - sub_system_name = RemoveLast(connections[j]); + sub_system_name = connections[j]; } - fConnections.push_back(make_pair(sub_system_name, sub_name)); + fConnections.push_back(make_pair(port_id->GetType(), make_pair(sub_system_name, sub_name))); jack_info("Save connection: %s %s", sub_system_name.c_str(), sub_name.c_str()); } } @@ -558,7 +562,7 @@ void JackDriver::SaveConnections(int alias) } } -string JackDriver::MatchPortName(const char* name, const char** ports, int alias) +string JackDriver::MatchPortName(const char* name, const char** ports, int alias, const std::string& type) { char alias1[REAL_JACK_PORT_NAME_SIZE]; char alias2[REAL_JACK_PORT_NAME_SIZE]; @@ -568,28 +572,35 @@ string JackDriver::MatchPortName(const char* name, const char** ports, int alias aliases[1] = alias2; for (int i = 0; ports && ports[i]; ++i) { - int res = fGraphManager->GetPort(fGraphManager->GetPort(ports[i]))->GetAliases(aliases); - string name_str; - if (res >= alias) { - name_str = string(aliases[alias-1]); - } else { - name_str = string(ports[i]); - } - if (name_str.find(name) != string::npos) { - return name_str; + + jack_port_id_t port_id2 = fGraphManager->GetPort(ports[i]); + JackPort* port2 = (port_id2 != NO_PORT) ? fGraphManager->GetPort(port_id2) : NULL; + + if (port2) { + int res = port2->GetAliases(aliases); + string name_str; + if (res >= alias) { + name_str = string(aliases[alias-1]); + } else { + name_str = string(ports[i]); + } + string sub_name = RemoveLast(name); + if ((name_str.find(sub_name) != string::npos) && (type == string(port2->GetType()))) { + return name_str; + } } - } + } return ""; } void JackDriver::RestoreConnections(int alias, bool full_name) { - list >::const_iterator it; + list > >::const_iterator it; if (full_name) { for (it = fConnections.begin(); it != fConnections.end(); it++) { - pair connection = *it; + pair connection = (*it).second; jack_info("Restore connection: %s %s", connection.first.c_str(), connection.second.c_str()); fEngine->PortConnect(fClientControl.fRefNum, connection.first.c_str(), connection.second.c_str()); } @@ -598,9 +609,9 @@ void JackDriver::RestoreConnections(int alias, bool full_name) const char** outputs = fGraphManager->GetPorts(NULL, NULL, JackPortIsOutput); for (it = fConnections.begin(); it != fConnections.end(); it++) { - pair connection = *it; - string real_input = MatchPortName(connection.first.c_str(), outputs, alias); - string real_output = MatchPortName(connection.second.c_str(), inputs, alias); + pair connection = (*it).second; + string real_input = MatchPortName(connection.first.c_str(), outputs, alias, (*it).first); + string real_output = MatchPortName(connection.second.c_str(), inputs, alias, (*it).first); if ((real_input != "") && (real_output != "")) { jack_info("Restore connection: %s %s", real_input.c_str(), real_output.c_str()); fEngine->PortConnect(fClientControl.fRefNum, real_input.c_str(), real_output.c_str()); diff --git a/common/JackDriver.h b/common/JackDriver.h index 227eb843..4b676858 100644 --- a/common/JackDriver.h +++ b/common/JackDriver.h @@ -169,7 +169,7 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface jack_port_id_t fPlaybackPortList[DRIVER_PORT_NUM]; jack_port_id_t fMonitorPortList[DRIVER_PORT_NUM]; - std::list > fConnections; // Connections list + std::list > > fConnections; // Connections list void CycleIncTime(); void CycleTakeBeginTime(); @@ -184,7 +184,7 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface virtual void SaveConnections(int alias); virtual void RestoreConnections(int alias, bool full_name = true); - std::string MatchPortName(const char* name, const char** ports, int alias); + std::string MatchPortName(const char* name, const char** ports, int alias, const std::string& type); virtual int StartSlaves(); virtual int StopSlaves(); diff --git a/common/JackNetDriver.cpp b/common/JackNetDriver.cpp index 90e0859f..c71298a1 100644 --- a/common/JackNetDriver.cpp +++ b/common/JackNetDriver.cpp @@ -380,7 +380,8 @@ namespace Jack for (int i = 0; i < fParams.fSendMidiChannels; ++i) { if (fCapturePortList[i] && (connections = fGraphManager->GetConnections(fMidiCapturePortList[i])) != 0) { for (int j = 0; connections[j]; j++) { - fConnections.push_back(make_pair(fGraphManager->GetPort(fMidiCapturePortList[i])->GetName(), connections[j])); + JackPort* port_id = fGraphManager->GetPort(fGraphManager->GetPort(connections[j])); + fConnections.push_back(make_pair(port_id->GetType(), make_pair(fGraphManager->GetPort(fMidiCapturePortList[i])->GetName(), connections[j]))); } free(connections); } @@ -389,7 +390,8 @@ namespace Jack for (int i = 0; i < fParams.fReturnMidiChannels; ++i) { if (fPlaybackPortList[i] && (connections = fGraphManager->GetConnections(fMidiPlaybackPortList[i])) != 0) { for (int j = 0; connections[j]; j++) { - fConnections.push_back(make_pair(connections[j], fGraphManager->GetPort(fMidiPlaybackPortList[i])->GetName())); + JackPort* port_id = fGraphManager->GetPort(fGraphManager->GetPort(connections[j])); + fConnections.push_back(make_pair(port_id->GetType(), make_pair(connections[j], fGraphManager->GetPort(fMidiPlaybackPortList[i])->GetName()))); } free(connections); }