major redesign of MIDI port heirarchy and management
[ardour.git] / libs / ardour / midiport_manager.cc
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.
7
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.
12
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.
16
17     $Id$
18 */
19
20 #include "ardour/audioengine.h"
21 #include "ardour/async_midi_port.h"
22 #include "ardour/midiport_manager.h"
23
24 #include "i18n.h"
25
26 using namespace ARDOUR;
27 using namespace std;
28 using namespace MIDI;
29 using namespace PBD;
30
31
32 MidiPortManager::MidiPortManager ()
33 {
34 }
35
36 MidiPortManager::~MidiPortManager ()
37 {
38         if (_midi_in) {
39                 AudioEngine::instance()->unregister_port (_midi_in);
40         }
41         if (_midi_in) {
42                 AudioEngine::instance()->unregister_port (_midi_in);
43         }
44         if (_mtc_input_port) {
45                 AudioEngine::instance()->unregister_port (_mtc_input_port);
46         }
47         if (_mtc_output_port) {
48                 AudioEngine::instance()->unregister_port (_mtc_output_port);
49         }
50         if (_midi_clock_input_port) {
51                 AudioEngine::instance()->unregister_port (_midi_clock_input_port);
52         }
53         if (_midi_clock_output_port) {
54                 AudioEngine::instance()->unregister_port (_midi_clock_output_port);
55         }
56
57 }
58
59 MidiPort*
60 MidiPortManager::port (string const & n)
61 {
62         boost::shared_ptr<MidiPort> mp =  boost::dynamic_pointer_cast<MidiPort> (AudioEngine::instance()->get_port_by_name (n));
63         return mp.get();
64 }
65
66 void
67 MidiPortManager::create_ports ()
68 {
69         _midi_in  = AudioEngine::instance()->register_input_port (DataType::MIDI, _("MIDI control in"), true);
70         _midi_out = AudioEngine::instance()->register_output_port (DataType::MIDI, _("MIDI control out"), true);
71         
72         _midi_input_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_midi_in).get();
73         _midi_output_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_midi_out).get();
74 }
75
76 void
77 MidiPortManager::set_port_states (list<XMLNode*> s)
78 {
79         PortManager::PortList pl;
80
81         AudioEngine::instance()->get_ports (DataType::MIDI, pl);
82         
83         for (list<XMLNode*>::iterator i = s.begin(); i != s.end(); ++i) {
84                 for (PortManager::PortList::const_iterator j = pl.begin(); j != pl.end(); ++j) {
85                         // (*j)->set_state (**i);
86                 }
87         }
88 }
89