74207238ad031349e190dd21005a5ff674c287b0
[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 #include <vector>
26
27 #include <fcntl.h>
28 #include <unistd.h>
29
30 #include "midi++/port.h"
31
32 #include <CoreMIDI/CoreMIDI.h>
33
34 namespace MIDI {
35
36     class CoreMidi_MidiPort:public Port {
37       public:
38         CoreMidi_MidiPort(const XMLNode& node);
39         virtual ~ CoreMidi_MidiPort();
40
41         int write (byte * msg, size_t msglen, timestamp_t timestamp);
42         int read (byte * buf, size_t max) {
43             return 0;
44         } 
45
46         virtual int selectable() const {
47             return -1;
48         }
49
50         static int discover (std::vector<PortSet>&);
51         static std::string typestring;
52
53       protected:
54
55         /* CoreMidi callback */
56         static void read_proc(const MIDIPacketList * pktlist,
57                               void *refCon, void *connRefCon);
58         
59         std::string get_typestring () const {
60                 return typestring;
61         }
62
63       private:
64         byte midi_buffer[1024];
65         MIDIClientRef midi_client;
66         MIDIEndpointRef midi_destination;
67         MIDIEndpointRef midi_source;
68
69         int Open(const Port::Descriptor&);
70         void Close();
71         static MIDITimeStamp MIDIGetCurrentHostTime();
72
73         bool firstrecv;
74         
75     };
76
77 } // namespace MIDI
78
79 #endif  // __coremidi_midiport_h__