diff --git a/CMakeLists.txt b/CMakeLists.txt index 47d03b0..fb7fa1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ pkg_check_modules(JACK jack>=0.118) pkg_check_modules(GTKMM gtkmm-2.4>=2.4) pkg_check_modules(CAIROMM cairomm-1.0>=1.0) pkg_check_modules(DBUS dbus-glib-1) +pkg_check_modules(PCRE libpcrecpp) SET(SOURCES src/config.cpp @@ -37,6 +38,7 @@ LINK_DIRECTORIES( ${GTKMM_LIBRARY_DIRS} ${CAIROMM_LIBRARY_DIRS} ${DBUS_LIBRARY_DIRS} + ${PCRE_LIBRARY_DIRS} ) INCLUDE_DIRECTORIES( @@ -44,6 +46,7 @@ INCLUDE_DIRECTORIES( ${GTKMM_INCLUDE_DIRS} ${CAIROMM_INCLUDE_DIRS} ${DBUS_INCLUDE_DIRS} + ${PCRE_INCLUDE_DIRS} ) ADD_DEFINITIONS(-g -Wall -Wextra -ansi -pedantic) @@ -54,4 +57,5 @@ TARGET_LINK_LIBRARIES(jsweeper ${GTKMM_LIBRARIES} ${CAIROMM_LIBRARIES} ${DBUS_LIBRARIES} + ${PCRE_LIBRARIES} ) diff --git a/src/config.cpp b/src/config.cpp index eccef32..70fb2dd 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -24,10 +24,12 @@ void Config::Read() FontFace = group->GetValue("fontface", "Sans"); group = ini.GetGroup("general"); - LocalAliases = group->GetValue("localaliases", true); + UseConnections = group->GetValue("useconnections", true); + UseAliases = group->GetValue("usealiases", true); + LocalAliases = group->GetValue("localaliases", true); SeparateByPortType = group->GetValue("separatebyporttype", false); - ExpandClients = group->GetValue("expandclients", true); - ExpandGroups = group->GetValue("expandgroups", false); + ExpandClients = group->GetValue("expandclients", true); + ExpandGroups = group->GetValue("expandgroups", false); group = ini.GetGroup("colours"); Background = Colour(group->GetValue("background", "#404040")); @@ -60,6 +62,8 @@ void Config::Write() group->SetValue("fontface", FontFace); group = ini.GetGroup("general"); + group->SetValue("useconnections", UseConnections); + group->SetValue("usealiases", UseAliases); group->SetValue("localaliases", LocalAliases); group->SetValue("separatebyporttype", SeparateByPortType); group->SetValue("expandclients", ExpandClients); @@ -83,7 +87,7 @@ void Config::Write() AliasList::const_iterator it; for (it = list.begin(); it != list.end(); ++it) { const Alias &a = *it; - group->SetValue(a.name, a.alias); + group->SetValue(a.match, a.replace); } ini.SaveToDisk(m_filename); diff --git a/src/config.h b/src/config.h index e2e865f..2e2b612 100644 --- a/src/config.h +++ b/src/config.h @@ -15,6 +15,8 @@ public: int FontSize; std::string FontFace; + bool UseConnections; + bool UseAliases; bool LocalAliases; bool SeparateByPortType; bool ExpandClients; diff --git a/src/portmanager.cpp b/src/portmanager.cpp index a3d4af2..5a93466 100644 --- a/src/portmanager.cpp +++ b/src/portmanager.cpp @@ -1,10 +1,24 @@ #include #include #include +#include #include "jack.h" #include "portmanager.h" #include "config.h" +bool Alias::Match(std::string name) +{ + pcrecpp::RE re(match); + return re.FullMatch(name); +} + +std::string Alias::Replace(std::string name) +{ + pcrecpp::RE re(match); + re.Replace(replace, &name); + return name; +} + void PortManager::Refresh() { // Clear all information @@ -44,28 +58,30 @@ void PortManager::Add(jack_port_t *port) std::string group_name; std::string port_name; - if (cfg.LocalAliases) { - jack_name = GetAlias(jack_name); - } else { - char *aliases[2]; - aliases[0] = new char[jack_port_name_size()]; - aliases[1] = new char[jack_port_name_size()]; + if (cfg.UseAliases) { + if (cfg.LocalAliases) { + jack_name = GetAlias(jack_name); + } else { + char *aliases[2]; + aliases[0] = new char[jack_port_name_size()]; + aliases[1] = new char[jack_port_name_size()]; - int num_aliases = jack_port_get_aliases(port, aliases); + int num_aliases = jack_port_get_aliases(port, aliases); - if (num_aliases < 2) { - AliasBay(port, num_aliases, aliases); - num_aliases = jack_port_get_aliases(port, aliases); + if (num_aliases < 2) { + AliasBay(port, num_aliases, aliases); + num_aliases = jack_port_get_aliases(port, aliases); + } + + if (num_aliases == 2) { + jack_name = aliases[1]; + } else if (num_aliases == 1) { + jack_name = aliases[0]; + } + + delete aliases[0]; + delete aliases[1]; } - - if (num_aliases == 2) { - jack_name = aliases[1]; - } else if (num_aliases == 1) { - jack_name = aliases[0]; - } - - delete aliases[0]; - delete aliases[1]; } size_t pos1 = jack_name.find(':'); @@ -330,8 +346,9 @@ std::string PortManager::GetAlias(std::string port_name) AliasList::iterator it; for (it = m_aliases.begin(); it != m_aliases.end(); ++it) { Alias &a = *it; - if (a.name == port_name) { - return a.alias; + + if (a.Match(port_name)) { + return a.Replace(port_name); } } @@ -345,13 +362,14 @@ void PortManager::AliasBay(jack_port_t *port, int num_aliases, char *aliases[2]) AliasList::iterator it; for (it = m_aliases.begin(); it != m_aliases.end(); ++it) { Alias &a = *it; - if (a.name == port_name) { + if (a.Match(port_name)) { + std::string alias = a.Replace(port_name); bool got = false; for (int i = 0; i < num_aliases; i++) { - if (a.alias == aliases[i]) got = true; + if (alias == aliases[i]) got = true; } if (!got) { - jack_port_set_alias(port, a.alias.c_str()); + jack_port_set_alias(port, alias.c_str()); } } } @@ -365,8 +383,8 @@ void PortManager::AliasClear() void PortManager::AliasAdd(std::string source, std::string target) { Alias a; - a.name = source; - a.alias = target; + a.match = source; + a.replace = target; m_aliases.push_back(a); } diff --git a/src/portmanager.h b/src/portmanager.h index d51c3bc..750cdff 100644 --- a/src/portmanager.h +++ b/src/portmanager.h @@ -6,8 +6,11 @@ struct Alias { - std::string name; - std::string alias; + std::string match; + std::string replace; + + bool Match(std::string name); + std::string Replace(std::string name); }; typedef std::list AliasList;