c20b2693f134f212dd6ab02f9f8f792066fd9f19
[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 protected:
51         /* Direct I/O */
52         int write(byte *msg, size_t msglen, timestamp_t timestamp);
53         int read(byte *buf, size_t max, timestamp_t timestamp);
54
55 private:
56         int create_ports(PortRequest &req);
57
58         jack_client_t* _jack_client;
59         jack_port_t*   _jack_input_port;
60         jack_port_t*   _jack_output_port;
61         nframes_t      _last_read_index;
62 };
63
64
65 } /* namespace MIDI */
66
67 #endif // __jack_midiport_h__
68