oscType: Construct OSC Type Tag String from Input Data

View source: R/oscType.R

oscTypeR Documentation

Construct OSC Type Tag String from Input Data

Description

Constructs an Open Sound Control (OSC) Type Tag String from the R data types of the input data.

Usage

oscType(data = NULL, integer = "i", double = "d", character = "s",
  null = "N", typecomma = TRUE)

Arguments

data

list or vector

integer

character. Tag to use for R data type "integer". Default = "i", specifying a 32-bit signed big-endian 2'S compliment integer. (Identical to the R "integer" type.)

double

character. Tag to use for R data type "integer". Default = "d", specifying a 64 bit IEEE 754 double (Identical the R "double" type.)

character

character. Tag to use for R data type "character". Default = "s", specifying a string.

null

character. Tag to use for R data type "character". Default = "s", specifying a string. ="N", typecomma=TRUE

typecomma

logical. If typecomma=TRUE (default), a comma (",") is prepended to the type tag string.

Details

The input is first converted into a one-level list with all elements length 1 using listFlatten, then a string is assembled containing one type tag for each element in the input data. oscType detects the R object data type and assigns the OSC style type tag specified for that dataype in the arguments. Currently, only R data types "integer," "double," "character," "NULL," and "logical" are supported. R type "logical" always produces type tag "T" or "F".

An OSC Type Tag String is a string of single character type tags preceded by the "," character. If a function cannot accept OSC string representations using comma-initial type strings, the comma may be ommitted with typecomma=FALSE. Warning: this would be a non-standard representation of OSC. Any OSC-compliant function expecting a comma-inital type string may interpret a type string with comma removed as the first data argument and attempt to construct a new type string dynamically with heuristic methods.

oscType is agnostic about the interpretation of type tags. You can use oscType to convert R datatypes to tags conforming to OSC 1.0, OSC 1.1 or libo / odot, for example, or even to non-standard tags.

For reference, the OSC 1.0 and related "libo" typ tag specifications are included here:

OSC 1.0 TYPE TAGS, including extended types http://opensoundcontrol.org/spec-1.0

tag definition
i 32-bit signed integer (big-endian 2'S compliment; equivalent of R type "integer")
u 32-bit unsigned integer (big-endian)
h 64 bit signed integer (big-endian two’s complement)
f 32 bit float (big-endian IEEE 754)
d 64 bit double (IEEE 754; equivalent of R type "double")
c an ascii character, sent as 32 bits
r 32 bit RGBA color stored, each channel stored as an 8-bit value: e.g.:
rgba(1.0,0.8,0.0,1.0) = 11111111 11001100 00000000 11111111 = 4291559679
m 4 byte MIDI message. Bytes from MSB to LSB are: port id, status byte, data1, data2
s OSC-string (sequence of non-null ASCII characters followed by a null, followed by
0-3 additional null characters to make the total number of bits a multiple of 32.)
S Alternate type represented as an OSC-string
e.g. for systems that differentiate "symbols" from "strings"
b OSC-blob (int32 size count n, followed by n 8-bit bytes of arbitrary binary data,
followed by 0-3 zero bytes to make total number of bits a multiple of 32.)
T True (No data argument is passed)
F False (No data argument is passed)
N Nil or Null (No data argument is passed)
I Infinitum (or "Impulse")
[ 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.
t OSC-timetag (64-bit big-endian fixed-point NTP timestamp.)
First 32 bits specify the number of seconds since midnight on January 1, 1900.
Last 32 bits specify fractional parts of a second. (Precision is ~200 picoseconds.)
Special case: 63 zero bits followed by one in least significant bit (000...0001)
means "immediately."

libo TYPE TAGS (an extension of OSC 1.0) http://www.cnmat.berkeley.edu/sites/default/files/attachments/2015_Dynamic_Message_Oriented_Middleware.pdf

tag definition
c 8-bit signed integer (big-endian 2'S compliment)
C 8-bit unsigned integer (big-endian 2'S compliment)
u 16-bit signed integer (big-endian 2'S compliment)
U 16-bit unsigned integer (big-endian 2'S compliment)
i 32-bit signed integer (big-endian 2'S compliment; equivalent of R type "integer")
I 32-bit unsigned integer (big-endian 2'S compliment)
h 64 bit signed integer (big-endian two’s complement)
H 64 bit unsigned integer (big-endian two’s complement)
d 64 bit double (IEEE 754; equivalent of R type "double")
s OSC-string
S Alternate type represented as an OSC-string
b OSC-blob
B odot bundle
A executable code
T True (No data argument is passed)
F False (No data argument is passed)
N Nil or Null (No data argument is passed)
t OSC-timetag

Value

character. An "OSC Type Tag String." e.g. ",iisdTNf"

Examples

oscType(7.1)
oscType(7:9)
oscType(c("foo","gorp"))
data <- list(list(3:4,"apple"), TRUE, list(list(5.1,"foo"),NULL))
oscType(data)
oscType(data, double = "f", typecomma=FALSE)


allopole/ROSC documentation built on May 9, 2023, 10:09 p.m.