2017-06-07 111 views
3

我正在使用MIDI的MacOS應用程序。我想要做的是將SysEx消息發送到MIDI設備。現在,我已經在Java中完成了一次,但從未在Swift中完成過。使用CoreMIDI發送系統專有消息

而且由於coremidi庫幾乎完全新的給我,我不知道如何做到這一點的工作。什麼到目前爲止,我已經想通了,是我要撰寫MIDISysexSendRequest,我已經走到這一步:

let SysEx = MIDISysexSendRequest(destination: self.endpointRef, data: UnsafePointer<UInt8>, bytesToSend: 8, complete: complete, reserved: (UInt8, UInt8, UInt8), completionProc: completionProc, completionRefCon: nil) 

在此,有混淆我的幾件事情:

  • 我應該用什麼方式組成data變量?我知道什麼是字節我想送,只是沒有如何格式化此爲雨燕
  • 什麼是reserved應該是什麼?

我找不到這些,我可以用任何實例或參考。可能有人能幫我嗎/

在此先感謝。

回答

2

保留意味着你不能使用它,如:「僅供內部使用」

struct MIDISysexSendRequest 
{ 
    MIDIEndpointRef  destination; 
    const Byte *  data; 
    UInt32    bytesToSend; 
    Boolean    complete; 
    Byte    reserved[3]; 
    MIDICompletionProc completionProc; 
    void * __nullable completionRefCon; 
}; 

/*! 
    @struct   MIDISysexSendRequest 
    @abstract  A request to transmit a system-exclusive event. 

    @field   destination 
         The endpoint to which the event is to be sent. 
    @field   data 
         Initially, a pointer to the sys-ex event to be sent. 
         MIDISendSysex will advance this pointer as bytes are 
         sent. 
    @field   bytesToSend 
         Initially, the number of bytes to be sent. MIDISendSysex 
         will decrement this counter as bytes are sent. 
    @field   complete 
         The client may set this to true at any time to abort 
         transmission. The implementation sets this to true when 
         all bytes have been sent. 
    @field   completionProc 
         Called when all bytes have been sent, or after the client 
         has set complete to true. 
    @field   completionRefCon 
         Passed as a refCon to completionProc. 

    @discussion 
     This represents a request to send a single system-exclusive MIDI event to 
     a MIDI destination asynchronously. 
*/ 

注意如何保留變量甚至沒有在標題中顯示出來。

快速谷歌表示寫在迅速許多項目使用MIDI。瀏覽其中的一些內容以查看工作示例。

我看了第一個似乎是完美的看到事情是如何完成的。它甚至有很多.java文件,所以你可能會更容易看到它與swift(或如何連接它們)的關係。

到這裏看看:MIDI in Swift

在CoreMIDI框架有一個名爲「MIDIServices.h」(取景器會幫您找到它)文件。它有很多關於MIDI的信息。

祝你好運!

+0

這是對這兩個問題的完整答案。那些貶低它的人請向我解釋什麼是缺乏的?我試圖避免編寫OP的代碼。就像「教人去釣魚」一樣。 – Mozahler

+0

感謝您的回答!它幫了我很多忙。除了'reserved'選項之外,我填充了所有內容,因爲我真的不確定我應該填寫什麼內容,並且簽有'(UInt8,UInt8,UInt8)''另外,沒有給出任何通信或答案,你是一個二維 – Wesley

+0

感謝您的支持 - 。爲了得到上面的列表,我把光標放在命令上,並做了一個命令 - 單擊來調出頭文件,因爲懸停並沒有給我提供有關該保留變量的信息... – Mozahler