PluginInfo::type added to copy constructor. But why is the copy constructor defined...
[ardour.git] / libs / midi++2 / midifactory.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 <fcntl.h>
21
22 #include <pbd/error.h>
23 #include <pbd/convert.h>
24
25 #include <midi++/types.h>
26 #include <midi++/factory.h>
27 #include <midi++/nullmidi.h>
28 #include <midi++/fifomidi.h>
29
30 std::string MIDI::Null_MidiPort::typestring = "null";
31 std::string MIDI::FIFO_MidiPort::typestring = "fifo";
32
33 #ifdef WITH_ALSA
34 #include <midi++/alsa_sequencer.h>
35 #include <midi++/alsa_rawmidi.h>
36
37 std::string MIDI::ALSA_SequencerMidiPort::typestring = "alsa/sequencer";
38 std::string MIDI::ALSA_RawMidiPort::typestring = "alsa/raw";
39
40 #endif // WITH_ALSA
41
42 #ifdef WITH_COREMIDI
43 #include <midi++/coremidi_midiport.h>
44
45 std::string MIDI::CoreMidi_MidiPort::typestring = "coremidi";
46
47 #endif // WITH_COREMIDI
48
49
50 using namespace std;
51 using namespace MIDI;
52 using namespace PBD;
53
54 Port *
55 PortFactory::create_port (const XMLNode& node)
56 {
57         Port::Descriptor desc (node);
58         Port *port;
59         
60         switch (desc.type) {
61 #ifdef WITH_ALSA
62         case Port::ALSA_RawMidi:
63                 port = new ALSA_RawMidiPort (node);
64                 break;
65
66         case Port::ALSA_Sequencer:
67                 port = new ALSA_SequencerMidiPort (node);
68                 break;
69 #endif // WITH_ALSA
70
71 #if WITH_COREMIDI
72         case Port::CoreMidi_MidiPort:
73                 port = new CoreMidi_MidiPort (node);
74                 break;
75 #endif // WITH_COREMIDI
76
77         case Port::Null:
78                 port = new Null_MidiPort (node);
79                 break;
80
81         case Port::FIFO:
82                 port = new FIFO_MidiPort (node);
83                 break;
84
85         default:
86                 return 0;
87         }
88
89         return port;
90 }
91
92 bool 
93 PortFactory::ignore_duplicate_devices (Port::Type type)
94 {
95         bool ret = false;
96
97         switch (type) {
98 #ifdef WITH_ALSA
99         case Port::ALSA_Sequencer:
100                 ret = true;
101                 break;
102 #endif // WITH_ALSA
103
104 #if WITH_COREMIDI
105         case Port::CoreMidi_MidiPort:
106                 ret = true;
107                 break;
108 #endif // WITH_COREMIDI
109
110         default:
111                 break;
112         }
113
114         return ret;
115 }
116
117 int
118 PortFactory::get_known_ports (vector<PortSet>& ports)
119 {
120         int n = 0;
121 #ifdef WITH_ALSA
122         n += ALSA_SequencerMidiPort::discover (ports);
123 #endif // WITH_ALSA
124
125 #if WITH_COREMIDI
126         n += CoreMidi_MidiPort::discover (ports);
127 #endif // WITH_COREMIDI
128         
129         return n;
130 }
131
132 std::string
133 PortFactory::default_port_type ()
134 {
135
136 #ifdef WITH_ALSA
137         return "alsa/sequencer";
138 #endif
139
140 #ifdef WITH_COREMIDI
141         return "coremidi";
142 #endif // WITH_COREMIDI
143         
144         PBD::fatal << "programming error: no default port type defined in midifactory.cc" << endmsg;
145 }
146
147 Port::Type
148 PortFactory::string_to_type (const string& xtype)
149 {
150         if (0){ 
151 #ifdef WITH_ALSA
152         } else if (strings_equal_ignore_case (xtype, ALSA_RawMidiPort::typestring)) {
153                 return Port::ALSA_RawMidi;
154         } else if (strings_equal_ignore_case (xtype, ALSA_SequencerMidiPort::typestring)) {
155                 return Port::ALSA_Sequencer;
156 #endif 
157 #ifdef WITH_COREMIDI
158         } else if (strings_equal_ignore_case (xtype, CoreMidi_MidiPort::typestring)) {
159                 return Port::CoreMidi_MidiPort;
160 #endif
161         } else if (strings_equal_ignore_case (xtype, Null_MidiPort::typestring)) {
162                 return Port::Null;
163         } else if (strings_equal_ignore_case (xtype, FIFO_MidiPort::typestring)) {
164                 return Port::FIFO;
165         } 
166
167         return Port::Unknown;
168 }
169
170 string
171 PortFactory::mode_to_string (int mode)
172 {
173         if (mode == O_RDONLY) {
174                 return "input";
175         } else if (mode == O_WRONLY) {
176                 return "output";
177         } 
178
179         return "duplex";
180 }
181
182 int
183 PortFactory::string_to_mode (const string& str)
184 {
185         if (strings_equal_ignore_case (str, "output") || strings_equal_ignore_case (str, "out")) {
186                 return O_WRONLY;
187         } else if (strings_equal_ignore_case (str, "input") || strings_equal_ignore_case (str, "in")) {
188                 return O_RDONLY;
189         }
190
191         return O_RDWR;
192 }