OSX and midi lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- corpusgemini · 2020-08-01 10:33 Hello, Has anyone successfully implemented MIDI in a project for OSX? If so, can they share the code used for it, because I find lots of posts of people having the same issue, but up till now no working solution. Thanks a lot, Tony ---------------------------------------------------------------------- trev · 2020-08-01 10:52 I wrote example code for a minimal MIDI player for the macOS MIDI article on the Wiki. ---------------------------------------------------------------------- corpusgemini · 2020-08-01 11:02 Thanks trev. However I am looking for a way to send and receive MIDI commands from devices. It should make use of CoreMIDI apparently. Best regards, Tony ---------------------------------------------------------------------- trev · 2020-08-01 11:08 Be aware that Apple is extending the CoreMIDI API for the forthcoming release of Big Sur (macOS 11.0). See: https://developer.apple.com/documentation/coremidi/ (I don't have a MIDI musical instrument, so haven't seriously looked at the CoreMIDI API). ---------------------------------------------------------------------- Jurassic Pork · 2023-04-24 05:41 Hello Trev, i have succeeded to compile  c++ rtmidi library under windows (with visual studio) and linux (ubuntu) to use with Lazarus. I have a project demo to read the midi in and out opened in a O.S and monitor midi events using callback. Rtmidi on Mac use COREMIDI : QuoteA set of C++ classes that provide a common API for realtime MIDI input/output across Linux (ALSA & JACK), Macintosh OS X (CoreMIDI) and Windows (Multimedia)Do you know is it possible to compile this library under OS X ? to generate midi events you can use a virtual midi keyboard like midikeys on Mac OS X. Friendly, J.P ---------------------------------------------------------------------- Jurassic Pork · 2023-04-25 08:39 Hello, Ultimately the rtmidi library also works under Mac Os X, with CoreMidi or with Jack library. Attachment shows a lazarus project listening for midi events generated by virtual midi keyboard midikeys on Mac OS X Catalina 10.15. Friendly, J.P ---------------------------------------------------------------------- Key-Real · 2023-05-23 07:28 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$linkframework AudioToolbox}{$linkframework CoreMIDI}{$MODE OBJFPC}uses MacOSAll,CocoaAll;  procedure checkError(error: OSStatus; msg: string);begin    if (error <> noErr) then begin        writeln('Error: ', error, ' ', msg);        halt;    end;end;  type              myMIDIPlayer = record                end;   procedure myMIDINotifyProc(message: MIDINotificationPTR; refCon: pointer); MWPascal;begin        writeln('MIDI Notify ',message^.messageID);end; procedure myMIDIReadProc(pktlist: MIDIPacketListPTR; refCon: pointer; connRefCon: pointer); MWPascal;var packet : MIDIPacketPTR;        i : longint;        midiStatus : byte;        midiCommand : byte;        note : byte;        velocity : byte;begin        packet:= @pktlist^.packet[0];         for i:=0 to pktlist^.numPackets-1 do begin                 midiStatus:= packet^.data[0];                midiCommand:= midiStatus shr 4; //            writeln(packet^.length, ' ', midiStatus);    // if midiStatus returns 0 and packet^.length an random value than your FPC is broken :(                 if (midiCommand = $09) then begin                      note:= packet^.data[1] and $7F;                        velocity:= packet^.data[2] and $7F;                        writeln('note ', note, ' stroke at ', velocity);                end;                 if (midiCommand = $08) then begin                        note:= packet^.data[1] and $7F;                        writeln('note ', note, ' releaced');                end;                  packet:= MIDIPacketNext(packet);         end; end;  var        client : MIDIClientRef;        inPort : MIDIPortRef;        src : MIDIEndpointRef;         sourceCount : dword;        endpointName : CFStringRef;         status : OSStatus;         strC : array [0..255] of char;         player : myMIDIPlayer;         i : longint;begin       status:= MIDIClientCreate(CFSTR('Core MIDI Demo'), @myMIDINotifyProc, @player, client);        checkError(status, 'Coundn''t create MIDI client');          status:= MIDIInputPortCreate(client,CFSTR('Input Port'), @myMIDIReadProc, @player, inPort);        checkError(status, 'Coundn''t create MIDI input port');          sourceCount:= MIDIGetNumberOfSources;        writeln(sourceCount, ' Sources found');         if sourceCount = 0 then halt;          for i:=0 to sourceCount - 1 do begin               src:= MIDIGetSource(i);                 status:= MIDIObjectGetStringProperty(src, kMIDIPropertyName, endpointName);              checkError(status, 'Coundn''t get endpoint name');               CFStringGetCString(endpointName, strC, 255, kCFStringEncodingUTF8);                writeln('- source ', i, ' ', strC);                                status:= MIDIPortConnectSource(inPort, src, nil);                checkError(status, 'Coundn''t connect MIDI port');         end;         readln;  end. BUT!!!! you have to patch your FPC Trunk manually: https://gitlab.com/freepascal.org/fpc/source/-/issues/35750