don't double-load NestedSource nodes, which are listed both forthe parent/root region...
[ardour2.git] / libs / midi++2 / manager.cc
blobd4b9b00715fe525f8ef672fc1573ecc71cbfd357
1 /*
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.
17 $Id$
20 #include <fcntl.h>
22 #include <glib.h>
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"
30 #include "midi++/mmc.h"
32 using namespace std;
33 using namespace MIDI;
34 using namespace PBD;
36 Manager *Manager::theManager = 0;
38 Manager::Manager (jack_client_t* jack)
40 _mmc = new MachineControl (this, jack);
42 _mtc_input_port = add_port (new MIDI::Port ("MTC in", Port::IsInput, jack));
43 _mtc_output_port = add_port (new MIDI::Port ("MTC out", Port::IsOutput, jack));
44 _midi_input_port = add_port (new MIDI::Port ("MIDI control in", Port::IsInput, jack));
45 _midi_output_port = add_port (new MIDI::Port ("MIDI control out", Port::IsOutput, jack));
46 _midi_clock_input_port = add_port (new MIDI::Port ("MIDI clock in", Port::IsInput, jack));
47 _midi_clock_output_port = add_port (new MIDI::Port ("MIDI clock out", Port::IsOutput, jack));
50 Manager::~Manager ()
52 delete _mmc;
54 /* This will delete our MTC etc. ports */
55 for (PortList::iterator p = _ports.begin(); p != _ports.end(); ++p) {
56 delete *p;
59 if (theManager == this) {
60 theManager = 0;
64 Port *
65 Manager::add_port (Port* p)
67 _ports.push_back (p);
69 PortsChanged (); /* EMIT SIGNAL */
71 return p;
74 void
75 Manager::cycle_start (pframes_t nframes)
77 for (PortList::iterator p = _ports.begin(); p != _ports.end(); ++p) {
78 (*p)->cycle_start (nframes);
82 void
83 Manager::cycle_end()
85 for (PortList::iterator p = _ports.begin(); p != _ports.end(); ++p) {
86 (*p)->cycle_end ();
90 /** Re-register ports that disappear on JACK shutdown */
91 void
92 Manager::reestablish (jack_client_t* jack)
94 for (PortList::const_iterator p = _ports.begin(); p != _ports.end(); ++p) {
95 (*p)->reestablish (jack);
99 /** Re-connect ports after a reestablish () */
100 void
101 Manager::reconnect ()
103 for (PortList::const_iterator p = _ports.begin(); p != _ports.end(); ++p) {
104 (*p)->reconnect ();
108 Port*
109 Manager::port (string const & n)
111 PortList::const_iterator p = _ports.begin();
112 while (p != _ports.end() && (*p)->name() != n) {
113 ++p;
116 if (p == _ports.end()) {
117 return 0;
120 return *p;
123 void
124 Manager::create (jack_client_t* jack)
126 assert (theManager == 0);
127 theManager = new Manager (jack);
130 void
131 Manager::set_port_states (list<XMLNode*> s)
133 for (list<XMLNode*>::iterator i = s.begin(); i != s.end(); ++i) {
134 for (PortList::const_iterator j = _ports.begin(); j != _ports.end(); ++j) {
135 (*j)->set_state (**i);