diff options
author | David Robillard <d@drobilla.net> | 2020-11-27 17:57:42 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-11-27 21:42:51 +0100 |
commit | f9ff5a5586166ee2f44b43f347726f98c9a966af (patch) | |
tree | a6f13e24579d2f56e41744d15a27fe1250d532f4 | |
parent | 47e93d947c4b5a468802c168be087b8145a67c62 (diff) | |
download | patchage-f9ff5a5586166ee2f44b43f347726f98c9a966af.tar.gz patchage-f9ff5a5586166ee2f44b43f347726f98c9a966af.tar.bz2 patchage-f9ff5a5586166ee2f44b43f347726f98c9a966af.zip |
Use enum classes
-rw-r--r-- | src/AlsaDriver.cpp | 43 | ||||
-rw-r--r-- | src/Configuration.cpp | 74 | ||||
-rw-r--r-- | src/Configuration.hpp | 14 | ||||
-rw-r--r-- | src/JackDbusDriver.cpp | 13 | ||||
-rw-r--r-- | src/JackDriver.cpp | 60 | ||||
-rw-r--r-- | src/Legend.hpp | 32 | ||||
-rw-r--r-- | src/Patchage.cpp | 4 | ||||
-rw-r--r-- | src/Patchage.hpp | 9 | ||||
-rw-r--r-- | src/PatchageCanvas.cpp | 45 | ||||
-rw-r--r-- | src/PatchageEvent.cpp | 18 | ||||
-rw-r--r-- | src/PatchageEvent.hpp | 16 | ||||
-rw-r--r-- | src/PatchageModule.cpp | 8 | ||||
-rw-r--r-- | src/PortID.hpp | 37 |
13 files changed, 222 insertions, 151 deletions
diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index f7143b2..b3eed6a 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -83,7 +83,7 @@ AlsaDriver::detach() static bool is_alsa_port(const PatchagePort* port) { - return port->type() == ALSA_MIDI; + return port->type() == PortType::ALSA_MIDI; } /** Destroy all JACK (canvas) ports. @@ -199,7 +199,7 @@ AlsaDriver::find_module(uint8_t client_id, ModuleType type) ++j) { if (j->second->type() == type) { return j->second; - } else if (j->second->type() == InputOutput) { + } else if (j->second->type() == ModuleType::InputOutput) { io_module = j->second; } } @@ -278,14 +278,15 @@ AlsaDriver::create_port_view_internal(Patchage* patchage, } if (!split) { - m = find_or_create_module(_app, addr.client, client_name, InputOutput); + m = find_or_create_module( + _app, addr.client, client_name, ModuleType::InputOutput); if (!m->get_port(port_name)) { port = create_port(*m, port_name, is_input, addr); port->show(); } } else { // split - ModuleType type = ((is_input) ? Input : Output); + ModuleType type = ((is_input) ? ModuleType::Input : ModuleType::Output); m = find_or_create_module(_app, addr.client, client_name, type); if (!m->get_port(port_name)) { port = create_port(*m, port_name, is_input, addr); @@ -293,7 +294,7 @@ AlsaDriver::create_port_view_internal(Patchage* patchage, } if (is_duplex) { - type = ((!is_input) ? Input : Output); + type = ((!is_input) ? ModuleType::Input : ModuleType::Output); m = find_or_create_module(_app, addr.client, client_name, type); if (!m->get_port(port_name)) { port = create_port(*m, port_name, !is_input, addr); @@ -309,13 +310,14 @@ AlsaDriver::create_port(PatchageModule& parent, bool is_input, snd_seq_addr_t addr) { - auto* ret = new PatchagePort(parent, - ALSA_MIDI, - name, - "", - is_input, - _app->conf()->get_port_color(ALSA_MIDI), - _app->show_human_names()); + auto* ret = + new PatchagePort(parent, + PortType::ALSA_MIDI, + name, + "", + is_input, + _app->conf()->get_port_color(PortType::ALSA_MIDI), + _app->show_human_names()); dynamic_cast<PatchageCanvas*>(parent.canvas()) ->index_port(PortID(addr, is_input), ret); @@ -545,7 +547,7 @@ AlsaDriver::_refresh_main() case SND_SEQ_EVENT_PORT_SUBSCRIBED: if (!ignore(ev->data.connect.sender) && !ignore(ev->data.connect.dest)) { - _events.push(PatchageEvent(PatchageEvent::CONNECTION, + _events.push(PatchageEvent(PatchageEvent::Type::CONNECTION, ev->data.connect.sender, ev->data.connect.dest)); } @@ -553,7 +555,7 @@ AlsaDriver::_refresh_main() case SND_SEQ_EVENT_PORT_UNSUBSCRIBED: if (!ignore(ev->data.connect.sender) && !ignore(ev->data.connect.dest)) { - _events.push(PatchageEvent(PatchageEvent::DISCONNECTION, + _events.push(PatchageEvent(PatchageEvent::Type::DISCONNECTION, ev->data.connect.sender, ev->data.connect.dest)); } @@ -566,7 +568,7 @@ AlsaDriver::_refresh_main() if (!ignore(ev->data.addr)) { _events.push(PatchageEvent( - PatchageEvent::PORT_CREATION, + PatchageEvent::Type::PORT_CREATION, PortID(ev->data.addr, (caps & SND_SEQ_PORT_CAP_READ)))); } break; @@ -574,10 +576,13 @@ AlsaDriver::_refresh_main() if (!ignore(ev->data.addr, false)) { // Note: getting caps at this point does not work // Delete both inputs and outputs (to handle duplex ports) - _events.push(PatchageEvent(PatchageEvent::PORT_DESTRUCTION, - PortID(ev->data.addr, true))); - _events.push(PatchageEvent(PatchageEvent::PORT_DESTRUCTION, - PortID(ev->data.addr, false))); + _events.push( + PatchageEvent(PatchageEvent::Type::PORT_DESTRUCTION, + PortID(ev->data.addr, true))); + _events.push( + PatchageEvent(PatchageEvent::Type::PORT_DESTRUCTION, + PortID(ev->data.addr, false))); + _port_addrs.erase( _app->canvas()->find_port(PortID(ev->data.addr, false))); _port_addrs.erase( diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 039cda0..29e3f10 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -43,17 +43,45 @@ Configuration::Configuration() , _sort_ports(true) { #ifdef PATCHAGE_USE_LIGHT_THEME - _port_colors[JACK_AUDIO] = _default_port_colors[JACK_AUDIO] = 0xA4BC8CFF; - _port_colors[JACK_MIDI] = _default_port_colors[JACK_MIDI] = 0xC89595FF; - _port_colors[ALSA_MIDI] = _default_port_colors[ALSA_MIDI] = 0x8F7198FF; - _port_colors[JACK_OSC] = _default_port_colors[JACK_OSC] = 0x7E8EAAFF; - _port_colors[JACK_CV] = _default_port_colors[JACK_CV] = 0x83AFABFF; + _port_colors[static_cast<unsigned>(PortType::JACK_AUDIO)] = + _default_port_colors[static_cast<unsigned>(PortType::JACK_AUDIO)] = + 0xA4BC8CFF; + + _port_colors[static_cast<unsigned>(PortType::JACK_MIDI)] = + _default_port_colors[static_cast<unsigned>(PortType::JACK_MIDI)] = + 0xC89595FF; + + _port_colors[static_cast<unsigned>(PortType::ALSA_MIDI)] = + _default_port_colors[static_cast<unsigned>(PortType::ALSA_MIDI)] = + 0x8F7198FF; + + _port_colors[static_cast<unsigned>(PortType::JACK_OSC)] = + _default_port_colors[static_cast<unsigned>(PortType::JACK_OSC)] = + 0x7E8EAAFF; + + _port_colors[static_cast<unsigned>(PortType::JACK_CV)] = + _default_port_colors[static_cast<unsigned>(PortType::JACK_CV)] = + 0x83AFABFF; #else - _port_colors[JACK_AUDIO] = _default_port_colors[JACK_AUDIO] = 0x3E5E00FF; - _port_colors[JACK_MIDI] = _default_port_colors[JACK_MIDI] = 0x650300FF; - _port_colors[ALSA_MIDI] = _default_port_colors[ALSA_MIDI] = 0x2D0043FF; - _port_colors[JACK_OSC] = _default_port_colors[JACK_OSC] = 0x4100FEFF; - _port_colors[JACK_CV] = _default_port_colors[JACK_CV] = 0x005E4EFF; + _port_colors[static_cast<unsigned>(PortType::JACK_AUDIO)] = + _default_port_colors[static_cast<unsigned>(PortType::JACK_AUDIO)] = + 0x3E5E00FF; + + _port_colors[static_cast<unsigned>(PortType::JACK_MIDI)] = + _default_port_colors[static_cast<unsigned>(PortType::JACK_MIDI)] = + 0x650300FF; + + _port_colors[static_cast<unsigned>(PortType::ALSA_MIDI)] = + _default_port_colors[static_cast<unsigned>(PortType::ALSA_MIDI)] = + 0x2D0043FF; + + _port_colors[static_cast<unsigned>(PortType::JACK_OSC)] = + _default_port_colors[static_cast<unsigned>(PortType::JACK_OSC)] = + 0x4100FEFF; + + _port_colors[static_cast<unsigned>(PortType::JACK_CV)] = + _default_port_colors[static_cast<unsigned>(PortType::JACK_CV)] = + 0x005E4EFF; #endif } @@ -69,11 +97,11 @@ Configuration::get_module_location(const std::string& name, } const ModuleSettings& settings = (*i).second; - if (type == Input && settings.input_location) { + if (type == ModuleType::Input && settings.input_location) { loc = *settings.input_location; - } else if (type == Output && settings.output_location) { + } else if (type == ModuleType::Output && settings.output_location) { loc = *settings.output_location; - } else if (type == InputOutput && settings.inout_location) { + } else if (type == ModuleType::InputOutput && settings.inout_location) { loc = *settings.inout_location; } else { return false; @@ -90,24 +118,22 @@ Configuration::set_module_location(const std::string& name, auto i = _module_settings.find(name); if (i == _module_settings.end()) { i = _module_settings - .insert( - std::make_pair(name, ModuleSettings(type != InputOutput))) + .insert(std::make_pair( + name, ModuleSettings(type != ModuleType::InputOutput))) .first; } ModuleSettings& settings = (*i).second; switch (type) { - case Input: + case ModuleType::Input: settings.input_location = loc; break; - case Output: + case ModuleType::Output: settings.output_location = loc; break; - case InputOutput: + case ModuleType::InputOutput: settings.inout_location = loc; break; - default: - break; // shouldn't reach here } } @@ -236,15 +262,15 @@ Configuration::load() file.ignore(1, '\"'); std::getline(file, name, '\"'); - ModuleType type = Input; + ModuleType type = ModuleType::Input; std::string type_str; file >> type_str; if (type_str == "input") { - type = Input; + type = ModuleType::Input; } else if (type_str == "output") { - type = Output; + type = ModuleType::Output; } else if (type_str == "inputoutput") { - type = InputOutput; + type = ModuleType::InputOutput; } else { std::cerr << "error: bad position type `" << type_str << "' for module `" << name << "'" << std::endl; diff --git a/src/Configuration.hpp b/src/Configuration.hpp index 27cd331..3ea564b 100644 --- a/src/Configuration.hpp +++ b/src/Configuration.hpp @@ -23,14 +23,14 @@ #include <map> #include <string> -enum ModuleType +enum class ModuleType { Input, Output, InputOutput }; -enum PortType +enum class PortType { JACK_AUDIO, JACK_MIDI, @@ -100,10 +100,14 @@ public: int get_messages_height() const { return _messages_height; } void set_messages_height(int height) { _messages_height = height; } - uint32_t get_port_color(PortType type) const { return _port_colors[type]; } - void set_port_color(PortType type, uint32_t rgba) + uint32_t get_port_color(PortType type) const { - _port_colors[type] = rgba; + return _port_colors[static_cast<unsigned>(type)]; + } + + void set_port_color(PortType type, uint32_t rgba) + { + _port_colors[static_cast<unsigned>(type)] = rgba; } Coord get_window_location() { return _window_location; } diff --git a/src/JackDbusDriver.cpp b/src/JackDbusDriver.cpp index 9c478ef..278c837 100644 --- a/src/JackDbusDriver.cpp +++ b/src/JackDbusDriver.cpp @@ -76,7 +76,8 @@ JackDriver::~JackDriver() static bool is_jack_port(const PatchagePort* port) { - return port->type() == JACK_AUDIO || port->type() == JACK_MIDI; + return port->type() == PortType::JACK_AUDIO || + port->type() == PortType::JACK_MIDI; } /** Destroy all JACK (canvas) ports. @@ -609,23 +610,23 @@ JackDriver::add_port(dbus_uint64_t client_id, switch (port_type) { case JACKDBUS_PORT_TYPE_AUDIO: - local_port_type = JACK_AUDIO; + local_port_type = PortType::JACK_AUDIO; break; case JACKDBUS_PORT_TYPE_MIDI: - local_port_type = JACK_MIDI; + local_port_type = PortType::JACK_MIDI; break; default: error_msg("Unknown JACK D-Bus port type"); return; } - ModuleType type = InputOutput; + ModuleType type = ModuleType::InputOutput; if (_app->conf()->get_module_split( client_name, port_flags & JACKDBUS_PORT_FLAG_TERMINAL)) { if (port_flags & JACKDBUS_PORT_FLAG_INPUT) { - type = Input; + type = ModuleType::Input; } else { - type = Output; + type = ModuleType::Output; } } diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index 556ef73..b74dd9c 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -114,8 +114,10 @@ JackDriver::detach() static bool is_jack_port(const PatchagePort* port) { - return (port->type() == JACK_AUDIO || port->type() == JACK_MIDI || - port->type() == JACK_OSC || port->type() == JACK_CV); + return (port->type() == PortType::JACK_AUDIO || + port->type() == PortType::JACK_MIDI || + port->type() == PortType::JACK_OSC || + port->type() == PortType::JACK_CV); } /** Destroy all JACK (canvas) ports. @@ -131,7 +133,7 @@ JackDriver::destroy_all() PatchagePort* JackDriver::create_port_view(Patchage* patchage, const PortID& id) { - assert(id.type == PortID::JACK_ID); + assert(id.type == PortID::Type::JACK_ID); jack_port_t* jack_port = jack_port_by_id(_client, id.id.jack_id); if (!jack_port) { @@ -146,13 +148,13 @@ JackDriver::create_port_view(Patchage* patchage, const PortID& id) std::string module_name, port_name; port_names(id, module_name, port_name); - ModuleType type = InputOutput; + ModuleType type = ModuleType::InputOutput; if (_app->conf()->get_module_split(module_name, (jack_flags & JackPortIsTerminal))) { if (jack_flags & JackPortIsInput) { - type = Input; + type = ModuleType::Input; } else { - type = Output; + type = ModuleType::Output; } } @@ -219,19 +221,19 @@ JackDriver::create_port(PatchageModule& parent, jack_port_t* port, PortID id) #endif const char* const type_str = jack_port_type(port); - PortType port_type = JACK_AUDIO; + PortType port_type = PortType::JACK_AUDIO; if (!strcmp(type_str, JACK_DEFAULT_AUDIO_TYPE)) { - port_type = JACK_AUDIO; + port_type = PortType::JACK_AUDIO; #ifdef HAVE_JACK_METADATA if (get_property(uuid, JACKEY_SIGNAL_TYPE) == "CV") { - port_type = JACK_CV; + port_type = PortType::JACK_CV; } #endif } else if (!strcmp(type_str, JACK_DEFAULT_MIDI_TYPE)) { - port_type = JACK_MIDI; + port_type = PortType::JACK_MIDI; #ifdef HAVE_JACK_METADATA if (get_property(uuid, JACKEY_EVENT_TYPES) == "OSC") { - port_type = JACK_OSC; + port_type = PortType::JACK_OSC; } #endif } else { @@ -250,7 +252,7 @@ JackDriver::create_port(PatchageModule& parent, jack_port_t* port, PortID id) _app->show_human_names(), order); - if (id.type != PortID::NULL_PORT_ID) { + if (id.type != PortID::Type::NULL_PORT_ID) { dynamic_cast<PatchageCanvas*>(parent.canvas())->index_port(id, ret); } @@ -302,13 +304,13 @@ JackDriver::refresh() client1_name = ports[i]; client1_name = client1_name.substr(0, client1_name.find(":")); - ModuleType type = InputOutput; + ModuleType type = ModuleType::InputOutput; if (_app->conf()->get_module_split( client1_name, (jack_port_flags(port) & JackPortIsTerminal))) { if (jack_port_flags(port) & JackPortIsInput) { - type = Input; + type = ModuleType::Input; } else { - type = Output; + type = ModuleType::Output; } } @@ -336,8 +338,9 @@ JackDriver::refresh() port1_name = client1_name.substr(colon + 1); client1_name = client1_name.substr(0, colon); - const ModuleType port1_type = - (jack_port_flags(port) & JackPortIsInput) ? Input : Output; + const ModuleType port1_type = (jack_port_flags(port) & JackPortIsInput) + ? ModuleType::Input + : ModuleType::Output; PatchageModule* client1_module = _app->canvas()->find_module(client1_name, port1_type); @@ -350,8 +353,9 @@ JackDriver::refresh() port2_name = client2_name.substr(colon + 1); client2_name = client2_name.substr(0, colon); - const ModuleType port2_type = - (port1_type == Input) ? Output : Input; + const ModuleType port2_type = (port1_type == ModuleType::Input) + ? ModuleType::Output + : ModuleType::Input; PatchageModule* client2_module = _app->canvas()->find_module(client2_name, port2_type); @@ -393,7 +397,7 @@ JackDriver::port_names(const PortID& id, { jack_port_t* jack_port = nullptr; - if (id.type == PortID::JACK_ID) { + if (id.type == PortID::Type::JACK_ID) { jack_port = jack_port_by_id(_client, id.id.jack_id); } @@ -471,10 +475,11 @@ JackDriver::jack_client_registration_cb(const char* name, assert(me->_client); if (registered) { - me->_events.push(PatchageEvent(PatchageEvent::CLIENT_CREATION, name)); + me->_events.push( + PatchageEvent(PatchageEvent::Type::CLIENT_CREATION, name)); } else { me->_events.push( - PatchageEvent(PatchageEvent::CLIENT_DESTRUCTION, name)); + PatchageEvent(PatchageEvent::Type::CLIENT_DESTRUCTION, name)); } } @@ -487,10 +492,11 @@ JackDriver::jack_port_registration_cb(jack_port_id_t port_id, assert(me->_client); if (registered) { - me->_events.push(PatchageEvent(PatchageEvent::PORT_CREATION, port_id)); + me->_events.push( + PatchageEvent(PatchageEvent::Type::PORT_CREATION, port_id)); } else { me->_events.push( - PatchageEvent(PatchageEvent::PORT_DESTRUCTION, port_id)); + PatchageEvent(PatchageEvent::Type::PORT_DESTRUCTION, port_id)); } } @@ -504,9 +510,11 @@ JackDriver::jack_port_connect_cb(jack_port_id_t src, assert(me->_client); if (connect) { - me->_events.push(PatchageEvent(PatchageEvent::CONNECTION, src, dst)); + me->_events.push( + PatchageEvent(PatchageEvent::Type::CONNECTION, src, dst)); } else { - me->_events.push(PatchageEvent(PatchageEvent::DISCONNECTION, src, dst)); + me->_events.push( + PatchageEvent(PatchageEvent::Type::DISCONNECTION, src, dst)); } } diff --git a/src/Legend.hpp b/src/Legend.hpp index b9e6b23..6887238 100644 --- a/src/Legend.hpp +++ b/src/Legend.hpp @@ -28,19 +28,31 @@ class Legend : public Gtk::HBox public: Legend(const Configuration& configuration) { - add_button( - JACK_AUDIO, "Audio", configuration.get_port_color(JACK_AUDIO)); + add_button(PortType::JACK_AUDIO, + "Audio", + configuration.get_port_color(PortType::JACK_AUDIO)); + #ifdef HAVE_JACK_METADATA - add_button(JACK_CV, "CV", configuration.get_port_color(JACK_CV)); - add_button(JACK_OSC, "OSC", configuration.get_port_color(JACK_OSC)); + add_button(PortType::JACK_CV, + "CV", + configuration.get_port_color(PortType::JACK_CV)); + add_button(PortType::JACK_OSC, + "OSC", + configuration.get_port_color(PortType::JACK_OSC)); #endif - add_button(JACK_MIDI, "MIDI", configuration.get_port_color(JACK_MIDI)); - add_button( - ALSA_MIDI, "ALSA MIDI", configuration.get_port_color(ALSA_MIDI)); + + add_button(PortType::JACK_MIDI, + "MIDI", + configuration.get_port_color(PortType::JACK_MIDI)); + + add_button(PortType::ALSA_MIDI, + "ALSA MIDI", + configuration.get_port_color(PortType::ALSA_MIDI)); + show_all_children(); } - void add_button(int id, const std::string& label, uint32_t rgba) + void add_button(const PortType id, const std::string& label, uint32_t rgba) { Gdk::Color col; col.set_rgb(((rgba >> 24) & 0xFF) * 0x100, @@ -58,7 +70,7 @@ public: this->pack_start(*Gtk::manage(box), false, false, 6); } - void on_color_set(const int id, + void on_color_set(const PortType id, const std::string& label, const Gtk::ColorButton* but) { @@ -70,7 +82,7 @@ public: signal_color_changed.emit(id, label, rgba); } - sigc::signal<void, int, std::string, uint32_t> signal_color_changed; + sigc::signal<void, PortType, std::string, uint32_t> signal_color_changed; }; #endif // PATCHAGE_LEGEND_HPP diff --git a/src/Patchage.cpp b/src/Patchage.cpp index 1605325..022eace 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -955,11 +955,11 @@ update_edge_color(GanvEdge* edge, void* data) } void -Patchage::on_legend_color_change(int id, +Patchage::on_legend_color_change(PortType id, const std::string& label, uint32_t rgba) { - _conf->set_port_color((PortType)id, rgba); + _conf->set_port_color(id, rgba); _canvas->for_each_node(update_port_colors, this); _canvas->for_each_edge(update_edge_color, this); } diff --git a/src/Patchage.hpp b/src/Patchage.hpp index 84c1140..ba02710 100644 --- a/src/Patchage.hpp +++ b/src/Patchage.hpp @@ -1,5 +1,5 @@ /* This file is part of Patchage. - * Copyright 2007-2014 David Robillard <http://drobilla.net> + * Copyright 2007-2020 David Robillard <d@drobilla.net> * * Patchage is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free @@ -127,8 +127,11 @@ protected: void on_increase_font_size(); void on_decrease_font_size(); void on_normal_font_size(); - void - on_legend_color_change(int id, const std::string& label, uint32_t rgba); + + void on_legend_color_change(PortType id, + const std::string& label, + uint32_t rgba); + void on_messages_resized(Gtk::Allocation& alloc); bool on_scroll(GdkEventScroll* ev); diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp index 1edd42e..b701fb2 100644 --- a/src/PatchageCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -60,7 +60,7 @@ PatchageCanvas::find_module(const std::string& name, ModuleType type) ++j) { if (j->second->type() == type) { return j->second; - } else if (j->second->type() == InputOutput) { + } else if (j->second->type() == ModuleType::InputOutput) { io_module = j->second; } } @@ -94,7 +94,7 @@ PatchageCanvas::find_port(const PortID& id) #ifdef PATCHAGE_LIBJACK // Alsa ports are always indexed (or don't exist at all) - if (id.type == PortID::JACK_ID) { + if (id.type == PortID::Type::JACK_ID) { jack_port_t* jack_port = jack_port_by_id(_app->jack_driver()->client(), id.id.jack_id); if (!jack_port) { @@ -105,9 +105,11 @@ PatchageCanvas::find_port(const PortID& id) std::string port_name; _app->jack_driver()->port_names(id, module_name, port_name); - PatchageModule* module = find_module( - module_name, - (jack_port_flags(jack_port) & JackPortIsInput) ? Input : Output); + PatchageModule* module = + find_module(module_name, + (jack_port_flags(jack_port) & JackPortIsInput) + ? ModuleType::Input + : ModuleType::Output); if (module) { pp = module->get_port(port_name); @@ -225,16 +227,21 @@ PatchageCanvas::connect(Ganv::Node* port1, Ganv::Node* port2) return; } - if ((p1->type() == JACK_AUDIO && p2->type() == JACK_AUDIO) || - (p1->type() == JACK_MIDI && p2->type() == JACK_MIDI) || - (p1->type() == JACK_AUDIO && p2->type() == JACK_CV) || - (p1->type() == JACK_CV && p2->type() == JACK_CV) || - (p1->type() == JACK_OSC && p2->type() == JACK_OSC)) { + if ((p1->type() == PortType::JACK_AUDIO && + p2->type() == PortType::JACK_AUDIO) || + (p1->type() == PortType::JACK_MIDI && + p2->type() == PortType::JACK_MIDI) || + (p1->type() == PortType::JACK_AUDIO && + p2->type() == PortType::JACK_CV) || + (p1->type() == PortType::JACK_CV && p2->type() == PortType::JACK_CV) || + (p1->type() == PortType::JACK_OSC && + p2->type() == PortType::JACK_OSC)) { #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) _app->jack_driver()->connect(p1, p2); #endif #ifdef HAVE_ALSA - } else if (p1->type() == ALSA_MIDI && p2->type() == ALSA_MIDI) { + } else if (p1->type() == PortType::ALSA_MIDI && + p2->type() == PortType::ALSA_MIDI) { _app->alsa_driver()->connect(p1, p2); #endif } else { @@ -263,13 +270,15 @@ PatchageCanvas::disconnect(Ganv::Node* port1, Ganv::Node* port2) return; } - if (input->type() == JACK_AUDIO || input->type() == JACK_MIDI || - input->type() == JACK_CV || input->type() == JACK_OSC) { + if (input->type() == PortType::JACK_AUDIO || + input->type() == PortType::JACK_MIDI || + input->type() == PortType::JACK_CV || + input->type() == PortType::JACK_OSC) { #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) _app->jack_driver()->disconnect(output, input); #endif #ifdef HAVE_ALSA - } else if (input->type() == ALSA_MIDI) { + } else if (input->type() == PortType::ALSA_MIDI) { _app->alsa_driver()->disconnect(output, input); #endif } else { @@ -285,11 +294,11 @@ PatchageCanvas::add_module(const std::string& name, PatchageModule* module) // Join partners, if applicable PatchageModule* in_module = nullptr; PatchageModule* out_module = nullptr; - if (module->type() == Input) { + if (module->type() == ModuleType::Input) { in_module = module; - out_module = find_module(name, Output); - } else if (module->type() == Output) { - in_module = find_module(name, Output); + out_module = find_module(name, ModuleType::Output); + } else if (module->type() == ModuleType::Output) { + in_module = find_module(name, ModuleType::Output); out_module = module; } diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp index 3c6806f..d986d5a 100644 --- a/src/PatchageEvent.cpp +++ b/src/PatchageEvent.cpp @@ -39,28 +39,28 @@ using boost::format; void PatchageEvent::execute(Patchage* patchage) { - if (_type == REFRESH) { + if (_type == Type::REFRESH) { patchage->refresh(); - } else if (_type == CLIENT_CREATION) { + } else if (_type == Type::CLIENT_CREATION) { // No empty modules (for now) g_free(_str); _str = nullptr; - } else if (_type == CLIENT_DESTRUCTION) { + } else if (_type == Type::CLIENT_DESTRUCTION) { patchage->canvas()->remove_module(_str); g_free(_str); _str = nullptr; - } else if (_type == PORT_CREATION) { + } else if (_type == Type::PORT_CREATION) { Driver* driver = nullptr; - if (_port_1.type == PortID::JACK_ID) { + if (_port_1.type == PortID::Type::JACK_ID) { #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) driver = patchage->jack_driver(); #endif #ifdef HAVE_ALSA - } else if (_port_1.type == PortID::ALSA_ADDR) { + } else if (_port_1.type == PortID::Type::ALSA_ADDR) { driver = patchage->alsa_driver(); #endif } @@ -77,11 +77,11 @@ PatchageEvent::execute(Patchage* patchage) (format("Unknown type for port `%1%'") % _port_1).str()); } - } else if (_type == PORT_DESTRUCTION) { + } else if (_type == Type::PORT_DESTRUCTION) { patchage->canvas()->remove_port(_port_1); - } else if (_type == CONNECTION) { + } else if (_type == Type::CONNECTION) { PatchagePort* port_1 = patchage->canvas()->find_port(_port_1); PatchagePort* port_2 = patchage->canvas()->find_port(_port_2); @@ -98,7 +98,7 @@ PatchageEvent::execute(Patchage* patchage) patchage->canvas()->make_connection(port_1, port_2); } - } else if (_type == DISCONNECTION) { + } else if (_type == Type::DISCONNECTION) { PatchagePort* port_1 = patchage->canvas()->find_port(_port_1); PatchagePort* port_2 = patchage->canvas()->find_port(_port_2); diff --git a/src/PatchageEvent.hpp b/src/PatchageEvent.hpp index 3adae18..7376915 100644 --- a/src/PatchageEvent.hpp +++ b/src/PatchageEvent.hpp @@ -1,5 +1,5 @@ /* This file is part of Patchage. - * Copyright 2007-2014 David Robillard <http://drobilla.net> + * Copyright 2007-2020 David Robillard <d@drobilla.net> * * Patchage is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free @@ -38,7 +38,7 @@ class Patchage; class PatchageEvent { public: - enum Type + enum class Type : uint8_t { NULL_EVENT = 0, REFRESH, @@ -50,7 +50,7 @@ public: DISCONNECTION }; - explicit PatchageEvent(Type type = NULL_EVENT) + explicit PatchageEvent(Type type = Type::NULL_EVENT) : _str(nullptr) , _type(type) {} @@ -77,13 +77,13 @@ public: void execute(Patchage* patchage); - inline Type type() const { return (Type)_type; } + inline Type type() const { return _type; } private: - char* _str; - PortID _port_1; - PortID _port_2; - uint8_t _type; + char* _str; + PortID _port_1; + PortID _port_2; + Type _type; }; #endif // PATCHAGE_PATCHAGEEVENT_HPP diff --git a/src/PatchageModule.cpp b/src/PatchageModule.cpp index d955900..61728ec 100644 --- a/src/PatchageModule.cpp +++ b/src/PatchageModule.cpp @@ -54,7 +54,7 @@ PatchageModule::update_menu() return; } - if (_type == InputOutput) { + if (_type == ModuleType::InputOutput) { bool has_in = false; bool has_out = false; for (const_iterator p = begin(); p != end(); ++p) { @@ -77,7 +77,7 @@ PatchageModule::show_menu(GdkEventButton* ev) { _menu = new Gtk::Menu(); Gtk::Menu::MenuList& items = _menu->items(); - if (_type == InputOutput) { + if (_type == ModuleType::InputOutput) { items.push_back(Gtk::Menu_Helpers::MenuElem( "_Split", sigc::mem_fun(this, &PatchageModule::split))); update_menu(); @@ -124,7 +124,7 @@ PatchageModule::store_location(double x, double y) void PatchageModule::split() { - assert(_type == InputOutput); + assert(_type == ModuleType::InputOutput); _app->conf()->set_module_split(_name, true); _app->refresh(); } @@ -132,7 +132,7 @@ PatchageModule::split() void PatchageModule::join() { - assert(_type != InputOutput); + assert(_type != ModuleType::InputOutput); _app->conf()->set_module_split(_name, false); _app->refresh(); } diff --git a/src/PortID.hpp b/src/PortID.hpp index ee1cde5..3c253cb 100644 --- a/src/PortID.hpp +++ b/src/PortID.hpp @@ -1,5 +1,5 @@ /* This file is part of Patchage. - * Copyright 2008-2014 David Robillard <http://drobilla.net> + * Copyright 2008-2020 David Robillard <d@drobilla.net> * * Patchage is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free @@ -33,27 +33,28 @@ struct PortID { + enum class Type + { + NULL_PORT_ID, + JACK_ID, + ALSA_ADDR + }; + PortID() - : type(NULL_PORT_ID) + : type(Type::NULL_PORT_ID) { memset(&id, 0, sizeof(id)); } + PortID(const PortID& copy) : type(copy.type) { memcpy(&id, ©.id, sizeof(id)); } - enum - { - NULL_PORT_ID, - JACK_ID, - ALSA_ADDR - } type; - #ifdef PATCHAGE_LIBJACK PortID(jack_port_id_t jack_id, bool ign = false) - : type(JACK_ID) + : type(Type::JACK_ID) { id.jack_id = jack_id; } @@ -61,13 +62,15 @@ struct PortID #ifdef HAVE_ALSA PortID(snd_seq_addr_t addr, bool in) - : type(ALSA_ADDR) + : type(Type::ALSA_ADDR) { id.alsa_addr = addr; id.is_input = in; } #endif + Type type; + union { #ifdef PATCHAGE_LIBJACK @@ -87,14 +90,14 @@ static inline std::ostream& operator<<(std::ostream& os, const PortID& id) { switch (id.type) { - case PortID::NULL_PORT_ID: + case PortID::Type::NULL_PORT_ID: return os << "(null)"; - case PortID::JACK_ID: + case PortID::Type::JACK_ID: #ifdef PATCHAGE_LIBJACK return os << "jack:" << id.id.jack_id; #endif break; - case PortID::ALSA_ADDR: + case PortID::Type::ALSA_ADDR: #ifdef HAVE_ALSA return os << "alsa:" << (int)id.id.alsa_addr.client << ":" << (int)id.id.alsa_addr.port << ":" @@ -114,14 +117,14 @@ operator<(const PortID& a, const PortID& b) } switch (a.type) { - case PortID::NULL_PORT_ID: + case PortID::Type::NULL_PORT_ID: return true; - case PortID::JACK_ID: + case PortID::Type::JACK_ID: #ifdef PATCHAGE_LIBJACK return a.id.jack_id < b.id.jack_id; #endif break; - case PortID::ALSA_ADDR: + case PortID::Type::ALSA_ADDR: #ifdef HAVE_ALSA if ((a.id.alsa_addr.client < b.id.alsa_addr.client) || ((a.id.alsa_addr.client == b.id.alsa_addr.client) && |