Allow disabling aliases
Use PCRE for alias matching/replacement git-svn-id: file:///home/vcs/svn/jsweeper/trunk@11 6611ac79-6612-48ef-a1e9-b906f853523emaster
parent
5c7f2794e0
commit
5b4fe30447
|
@ -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}
|
||||
)
|
||||
|
|
|
@ -24,6 +24,8 @@ void Config::Read()
|
|||
FontFace = group->GetValue("fontface", "Sans");
|
||||
|
||||
group = ini.GetGroup("general");
|
||||
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);
|
||||
|
@ -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);
|
||||
|
|
|
@ -15,6 +15,8 @@ public:
|
|||
int FontSize;
|
||||
std::string FontFace;
|
||||
|
||||
bool UseConnections;
|
||||
bool UseAliases;
|
||||
bool LocalAliases;
|
||||
bool SeparateByPortType;
|
||||
bool ExpandClients;
|
||||
|
|
|
@ -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,6 +58,7 @@ void PortManager::Add(jack_port_t *port)
|
|||
std::string group_name;
|
||||
std::string port_name;
|
||||
|
||||
if (cfg.UseAliases) {
|
||||
if (cfg.LocalAliases) {
|
||||
jack_name = GetAlias(jack_name);
|
||||
} else {
|
||||
|
@ -67,6 +82,7 @@ void PortManager::Add(jack_port_t *port)
|
|||
delete aliases[0];
|
||||
delete aliases[1];
|
||||
}
|
||||
}
|
||||
|
||||
size_t pos1 = jack_name.find(':');
|
||||
size_t pos2 = jack_name.find('.', pos1);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue