2015年4月28日火曜日

Web MIDI Browser 1.0.5: 最新の Web MIDI API をサポート

Web MIDI Browser 1.0.5: 最新の Web MIDI API をサポート

Web MIDI Browser の 1.0.5 で、Web MIDI API の最新ドラフト (17 March 2015) 日本語版)で規定された API を提供するようになりました。この版のハイライトは、なんと言ってもホットプラグ対応です。ブラウザ内で Web アプリが動作している状態で、iOS デバイスへMIDI 機器が接続された場合に、Web アプリは通知を受けられるようになります。この機能により、Web アプリの操作性を、ネイティブアプリに近づけられるはずです。中で使っている WebMIDIAPIShimForiOS も更新しました。

実は、まだ仕様に完全対応とは言えず、現在の Wrapper の設計と相容れない部分があって、未実装になっている仕様があります。onstatechange や、state,  connection など、主要なインターフェイスは Chorme 43 Beta にそっくりにしてあります。してあるはずです。なっていなかったらごめんなさい。(間違っているところを見つけたらこっそり教えてください)



2015年4月20日月曜日

Web MIDI Browser 1.0.4: Apple Watch support

Web MIDI Browser 1.0.4: Apple Watch support

Web MIDI Browser 1.0.4 has been released. This version includes some bug fixes and Watch App extension. I don't know whether or not it's suitable as a Watch App. But we, Apple fans, must join the festival... right?

It's easy to use. You can enable "Enable Apple Watch Remote" option in the setting pane of the app. Then, a virtual MIDI port will appear. By pressing the button on Apple Watch, control change messages can be obtained from the virtual port. And then, cook them as you like. The function is available on iPhone 5/5s/5c/6/6Plus.


Watch Kit is a simple framework and has many restrictions. The button control, WKInterfaceButton, can observe Touch Up event only. So, I could NOT implement a control like a musical keyboard, sending noteon by touching-down, sending noteoff by touching-up. I really hope that it will get more controllable APIs in iOS 9... please, Apple guys.

And I fixed some bugs in this version. The next version, 1.0.5, will support the latest Web MIDI API, Chrome 43 spec, which includes the hot-plugging functionality. The polyfill library, WebMIDIAPIShimForiOS, is available on GitHub. It will be updated. Enjoy!

Web MIDI Browser 1.0.4 をリリースしました。このバージョンでは、バグ修正のほか、Apple Watch への対応を行いました。Apple Watch のアプリとして実用的かどうかはわかりませんが、お祭りなので。

使い方は簡単です。設定画面から"Enable Apple Watch Remote" を有効にすると、ブラウザ内で動作する Web アプリから仮想の MIDI Input Port が見えるようになります。そして、Apple Watch 上に現れるボタンを押すと、コントロールチェンジ ("0xb0 0x51 0x7f" 〜 "0xb0 0x54 0x7f") を送信します。あとは皆さんのアイデア次第。いろいろ遊んでみてください。この機能は、iPhone 5/5s/5c/6/6Plus で使えます。

iOS 8 の Watch Kit でできることは限られていて、このアプリでも使っている標準コントロールのボタン (Watch Extension 的には WKInterfaceButton) は、Touch Up (押したあと、離した時にイベント発生)しか検知できません。そのため、音楽アプリで使う鍵盤のように、押して Note On、離して Note Off を送信することはできないようでした。もう少し細かい制御ができれば、アプリの作り甲斐があるのですが。6 月に発表される iOS 9 に期待しています。

そのほか、いくつかのバグもあわせて修正しています。

今後ですが、次のバージョン (1.0.5) で、最新の Web MIDI API への対応を予定しています。今実装してあるのは少し古い Chrome 39 spec で、次のバージョンで Hotplug にも対応した Chrome 43 spec に合わせる予定です。中で使っている Web MIDI API の Polyfill は、WebMIDIAPIShimForiOS として GitHub で公開しています。こちらもあわせて更新されます。



2015年2月15日日曜日

Trying Gracenote API

Trying Gracenote API



My wife has tons of MD (mini disk). MD was a major medium for portable music player in '90s Japan. Unfortunately, it was killed by iPod. MD mediums and MD players no longer be able to buy nowadays. Therefore, she wanted to migrate songs from her MDs to iTunes library before her player breaks.

To help her, I bought a Behringer's USB Audio interface and connected her dated MD player. And I recorded whole tracks of the MDs through Audacity. Audacity has a function to split the recorded audio into multiple audio files by certain length of silences. The accuracy is so so. I needed to remove wrong split points sometimes. Anyway, the things worked well so far.

But, of course, these audio files have no name. It's a big deal nowadays. Because the song name is the ONLY identifier for selecting a song in iTunes library. But setting song name manually for all taped audio tracks is a heavy work... So, I tried Gracenote API to set song title into ID3 tag automatically. We can use Gracenote API for free of charge in non-commercial use.

I made a program for querying song title through Gracenote API. It's remodeled from a sample program in GNSDK. It can print a title string by querying fingerprint of the audio file which is designated in command line argument. I also made a simple shell script to rewrite ID3 tag from the output of the title query tool. I used id3v2 for editing ID3 tag. The accuracy of song name detection is slightly better than I expected. Anyway, it's really better than "no name". 

So, I could help her in return for chocolates her gave me today. (I wrote this article on 14th Feb)



2015年2月9日月曜日

DXi FM synth supports Bluetooth MIDI



DXi FM synthesizer version 3.8.0 is out. It supports Bluetooth MIDI instruments, e.g. Miselu C.24. Enjoy!

DXi FM synthesizer のバージョン 3.8.0 がリリースされ、Bluetooth MIDI 機器(Miselu の C.24 など)をサポートしました!お試しください。


2015年1月31日土曜日

Web MIDI Browser 1.0.1


Web MIDI Browser has been updated to 1.0.1. This new version includes an “Action Extension”. The Action Extension will let you launch the app from Action Menu in Mobile Safari. And then, Web MIDI Browser will automatically open the URL which is being opened in Safari at the time. The app’s functionalities are not enough for usual web browsing. So, I suggest
  • Use Safari in usual
  • Use Web MIDI Browser for web sites using Web MIDI API (You can smoothly launch the app from Action Menu)
And a small bug was fixed. Enjoy!

Web MIDI Browser のバージョン 1.0.1 をリリースしました。このバージョンには、”Action Extension” が同梱されています。Action Extension を使うと、iOS 標準のブラウザ Safari のアクションメニューから、このアプリを起動することができます。この時、Safari が開いている URL を自動的に開いてくれます。Web MIDI Browser のブラウザとしての機能は貧弱です。そのため、
  • 普段のウェブブラウズはもちろん Safari で
  • Web MIDI API を使ったサイト開くときだけアクションメニューから Web MIDI Browser にスイッチする
という使い方が良いと思います。

また、このバージョンで、小さなバグを直しました。
ご要望などあればぜひお知らせください。



2015年1月8日木曜日

iOS 8 Safari Action Extension でハマる - 解決編

iOS 8 Safari Action Extension でハマる - 解決編

先日の記事で、iOS 8 Safari Action Extension から、URL Scheme を使ったアプリ起動に失敗した件、結局解決できたので追記。

non-UI Extension 用に用意されている JavaScript アダプタ内で location.href を書き換え

Action Extension には、UIを提供するタイプ("Presents User Interface") のものと、UIを提供しないもの("No User Interface") の 2 種類がある。後者の場合、Safari から Extension が
起動されたときに、Extension にバンドルされた JavaScript がロードされるようになっている。この JavaScript では、Pre 処理と Post 処理を記述できるようになっている。Pre 処理 (ExtensionPreprocessingJS.run 関数)で、DOM から必要な要素をピックアップし、Native 側に渡す。で、Native 側で必要な処理を行い、Post 処理(ExtensionPreprocessingJS.finalize)に渡して DOM へ変更を反映するという設計思想。
この Post 処理の中で、location.href を変更すれば、Safari が URL scheme をキックしてくれるので、マッチした URL scheme が登録されているアプリを起動できる。

実装方法

JavaScript を Action.js として Extension にバンドルする。

Safari の Action Menu を開き、作成した Extension のアイコンをタップすると、-(void)beginRequestWithExtensionContext: が呼びだされる。Native 側では特になにもせず、completion handler を呼びだすだけ。ただ、completeRequestReturningItems に、適当なパラメータを渡してやらないと、なぜか、ExtensionPreprocessingJS.finalize() が呼ばれなかった。

もうちょっとシンプルな方法がありそうだけど、ひとまず目的は達成。あとで内容を整理して、Qiita に投稿する→投稿した


2015年1月1日木曜日

iOS 8 Safari Action Extension でハマる

Safari Action Extension でハマる

iOS 8 から、Safari Action Extension という、Mobile Safari のアクションメニューからプラグインのようにサードパーティアプリのコンポーネントを呼び出す拡張機能を提供できるようになった。早速これを使ってみようと思っていろいろ試したが結局使えなかった、という話。  →結局解決

Language: Swift を選択して生成した Action Extension のテンプレートが動かない

まず最初にハマったのが、Action Extension のテンプレートを生成するところで、Language: Swift を選んだところ、これが思うように動かない。具体的には、NSItemProvider の loadItemForTypeIdentifier の completionHandler が呼ばれない。結果、生成されるサンプルコード(DOM を操作して、背景色を赤にする)もちゃんと動いていない。

この問題は、テンプレート生成時に Language: Objective-C にすることで解決。Xcode 6.2 beta 3 でも再現するので Apple へバグレポートするかな...

Safari Action Extension からは Open URL できない

Extension のテンプレートは動くようになったので、本当にやりたかった、Extension から他のアプリの起動を試す。しかし、うまくいかない。まず、openURL: を使うために、UIApplication.sharedApplication が必要になるが、これにアクセスできない。まぁ、これは Extension のアーキテクチャから考えてもなんとなく想像できた。

Extension が起動されるときには、NSExtensionContext のインスタンスが渡されてきて、このインスタンスメソッドに openURL: がある。これだ!と思いきや、うまくいかない。NSExtensionContext の openURL: は、Today Extension からでないと使えないように制限がかけられている。
http://stackoverflow.com/questions/24297273/openurl-not-work-in-action-extension

で、この記事でも紹介されていた hack、UIWebView を経由して URL scheme をキックする方法を試したが、iOS 8.1.2 では弾かれてしまう。まぁ、仮に上手く動いたとしても、そもそも前述の openURL: の振舞いから想像するに、明確な設計思想による制約のようなので、App Review をパスできるかどうか微妙。

まとめ

結局、Action Extension から外部アプリを起動することはできなかった。
→解決しました