ラベル Android の投稿を表示しています。 すべての投稿を表示
ラベル Android の投稿を表示しています。 すべての投稿を表示

2021年8月16日月曜日

Unityアセット「MIDI Plugin for Mobile and Desktop」紹介(2026年更新)

最終更新: 2026-09-27 / 対象アセット版: 2.0.3

MIDI Plugin for Mobile and Desktop — Asset Store カバー画像

MIDI Plugin for Mobile and Desktop (Unity Asset Store)

ドキュメント(購入前でも閲覧可): マニュアル全文は supports リポジトリ で公開しています。入口は documents/index.md、 または README にある結合版 Markdown / PDF(英語 / 日本語 / 中文)です。

購入後はパッケージ内 Assets/MIDI/documents/ にも同内容が入ります。インストール済みバージョンに合った方を正としてください。本記事は紹介用です。

クイックリンク

Unity 向けプラグインをアセットストアで公開しています。製品名は MIDI Plugin for Mobile and Desktop です。

Unity プロジェクトに MIDI の送受信、SMF の再生・録音、各種トランスポートを追加します。 対象は モバイル・デスクトップ・Unity Editor・WebGL などです。

この記事では概要を紹介します。プラットフォーム対応表や API の詳細は 公開ドキュメント (購入後はパッケージ同梱の同内容)を参照してください。

このプラグインができること / できないこと

できること できないこと(別途必要)
MIDI 入出力・メッセージ配送 内蔵シンセ / SoundFont 再生そのもの
SMF / シーケンサ周辺 DAW 相当のオーディオエンジン代替
Maestro MPTK との任意連携で発音 MPTK の購入必須ではない(音は任意)

Editor や実機で「音」を出したい場合は、例えば Maestro MIDI Player Tool Kit など音源と組み合わせるか、Note On を受け取って自前のオーディオを鳴らしてください。

対応プラットフォーム(要約)

詳細・制限は公開ドキュメントの platforms.md (日本語: i18n/ja/platforms.md) を参照してください。

区分 例
モバイル iOS、Android(Meta Quest 含む)
デスクトップ / Editor Windows、macOS、Linux — Unity Editor の Play Mode 対応
Web WebGL(ブラウザの WebMIDI が許す範囲で USB / BLE)
トランスポート USB MIDI、Bluetooth MIDI (BLE)、Network / RTP-MIDI、Nearby、アプリ間 MIDI(プラットフォーム依存)
プロトコル MIDI 1.0、MIDI 2.0 / UMP(プラットフォーム依存。ドキュメント参照)

過去の記述について: 本記事の初版(2021年)時点ではモバイル向けビルドが中心で、 Unity Editor では動作しませんと書いていました。 v1.3.0 以降は Standalone および Unity Editor(Windows / macOS / Linux) に対応しています。 「Editor では動かない」という断定は現行版には当てはまりません。

インストール

  1. Unity Asset Store からインストールします。
  2. サンプルは Assets/MIDI/Samples/Scenes/ (まずは MidiSampleScene.unity、 または Window → MIDI → Samples)。
  3. Editor での確認: Play Mode に入り、Window → MIDI → Monitor でメッセージを監視できます。
  4. 実機: iOS / Android / Standalone / WebGL / UWP などへ切り替え、ビルドして実デバイスで USB / BLE を確認します。

購入前でも、GitHub 上の スタートガイド と プラットフォーム対応表 を読めます。

推奨 Unity バージョンは Asset Store の表記に従ってください(公開パッケージはおおむね 2022.3 系)。

MidiSampleScene

  • 左: MIDI デバイス選択と送信
  • 右: 受信メッセージ表示

MidiSampleScene — デバイス一覧・送信 UI・受信ログ

初期化は MidiManager.InitializeMidi 周辺にあります。 接続・切断は IMidiDeviceEventHandler、 デバイス名は MidiManager.GetDeviceName (名前未取得時は空のことがあります)。

MIDI デバイスとの接続

Android

  • USB / Bluetooth MIDI は検出・接続され、リストに表示されます(権限・Companion Device はドキュメント参照)。

iOS / macOS

  • Network MIDI や USB / BLE は Core MIDI の挙動に従います。BLE はスキャン時に選択 UI が出ます。

Windows / Linux / WebGL

  • 対応・非対応(例: Windows の BLE MIDI は未対応)は platforms.md を参照してください。

MIDI イベントの送信

MidiManager.Instance.SendMidiNoteOn(
    "deviceId",
    0 /*group*/,
    0 /*channel*/,
    60 /*note*/,
    127 /*velocity*/
);

Fluent API:

using jp.kshoji.unity.midi.util;

MidiSend.ToFirstOutput().Channel(0).NoteOn(60, 127);

MIDI イベントの受信

IMidiNoteOnEventHandler などを実装した MonoBehaviour を MidiManager.Instance.RegisterEventHandleObject(gameObject) で登録し、 InitializeMidi を呼び出します。全文は getting-started.md(日本語) を参照してください(パッケージ同梱版と同一内容です)。

Android ベースの VR(Meta Quest)

Oculus Quest / Meta Quest など Android ベースの VR でも動作します。 VR オブジェクトと実世界の MIDI 機器を相互に反応させられます。 Quest の USB / BLE は ビルド後処理 (GameActivity / Companion Device 含む)の手順に従ってください。

オープンソース

パッケージの一部はオープンソースです。不具合報告・機能要望は supports リポジトリ へどうぞ。

例:

(一覧は contacts.md)

2021年8月14日土曜日

MIDI Plugin for Mobile and Desktop (Unity Asset) — 2026 update

Last updated: 2026-09-27 · Asset version: 2.0.3

MIDI Plugin for Mobile and Desktop — Asset Store cover

MIDI Plugin for Mobile and Desktop (Unity Asset Store)

Documentation (no purchase required): Full manuals are published on the supports repository — start at documents/index.md or the combined PDF/Markdown listed in that README (English / 日本語 / 中文).

After you buy the asset, the same content also ships under Assets/MIDI/documents/ in the package. Prefer whichever copy matches your installed version. This blog post is an introduction only.

Quick links

I publish MIDI Plugin for Mobile and Desktop on the Unity Asset Store. It adds MIDI input/output, SMF play/record, and related transports to Unity projects — on mobile, desktop, Editor, WebGL, and more.

This post introduces the plugin. For platform matrices and APIs, use the public documentation (or the same files inside the package after purchase).

What this plugin is (and is not)

Is Is not
MIDI I/O and message routing A built-in synthesizer / SoundFont player
SMF / sequencer helpers A replacement for DAW audio engines
Optional integration with Maestro MPTK for sound Required to buy MPTK (sound is optional)

If you need audible notes in the Editor or on device, pair this plugin with a sound source (for example Maestro MIDI Player Tool Kit), or drive your own audio from Note On events.

Platforms (summary)

Current support includes (details and caveats in platforms.md):

Area Examples
Mobile iOS, Android (including Meta Quest)
Desktop / Editor Windows, macOS, Linux — Unity Editor Play Mode supported
Web WebGL (USB / BLE via WebMIDI where the browser allows)
Transports USB MIDI, Bluetooth MIDI (BLE), Network / RTP-MIDI, Nearby, Inter-App MIDI (platform-dependent)
Protocols MIDI 1.0, MIDI 2.0 / UMP (platform-dependent; see docs)

Historical note: When this article was first written (2021), the product focused on mobile builds and did not run in the Unity Editor. From v1.3.0 onward, Standalone and Unity Editor (Windows / macOS / Linux) are supported. Please ignore any older statement that “the plugin doesn't work with Unity Editor.”

Install

  1. Install from the Unity Asset Store.
  2. Open a sample under Assets/MIDI/Samples/Scenes/ (start with MidiSampleScene.unity or the sample menu: Window → MIDI → Samples).
  3. For Editor testing: enter Play Mode, then open Window → MIDI → Monitor to watch messages.
  4. For device builds: switch platform (iOS / Android / Standalone / WebGL / UWP), build, and run on hardware when you need real USB/BLE devices.

Before purchasing, you can read the full Getting Started and platform matrix on GitHub.

Recommended Unity: follow the Asset Store listing (currently 2022.3+ lineage for the published package).

MidiSampleScene

The sample shows:

  • Left: device selection and send controls
  • Right: received MIDI messages

MidiSampleScene — device list, send controls, and received MIDI log

Initialization lives around MidiManager.InitializeMidi. Device attach/detach uses IMidiDeviceEventHandler. Device names come from MidiManager.GetDeviceName (may be empty until the name is known).

Connect MIDI devices

Android

  • USB / Bluetooth MIDI devices are discovered and listed (permissions and Companion Device options apply — see docs).

iOS / macOS

  • Network MIDI and USB/BLE follow Apple Core MIDI behavior; BLE selection UI appears when scanning.

Windows / Linux / WebGL

  • See platforms.md for what is ○ / △ / unsupported (e.g. Windows BLE MIDI is not supported yet).

Sending MIDI events

MidiManager.Instance.SendMidiNoteOn(
    "deviceId",
    0 /*group*/,
    0 /*channel*/,
    60 /*note*/,
    127 /*velocity*/
);

Fluent helper:

using jp.kshoji.unity.midi.util;

MidiSend.ToFirstOutput().Channel(0).NoteOn(60, 127);

Receiving MIDI events

Implement handler interfaces (for example IMidiNoteOnEventHandler) on a MonoBehaviour, register with MidiManager.Instance.RegisterEventHandleObject(gameObject), then call InitializeMidi. Full snippets: getting-started.md (same file ships in the package).

VR (Meta Quest)

Android-based headsets such as Meta Quest work with the Android backend. You can drive real MIDI hardware from VR objects and the reverse. For USB MIDI / BLE on Quest, follow Build PostProcessing notes (including GameActivity / Companion Device).

Open source dependencies

Parts of the package rely on open-source libraries (many by the same author). Issue reports and feature requests are welcome on GitHub — start at the supports repository.

Examples:

(Full list: contacts.md.)

2015年1月21日水曜日

MIDI over Bluetooth LE library for Android

I've been developing the library to enable BLE MIDI feature on the Android devices from last year. The Apple Bluetooth Low Energy MIDI Specification(PDF) had revealed at December 2014. And finally, I implemented all of features on the specification.

Using this library, the app can connect with BLE MIDI devices, and BLE MIDI compatible iOS/Android/OS X apps. On the Android Lollipop, the app can act as BLE MIDI device.

Note:
This Apple's specification has not been approved by MIDI Manufacturers Association(MMA). I've asked about the specification to MMA at the past, but it was under discussion with MMA members.
The MMA's official release version's specification might be different from Apple's one.

The library's features

With this library, the Android can provide BLE MIDI Central / Peripheral features.

BLE MIDI Central feature

The Android app can host BLE MIDI devices. The app can receive MIDI messages from BLE MIDI devices, and send MIDI messages to them.
This feature requires Android KitKat(4.4 / API Level 19) or later.

BLE MIDI Peripheral feature

The Android app can pretend as BLE MIDI device. The application on the another machine(Android / iOS / OS X) can connect with the Android app.

2014年11月10日月曜日

BLE MIDIのAndroid向けライブラリを作っています

iOS 8での新機能、MIDI over Bluetooth LEの最初のデバイス「mi.1」がindiegogoにて発表されていたので、早速投資して3つポチりました。


その後、ブツが届いたのはいいのですがファームウェアが導入されておらず、実際に使えるようになるまでにしばらく掛かりました。
製品版ではファームウェア書き込み済の状態で出荷しないとユーザが混乱しそうです。

まだmi.1が届いていないうちから、Android 4.3にて追加されたBluetooth LEのAPIを使ってMIDIっぽい通信をするライブラリを書いていました。
Appleが仕様を作るとして、極力既存のMIDIと互換を持たせたシンプルな形に実装するだろう、おそらくBluetooth LEにレガシMIDIのデータをそのまま垂れ流す程度のものだろう、などと想像しつつ先行して実装していました。
mi.1のファームウェアを更新した後、受信したデータをログに出したりしつつプロトコルを調整して、受信までは動作確認できました。

というわけで、まだ道半ばですが現状報告な感じで。

2013年4月5日金曜日

仮想化環境で動くAndroid「AndroVM」を使ってみた

過去記事「仮想マシン上のAndroidでUSBホストを使う」で載せてたAndroid-x86なVMイメージが「AndroVM」として公開されていたので使ってみました。

仮想ディスクイメージのダウンロード

上記の「ダウンロード」のページから「vbox86tp version with gapps & houdini & flash」などといったファイルをダウンロードします。
「vbox86tp」「vbox86t」「vbox86p」の三種類がありますが、「t」がTablet、「p」がPhoneを指すようです。Google Playからアプリをダウンロードしたい場合は「with gapps & 〜〜」のバージョンをダウンロードします。

VirtualBoxにインポートして、設定を変更

VirtualBoxを開き「ファイル→仮想アプライアンスのインポート」から、ダウンロードした「ova」形式のファイルを指定してインポートします。
VirtualBox Managerから、仮想マシン「androVM……」の設定を開き、下記のように設定を変更します。
  • ディスプレイ→ビデオメモリ を 適量 (64MBに変更しました)
  • ディスプレイ→3Dアクセラレーションを有効化 をオン (効くかどうかはわかりませんが…)
  • ネットワーク→アダプター1にホストオンリーアダプターを指定。無い場合はVirtualBoxの設定から作成できます。アダプター2はそのままにします(Wi-Fi用として認識されるようです)
あとは普通にVMを実行すれば起動します。

IPアドレスは「androVM Configuration」というアプリで確認できます。
上記画像の場合、コマンドラインから adb connect 192.168.56.101 とやると、デバッグ接続ができます。(もちろん、デバッグ機能を有効にする必要があります)。

ざっくり使ってみた感想

  • OSのバージョンは4.1.1
  • 起動まで10秒くらい。速い。
  • 動作も普通にサクサクしてる。
  • メモリは1GBとけっこう消費します。
  • rootが使えたり、busyboxがインストールされていたり。アレなファイルを探したりするのが楽です。
  • USBデバイスもつながります。
  • センサーとかNFCとかのデバイス系が絡まないアプリであれば、けっこう快適に開発できる環境だと思います。

2012年12月26日水曜日

[Android Advent Calendar] 自作のUSBデバイスを、Androidで動かす

Android Advent Calendar 2012/12/26(表) 向けの記事です。裏は@l_b__さんです。

今年の後半にかけてAndroidのUSBホスト周りに少し詳しくなってきた、@kshojiです。Android USB MIDI Driverなどというものを作って公開しております。

USBデバイスを自分で作って、Android側でドライバを書いたら、好きなデバイスを作ってAndroidで自由に動かせて、楽しいんじゃないかなー。ということで、今回この記事を書いてみます。
TwitterのTLで尋ねてみると、USB HIDなデバイスが今時の流行っぽいので、それに乗ってみることにします。USBデバイスの自作と、そのデバイスに対応するアプリ作成の参考になれば嬉しいです。

AndroidがUSBホストに対応

Android OS 3.1からUSBホスト機能に対応して、アプリで、JavaのAPIを使ってUSBデバイスのドライバが書けるようになりました。LinuxのデバイスドライバといえばC(libusb)で書く、もしくはカーネル側をいじるという印象があるので、これはすごく画期的なことだと思います。なんといっても、Javaはとっつきやすいですから。

Android SDKにもUSBミサイルランチャを操作するサンプルが付いています。USBミサイルランチャは色々な環境でサンプルとして使われているようです。

注:必ずしもUSBデバイスであればなんでも認識する、というわけではないようです。HTC J ButterflyではUSB HIDなデバイスは認識しましたが、USB MIDIなデバイスは認識しませんでした。

AndroidでのUSBホストの使いかた

Android の USBホストの公式ドキュメントはこちらからどうぞ。

githubのリポジトリにこの記事用のコード一式を置いてみました。
いちおう、見通しがよくなるようにしているつもりです。
…と言っても、AbstractDeviceActivityクラスあたりから見ていくと、なんとなくわかるかな、程度ですが。WTFPLにしてあるので、煮るなり焼くなりお好きにどうぞ。

2012年12月21日金曜日

In-App Billing version 3を使ってみた


先日、既存の有料アプリを無料化→アプリ内課金を追加しよう、という流れで実装をしてみました。
たまたま新しいバージョンのライブラリが出たタイミングだったようで、折角だからこのライブラリを使って実装してみたときのメモです。

In-App Billing version3との遭遇

いつも通りに、「In-App Billingのサンプルが載っているブログ・サイトを探して、それを参考にしながら実装を進めていこう!」 と思っていたところ、IInAppBillingService.aidlを使ったサンプルがさっぱり見つからず、見つかるのはIMarketBillingService.aidlを使うものばかり…。
記事がないとか、そんなバカな…とか思っていたら、Android Developer Blogの記事を見つけました。つい最近バージョンアップしてたんですね。

先の記事によると、向上した点はこんな感じのようです。

  • 設計を改善して、アプリが完結に書けてデバッグ・メンテナンスしやすくなった。以前だと数100行書かないといけなかったコードが、50行くらいでできるように。
  • 堅牢なアーキテクチャにより、決済のロストが少なくなった。
  • ローカルへのキャッシュによって、API 呼び出しが高速になった。
  • 待望されていた、「一度だけ購入できるアイテム」の購入や、アイテム情報の問合せができるようになった。

SDKのサンプルを試そう

というわけで、SDKのサンプルを見ていくことにしました。まずは、SDK Managerから「Google Play Billing Library」をインストールします。
サンプルプロジェクトはSDKをインストールしたディレクトリ内の「extras/google/play_billing/in-app-billing-v03」にあります。Eclipseに取り込んでビルドします。

2012年11月2日金曜日

Android USB MIDI Driverのご紹介

Android USB MIDI Driverって?

「Android 3.1 (API Level 12)以降向けの、USB MIDIを使うためのライブラリ」です。
Android 3系のタブレットや、Android4系のスマートフォンを使って、特に改造やroot化することなしに、USB MIDI対応の楽器や機器を繋げることができるようになります。

注意:端末がUSB Host機能に対応している必要があります。USB Host対応端末であっても、USB MIDI機器が認識しない場合があります。

USB MIDI対応デバイスの例:キーボード、電子ピアノ、シンセサイザー、音源モジュールなどの楽器・コントローラ、変換ケーブルなどのPC用MIDIインタフェースなど。

ライブラリのソースコードは、こちらのgithubリポジトリからダウンロードできます。Apache ライセンス バージョン 2.0です。
https://github.com/kshoji/USB-MIDI-Driver

応用アプリの例

  • (楽器のほうの)キーボードを使ってプレゼンを操作
  • 演奏をディスプレイ上にリアルタイムで可視化
  • TENORI-ON/monomeのようなインタラクティブなシーケンサー
  • 加速度やジャイロなどのセンサーを使用したコントローラ
などなど…

2012年10月17日水曜日

仮想マシン上のAndroidでUSBホストを使う

Android SDKに含まれるエミュレータはUSBデバイスの接続に対応していません。
「android-x86」のLiveCDイメージを使うことで、USBホストのテストがPC上で可能になります。
今回はVMWare FusionとVirtualBoxで動かしてみました。


  • ISOイメージをこちらからダウンロードします。「new version here」というリンクのもの(android-x86-vm-20120130.iso.gz)を使用しました。→ http://www.buildroid.org/blog/?p=86 
  • 新しい仮想マシンをセットアップし、CDドライブにLiveCDを指定してVMを開始します。
  • 「Live CD - Run Android-x86 without installation」を選択して、Androidを起動します。
  • VirtualBoxの場合、「Machine」メニューから「Disable Mouse Integration」をチェックします。
  • VMware/VirtualBoxの「ネットワークアダプタ」のモードを「ブリッジ(自動設定)」「Bridged Adapter」に変更します。
  • Android側の「Terminal Emulator」アプリを開き、以下のコマンドを実行します。固定IPを設定するので、LAN内で空いているIPアドレスを確認しておいてください。(今回は192.168.1.111とします)。
$ su
# ifconfig eth0 192.168.1.111 up



  • ホストOS上から、下記のコマンドを実行します。
$ adb connect 192.168.1.111

これで、仮想マシンのAndroidとadbが接続され、Eclipseなどからアプリが流しこめます。
仮想マシン側にUSBデバイスを接続することで、そのデバイスをAndroidで使用することができます。