Allow disabling aliases

Use PCRE for alias matching/replacement


git-svn-id: file:///home/vcs/svn/jsweeper/trunk@11 6611ac79-6612-48ef-a1e9-b906f853523e
master
petern 2009-11-27 23:02:08 +00:00
parent 5c7f2794e0
commit 5b4fe30447
5 changed files with 63 additions and 32 deletions

View File

@ -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}
)

View File

@ -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);

View File

@ -15,6 +15,8 @@ public:
int FontSize;
std::string FontFace;
bool UseConnections;
bool UseAliases;
bool LocalAliases;
bool SeparateByPortType;
bool ExpandClients;

View File

@ -1,10 +1,24 @@
#include <iostream>
#include <fstream>
#include <cstring>
#include <pcrecpp.h>
#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);
}

View File

@ -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<Alias> AliasList;