add new sigc++2 directory
[ardour.git] / libs / midi++2 / midi++ / alsa_sequencer.h
1 /*
2     Copyright (C) 2004 Paul 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 */
18
19 #ifndef __alsa_sequencer_midiport_h__
20 #define __alsa_sequencer_midiport_h__
21
22 #include <vector>
23 #include <string>
24
25 #include <fcntl.h>
26 #include <unistd.h>
27
28 #include <alsa/asoundlib.h>
29 #include <midi++/port.h>
30
31 namespace MIDI {
32
33 class ALSA_SequencerMidiPort : public Port
34
35 {
36   public:
37         ALSA_SequencerMidiPort (const XMLNode&);
38         virtual ~ALSA_SequencerMidiPort ();
39
40         int write (byte *msg, size_t msglen, timestamp_t timestamp);    
41         int read (byte *buf, size_t max);
42
43         /* select(2)/poll(2)-based I/O */
44
45         virtual int selectable() const;
46         
47         static int discover (std::vector<PortSet>&);
48         static std::string typestring;
49
50         XMLNode& get_state() const;
51         void set_state (const XMLNode&);
52
53   protected:
54
55         std::string get_typestring () const {
56                 return typestring;
57         }
58
59   private:
60         snd_midi_event_t *decoder, *encoder;
61         int port_id;
62         snd_seq_event_t SEv;
63
64         int create_ports (const Port::Descriptor&);
65
66         static int init_client (std::string name);
67         static snd_seq_t* seq;
68
69         typedef std::pair<int,int> SequencerPortAddress;
70         void get_connections (std::vector<SequencerPortAddress>&, int dir) const;
71 };
72
73 }; /* namespace MIDI */
74
75 #endif // __alsa_sequencer_midiport_h__
76