This module implements parsing and serializing of OSC messages.
Types
OscMessage = object address*: string args*: seq[OscValue]
- Source Edit
OscMidi {.packed.} = object portId*: uint8 status*: uint8 data1*: uint8 data2*: uint8
- MIDI message. Bytes from MSB to LSB are: port id, status byte, data1, data2 Source Edit
OscPacket = object case kind*: OscPacketKind of oscMessage: msg*: OscMessage of oscBundle: bundle*: OscBundle
- Source Edit
OscPacketKind = enum oscMessage, oscBundle
- Source Edit
OscType = enum oscFloat = "f", oscInt = "i", oscString = "s", oscBlob = "b", oscTrue = "T", oscFalse = "F", oscNil = "N", oscInf = "I", oscArray = "[", oscTime = "t", oscBigInt = "h", oscDouble = "d", oscChar = "c", oscColor = "r", oscMidi = "m"
- Source Edit
OscValue = object case kind*: OscType of oscInt: intVal*: int32 of oscFloat: floatVal*: float32 of oscString: strVal*: string of oscBlob: blobVal*: seq[byte] of oscTrue: nil of oscFalse: nil of oscNil: nil of oscInf: nil of oscArray: arrayVal*: seq[OscValue] of oscTime: timeVal*: OscTime of oscBigInt: bigIntVal*: int64 of oscDouble: doubleVal*: float64 of oscChar: charVal*: char of oscColor: colorVal*: OscColor of oscMidi: midiVal*: OscMidi
- Source Edit
Consts
OscInf = (kind: oscInf, intVal: 0, floatVal: 0.0, strVal: "", blobVal: [], arrayVal: [], timeVal: (seconds: 0'u, frac: 0'u), bigIntVal: 0, doubleVal: 0.0, charVal: 0, colorVal: (r: 0'u, g: 0'u, b: 0'u, a: 0'u), midiVal: (portId: 0'u, status: 0'u, data1: 0'u, data2: 0'u))
- Source Edit
OscNil = (kind: oscNil, intVal: 0, floatVal: 0.0, strVal: "", blobVal: [], arrayVal: [], timeVal: (seconds: 0'u, frac: 0'u), bigIntVal: 0, doubleVal: 0.0, charVal: 0, colorVal: (r: 0'u, g: 0'u, b: 0'u, a: 0'u), midiVal: (portId: 0'u, status: 0'u, data1: 0'u, data2: 0'u))
- Source Edit
OscTimeImmediate = (seconds: 0'u, frac: 1'u)
- Source Edit
Procs
proc `$`(msg: OscMessage): string {....raises: [], tags: [], forbids: [].}
- Source Edit
proc addArguments(buffer: var string; args: seq[OscValue]; pad: bool = true) {. ...raises: [], tags: [], forbids: [].}
- Source Edit
proc addMessage(buffer: var string; msg: OscMessage) {....raises: [], tags: [], forbids: [].}
- Write the given OscMessage to a string. This is the inverse of readMessage. Source Edit
proc addPaddedStr(buffer: var string; val: string) {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc addPaddedTags(buffer: var string; args: seq[OscValue]) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc dgram(msg: OscBundle): string {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Serialize the given OscBundle to a new string and return it. Source Edit
proc dgram(msg: OscMessage): string {....raises: [], tags: [], forbids: [].}
- Serialize the given OscMessage to a new string and return it. Source Edit
proc fractionToNano(fraction: uint32): uint32 {....raises: [], tags: [], forbids: [].}
- Source Edit
proc isImmediate(time: OscTime): bool {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc nanoToFraction(nanoseconds: uint32): uint32 {....raises: [], tags: [], forbids: [].}
- Source Edit
func parseMessage(data: string): OscMessage {....raises: [OscParseError], tags: [], forbids: [].}
- Parse the given data into an OscMessage object. Raise an OSCParseError if the data is invalid. Source Edit
proc readBundle(data: string): OscBundle {....raises: [OscParseError, Exception], tags: [RootEffect], forbids: [].}
- Source Edit
proc readBundle(data: string; i: var int): OscBundle {. ...raises: [OscParseError, Exception], tags: [RootEffect], forbids: [].}
- Source Edit
proc readPacket(data: string): OscPacket {....raises: [OscParseError, Exception], tags: [RootEffect], forbids: [].}
- Source Edit
proc readPacket(data: string; i: var int): OscPacket {. ...raises: [OscParseError, Exception], tags: [RootEffect], forbids: [].}
- Source Edit
proc toOscColor(c: Color; alpha: uint8): OscColor {....raises: [], tags: [], forbids: [].}
- Source Edit
proc toOscDouble(v: float64): OscValue {....raises: [], tags: [], forbids: [].}
- I decided to not add a % overload for float64, since it's not a standard OSC type and you want float32 most of the time. Source Edit
proc toTime(time: OscTime): Time {....raises: [], tags: [], forbids: [].}
-
Convert the given OSC/NTP timestamp to a Time object.
This conversation is lossy. Doing a round-trip will have a deviation of 1 nanosecond. See test/times.nim for the test that shows that.
NOTE: This does not handle the special case of an immediate time. You have to check using isImmediate yourself.
Source Edit
Templates
template msg(addrs: string; arguments: untyped): OscMessage
- Source Edit