a4b4ba856f161b37826d1999c9fa4e0a2e443e1f
[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     $Id$
18 */
19
20 #ifndef __alsa_sequencer_midiport_h__
21 #define __alsa_sequencer_midiport_h__
22
23 #include <vector>
24 #include <string>
25
26 #include <fcntl.h>
27 #include <unistd.h>
28
29 #include <alsa/asoundlib.h>
30 #include <midi++/port.h>
31
32 namespace MIDI {
33
34 class ALSA_SequencerMidiPort : public Port
35
36 {
37   public:
38         ALSA_SequencerMidiPort (PortRequest &req);
39         virtual ~ALSA_SequencerMidiPort ();
40
41         /* select(2)/poll(2)-based I/O */
42
43         virtual int selectable() const;
44
45   protected:
46         /* Direct I/O */
47         int write (byte *msg, size_t msglen, timestamp_t timestamp);    
48         int read (byte *buf, size_t max, timestamp_t timestamp);
49
50   private:
51         snd_midi_event_t *decoder, *encoder;
52         int port_id;
53         snd_seq_event_t SEv;
54
55         int CreatePorts(PortRequest &req);
56
57         static int init_client (std::string name);
58         static snd_seq_t* seq;
59 };
60
61 }; /* namespace MIDI */
62
63 #endif // __alsa_sequencer_midiport_h__
64