diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/AlsaDriver.cpp | 39 | ||||
-rw-r--r-- | src/JackDriver.cpp | 36 | ||||
-rw-r--r-- | src/Patchage.cpp | 18 | ||||
-rw-r--r-- | src/PatchageCanvas.cpp | 27 | ||||
-rw-r--r-- | src/PatchageEvent.cpp | 14 | ||||
-rw-r--r-- | src/PatchageModule.cpp | 8 | ||||
-rw-r--r-- | src/PortID.hpp | 3 |
7 files changed, 93 insertions, 52 deletions
diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index 4ce4ae4..64b13c4 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -59,8 +59,9 @@ AlsaDriver::attach(bool /*launch_daemon*/) ret = pthread_create( &_refresh_thread, &attr, &AlsaDriver::refresh_main, this); - if (ret) + if (ret) { _app->error_msg("Alsa: Failed to start refresh thread."); + } signal_attached.emit(); } @@ -100,8 +101,9 @@ AlsaDriver::destroy_all() void AlsaDriver::refresh() { - if (!is_attached()) + if (!is_attached()) { return; + } assert(_seq); @@ -187,8 +189,9 @@ PatchageModule* AlsaDriver::find_module(uint8_t client_id, ModuleType type) { const Modules::const_iterator i = _modules.find(client_id); - if (i == _modules.end()) + if (i == _modules.end()) { return nullptr; + } PatchageModule* io_module = nullptr; for (Modules::const_iterator j = i; @@ -227,8 +230,9 @@ AlsaDriver::create_port_view_internal(Patchage* patchage, PatchageModule*& m, PatchagePort*& port) { - if (ignore(addr)) + if (ignore(addr)) { return; + } snd_seq_client_info_t* cinfo; snd_seq_client_info_alloca(&cinfo); @@ -251,12 +255,13 @@ AlsaDriver::create_port_view_internal(Patchage* patchage, int type = snd_seq_port_info_get_type(pinfo); // Figure out direction - if ((caps & SND_SEQ_PORT_CAP_READ) && (caps & SND_SEQ_PORT_CAP_WRITE)) + if ((caps & SND_SEQ_PORT_CAP_READ) && (caps & SND_SEQ_PORT_CAP_WRITE)) { is_duplex = true; - else if (caps & SND_SEQ_PORT_CAP_READ) + } else if (caps & SND_SEQ_PORT_CAP_READ) { is_input = false; - else if (caps & SND_SEQ_PORT_CAP_WRITE) + } else if (caps & SND_SEQ_PORT_CAP_WRITE) { is_input = true; + } is_application = (type & SND_SEQ_PORT_TYPE_APPLICATION); @@ -323,11 +328,13 @@ AlsaDriver::create_port(PatchageModule& parent, bool AlsaDriver::ignore(const snd_seq_addr_t& addr, bool add) { - if (_ignored.find(addr) != _ignored.end()) + if (_ignored.find(addr) != _ignored.end()) { return true; + } - if (!add) + if (!add) { return false; + } snd_seq_client_info_t* cinfo; snd_seq_client_info_alloca(&cinfo); @@ -409,12 +416,13 @@ AlsaDriver::connect(PatchagePort* src_port, PatchagePort* dst_port) result = false; } - if (result) + if (result) { _app->info_msg(std::string("Alsa: Connected ") + src_port->full_name() + " => " + dst_port->full_name()); - else + } else { _app->error_msg(std::string("Alsa: Unable to connect ") + src_port->full_name() + " => " + dst_port->full_name()); + } return (!result); } @@ -536,17 +544,19 @@ AlsaDriver::_refresh_main() switch (ev->type) { case SND_SEQ_EVENT_PORT_SUBSCRIBED: if (!ignore(ev->data.connect.sender) && - !ignore(ev->data.connect.dest)) + !ignore(ev->data.connect.dest)) { _events.push(PatchageEvent(PatchageEvent::CONNECTION, ev->data.connect.sender, ev->data.connect.dest)); + } break; case SND_SEQ_EVENT_PORT_UNSUBSCRIBED: if (!ignore(ev->data.connect.sender) && - !ignore(ev->data.connect.dest)) + !ignore(ev->data.connect.dest)) { _events.push(PatchageEvent(PatchageEvent::DISCONNECTION, ev->data.connect.sender, ev->data.connect.dest)); + } break; case SND_SEQ_EVENT_PORT_START: snd_seq_get_any_client_info(_seq, ev->data.addr.client, cinfo); @@ -554,10 +564,11 @@ AlsaDriver::_refresh_main() _seq, ev->data.addr.client, ev->data.addr.port, pinfo); caps = snd_seq_port_info_get_capability(pinfo); - if (!ignore(ev->data.addr)) + if (!ignore(ev->data.addr)) { _events.push(PatchageEvent( PatchageEvent::PORT_CREATION, PortID(ev->data.addr, (caps & SND_SEQ_PORT_CAP_READ)))); + } break; case SND_SEQ_EVENT_PORT_EXIT: if (!ignore(ev->data.addr, false)) { diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index 6cb4e1f..7f3402c 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -62,8 +62,9 @@ void JackDriver::attach(bool launch_daemon) { // Already connected - if (_client) + if (_client) { return; + } jack_options_t options = (!launch_daemon) ? JackNoStartServer : JackNullOption; @@ -319,8 +320,9 @@ JackDriver::refresh() _app->canvas()->add_module(client1_name, m); } - if (!m->get_port(jack_port_short_name(port))) + if (!m->get_port(jack_port_short_name(port))) { create_port(*m, port, PortID()); + } } // Add all connections @@ -357,8 +359,9 @@ JackDriver::refresh() Ganv::Port* port1 = client1_module->get_port(port1_name); Ganv::Port* port2 = client2_module->get_port(port2_name); - if (!port1 || !port2) + if (!port1 || !port2) { continue; + } Ganv::Port* src = nullptr; Ganv::Port* dst = nullptr; @@ -371,8 +374,9 @@ JackDriver::refresh() dst = port1; } - if (src && dst && !_app->canvas()->get_edge(src, dst)) + if (src && dst && !_app->canvas()->get_edge(src, dst)) { _app->canvas()->make_connection(src, dst); + } } jack_free(connected_ports); @@ -389,8 +393,9 @@ JackDriver::port_names(const PortID& id, { jack_port_t* jack_port = nullptr; - if (id.type == PortID::JACK_ID) + if (id.type == PortID::JACK_ID) { jack_port = jack_port_by_id(_client, id.id.jack_id); + } if (!jack_port) { module_name.clear(); @@ -413,18 +418,20 @@ JackDriver::port_names(const PortID& id, bool JackDriver::connect(PatchagePort* src_port, PatchagePort* dst_port) { - if (_client == nullptr) + if (_client == nullptr) { return false; + } int result = jack_connect( _client, src_port->full_name().c_str(), dst_port->full_name().c_str()); - if (result == 0) + if (result == 0) { _app->info_msg(std::string("Jack: Connected ") + src_port->full_name() + " => " + dst_port->full_name()); - else + } else { _app->error_msg(std::string("Jack: Unable to connect ") + src_port->full_name() + " => " + dst_port->full_name()); + } return (!result); } @@ -437,18 +444,20 @@ bool JackDriver::disconnect(PatchagePort* const src_port, PatchagePort* const dst_port) { - if (_client == nullptr) + if (_client == nullptr) { return false; + } int result = jack_disconnect( _client, src_port->full_name().c_str(), dst_port->full_name().c_str()); - if (result == 0) + if (result == 0) { _app->info_msg(std::string("Jack: Disconnected ") + src_port->full_name() + " => " + dst_port->full_name()); - else + } else { _app->error_msg(std::string("Jack: Unable to disconnect ") + src_port->full_name() + " => " + dst_port->full_name()); + } return (!result); } @@ -530,10 +539,11 @@ JackDriver::jack_shutdown_cb(void* jack_driver) jack_nframes_t JackDriver::buffer_size() { - if (_is_activated) + if (_is_activated) { return _buffer_size; - else + } else { return jack_get_buffer_size(_client); + } } void diff --git a/src/Patchage.cpp b/src/Patchage.cpp index 516f490..8f9f78d 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -410,13 +410,15 @@ Patchage::attach() _enable_refresh = false; #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) - if (_jack_driver_autoattach) + if (_jack_driver_autoattach) { _jack_driver->attach(true); + } #endif #ifdef HAVE_ALSA - if (_alsa_driver_autoattach) + if (_alsa_driver_autoattach) { _alsa_driver->attach(); + } #endif _enable_refresh = true; @@ -454,12 +456,14 @@ Patchage::idle_callback() refresh(); } else if (_driver_detached) { #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) - if (_jack_driver && !_jack_driver->is_attached()) + if (_jack_driver && !_jack_driver->is_attached()) { _jack_driver->destroy_all(); + } #endif #ifdef HAVE_ALSA - if (_alsa_driver && !_alsa_driver->is_attached()) + if (_alsa_driver && !_alsa_driver->is_attached()) { _alsa_driver->destroy_all(); + } #endif } @@ -538,13 +542,15 @@ Patchage::refresh() _canvas->clear(); #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) - if (_jack_driver) + if (_jack_driver) { _jack_driver->refresh(); + } #endif #ifdef HAVE_ALSA - if (_alsa_driver) + if (_alsa_driver) { _alsa_driver->refresh(); + } #endif } } diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp index 67668b3..1edd42e 100644 --- a/src/PatchageCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -50,8 +50,9 @@ PatchageModule* PatchageCanvas::find_module(const std::string& name, ModuleType type) { const ModuleIndex::const_iterator i = _module_index.find(name); - if (i == _module_index.end()) + if (i == _module_index.end()) { return nullptr; + } PatchageModule* io_module = nullptr; for (ModuleIndex::const_iterator j = i; @@ -96,8 +97,9 @@ PatchageCanvas::find_port(const PortID& id) if (id.type == PortID::JACK_ID) { jack_port_t* jack_port = jack_port_by_id(_app->jack_driver()->client(), id.id.jack_id); - if (!jack_port) + if (!jack_port) { return nullptr; + } std::string module_name; std::string port_name; @@ -107,11 +109,13 @@ PatchageCanvas::find_port(const PortID& id) module_name, (jack_port_flags(jack_port) & JackPortIsInput) ? Input : Output); - if (module) + if (module) { pp = module->get_port(port_name); + } - if (pp) + if (pp) { index_port(id, pp); + } } #endif // PATCHAGE_LIBJACK @@ -196,15 +200,17 @@ PatchageCanvas::find_port_by_name(const std::string& client_name, const std::string& port_name) { const ModuleIndex::const_iterator i = _module_index.find(client_name); - if (i == _module_index.end()) + if (i == _module_index.end()) { return nullptr; + } for (ModuleIndex::const_iterator j = i; j != _module_index.end() && j->first == client_name; ++j) { PatchagePort* port = j->second->get_port(port_name); - if (port) + if (port) { return port; + } } return nullptr; @@ -215,8 +221,9 @@ PatchageCanvas::connect(Ganv::Node* port1, Ganv::Node* port2) { auto* p1 = dynamic_cast<PatchagePort*>(port1); auto* p2 = dynamic_cast<PatchagePort*>(port2); - if (!p1 || !p2) + if (!p1 || !p2) { return; + } if ((p1->type() == JACK_AUDIO && p2->type() == JACK_AUDIO) || (p1->type() == JACK_MIDI && p2->type() == JACK_MIDI) || @@ -240,8 +247,9 @@ PatchageCanvas::disconnect(Ganv::Node* port1, Ganv::Node* port2) { auto* input = dynamic_cast<PatchagePort*>(port1); auto* output = dynamic_cast<PatchagePort*>(port2); - if (!input || !output) + if (!input || !output) { return; + } if (input->is_output() && output->is_input()) { // Damn, guessed wrong @@ -285,8 +293,9 @@ PatchageCanvas::add_module(const std::string& name, PatchageModule* module) out_module = module; } - if (in_module && out_module) + if (in_module && out_module) { out_module->set_partner(in_module); + } } static void diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp index a1b3f0a..3c6806f 100644 --- a/src/PatchageEvent.cpp +++ b/src/PatchageEvent.cpp @@ -86,31 +86,33 @@ PatchageEvent::execute(Patchage* patchage) PatchagePort* port_1 = patchage->canvas()->find_port(_port_1); PatchagePort* port_2 = patchage->canvas()->find_port(_port_2); - if (!port_1) + if (!port_1) { patchage->error_msg( (format("Unable to find port `%1%' to connect") % _port_1) .str()); - else if (!port_2) + } else if (!port_2) { patchage->error_msg( (format("Unable to find port `%1%' to connect") % _port_2) .str()); - else + } else { patchage->canvas()->make_connection(port_1, port_2); + } } else if (_type == DISCONNECTION) { PatchagePort* port_1 = patchage->canvas()->find_port(_port_1); PatchagePort* port_2 = patchage->canvas()->find_port(_port_2); - if (!port_1) + if (!port_1) { patchage->error_msg( (format("Unable to find port `%1%' to disconnect") % _port_1) .str()); - else if (!port_2) + } else if (!port_2) { patchage->error_msg( (format("Unable to find port `%1%' to disconnect") % _port_2) .str()); - else + } else { patchage->canvas()->remove_edge_between(port_1, port_2); + } } } diff --git a/src/PatchageModule.cpp b/src/PatchageModule.cpp index 3a802f6..8c68625 100644 --- a/src/PatchageModule.cpp +++ b/src/PatchageModule.cpp @@ -50,8 +50,9 @@ PatchageModule::~PatchageModule() void PatchageModule::update_menu() { - if (!_menu) + if (!_menu) { return; + } if (_type == InputOutput) { bool has_in = false; @@ -106,10 +107,11 @@ PatchageModule::load_location() { Coord loc; - if (_app->conf()->get_module_location(_name, _type, loc)) + if (_app->conf()->get_module_location(_name, _type, loc)) { move_to(loc.x, loc.y); - else + } else { move_to(20 + rand() % 640, 20 + rand() % 480); + } } void diff --git a/src/PortID.hpp b/src/PortID.hpp index 01a8ec4..ee1cde5 100644 --- a/src/PortID.hpp +++ b/src/PortID.hpp @@ -109,8 +109,9 @@ operator<<(std::ostream& os, const PortID& id) static inline bool operator<(const PortID& a, const PortID& b) { - if (a.type != b.type) + if (a.type != b.type) { return a.type < b.type; + } switch (a.type) { case PortID::NULL_PORT_ID: |