1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
7 **************************************************************************
8 * This file contains implementation of the canvas class
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "PatchageCanvas.hpp"
29 #include "Patchage.hpp"
30 #include "PatchageModule.hpp"
31 #include "PatchagePort.hpp"
33 PatchageCanvas::PatchageCanvas(Patchage
* app
, int width
, int height
) : _app(app
)
35 canvas_create(width
, height
, &_canvas
);
39 boost::shared_ptr
<PatchageModule
>
40 PatchageCanvas::find_module(const string
& name
, ModuleType type
)
42 for (ItemList::iterator m
= _items
.begin(); m
!= _items
.end(); ++m
) {
43 boost::shared_ptr
<PatchageModule
> pm
= boost::dynamic_pointer_cast
<PatchageModule
>(*m
);
44 if (pm
&& pm
->identify(name
, type
)) {
49 return boost::shared_ptr
<PatchageModule
>();
54 PatchageCanvas::connect(boost::shared_ptr
<Connectable
> port1
, boost::shared_ptr
<Connectable
> port2
)
56 _app
->connect(boost::dynamic_pointer_cast
<PatchagePort
>(port1
), boost::dynamic_pointer_cast
<PatchagePort
>(port2
));
61 PatchageCanvas::disconnect(boost::shared_ptr
<Connectable
> port1
, boost::shared_ptr
<Connectable
> port2
)
63 _app
->disconnect(boost::dynamic_pointer_cast
<PatchagePort
>(port1
), boost::dynamic_pointer_cast
<PatchagePort
>(port2
));
68 PatchageCanvas::status_message(const string
& msg
)
70 _app
->status_msg(string("[Canvas] ").append(msg
));
74 boost::shared_ptr
<PatchagePort
>
75 PatchageCanvas::get_port(const string
& node_name
, const string
& port_name
)
77 for (ItemList::iterator i
= _items
.begin(); i
!= _items
.end(); ++i
) {
78 const boost::shared_ptr
<Item
> item
= *i
;
79 const boost::shared_ptr
<Module
> module
80 = boost::dynamic_pointer_cast
<Module
>(item
);
83 const boost::shared_ptr
<Port
> port
= module
->get_port(port_name
);
84 if (module
->name() == node_name
&& port
)
85 return dynamic_pointer_cast
<PatchagePort
>(port
);
88 return boost::shared_ptr
<PatchagePort
>();
91 boost::shared_ptr
<PatchagePort
>
92 PatchageCanvas::lookup_port_by_a2j_jack_port_name(
93 const char * a2j_jack_port_name
)
95 for (ItemList::iterator i
= _items
.begin(); i
!= _items
.end(); ++i
)
97 const boost::shared_ptr
<Item
> item
= *i
;
98 const boost::shared_ptr
<Module
> module
= boost::dynamic_pointer_cast
<Module
>(item
);
102 PortVector ports
= module
->ports(); // copy
103 for (PortVector::iterator p
= ports
.begin(); p
!= ports
.end(); ++p
)
105 boost::shared_ptr
<PatchagePort
> port
= boost::dynamic_pointer_cast
<PatchagePort
>(*p
);
106 if (port
->is_a2j_mapped
&& port
->a2j_jack_port_name
== a2j_jack_port_name
)
108 return dynamic_pointer_cast
<PatchagePort
>(port
);
113 return boost::shared_ptr
<PatchagePort
>();