Open Sound Control 1.0仕様

バージョン 1.0, 2002年3月26日, Matt Wright

導入

Open Sound Control (OSC)は、コンピュータ、サウンド シンセサイザ、その他のマルチメディアデバイスの通信用に開発された、オープンで、トランスポート独立で、メッセージ指向のプロトコルである。

OSCの文法

このセクションではOSCデータの文法を定義する。

アトミックデータ型

全てのOSCデータは以下の基礎データ型のいずれかによって構成される:

int32
32ビット、ビッグエンディアン、2の補数による整数型
OSC-timetag
64ビット、ビッグエンディアン、固定小数点による時刻タグ(以下で意味を規定)
float32
32ビット、ビッグエンディアン、IEEE754浮動小数点数
OSC文字列 (OSC-string)
nullを終端とする非null ASCII文字の列。0~3個のnull文字をとり、32の倍数ビットに揃えられる。(OSC文字列の例) このドキュメントでは、例示されるOSC文字列はnull文字を終端とせず、二重引用符によって囲まれている。
OSC-blob
int32サイズの大きさを有し、8ビットの整数倍となる任意のバイナリデータ。0~3個の0バイトをとり、32の倍数ビットに揃えられる。

OSCの全てのアトミックデータ型のサイズは、32ビットの倍数となる。この事実により、もしOSCデータのブロックの先頭が32ビット境界にあれば、全てのOSCデータにおける数値が32ビットに揃えられることが保証される。

OSCパケット

OSCの転送単位はOSCパケットである。OSCパケットを送信するアプリケーションはOSCクライアントである。OSCパケットを受信するアプリケーションはOSCサーバである。

OSCパケットは、バイナリデータの連続ブロックであるコンテンツと、8ビット バイトの整数で表されるサイズからなる。 OSCパケットのサイズは常に4の倍数となる。

OSCパケットを配信する下位ネットワークが、OSCアプリケーションにコンテンツとサイズの両方を配信する責務を負う。 OSCパケットは、UDPのようなネットワークプロトコルによって、データグラムとして自然に表現される。TCPのようなストリームベースのプロトコルでは、ストリームはint32で最初のパケットを送り、最初のパケットの内容を続け、次のパケットのサイズを送る…といった順序で行われることになろう。

OSCパケットのコンテンツは、OSCメッセージまたはOSCバンドルである。パケットのコンテンツの1バイト目が、この2種類を明確に区別する。

OSCメッセージ

OSCメッセージは、OSCアドレスパターンOSC型タグ文字列、任意の数のOSC引数からなる。

備考: OSCの古い実装のいくつかは、OSC型タグ文字列を省略することがある。そのような実装が全てアップデートされるまで、OSC実装はそのようなOSC型タグ文字列の欠落に耐えるよう作成されるべきである。

OSCアドレスパターン

OSCアドレスパターンは、'/' 文字(前方向スラッシュ)で始まるOSC文字列である。

OSC型タグ文字列

OSC型タグ文字列は、','(コンマ)で始まり、そのメッセージのOSC引数に一致する数の文字の列で続けられる、OSC文字列である。 コンマ以降の各文字はOSC型タグと呼ばれ、OSC引数に対応する型を表す。 (OSC型タグ文字列がコンマで始まるという要件は、OSCメッセージにOSC型タグ文字列が欠落しているかどうかを、メッセージ受信者が判別するために有用なものである。)

この表では、OSC型タグと対応するOSC引数の型の対応を示す:

各OSC型タグの意味
OSC型タグ 対応する引数の型
i int32
f float32
s OSC文字列
b OSC-blob

OSCのアプリケーションには、この仕様で規定されていない、追加の非標準引数型を用いて通信するものがある。OSCアプリケーションは、これらの型を認識しなくてもよい。OSCアプリケーションは、OSC型タグ文字列のうちに認識できないOSC型タグを含むようなメッセージを、破棄すべきである。 追加の引数型を使用するアプリケーションは、次の表に示すOSC型タグを用いてそれらをエンコードしなければならない:

ある種の非標準引数型に用いられるOSC型タグ
OSC型タグ 対応する引数型
h 64ビット、ビッグエンディアン、2の補数による整数
t OSC時刻タグ
d 64ビット(倍精度)IEEE 754浮動小数点数
S OSC文字列として表現される型(例えば、"symbols" を "strings"と区別するシステム)
c 32ビットで送信されるASCII文字
r 32ビットのRGBA色
m 4バイトMIDIメッセージ. MSBからLSBの順に: ポートID、ステータスバイト、データ1、データ2
T 真。引数データ バイトには何も確保されない。
F 偽。引数データ バイトには何も確保されない。
N Nil値。引数データ バイトには何も確保されない。
I 無限。引数データ バイトには何も確保されない。
[ Indicates the beginning of an array. The tags following are for data in the Array until a close brace tag is reached.
] Indicates the end of an array.

OSC型タグ文字列の例

OSC引数

OSC引数の列は、それぞれの引数のバイナリ表現の連続列として表現される。

OSC バンドル

OSCバンドルは、順に、OSC文字列 "#bundle"、OSC時刻タグ、任意の数のOSCバンドル要素から成る。OSC時刻タグは、64ビットの固定小数点時刻タグであり、その意味は以下で説明する

1つのOSCバンドル要素は、サイズコンテンツからなる。 サイズは8ビットバイトの数を表すint32であり、常に4の倍数となる。 コンテンツは1つのOSCメッセージまたは1つのOSCバンドルとなる。

再帰的な定義であることに注意: バンドルにはバンドルが含まれうる。

この表は、2つ以上の要素を有するOSCバンドルの部分とそれぞれのサイズを8ビットバイトで示している。

OSCバンドルの部分
データ サイズ 目的
OSC文字列 "#bundle" 8バイト これがバンドルであることを認識する手段
OSC時刻タグ 8バイト このバンドル全体に適用される時刻タグ
最初のバンドル要素のサイズ int32 = 4バイト 最初のバンドル要素
最初のバンドル要素の内容 「最初のバンドル要素のサイズ」で指定されたバイト数
2番目のバンドル要素のサイズ int32 = 4バイト 2番目のバンドル要素
2番目のバンドル要素の内容 「2番目のバンドル要素のサイズ」で指定されたバイト数
etc.   さらなるバンドル要素

OSCのセマンティクス

このセクションではOSCデータのセマンティクス(意味)を定義する。

OSCアドレス空間とOSCアドレス

全てのOSCサーバには、OSCメソッドの集合が含まれる。 OSCメソッドは、OSCサーバが受信したOSCメッセージの潜在的な目的地であり、アプリケーションが利用可能にしている、それぞれの制御点に該当する。OSCメソッドを「呼び出す」というのは、プロシージャ コールに類するものである。メソッドと引数を渡して、そのメソッドを実行するということを意味するものといえる。

OSCサーバに含まれるOSCメソッドは、OSCアドレス空間と呼ばれるツリー構造に並べられる。このツリーのリーフノードはOSCメソッドであり、ブランチノードはOSCコンテナと呼ばれる。 OSCサーバのOSCアドレス空間は動的なものでありうる。つまり、そのコンテンツおよび形体は、時間とともに変化しうる。

ツリーのルート以外の各OSCメソッドおよび各OSCコンテナには、以下のものを除く印刷可能文字のASCII文字列からなるシンボル名がある:

OSCメソッドおよびOSCコンテナで許容されないASCII印刷可能文字
文字 名前 ASCIIコード (整数)
' ' 空白 32
# ナンバーサイン(いげた) 35
* アスタリスク 42
, コンマ 44
/ 前方向スラッシュ 47
? 疑問符 63
[ 開き角括弧 91
] 閉じ角括弧 93
{ 開き中括弧 123
} 閉じ中括弧 125

The OSC Address of an OSC Method is a symbolic name giving the full path to the OSC Method in the OSC Address Space, starting from the root of the tree. An OSC Method's OSC Address begins with the character '/' (forward slash), followed by the names of all the containers, in order, along the path from the root of the tree to the OSC Method, separated by forward slash characters, followed by the name of the OSC Method. The syntax of OSC Addresses was chosen to match the syntax of URLs. (OSC Address Examples)

OSC Message Dispatching and Pattern Matching

When an OSC server receives an OSC Message, it must invoke the appropriate OSC Methods in its OSC Address Space based on the OSC Message's OSC Address Pattern. This process is called dispatching the OSC Message to the OSC Methods that match its OSC Address Pattern. All the matching OSC Methods are invoked with the same argument data, namely, the OSC Arguments in the OSC Message.

The parts of an OSC Address or an OSC Address Pattern are the substrings between adjacent pairs of forward slash characters and the substring after the last forward slash character. (examples)

A received OSC Message must be disptched to every OSC method in the current OSC Address Space whose OSC Address matches the OSC Message's OSC Address Pattern. An OSC Address Pattern matches an OSC Address if

  1. The OSC Address and the OSC Address Pattern contain the same number of parts; and
  2. Each part of the OSC Address Pattern matches the corresponding part of the OSC Address.

A part of an OSC Address Pattern matches a part of an OSC Address if every consecutive character in the OSC Address Pattern matches the next consecutive substring of the OSC Address and every character in the OSC Address is matched by something in the OSC Address Pattern. These are the matching rules for characters in the OSC Address Pattern:

  1. '?' in the OSC Address Pattern matches any single character
  2. '*' in the OSC Address Pattern matches any sequence of zero or more characters
  3. A string of characters in square brackets (e.g., "[string]") in the OSC Address Pattern matches any character in the string. Inside square brackets, the minus sign (-) and exclamation point (!) have special meanings:
  4. A comma-separated list of strings enclosed in curly braces (e.g., "{foo,bar}") in the OSC Address Pattern matches any of the strings in the list.
  5. Any other character in an OSC Address Pattern can match only the same character.

Temporal Semantics and OSC Time Tags

An OSC server must have access to a representation of the correct current absolute time. OSC does not provide any mechanism for clock synchronization.

When a received OSC Packet contains only a single OSC Message, the OSC Server should invoke the correponding OSC Methods immediately, i.e., as soon as possible after receipt of the packet. Otherwise a received OSC Packet contains an OSC Bundle, in which case the OSC Bundle's OSC Time Tag determines when the OSC Bundle's OSC Messages' corresponding OSC Methods should be invoked. If the time represented by the OSC Time Tag is before or equal to the current time, the OSC Server should invoke the methods immediately (unless the user has configured the OSC Server to discard messages that arrive too late). Otherwise the OSC Time Tag represents a time in the future, and the OSC server must store the OSC Bundle until the specified time and then invoke the appropriate OSC Methods.

Time tags are represented by a 64 bit fixed point number. The first 32 bits specify the number of seconds since midnight on January 1, 1900, and the last 32 bits specify fractional parts of a second to a precision of about 200 picoseconds. This is the representation used by Internet NTP timestamps.The time tag value consisting of 63 zero bits followed by a one in the least signifigant bit is a special case meaning "immediately."

OSC Messages in the same OSC Bundle are atomic; their corresponding OSC Methods should be invoked in immediate succession as if no other processing took place between the OSC Method invocations.

When an OSC Address Pattern is dispatched to multiple OSC Methods, the order in which the matching OSC Methods are invoked is unspecified. When an OSC Bundle contains multiple OSC Messages, the sets of OSC Methods corresponding to the OSC Messages must be invoked in the same order as the OSC Messages appear in the packet. (example)

When bundles contain other bundles, the OSC Time Tag of the enclosed bundle must be greater than or equal to the OSC Time Tag of the enclosing bundle. The atomicity requirement for OSC Messages in the same OSC Bundle does not apply to OSC Bundles within an OSC Bundle.