Debian Codegraph @

src/gui/midi_coremidi.h

raw symbols SCIP
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */
16
17 #include <CoreMIDI/MIDIServices.h>
18
19 class MidiHandler_coremidi : public MidiHandler {
20 private:
21 MIDIPortRef m_port;
22 MIDIClientRef m_client;
23 MIDIEndpointRef m_endpoint;
24 MIDIPacket* m_pCurPacket;
25 public:
26 MidiHandler_coremidi() {m_pCurPacket = 0;}
27 const char * GetName(void) { return "coremidi"; }
28 bool Open(const char * conf) {
29
30 // Get the MIDIEndPoint
31 m_endpoint = 0;
32 OSStatus result;
33 Bitu numDests = MIDIGetNumberOfDestinations();
34 Bitu destId = 0;
35 if(conf && conf[0]) destId = atoi(conf);
36 if (destId < numDests)
37 {
38 m_endpoint = MIDIGetDestination(destId);
39 }
40
41 // Create a MIDI client and port
42 MIDIClientCreate(CFSTR("MyClient"), 0, 0, &m_client);
43
44 if (!m_client)
45 {
46 LOG_MSG("MIDI:coremidi: No client created.");
47 return false;
48 }
49
50 MIDIOutputPortCreate(m_client, CFSTR("MyOutPort"), &m_port);
51
52 if (!m_port)
53 {
54 LOG_MSG("MIDI:coremidi: No port created.");
55 return false;
56 }
57
58
59 return true;
60 }
61
62 void Close(void) {
63 // Dispose the port
64 MIDIPortDispose(m_port);
65
66 // Dispose the client
67 MIDIClientDispose(m_client);
68
69 // Dispose the endpoint
70 MIDIEndpointDispose(m_endpoint);
71 }
72
73 void PlayMsg(Bit8u * msg) {
74 // Acquire a MIDIPacketList
75 Byte packetBuf[128];
76 MIDIPacketList *packetList = (MIDIPacketList *)packetBuf;
77 m_pCurPacket = MIDIPacketListInit(packetList);
78
79 // Determine the length of msg
80 Bitu len=MIDI_evt_len[*msg];
81
82 // Add msg to the MIDIPacketList
83 MIDIPacketListAdd(packetList, (ByteCount)sizeof(packetBuf), m_pCurPacket, (MIDITimeStamp)0, len, msg);
84
85 // Send the MIDIPacketList
86 MIDISend(m_port,m_endpoint,packetList);
87 }
88
89 void PlaySysex(Bit8u * sysex, Bitu len) {
90 // Acquire a MIDIPacketList
91 Byte packetBuf[SYSEX_SIZE*4];
92 Bitu pos=0;
93 MIDIPacketList *packetList = (MIDIPacketList *)packetBuf;
94 m_pCurPacket = MIDIPacketListInit(packetList);
95
96 // Add msg to the MIDIPacketList
97 MIDIPacketListAdd(packetList, (ByteCount)sizeof(packetBuf), m_pCurPacket, (MIDITimeStamp)0, len, sysex);
98
99 // Send the MIDIPacketList
100 MIDISend(m_port,m_endpoint,packetList);
101 }
102 };
103
104 MidiHandler_coremidi Midi_coremidi;
105