d8119e362eefcddfc6af3f5e39145298f856b9bc
[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 <cassert>
21 #include <midi++/types.h>
22 #include <midi++/factory.h>
23 #include <midi++/nullmidi.h>
24 #include <midi++/fifomidi.h>
25
26 #ifdef WITH_JACK_MIDI
27 #include <midi++/jack.h>
28 #endif // WITH_JACK_MIDI
29
30 #ifdef WITH_ALSA
31 #include <midi++/alsa_sequencer.h>
32 #include <midi++/alsa_rawmidi.h>
33 #endif // WITH_ALSA
34
35 #ifdef WITH_COREMIDI
36 #include <midi++/coremidi_midiport.h>
37 #endif // WITH_COREMIDI
38
39
40 using namespace std;
41 using namespace MIDI;
42
43 // FIXME: void* data pointer, filthy
44 Port *
45 PortFactory::create_port (PortRequest &req, void* data)
46
47 {
48         Port *port;
49         
50         switch (req.type) {
51 #ifdef WITH_JACK_MIDI
52         case Port::JACK_Midi:
53                 assert(data != NULL);
54                 port = new JACK_MidiPort (req, (jack_client_t*)data);
55                 break;
56 #endif // WITH_JACK_MIDI
57         
58 #ifdef WITH_ALSA
59         case Port::ALSA_RawMidi:
60                 port = new ALSA_RawMidiPort (req);
61                 break;
62
63         case Port::ALSA_Sequencer:
64                 port = new ALSA_SequencerMidiPort (req);
65                 break;
66 #endif // WITH_ALSA
67
68 #if WITH_COREMIDI
69         case Port::CoreMidi_MidiPort:
70                 port = new CoreMidi_MidiPort (req);
71                 break;
72 #endif // WITH_COREMIDI
73
74         case Port::Null:
75                 port = new Null_MidiPort (req);
76                 break;
77
78         case Port::FIFO:
79                 port = new FIFO_MidiPort (req);
80                 break;
81
82         default:
83                 req.status = PortRequest::TypeUnsupported;
84                 return 0;
85         }
86
87         req.status = PortRequest::OK;
88
89         return port;
90 }
91
92 void
93 PortFactory::add_port_request (vector<PortRequest *> &reqs, 
94                                    const string &str)
95         
96 {
97         PortRequest *req;
98
99         req = new PortRequest;
100         req->devname = strdup (str.c_str());
101         req->tagname = strdup (str.c_str());
102
103         req->mode = O_RDWR;
104         req->type = Port::ALSA_RawMidi;
105
106         reqs.push_back (req);
107 }
108