2012-12-16 3 views
1

RubyMotion 프로젝트에서 CoreMIDI를 사용하려고합니다. Pointer.new (: uint)가 CoreMIDI (RubyMotion)의 적절한 유형으로 변환되지 않습니다.

clientName = "Client" 
clientRef = Pointer.new(:uint) 
MIDIClientCreate(clientName, nil, nil, clientRef) 

는 다음과 같은 요지의 자세한 코드 및 역 추적을 참조하십시오

: https://gist.github.com/4299810

다음과 같은 오류에서 그 코드 결과 :

(main)> 2012-12-15 14:43:27.410 core-midi-test[42560:c07] app_delegate.rb:5:in application:didFinishLaunchingWithOptions:': expected instance of Pointer of type ^{OpaqueMIDIClient}', got I' (TypeError) 2012-12-15 14:43:27.412 core-midi-test[42560:c07] *** Terminating app due to uncaught exception 'TypeError', reason: 'app_delegate.rb:5:in application:didFinishLaunchingWithOptions:': expected instance of Pointer of type ^{OpaqueMIDIClient}', got I' (TypeError)'

이 오류는 분명히 여기에 코드의 간단한 예입니다 네 번째 인수는 MIDIClientCreate입니다. MIDIClientCreate 쇼에 대한 문서 :

OSStatus MIDIClientCreate (
    CFStringRef  name, 
    MIDINotifyProc notifyProc, 
    void   *notifyRefCon, 
    MIDIClientRef *outClient 
); 

MIDIClientRef가 UINT32으로 정의된다 MIDIObjectRef에서 유래, 그래서 Pointer.new 것을 확신한다 (: UINT)가 RubyMotion에 사용할 올바른 유형입니다.

내가 아는 한
<function name='MIDIClientCreate'> 
    <arg name='name' type='^{__CFString=}' declared_type='CFStringRef'/> 
    <arg name='notifyProc' function_pointer='true' type='^?' declared_type='MIDINotifyProc'> 
     <arg type='^{MIDINotification=iI}' declared_type='MIDINotification*' const='true'/> 
     <arg type='^v' declared_type='void*'/> 
     <retval type='v' declared_type='void'/> 
    </arg> 
    <arg name='notifyRefCon' type='^v' declared_type='void*'/> 
    <arg name='outClient' type='^^{OpaqueMIDIClient}' declared_type='MIDIClientRef*'/> 
    <retval type='l' declared_type='OSStatus'/> 
</function> 

에서, bridgesupport 정의가 적절한 변환을 위해 필요한 배관을 포함한다 :

여기 RubyMotion 사용되는 CoreMIDI.bridgesupport 파일의 해당 부분이다. 물론 그것은 작동하지 않습니다.

내 코드에 문제가 있습니까? 아니면 CoreMIDI.bridgesupport 파일이 RubyMotion에 포함되어 있습니까?

답변

2

나는 하나가 명시 적으로 같은 포인터 생성자에 원하는 포인터 타입을 전달할 수 있다는 MacRuby에 대한 설명서를 읽어 발견 :

clientName = "Client" 
clientRef = Pointer.new(MIDIClientRef.type) 
MIDIClientCreate(clientName, nil, nil, clientRef) 

portName = "Output" 
outport = Pointer.new(MIDIPortRef.type) 
MIDIOutputPortCreate(clientRef[0], portName, outport)