coremidi.c 2.5 KB
Newer Older
1
/*
2
 * Wine Midi driver for Mac OS X
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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"

#ifdef HAVE_COREAUDIO_COREAUDIO_H
25

26
#include <CoreMIDI/CoreMIDI.h>
27
#include <mach/mach_time.h>
28 29 30

#include "coremidi.h"

31

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
MIDIClientRef CoreMIDI_CreateClient(CFStringRef name)
{
    MIDIClientRef client = NULL;

    if (MIDIClientCreate(name, NULL /* FIXME use notify proc */, NULL, &client) != noErr)
        return NULL;

    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);
    }
}

55 56 57 58 59 60 61 62 63 64 65
/*
 *  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) {
66
        msg.devID = *((UInt16 *)connRefCon);
67 68 69
        msg.length = packet->length;
        memcpy(msg.data, packet->data, sizeof(packet->data));

70
        MIDIIn_SendMessage(msg);
71 72 73 74

        packet = MIDIPacketNext(packet);
    }
}
75 76 77 78 79 80 81 82 83 84 85 86

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);
}
87
#endif /* HAVE_COREAUDIO_COREAUDIO_H */