1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Wine Midi driver for Mac OS X
*
* Copyright 2006 Emmanuel Maillard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include <CoreMIDI/CoreMIDI.h>
#include <mach/mach_time.h>
#include "coremidi.h"
MIDIClientRef CoreMIDI_CreateClient(CFStringRef name)
{
MIDIClientRef client = 0;
if (MIDIClientCreate(name, NULL /* FIXME use notify proc */, NULL, &client) != noErr)
return 0;
return client;
}
void CoreMIDI_GetObjectName(MIDIObjectRef obj, char *name, int size)
{
OSStatus err = noErr;
CFStringRef cfname;
err = MIDIObjectGetStringProperty(obj, kMIDIPropertyName, &cfname);
if (err == noErr)
{
CFStringGetCString(cfname, name, size, kCFStringEncodingASCII);
CFRelease(cfname);
}
}
/*
* CoreMIDI IO threaded callback,
* we can't call Wine debug channels, critical section or anything using NtCurrentTeb here.
*/
void MIDIIn_ReadProc(const MIDIPacketList *pktlist, void *refCon, void *connRefCon)
{
unsigned int i;
MIDIMessage msg;
MIDIPacket *packet = (MIDIPacket *)pktlist->packet;
for (i = 0; i < pktlist->numPackets; ++i) {
msg.devID = *((UInt16 *)connRefCon);
msg.length = packet->length;
memcpy(msg.data, packet->data, sizeof(packet->data));
MIDIIn_SendMessage(msg);
packet = MIDIPacketNext(packet);
}
}
void MIDIOut_Send(MIDIPortRef port, MIDIEndpointRef dest, UInt8 *buffer, unsigned length)
{
Byte packetBuff[512];
MIDIPacketList *packetList = (MIDIPacketList *)packetBuff;
MIDIPacket *packet = MIDIPacketListInit(packetList);
packet = MIDIPacketListAdd(packetList, sizeof(packetBuff), packet, mach_absolute_time(), length, buffer);
if (packet)
MIDISend(port, dest, packetList);
}