2006-06-09 05:18:57 +03:00
|
|
|
/* This file is part of Patchage. Copyright (C) 2004 Dave Robillard.
|
|
|
|
*
|
|
|
|
* 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 Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* Patchage is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2006-11-11 03:28:33 +02:00
|
|
|
#include "config.h"
|
2006-06-09 05:18:57 +03:00
|
|
|
#include "PatchageFlowCanvas.h"
|
|
|
|
#include "Patchage.h"
|
|
|
|
#include "JackDriver.h"
|
|
|
|
#include "PatchageModule.h"
|
|
|
|
#include "PatchagePort.h"
|
2006-11-11 03:28:33 +02:00
|
|
|
#ifdef HAVE_ALSA
|
|
|
|
#include "AlsaDriver.h"
|
|
|
|
#endif
|
2006-06-09 05:18:57 +03:00
|
|
|
|
|
|
|
PatchageFlowCanvas::PatchageFlowCanvas(Patchage* app, int width, int height)
|
|
|
|
: FlowCanvas(width, height),
|
2007-02-07 05:22:42 +02:00
|
|
|
_app(app)
|
2006-06-09 05:18:57 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-02 23:56:28 +03:00
|
|
|
boost::shared_ptr<PatchageModule>
|
2006-06-09 05:18:57 +03:00
|
|
|
PatchageFlowCanvas::find_module(const string& name, ModuleType type)
|
|
|
|
{
|
2007-02-07 05:22:42 +02:00
|
|
|
for (ModuleMap::iterator m = _modules.begin(); m != _modules.end(); ++m) {
|
2006-10-02 23:56:28 +03:00
|
|
|
boost::shared_ptr<PatchageModule> pm = boost::dynamic_pointer_cast<PatchageModule>((*m).second);
|
|
|
|
if (pm && pm->name() == name && pm->type() == type) {
|
2006-06-09 05:18:57 +03:00
|
|
|
return pm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-02 23:56:28 +03:00
|
|
|
return boost::shared_ptr<PatchageModule>();
|
2006-06-09 05:18:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-11 03:00:47 +02:00
|
|
|
#ifdef HAVE_ALSA
|
2006-10-02 23:56:28 +03:00
|
|
|
boost::shared_ptr<PatchagePort>
|
|
|
|
PatchageFlowCanvas::find_port(const snd_seq_addr_t* alsa_addr)
|
2006-06-09 05:18:57 +03:00
|
|
|
{
|
2006-10-02 23:56:28 +03:00
|
|
|
boost::shared_ptr<PatchagePort> pp;
|
2007-02-07 05:22:42 +02:00
|
|
|
for (ModuleMap::iterator m = _modules.begin(); m != _modules.end(); ++m) {
|
2006-10-02 23:56:28 +03:00
|
|
|
for (PortVector::const_iterator p = (*m).second->ports().begin(); p != (*m).second->ports().end(); ++p) {
|
|
|
|
pp = boost::dynamic_pointer_cast<PatchagePort>(*p);
|
|
|
|
if (pp && pp->type() == ALSA_MIDI && pp->alsa_addr()
|
2006-06-09 05:18:57 +03:00
|
|
|
&& pp->alsa_addr()->client == alsa_addr->client
|
|
|
|
&& pp->alsa_addr()->port == alsa_addr->port)
|
|
|
|
return pp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-02 23:56:28 +03:00
|
|
|
return boost::shared_ptr<PatchagePort>();
|
2006-06-09 05:18:57 +03:00
|
|
|
}
|
2006-11-11 03:00:47 +02:00
|
|
|
#endif
|
2006-06-09 05:18:57 +03:00
|
|
|
|
|
|
|
void
|
2007-02-07 07:31:08 +02:00
|
|
|
PatchageFlowCanvas::connect(boost::shared_ptr<Connectable> port1, boost::shared_ptr<Connectable> port2)
|
2006-06-09 05:18:57 +03:00
|
|
|
{
|
2006-10-02 23:56:28 +03:00
|
|
|
boost::shared_ptr<PatchagePort> p1 = boost::dynamic_pointer_cast<PatchagePort>(port1);
|
|
|
|
boost::shared_ptr<PatchagePort> p2 = boost::dynamic_pointer_cast<PatchagePort>(port2);
|
|
|
|
if (!p1 || !p2)
|
|
|
|
return;
|
|
|
|
|
2006-06-09 05:18:57 +03:00
|
|
|
if (p1->type() == JACK_AUDIO && p2->type() == JACK_AUDIO
|
|
|
|
|| (p1->type() == JACK_MIDI && p2->type() == JACK_MIDI))
|
2007-02-07 05:22:42 +02:00
|
|
|
_app->jack_driver()->connect(p1, p2);
|
2006-11-11 03:00:47 +02:00
|
|
|
#ifdef HAVE_ALSA
|
2006-06-09 05:18:57 +03:00
|
|
|
else if (p1->type() == ALSA_MIDI && p2->type() == ALSA_MIDI)
|
2007-02-07 05:22:42 +02:00
|
|
|
_app->alsa_driver()->connect(p1, p2);
|
2006-11-11 03:00:47 +02:00
|
|
|
#endif
|
2006-06-09 05:18:57 +03:00
|
|
|
else
|
2006-10-02 23:56:28 +03:00
|
|
|
status_message("WARNING: Cannot make connection, incompatible port types.");
|
2006-06-09 05:18:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2007-02-07 07:31:08 +02:00
|
|
|
PatchageFlowCanvas::disconnect(boost::shared_ptr<Connectable> port1, boost::shared_ptr<Connectable> port2)
|
2006-06-09 05:18:57 +03:00
|
|
|
{
|
2007-02-07 07:31:08 +02:00
|
|
|
boost::shared_ptr<PatchagePort> input
|
|
|
|
= boost::dynamic_pointer_cast<PatchagePort>(port1);
|
|
|
|
boost::shared_ptr<PatchagePort> output
|
|
|
|
= boost::dynamic_pointer_cast<PatchagePort>(port2);
|
|
|
|
|
|
|
|
if (!input || !output)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (input->is_output() && output->is_input()) {
|
|
|
|
// Damn, guessed wrong
|
|
|
|
boost::shared_ptr<PatchagePort> swap = input;
|
|
|
|
input = output;
|
|
|
|
output = swap;
|
2006-10-02 23:56:28 +03:00
|
|
|
}
|
|
|
|
|
2007-02-07 07:31:08 +02:00
|
|
|
if (!input || !output || input->is_output() || output->is_input()) {
|
2006-10-02 23:56:28 +03:00
|
|
|
status_message("ERROR: Attempt to disconnect mismatched/unknown ports");
|
2006-06-09 05:18:57 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input->type() == JACK_AUDIO && output->type() == JACK_AUDIO
|
|
|
|
|| input->type() == JACK_MIDI && output->type() == JACK_MIDI)
|
2007-02-07 05:22:42 +02:00
|
|
|
_app->jack_driver()->disconnect(output, input);
|
2006-11-11 03:00:47 +02:00
|
|
|
#ifdef HAVE_ALSA
|
2006-06-09 05:18:57 +03:00
|
|
|
else if (input->type() == ALSA_MIDI && output->type() == ALSA_MIDI)
|
2007-02-07 05:22:42 +02:00
|
|
|
_app->alsa_driver()->disconnect(output, input);
|
2006-11-11 03:00:47 +02:00
|
|
|
#endif
|
2006-06-09 05:18:57 +03:00
|
|
|
else
|
2006-10-02 23:56:28 +03:00
|
|
|
status_message("ERROR: Attempt to disconnect ports with mismatched types");
|
2006-06-09 05:18:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchageFlowCanvas::status_message(const string& msg)
|
|
|
|
{
|
2007-02-07 05:22:42 +02:00
|
|
|
_app->status_message(string("[Canvas] ").append(msg));
|
2006-06-09 05:18:57 +03:00
|
|
|
}
|
|
|
|
|