翻译[The Open Sound Control 1.0 Specification]
Open Sound Control 1.0 说明
版本 1.0, 3月26日 2002年, Matt Wright
介绍
Introduction
Open Sound Control(OSC)是为了在计算机、声音合成器以及其他媒体设备间进行通讯而研发出的一种开放式的、独立传输的基于消息的协议。
Open Sound Control (OSC) is an open, transport-independent, message-based protocol developed for communication among computers, sound synthesizers, and other multimedia devices.
OSC 结构
OSC Syntax
这一节定义了OSC数据的结构
This section defines the syntax of OSC data.
原子数据类型
Atomic Data Types
所有的OSC数据都由以下基本数据类型组成:
All OSC data is composed of the following fundamental data types:
OSC Packets
The unit of transmission of OSC is an OSC Packet. Any application that sends OSC Packets is an OSC Client; any application that receives OSC Packets is an OSC Server.
OSC协议的数据单元叫做一个OSC Packet。所有发送OSC Packet的都是OSC Client,所有接收OSC Packet的都是OSC Server。
An OSC packet consists of its contents, a contiguous block of binary data, and its size, the number of 8-bit bytes that comprise the contents. The size of an OSC packet is always a multiple of 4.
一个OSC Packet由两部分组成,它的数据部分是一串连续的二进制数据,此外它还包括这串二进制数据的大小,也就是8-bit大小的数据的数量。OSC Packet的大小总是4的倍数
The underlying network that delivers an OSC packet is responsible for delivering both the contents and the size to the OSC application. An OSC packet can be naturally represented by a datagram by a network protocol such as UDP. In a stream-based protocol such as TCP, the stream should begin with an int32 giving the size of the first packet, followed by the contents of the first packet, followed by the size of the second packet, etc.
基础网络负责传输OSC Packet中的数据以及大小到OSC应用程序中去。一个OSC Packet可以通过类似UDP数据报的形式发出。如果使用TCP这种数据流协议,数据流起始为一个包含第一个Packet大小的int32数据,随后是第一个Packet的内容,随后是第二个Packet的大小,等等。
The contents of an OSC packet must be either an OSC Message or an OSC Bundle. The first byte of the packet’s contents unambiguously distinguishes between these two alternatives.
OSC Packet只能是OSC Message或者OSC Bundle。OSC Packet内容的第一个字节会明确指出它是哪种类型。
OSC Messages
An OSC message consists of an OSC Address Pattern followed by an OSC Type Tag String followed by zero or more OSC Arguments.
一个OSC Message由一个OSC Address Pattern以及一个OSC Type Tag String以及零个或者多个OSC Arguments组成
Note: some older implementations of OSC may omit the OSC Type Tag string. Until all such implementations are updated, OSC implementations should be robust in the case of a missing OSC Type Tag String.
注意:一些老版本的OSC程序可能忽略OSC Type Tag String。直到所有程序都更新到最新版的OSC协议时,OSC应用程序最好具有面对OSC Type Tag String的鲁棒性。
OSC Address Patterns
An OSC Address Pattern is an OSC-string beginning with the character ‘/’ (forward slash).
一个OSC Address Pattern是一个OSC-string类型,由’/’开始。
OSC Type Tag String
An OSC Type Tag String is an OSC-string beginning with the character ‘,’ (comma) followed by a sequence of characters corresponding exactly to the sequence of OSC Arguments in the given message. Each character after the comma is called an OSC Type Tag and represents the type of the corresponding OSC Argument. (The requirement for OSC Type Tag Strings to start with a comma makes it easier for the recipient of an OSC Message to determine whether that OSC Message is lacking an OSC Type Tag String.)
一个OSC Type Tag String是有字符’,’(逗号)起始的OSC-string类型,随后的字符串数据由Message中的OSC Argument的内容决定。逗号后面的每一个字符都是一个OSC Type Tag并用来表示OSC Argument的类型。(OSC Type Tag由逗号起始,主要是为了方便的判断OSC Message是否包含OSC Type Tag String。)
This table lists the correspondance between each OSC Type Tag and the type of its corresponding OSC Argument:
这个表格列出了每一个OSC Type Tag和OSC Argument的关系
The meaning of each OSC Type Tag
每一个OSC Type Tag的意思
OSC Type Tag | Type of corresponding argument |
---|---|
i | int32 |
f | float32 |
s | OSC-string |
b | OSC-blob |
Some OSC applications communicate among instances of themselves with additional, nonstandard argument types beyond those specified above. OSC applications are not required to recognize these types; an OSC application should discard any message whose OSC Type Tag String contains any unrecognized OSC Type Tags. An application that does use any additional argument types must encode them with the OSC Type Tags in this table:
一些OSC程序在内部通讯时可能包含一些额外的、非标准的超出上述描述的类型。OSC程序不需要识别这种类型;OSC程序应该丢弃那些OSC Type Tag String中包含不可识别的 OSC Type Tag的Message。如果一个程序需要使用额外的类型那么必须遵守下述表格中的OSC Type Tag:
OSC Type Tags that must be used for certain nonstandard argument types
OSC Type Tag必须使用下列非标准的类型
OSC Type Tag | Type of corresponding argument |
---|---|
h | 64 bit big-endian two’s complement integer |
h | 64位大端补码整数 |
t | OSC-timetag |
d | 64 bit (“double”) IEEE 754 floating point number |
d | 64位(“double”)IEEE754浮点数 |
S | Alternate type represented as an OSC-string (for example, for systems that differentiate “symbols” from “strings”) |
S | 和一个OSC-string一样的可变类型(比如,对系统而言用来区分“符号”和“字符” |
c | an ascii character, sent as 32 bits |
c | 一个ASCII字符,长度为32bits |
r | 32 bit RGBA color |
r | 32位RGBA颜色 |
m | 4 byte MIDI message. Bytes from MSB to LSB are: port id, status byte, data1, data2 |
m | 4字节MIDI消息 |
T | True. No bytes are allocated in the argument data. |
T | 真。这个类型没有数据 |
F | False. No bytes are allocated in the argument data. |
F | 假。这个类型没有数据 |
N | Nil. No bytes are allocated in the argument data. |
N | 空。这个类型没有数据 |
I | Infinitum. No bytes are allocated in the argument data. |
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 Type Tag String examples.
OSC Type Tag String 例子
OSC Arguments
A sequence of OSC Arguments is represented by a contiguous sequence of the binary representations of each argument.
一个OSC Arguments数据队列由多个包含了一串二进制数据的Argument组成
OSC Bundles
An OSC Bundle consists of the OSC-string “#bundle” followed by an OSC Time Tag, followed by zero or more OSC Bundle Elements. The OSC-timetag is a 64-bit fixed point time tag whose semantics are described below.
一个OSC Bundle有一个OSC-string“#bundle”开始,随后是OSC Time Tag,随后跟随零或多个OSC Bundle Element。OSC-timetag是一个64-bit的定点数时间标志,将在随后描述。
An OSC Bundle Element consists of its size and its contents. The size is an int32 representing the number of 8-bit bytes in the contents, and will always be a multiple of 4. The contents are either an OSC Message or an OSC Bundle.
一个OSC Bundle Element包含它的大小和内容。大小是一个int32表示内容中8-bit长度数据的数量,并且总是4的倍数。它的内容可以是一个OSC Message或者一个OSC Bundle。
Note this recursive definition: bundle may contain bundles.
注意这个递归形式:一个Bundle可能包含多个Bundle
This table shows the parts of a two-or-more-element OSC Bundle and the size (in 8-bit bytes) of each part.
下面的表格展示了两个或者多个Element的OSC Bundle以及每一部分的长度。
Parts of an OSC Bundle
OSC Bundle构成
Data | Size | Purpost |
---|---|---|
数据 | 大小 | 功能 |
OSC-string “#bundle” | 8 bytes | How to know that this data is a bundle |
OSC-string “#bundle” | 8 bytes | 如何辨别一个Bundle |
OSC-timetag | 8 bytes | Time tag that applies to the entire bundle |
OSC-timetag | 8 bytes | 整个Bundle的Time tag |
Size of first bundle element | int32 = 4 bytes | First |
第一个Bundle Element的大小 | int32=4 bytes | 第一个 |
First bundle element’s contents | As many bytes as given by “size of first bundle element” | bundle element |
第一个Bundle Element的内容 | Bundle Element | Bundle Element |
Size of Second bundle element | int32 = 4 bytes | Second |
第二个Bundle Element的大小 | int32=4 bytes | 第二个 |
Second bundle element’s contents | As many bytes as given by “size of Second bundle element” | bundle element |
第二个Bundle Element的内容 | Bundle Element | Bundle Element |
etc. | Addtional bundle elements | |
其他 |
OSC Semantics
This section defines the semantics of OSC data.
这一节描述OSC数据的语法结构。
OSC Address Spaces and OSC Addresses
Every OSC server has a set of OSC Methods. OSC Methods are the potential destinations of OSC messages received by the OSC server and correspond to each of the points of control that the application makes available. “Invoking” an OSC method is analogous to a procedure call; it means supplying the method with arguments and causing the method’s effect to take place.
每一个OSC Server都有一组OSC Method。OSC Method是OSC Server接收到OSC Message后的潜在目标,并且表示了应用程序的可用节点。“调用”OSC Method类似于过程调用; 它意味着为方法提供参数并使方法生效。
An OSC Server’s OSC Methods are arranged in a tree strcuture called an OSC Address Space. The leaves of this tree are the OSC Methods and the branch nodes are called OSC Containers. An OSC Server’s OSC Address Space can be dynamic; that is, its contents and shape can change over time.
OSC服务器的OSC方法被排列在称为OSC地址空间的树结构中。 这棵树的叶子就是OSC方法,分支节点被称为OSC容器。 OSC服务器的OSC地址空间可以是动态的; 也就是说,其内容和形状可以随间改变。
Each OSC Method and each OSC Container other than the root of the tree has a symbolic name, an ASCII string consiting of printable characters other than the following:
每个OSC方法和除树根之外的每个OSC容器都有一个符号名称,一个ASCII字符串,包含可打印字符,但不包括以下内容:
Printable ASCII characters not allowed in names of OSC Methods or OSC Containers
OSC方法或OSC容器名称中不允许使用可打印的ASCII字符
character | name | ASCII code (decimal) |
---|---|---|
’ ‘ | space | 32 |
# | number sign | 35 |
* | asterisk | 42 |
, | comma | 44 |
/ | forward slash | 47 |
? | question mark | 63 |
[ | open bracket | 91 |
] | close bracket | 93 |
{ | open curly brace | 123 |
} | close curly brace | 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方法的OSC地址是一个符号名称,提供OSC方法在OSC地址空间中从树的根开始的完整路。 OSC方法的OSC地址以字符“/”(斜杠)开头,后面跟着所有容器的名称,顺序是从树根到OSC方法,由斜杠字符分隔,最后是OSC方法的名称。 选择OSC地址的语法和匹配URL的语法相同。 (OSC地址示例)
OSC Message Dispatching and Pattern Matching
OSC消息分发和模式匹配
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.
当OSC服务器接收到OSC消息时,它必须基于OSC消息的OSC地址模式在其OSC地址空间中调用适当的OSC方法。 此过程称为将OSC消息分派给与其OSC地址模式匹配的OSC方法。 所有匹配的OSC方法都使用相同的参数数据进行调用,也就是,OSC消息中的OSC参数。
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)
OSC地址或OSC地址模式的片段就是是相邻正斜杠字符对之间的字符串,以及最后正斜杠字符之后的字符串。 (例子)
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
如果一个OSC信息中的OSC地址模式与当前OSC地址空间中的OSC方法的OSC地址匹配,那么这个接收到的OSC信息就要被分发到每一个OSC方法中。一个OSC地址模式与OSC地址匹配的条件是:
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:
如果OSC地址模式中的每个连续字符与OSC地址的下一个连续子字符匹配,并且OSC地址中的每个字符都与OSC地址模式中的某个字符匹配,则OSC地址模式的片段与OSC地址的片段匹配。 这些是OSC地址模式中字符的匹配规则:
Temporal Semantics and OSC Time Tags
时间语法以及OSC Time Tag
An OSC server must have access to a representation of the correct current absolute time. OSC does not provide any mechanism for clock synchronization.
OSC服务器必须能够访问一个代理获取当前绝对时间。 OSC不提供任何时钟同步的机制。
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.
当接收的OSC包仅包含单个OSC消息时,OSC服务器应立即调用相应的OSC方法,就是说,在接收到分组之后尽快执行。 或者,接收到的OSC包包含OSC Bundle,在这种情况下OSC Bundle的OSC时间标签确定何时应该调用与OSC Bundle中的OSC消息对应的OSC方法。 如果OSC时间标签表示的时间在当前时间之前或者等于当前时间,OSC服务器应立即调用方法(除非用户已将OSC服务器配置为丢弃到达时间太晚的消息)。 或者,OSC时间标签表示未来的时间,OSC服务器必须存储OSC Bundle直到指定的时间到来,然后调用相应的OSC方法。
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.”
时间标签由64位定点数表示。 前32位指定从1900年1月1日午夜起的秒数,最后32位指定一秒的小数部分,精度约为200皮秒。 这是NTP时间戳所使用的表示法。如果时间标签由63个0和一个组成,它表示一种特殊意义:“立即”
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.
同一个OSC Bundle中的OSC消息是原子的; 如果它们相应的OSC方法没有处在执行中,则应该被立即调用。
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)
当OSC地址模式被分发给多个OSC方法时,匹配的OSC方法被调用的顺序是随机的。 当OSC Bundle包含多个OSC消息时,必须以与OSC消息出现在OSC包中相同的顺序调用对应的OSC方法。 (例,PS:这个链接坏掉了)
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.
当一个Bundle包含其他Bundle时,被封装的Bundle的OSC时间标签必须大于或等于其依附的Bundle的OSC时间标签。OSC Bundle中的OSC Bundle不需要具有OSC Bundle中OSC Message的原子性。