Attention! Translated article might be found on my English blog.

2016年8月1日月曜日

自作Audio Unit App Extensionをサードパーティ製ホストアプリケーションで認識させる

NOTE: English version of this article is available.

この記事はAudio Unit App Extensionをインストールした際のメモです。試行錯誤しながら調べたので間違ってる箇所があるかもしれません。

詳細

Xcode 7.3 の"Add Target..." で追加できるAudio Unit App Extension に関して、
ビルドした .appexを ~/Library/Audio/Plug-Ins/Components/ に入れても
ホストアプリやauvaltoolなどで認識されませんでした。

色々調べた結果、従来のAUのように ~/Library/Audio/Plug-Ins/Components/に入れるのではなく、
Today App Extension のように内包アプリケーション(embed application)を作り、
そのアプリを起動させる必要があるようでした。

この件に関しては、以下のサイトの議論が大変参考になりました。

Audio Units v3 OS x: Instantiating custom audio... | Apple Developer Forums

インストールが正常に行われると、syslogに以下のようなログが吐き出されます。
Aug  1 10:23:41 MBP13R pkd[308] <Warning>: INSTALLED:com.shakeyama-mi.MyAUHost.Vibrato com.shakeyama-mi.MyAUHost.Vibrato(1.5) <__NSConcreteUUID 0x7fc9b2c19020> C3C2F430-0567-4651-800A-B8D0EE39A8E9 /Users/shakeyama/Library/Developer/Xcode/DerivedData/AU-auuapdgoorecwwhayzytocylavpn/Build/Products/Release/MyAUHost.app/Contents/PlugIns/Vibrato.appex

もちろんConsole.appからでも確認できます。
こちらの環境では、Xcodeから内包アプリを起動しただけでは上記メッセージは出力されず、
Finderから起動することで出力されました。
Xcodeからの場合、Xcodeが内包アプリのプロセスにアタッチするのがよくないのかもしれません。
 syslogには以下のようなログが出ていましたが関係あるのかは分かりません。

<Notice>: <rdar://problem/11489077> A sandboxed application with pid 1277, "MyAUHost" checked in with appleeventsd, but its code signature could not be read and validated by appleeventsd, and so it cannot receive AppleEvents targeted by name, bundle id, or signature. Install the application in /Applications/ or some other world readable location to resolve this issue. Error=ERROR: #100013  { "NSDescription"="SecCodeCopySigningInformation() returned 100013, -." }  (handleMessage()/appleEventsD.cp #2098) com.apple.root.default-qos

インストール後は内包アプリを終了しても大丈夫なようで、
サードパーティ製のホストアプリやauvaltoolで無事自作AUを確認できました。

しかし、内包アプリの起動と終了を繰り返していると、再び認識されなくなりました。
syslogを見ると、

Aug  1 11:21:27 MBP13R pkd[308] <Warning>: UNINSTALLED:com.shakeyama-mi.MyAUHost.Vibrato com.shakeyama-mi.MyAUHost.Vibrato(1.5) C0F51268-6DA2-41E2-9805-03D7119241ED /Users/shakeyama/Desktop/MyAUHost 0028-08-01 11-19-53/MyAUHost.app/Contents/PlugIns/Vibrato.appex

と表示されていました。
おそらく内包アプリを起動すると、一旦アンインストールしてから再びインストールするようですが、
何かの拍子にインストールされなくなってしまったようです。
この原因についてはよく分かってません。


・その他気づいたこと

自作AUはbundle identifierは内包アプリのbundle identifierをprefixとしてつける必要があるようで、
この条件を満たしてない場合

error: Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier.

Embedded Binary Bundle Identifier: com.shakeyama-mi.AU.Vibrato
Parent App Bundle Identifier: com.shakeyama-mi.MyAUHost
というエラーが出てビルドできないようでした。


また、新たに内包アプリターゲットを追加し、そのアプリに.appexをプラグインとして設定するには
内包アプリのターゲットを選択し、"Build Phases"から"+"ボタンを押下し、"New Copy Files Phase"、"Destination"を"PlugIns"、下部の"+"ボタンを押下して.appexを選択します。
この手順ではなく、"Copy Bundle Resources"の方に入れてしまうと、内包アプリでは認識されるものの、syslogにはINSTALLEDとは表示されず、サードパーティアプリからは認識されないようでした。