2 Copyright (C) 1998-99 Paul Barton-Davis
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "pbd/error.h"
26 #include "midi++/types.h"
27 #include "midi++/manager.h"
28 #include "midi++/channel.h"
29 #include "midi++/port.h"
35 /* XXX check for strdup leaks */
37 Manager *Manager::theManager = 0;
43 inputChannelNumber = 0;
44 outputChannelNumber = 0;
50 for (PortList::iterator p = _ports.begin(); p != _ports.end(); ++p) {
54 if (theManager == this) {
60 Manager::add_port (const XMLNode& node)
62 Port::Descriptor desc (node);
66 for (p = _ports.begin(); p != _ports.end(); ++p) {
68 if (desc.tag == (*p)->name()) {
74 if (p != _ports.end()) {
78 port = new Port (node, (jack_client_t *) api_data);
89 _ports.push_back (port);
91 /* first port added becomes the default input
99 if (outputPort == 0) {
103 PortsChanged (); /* EMIT SIGNAL */
109 Manager::remove_port (Port* port)
111 if (inputPort == port) {
115 if (outputPort == port) {
119 _ports.remove (port);
122 PortsChanged (); /* EMIT SIGNAL */
128 Manager::set_input_port (string tag)
130 for (PortList::iterator p = _ports.begin(); p != _ports.end(); ++p) {
131 if ((*p)->name() == tag) {
141 Manager::set_output_port (string tag)
143 PortList::iterator p;
145 for (p = _ports.begin(); p != _ports.end(); ++p) {
146 if ((*p)->name() == tag) {
152 if (p == _ports.end()) {
156 // XXX send a signal to say we're about to change output ports
159 for (channel_t chan = 0; chan < 16; chan++) {
160 outputPort->channel (chan)->all_notes_off (0);
166 // XXX send a signal to say we've changed output ports
172 Manager::port (string name)
174 for (PortList::iterator p = _ports.begin(); p != _ports.end(); ++p) {
175 if (name == (*p)->name()) {
184 Manager::foreach_port (int (*func)(const Port &, size_t, void *),
189 for (PortList::const_iterator p = _ports.begin(); p != _ports.end(); ++p, ++n) {
192 if ((retval = func (**p, n, arg)) != 0) {
201 Manager::cycle_start(nframes_t nframes)
203 for (PortList::iterator p = _ports.begin(); p != _ports.end(); ++p) {
204 (*p)->cycle_start (nframes);
211 for (PortList::iterator p = _ports.begin(); p != _ports.end(); ++p) {
216 /** Re-register ports that disappear on JACK shutdown */
218 Manager::reestablish (void* a)
220 for (PortList::const_iterator p = _ports.begin(); p != _ports.end(); ++p) {
221 (*p)->reestablish (a);
225 /** Re-connect ports after a reestablish () */
227 Manager::reconnect ()
229 for (PortList::const_iterator p = _ports.begin(); p != _ports.end(); ++p) {