breakout control protocol code into LGPL library; fix panner buttons even more than...
[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 <midi++/types.h>
21 #include <midi++/factory.h>
22 #include <midi++/nullmidi.h>
23 #include <midi++/fifomidi.h>
24
25 #ifdef WITH_ALSA
26 #include <midi++/alsa_sequencer.h>
27 #include <midi++/alsa_rawmidi.h>
28 #endif // WITH_ALSA
29
30 #ifdef WITH_COREMIDI
31 #include <midi++/coremidi_midiport.h>
32 #endif // WITH_COREMIDI
33
34
35 using namespace std;
36 using namespace MIDI;
37
38 Port *
39 PortFactory::create_port (PortRequest &req)
40
41 {
42         Port *port;
43         
44         switch (req.type) {
45 #ifdef WITH_ALSA
46         case Port::ALSA_RawMidi:
47                 port = new ALSA_RawMidiPort (req);
48                 break;
49
50         case Port::ALSA_Sequencer:
51                 port = new ALSA_SequencerMidiPort (req);
52                 break;
53 #endif // WITH_ALSA
54
55 #if WITH_COREMIDI
56         case Port::CoreMidi_MidiPort:
57                 port = new CoreMidi_MidiPort (req);
58                 break;
59 #endif // WITH_COREMIDI
60
61         case Port::Null:
62                 port = new Null_MidiPort (req);
63                 break;
64
65         case Port::FIFO:
66                 port = new FIFO_MidiPort (req);
67                 break;
68
69         default:
70                 req.status = PortRequest::TypeUnsupported;
71                 return 0;
72         }
73
74         req.status = PortRequest::OK;
75
76         return port;
77 }
78
79 void
80 PortFactory::add_port_request (vector<PortRequest *> &reqs, 
81                                    const string &str)
82         
83 {
84         PortRequest *req;
85
86         req = new PortRequest;
87         req->devname = strdup (str.c_str());
88         req->tagname = strdup (str.c_str());
89
90         req->mode = O_RDWR;
91         req->type = Port::ALSA_RawMidi;
92
93         reqs.push_back (req);
94 }
95