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