Committed filthy mess of a working copy solely for moving between machines.
[ardour.git] / libs / midi++2 / midi++ / coremidi_midiport.h
1 /*
2   Copyright (C) 2004 Paul Davis
3   Copyright (C) 2004 Grame
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (at your option) any later version.
8  
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. �See the
12   GNU General Public License for more details.
13  
14   You should have received a copy of the GNU General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  
18  */
19
20 #ifndef __coremidi_midiport_h__
21 #define __coremidi_midiport_h__
22
23 #include <list>
24 #include <string>
25
26 #include <fcntl.h>
27 #include <unistd.h>
28
29 #include <midi++/port.h>
30
31 #include <CoreMIDI/CoreMIDI.h>
32
33 namespace MIDI {
34
35 class CoreMidi_MidiPort:public Port {
36         public:
37                 CoreMidi_MidiPort(PortRequest & req);
38                 virtual ~ CoreMidi_MidiPort();
39
40                 virtual int selectable() const {
41                         return -1;
42                 }
43         protected:
44                 /* Direct I/O */
45                 int write (byte *msg, size_t msglen, timestamp_t timestamp);    
46                 int read (byte *buf, size_t max, timestamp_t timestamp);
47
48                 /* CoreMidi callback */
49                 static void read_proc(const MIDIPacketList * pktlist,
50                                 void *refCon, void *connRefCon);
51
52         private:
53                 byte midi_buffer[1024];
54                 MIDIClientRef midi_client;
55                 MIDIEndpointRef midi_destination;
56                 MIDIEndpointRef midi_source;
57
58                 int Open(PortRequest & req);
59                 void Close();
60                 static MIDITimeStamp MIDIGetCurrentHostTime();
61
62                 bool firstrecv;
63 };
64
65 }; /* namespace MIDI */
66
67 #endif  // __coremidi_midiport_h__