merge changes to libmidi++ API from 2.0-ongoing
[ardour.git] / libs / midi++2 / midi++ / jack.h
1 /*
2     Copyright (C) 2006 Paul Davis 
3         Written by Dave Robillard
4  
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9  
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14  
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  
19     $Id: jack.h 4 2005-05-13 20:47:18Z taybin $
20 */
21
22 #ifndef __jack_midiport_h__
23 #define __jack_midiport_h__
24
25 #include <vector>
26 #include <string>
27
28 #include <fcntl.h>
29 #include <unistd.h>
30
31 #include <jack/jack.h>
32 #include <jack/midiport.h>
33 #include <midi++/port.h>
34
35 namespace MIDI
36 {
37
38
39 class JACK_MidiPort : public Port
40 {
41 public:
42         JACK_MidiPort (PortRequest &req, jack_client_t* jack_client);
43         virtual ~JACK_MidiPort ();
44
45         /* No select(2)/poll(2)-based I/O */
46         virtual int selectable() const { return -1; }
47         
48         virtual void cycle_start(nframes_t nframes);
49
50         static std::string typestring;
51
52   protected:
53         std::string get_typestring () const {
54                 return typestring;
55         }
56
57 protected:
58         /* Direct I/O */
59         int write(byte *msg, size_t msglen, timestamp_t timestamp);
60         int read(byte *buf, size_t max, timestamp_t timestamp);
61
62 private:
63         int create_ports(PortRequest &req);
64
65         jack_client_t* _jack_client;
66         jack_port_t*   _jack_input_port;
67         jack_port_t*   _jack_output_port;
68         nframes_t      _last_read_index;
69 };
70
71
72 } /* namespace MIDI */
73
74 #endif // __jack_midiport_h__
75