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(GTKMM gtkmm-2.4>=2.4)
|
||||||
pkg_check_modules(CAIROMM cairomm-1.0>=1.0)
|
pkg_check_modules(CAIROMM cairomm-1.0>=1.0)
|
||||||
pkg_check_modules(DBUS dbus-glib-1)
|
pkg_check_modules(DBUS dbus-glib-1)
|
||||||
|
pkg_check_modules(PCRE libpcrecpp)
|
||||||
|
|
||||||
SET(SOURCES
|
SET(SOURCES
|
||||||
src/config.cpp
|
src/config.cpp
|
||||||
|
@ -37,6 +38,7 @@ LINK_DIRECTORIES(
|
||||||
${GTKMM_LIBRARY_DIRS}
|
${GTKMM_LIBRARY_DIRS}
|
||||||
${CAIROMM_LIBRARY_DIRS}
|
${CAIROMM_LIBRARY_DIRS}
|
||||||
${DBUS_LIBRARY_DIRS}
|
${DBUS_LIBRARY_DIRS}
|
||||||
|
${PCRE_LIBRARY_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(
|
INCLUDE_DIRECTORIES(
|
||||||
|
@ -44,6 +46,7 @@ INCLUDE_DIRECTORIES(
|
||||||
${GTKMM_INCLUDE_DIRS}
|
${GTKMM_INCLUDE_DIRS}
|
||||||
${CAIROMM_INCLUDE_DIRS}
|
${CAIROMM_INCLUDE_DIRS}
|
||||||
${DBUS_INCLUDE_DIRS}
|
${DBUS_INCLUDE_DIRS}
|
||||||
|
${PCRE_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_DEFINITIONS(-g -Wall -Wextra -ansi -pedantic)
|
ADD_DEFINITIONS(-g -Wall -Wextra -ansi -pedantic)
|
||||||
|
@ -54,4 +57,5 @@ TARGET_LINK_LIBRARIES(jsweeper
|
||||||
${GTKMM_LIBRARIES}
|
${GTKMM_LIBRARIES}
|
||||||
${CAIROMM_LIBRARIES}
|
${CAIROMM_LIBRARIES}
|
||||||
${DBUS_LIBRARIES}
|
${DBUS_LIBRARIES}
|
||||||
|
${PCRE_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,10 +24,12 @@ void Config::Read()
|
||||||
FontFace = group->GetValue("fontface", "Sans");
|
FontFace = group->GetValue("fontface", "Sans");
|
||||||
|
|
||||||
group = ini.GetGroup("general");
|
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);
|
SeparateByPortType = group->GetValue("separatebyporttype", false);
|
||||||
ExpandClients = group->GetValue("expandclients", true);
|
ExpandClients = group->GetValue("expandclients", true);
|
||||||
ExpandGroups = group->GetValue("expandgroups", false);
|
ExpandGroups = group->GetValue("expandgroups", false);
|
||||||
|
|
||||||
group = ini.GetGroup("colours");
|
group = ini.GetGroup("colours");
|
||||||
Background = Colour(group->GetValue("background", "#404040"));
|
Background = Colour(group->GetValue("background", "#404040"));
|
||||||
|
@ -60,6 +62,8 @@ void Config::Write()
|
||||||
group->SetValue("fontface", FontFace);
|
group->SetValue("fontface", FontFace);
|
||||||
|
|
||||||
group = ini.GetGroup("general");
|
group = ini.GetGroup("general");
|
||||||
|
group->SetValue("useconnections", UseConnections);
|
||||||
|
group->SetValue("usealiases", UseAliases);
|
||||||
group->SetValue("localaliases", LocalAliases);
|
group->SetValue("localaliases", LocalAliases);
|
||||||
group->SetValue("separatebyporttype", SeparateByPortType);
|
group->SetValue("separatebyporttype", SeparateByPortType);
|
||||||
group->SetValue("expandclients", ExpandClients);
|
group->SetValue("expandclients", ExpandClients);
|
||||||
|
@ -83,7 +87,7 @@ void Config::Write()
|
||||||
AliasList::const_iterator it;
|
AliasList::const_iterator it;
|
||||||
for (it = list.begin(); it != list.end(); ++it) {
|
for (it = list.begin(); it != list.end(); ++it) {
|
||||||
const Alias &a = *it;
|
const Alias &a = *it;
|
||||||
group->SetValue(a.name, a.alias);
|
group->SetValue(a.match, a.replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
ini.SaveToDisk(m_filename);
|
ini.SaveToDisk(m_filename);
|
||||||
|
|
|
@ -15,6 +15,8 @@ public:
|
||||||
int FontSize;
|
int FontSize;
|
||||||
std::string FontFace;
|
std::string FontFace;
|
||||||
|
|
||||||
|
bool UseConnections;
|
||||||
|
bool UseAliases;
|
||||||
bool LocalAliases;
|
bool LocalAliases;
|
||||||
bool SeparateByPortType;
|
bool SeparateByPortType;
|
||||||
bool ExpandClients;
|
bool ExpandClients;
|
||||||
|
|
|
@ -1,10 +1,24 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <pcrecpp.h>
|
||||||
#include "jack.h"
|
#include "jack.h"
|
||||||
#include "portmanager.h"
|
#include "portmanager.h"
|
||||||
#include "config.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()
|
void PortManager::Refresh()
|
||||||
{
|
{
|
||||||
// Clear all information
|
// Clear all information
|
||||||
|
@ -44,28 +58,30 @@ void PortManager::Add(jack_port_t *port)
|
||||||
std::string group_name;
|
std::string group_name;
|
||||||
std::string port_name;
|
std::string port_name;
|
||||||
|
|
||||||
if (cfg.LocalAliases) {
|
if (cfg.UseAliases) {
|
||||||
jack_name = GetAlias(jack_name);
|
if (cfg.LocalAliases) {
|
||||||
} else {
|
jack_name = GetAlias(jack_name);
|
||||||
char *aliases[2];
|
} else {
|
||||||
aliases[0] = new char[jack_port_name_size()];
|
char *aliases[2];
|
||||||
aliases[1] = new char[jack_port_name_size()];
|
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) {
|
if (num_aliases < 2) {
|
||||||
AliasBay(port, num_aliases, aliases);
|
AliasBay(port, num_aliases, aliases);
|
||||||
num_aliases = jack_port_get_aliases(port, 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(':');
|
size_t pos1 = jack_name.find(':');
|
||||||
|
@ -330,8 +346,9 @@ std::string PortManager::GetAlias(std::string port_name)
|
||||||
AliasList::iterator it;
|
AliasList::iterator it;
|
||||||
for (it = m_aliases.begin(); it != m_aliases.end(); ++it) {
|
for (it = m_aliases.begin(); it != m_aliases.end(); ++it) {
|
||||||
Alias &a = *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;
|
AliasList::iterator it;
|
||||||
for (it = m_aliases.begin(); it != m_aliases.end(); ++it) {
|
for (it = m_aliases.begin(); it != m_aliases.end(); ++it) {
|
||||||
Alias &a = *it;
|
Alias &a = *it;
|
||||||
if (a.name == port_name) {
|
if (a.Match(port_name)) {
|
||||||
|
std::string alias = a.Replace(port_name);
|
||||||
bool got = false;
|
bool got = false;
|
||||||
for (int i = 0; i < num_aliases; i++) {
|
for (int i = 0; i < num_aliases; i++) {
|
||||||
if (a.alias == aliases[i]) got = true;
|
if (alias == aliases[i]) got = true;
|
||||||
}
|
}
|
||||||
if (!got) {
|
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)
|
void PortManager::AliasAdd(std::string source, std::string target)
|
||||||
{
|
{
|
||||||
Alias a;
|
Alias a;
|
||||||
a.name = source;
|
a.match = source;
|
||||||
a.alias = target;
|
a.replace = target;
|
||||||
m_aliases.push_back(a);
|
m_aliases.push_back(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,11 @@
|
||||||
|
|
||||||
struct Alias
|
struct Alias
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string match;
|
||||||
std::string alias;
|
std::string replace;
|
||||||
|
|
||||||
|
bool Match(std::string name);
|
||||||
|
std::string Replace(std::string name);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::list<Alias> AliasList;
|
typedef std::list<Alias> AliasList;
|
||||||
|
|
Loading…
Reference in New Issue