Why doesn't this simple CoreMIDI program produce MIDI output?

后端 未结 4 552
独厮守ぢ
独厮守ぢ 2020-12-23 23:56

Here is an extremely simple CoreMIDI OS X application that sends MIDI data. The problem is that it doesn\'t work. It compiles fine, and runs. It reports no errors, and does

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-24 00:42

    I'm just leaving this here for my own reference. It's a full example based 100% on yours, but including the other side (receiving), my bad C code and the accepted answer's corrections (of course).

    #import "AppDelegate.h"
    
    @implementation AppDelegate
    
    @synthesize window = _window;
    
    #define NSLogError(c,str) do{if (c) NSLog(@"Error (%@): %u:%@", str, (unsigned int)c,[NSError errorWithDomain:NSMachErrorDomain code:c userInfo:nil]); }while(false)
    
    static void spit(Byte* values, int length, BOOL useHex) {
        NSMutableString *thing = [@"" mutableCopy];
        for (int i=0; ipacket[0];
    
        for (int i = 0; i < packetList->numPackets; i++)
        {
    
            NSData *data = [NSData dataWithBytes:packet->data length:packet->length];
            spit((Byte*)data.bytes, data.length, YES);
    
            packet = MIDIPacketNext(packet);
        }
    }
    
    - (void) setupReceiver {
        OSStatus s;
        MIDIEndpointRef virtualInTemp;
        NSString *inName = [NSString stringWithFormat:@"Magical MIDI Destination"];
        s = MIDIDestinationCreate(theMidiClient, (__bridge CFStringRef)inName, ReadProc,  (__bridge void *)self, &virtualInTemp);
        NSLogError(s, @"Create virtual MIDI in");
    }
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        MIDIClientCreate(CFSTR("Magical MIDI"), NULL, NULL,
                         &theMidiClient);
        [self setupReceiver];
        [self startSending];
    
    }
    
    @end
    

提交回复
热议问题