summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Canvas.cpp89
-rw-r--r--src/Configuration.cpp59
-rw-r--r--src/Patchage.cpp136
3 files changed, 145 insertions, 139 deletions
diff --git a/src/Canvas.cpp b/src/Canvas.cpp
index 7b9203a..3624933 100644
--- a/src/Canvas.cpp
+++ b/src/Canvas.cpp
@@ -48,6 +48,52 @@ PATCHAGE_RESTORE_WARNINGS
#include <utility>
namespace patchage {
+namespace {
+
+struct RemovePortsData {
+ using Predicate = bool (*)(const CanvasPort*);
+
+ explicit RemovePortsData(Predicate p)
+ : pred(p)
+ {}
+
+ Predicate pred;
+ std::set<ClientID> empty_clients;
+};
+
+void
+delete_port_if_matches(GanvPort* port, void* cdata)
+{
+ auto* data = static_cast<RemovePortsData*>(cdata);
+ auto* pport = dynamic_cast<CanvasPort*>(Glib::wrap(port));
+ if (pport && data->pred(pport)) {
+ delete pport;
+ }
+}
+
+void
+remove_ports_matching(GanvNode* node, void* cdata)
+{
+ if (!GANV_IS_MODULE(node)) {
+ return;
+ }
+
+ Ganv::Module* cmodule = Glib::wrap(GANV_MODULE(node));
+ auto* pmodule = dynamic_cast<CanvasModule*>(cmodule);
+ if (!pmodule) {
+ return;
+ }
+
+ auto* data = static_cast<RemovePortsData*>(cdata);
+
+ pmodule->for_each_port(delete_port_if_matches, data);
+
+ if (pmodule->num_ports() == 0) {
+ data->empty_clients.insert(pmodule->id());
+ }
+}
+
+} // namespace
Canvas::Canvas(ILog& log, ActionSink& action_sink, int width, int height)
: Ganv::Canvas(width, height)
@@ -183,49 +229,6 @@ Canvas::remove_port(const PortID& id)
delete port;
}
-struct RemovePortsData {
- using Predicate = bool (*)(const CanvasPort*);
-
- explicit RemovePortsData(Predicate p)
- : pred(p)
- {}
-
- Predicate pred;
- std::set<ClientID> empty_clients;
-};
-
-static void
-delete_port_if_matches(GanvPort* port, void* cdata)
-{
- auto* data = static_cast<RemovePortsData*>(cdata);
- auto* pport = dynamic_cast<CanvasPort*>(Glib::wrap(port));
- if (pport && data->pred(pport)) {
- delete pport;
- }
-}
-
-static void
-remove_ports_matching(GanvNode* node, void* cdata)
-{
- if (!GANV_IS_MODULE(node)) {
- return;
- }
-
- Ganv::Module* cmodule = Glib::wrap(GANV_MODULE(node));
- auto* pmodule = dynamic_cast<CanvasModule*>(cmodule);
- if (!pmodule) {
- return;
- }
-
- auto* data = static_cast<RemovePortsData*>(cdata);
-
- pmodule->for_each_port(delete_port_if_matches, data);
-
- if (pmodule->num_ports() == 0) {
- data->empty_clients.insert(pmodule->id());
- }
-}
-
void
Canvas::remove_ports(bool (*pred)(const CanvasPort*))
{
diff --git a/src/Configuration.cpp b/src/Configuration.cpp
index a4d71e9..9bb2ac6 100644
--- a/src/Configuration.cpp
+++ b/src/Configuration.cpp
@@ -20,6 +20,37 @@
// IWYU pragma: no_include <algorithm>
namespace patchage {
+namespace {
+
+/// Return a vector of filenames in descending order by preference
+std::vector<std::string>
+get_filenames()
+{
+ std::vector<std::string> filenames;
+ const std::string prefix;
+
+ const char* xdg_config_home = getenv("XDG_CONFIG_HOME");
+ const char* home = getenv("HOME");
+
+ // XDG spec
+ if (xdg_config_home) {
+ filenames.push_back(std::string(xdg_config_home) + "/patchagerc");
+ } else if (home) {
+ filenames.push_back(std::string(home) + "/.config/patchagerc");
+ }
+
+ // Old location
+ if (home) {
+ filenames.push_back(std::string(home) + "/.patchagerc");
+ }
+
+ // Current directory (bundle or last-ditch effort)
+ filenames.emplace_back("patchagerc");
+
+ return filenames;
+}
+
+} // namespace
static const char* const port_type_names[Configuration::n_port_types] =
{"JACK_AUDIO", "JACK_MIDI", "ALSA_MIDI", "JACK_OSC", "JACK_CV"};
@@ -152,34 +183,6 @@ Configuration::set_module_split(const std::string& name, bool split)
}
}
-/** Return a vector of filenames in descending order by preference. */
-static std::vector<std::string>
-get_filenames()
-{
- std::vector<std::string> filenames;
- const std::string prefix;
-
- const char* xdg_config_home = getenv("XDG_CONFIG_HOME");
- const char* home = getenv("HOME");
-
- // XDG spec
- if (xdg_config_home) {
- filenames.push_back(std::string(xdg_config_home) + "/patchagerc");
- } else if (home) {
- filenames.push_back(std::string(home) + "/.config/patchagerc");
- }
-
- // Old location
- if (home) {
- filenames.push_back(std::string(home) + "/.patchagerc");
- }
-
- // Current directory (bundle or last-ditch effort)
- filenames.emplace_back("patchagerc");
-
- return filenames;
-}
-
void
Configuration::load()
{
diff --git a/src/Patchage.cpp b/src/Patchage.cpp
index a51c1ca..785cd2d 100644
--- a/src/Patchage.cpp
+++ b/src/Patchage.cpp
@@ -165,6 +165,74 @@ on_setting_toggled(Reactor* const reactor, const Gtk::CheckMenuItem* const item)
(*reactor)(action::ChangeSetting{{S{item->get_active()}}});
}
+void
+update_labels(GanvNode* node, void* data)
+{
+ const bool human_names = *static_cast<const bool*>(data);
+ if (GANV_IS_MODULE(node)) {
+ Ganv::Module* gmod = Glib::wrap(GANV_MODULE(node));
+ auto* pmod = dynamic_cast<CanvasModule*>(gmod);
+ if (pmod) {
+ for (Ganv::Port* gport : *gmod) {
+ auto* pport = dynamic_cast<CanvasPort*>(gport);
+ if (pport) {
+ pport->show_human_name(human_names);
+ }
+ }
+ }
+ }
+}
+
+inline guint
+highlight_color(guint c, guint delta)
+{
+ const guint max_char = 255;
+ const guint r = MIN((c >> 24) + delta, max_char);
+ const guint g = MIN(((c >> 16) & 0xFF) + delta, max_char);
+ const guint b = MIN(((c >> 8) & 0xFF) + delta, max_char);
+ const guint a = c & 0xFF;
+
+ return ((r << 24u) | (g << 16u) | (b << 8u) | a);
+}
+
+void
+update_port_colors(GanvNode* node, void* data)
+{
+ auto* patchage = static_cast<Patchage*>(data);
+ if (!GANV_IS_MODULE(node)) {
+ return;
+ }
+
+ Ganv::Module* gmod = Glib::wrap(GANV_MODULE(node));
+ auto* pmod = dynamic_cast<CanvasModule*>(gmod);
+ if (!pmod) {
+ return;
+ }
+
+ for (Ganv::Port* p : *pmod) {
+ auto* port = dynamic_cast<CanvasPort*>(p);
+ if (port) {
+ const uint32_t rgba = patchage->conf().get_port_color(port->type());
+ port->set_fill_color(rgba);
+ port->set_border_color(highlight_color(rgba, 0x20));
+ }
+ }
+}
+
+void
+update_edge_color(GanvEdge* edge, void* data)
+{
+ auto* patchage = static_cast<Patchage*>(data);
+ Ganv::Edge* edgemm = Glib::wrap(edge);
+
+ if (edgemm) {
+ auto* tail = dynamic_cast<CanvasPort*>((edgemm)->get_tail());
+ if (tail) {
+ edgemm->set_color(patchage->conf().get_port_color(tail->type()));
+ }
+ }
+}
+
} // namespace
#define INIT_WIDGET(x) x(_xml, (#x) + 1)
@@ -572,24 +640,6 @@ Patchage::operator()(const setting::FontSize& setting)
}
}
-static void
-update_labels(GanvNode* node, void* data)
-{
- const bool human_names = *static_cast<const bool*>(data);
- if (GANV_IS_MODULE(node)) {
- Ganv::Module* gmod = Glib::wrap(GANV_MODULE(node));
- auto* pmod = dynamic_cast<CanvasModule*>(gmod);
- if (pmod) {
- for (Ganv::Port* gport : *gmod) {
- auto* pport = dynamic_cast<CanvasPort*>(gport);
- if (pport) {
- pport->show_human_name(human_names);
- }
- }
- }
- }
-}
-
void
Patchage::operator()(const setting::HumanNames& setting)
{
@@ -624,56 +674,6 @@ Patchage::operator()(const setting::MessagesVisible& setting)
_menu_view_messages->set_active(setting.value);
}
-inline guint
-highlight_color(guint c, guint delta)
-{
- const guint max_char = 255;
- const guint r = MIN((c >> 24) + delta, max_char);
- const guint g = MIN(((c >> 16) & 0xFF) + delta, max_char);
- const guint b = MIN(((c >> 8) & 0xFF) + delta, max_char);
- const guint a = c & 0xFF;
-
- return ((r << 24u) | (g << 16u) | (b << 8u) | a);
-}
-
-static void
-update_port_colors(GanvNode* node, void* data)
-{
- auto* patchage = static_cast<Patchage*>(data);
- if (!GANV_IS_MODULE(node)) {
- return;
- }
-
- Ganv::Module* gmod = Glib::wrap(GANV_MODULE(node));
- auto* pmod = dynamic_cast<CanvasModule*>(gmod);
- if (!pmod) {
- return;
- }
-
- for (Ganv::Port* p : *pmod) {
- auto* port = dynamic_cast<CanvasPort*>(p);
- if (port) {
- const uint32_t rgba = patchage->conf().get_port_color(port->type());
- port->set_fill_color(rgba);
- port->set_border_color(highlight_color(rgba, 0x20));
- }
- }
-}
-
-static void
-update_edge_color(GanvEdge* edge, void* data)
-{
- auto* patchage = static_cast<Patchage*>(data);
- Ganv::Edge* edgemm = Glib::wrap(edge);
-
- if (edgemm) {
- auto* tail = dynamic_cast<CanvasPort*>((edgemm)->get_tail());
- if (tail) {
- edgemm->set_color(patchage->conf().get_port_color(tail->type()));
- }
- }
-}
-
void
Patchage::operator()(const setting::PortColor&)
{