Class: CZMQ::FFI::Zosc

Inherits:
Object
  • Object
show all
Defined in:
lib/czmq-ffi-gen/czmq/ffi/zosc.rb

Overview

Note:

This class is 100% generated using zproject.

Create and decode Open Sound Control messages. (OSC)

OSC is a serialisation format (and usually transported over UDP) which is supported by many applications and appliances. It is a de facto protocol for networking sound synthesizers, computers, and other multimedia devices for purposes such as musical performance or show control. It is also often used for rapid prototyping purposes due to the support by many applications and frameworks in this field. With ZeroMQ’s DGRAM sockets it is possible to use ZeroMQ to send and receive OSC messages which can be understood by any device supporting OSC.

Example creating an OSC message:

zosc_t* conm = zosc_create("/someaddress", "iihfdscF",
                    1, 2, 3, 3.14, 6.283185307179586, "greetings", 'q');

Decoding a message:

int rc = zosc_retr(oscmsg, "iihfdscF", &intx, &inty, &intz, &floatz,
                    &doublez, &strings, &charq, &someBool);

See the class’s test method for more examples how to use the class.

Defined Under Namespace

Classes: DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Zosc

Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.

Parameters:

  • ptr (::FFI::Pointer)
  • finalize (Boolean) (defaults to: true)


45
46
47
48
49
50
51
52
53
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 45

def initialize(ptr, finalize = true)
  @ptr = ptr
  if @ptr.null?
    @ptr = nil # Remove null pointers so we don't have to test for them.
  elsif finalize
    @finalizer = self.class.create_finalizer_for @ptr
    ObjectSpace.define_finalizer self, @finalizer
  end
end

Class Method Details

.__newObject



39
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 39

alias :__new :new

.create(address, format, *args) ⇒ CZMQ::Zosc

Create a new zosc message from the given format and arguments. The format type tags are as follows:

i - 32bit integer
h - 64bit integer
f - 32bit floating point number (IEEE)
d - 64bit (double) floating point number
s - string (NULL terminated)
t = timetag: an OSC timetag in NTP format (uint64_t)
S - symbol
c - char
m - 4 byte midi packet (8 digits hexadecimal)
T - TRUE (no value required)
F - FALSE (no value required)
N - NIL (no value required)
I - Impulse (for triggers) or INFINITUM (no value required)
b - binary blob

Parameters:

  • address (String, #to_s, nil)
  • format (String, #to_s, nil)
  • args (Array<Object>)

Returns:

  • (CZMQ::Zosc)


156
157
158
159
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 156

def self.create(address, format, *args)
  ptr = ::CZMQ::FFI.zosc_create(address, format, *args)
  __new ptr
end

.create_finalizer_for(ptr) ⇒ Proc

Parameters:

  • ptr (::FFI::Pointer)

Returns:

  • (Proc)


56
57
58
59
60
61
62
63
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 56

def self.create_finalizer_for(ptr)
  ptr_ptr = ::FFI::MemoryPointer.new :pointer

  Proc.new do
    ptr_ptr.write_pointer ptr
    ::CZMQ::FFI.zosc_destroy ptr_ptr
  end
end

.fromframe(frame) ⇒ CZMQ::Zosc

Create a new OSC message from the specified zframe. Takes ownership of the zframe.

Parameters:

Returns:

  • (CZMQ::Zosc)


110
111
112
113
114
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 110

def self.fromframe(frame)
  frame = frame.__ptr if frame
  ptr = ::CZMQ::FFI.zosc_fromframe(frame)
  __new ptr
end

.frommem(data, size) ⇒ CZMQ::Zosc

Create a new zosc message from memory. Take ownership of the memory and calling free on the data after construction.

Parameters:

  • data (::FFI::Pointer, #to_ptr)
  • size (Integer, #to_int, #to_i)

Returns:

  • (CZMQ::Zosc)


121
122
123
124
125
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 121

def self.frommem(data, size)
  size = Integer(size)
  ptr = ::CZMQ::FFI.zosc_frommem(data, size)
  __new ptr
end

.fromstring(oscstring) ⇒ CZMQ::Zosc

Create a new zosc message from a string. This the same syntax as zosc_create but written as a single line string.

Parameters:

  • oscstring (String, #to_s, nil)

Returns:

  • (CZMQ::Zosc)


131
132
133
134
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 131

def self.fromstring(oscstring)
  ptr = ::CZMQ::FFI.zosc_fromstring(oscstring)
  __new ptr
end

.is(self_) ⇒ Boolean

Probe the supplied object, and report if it looks like a zosc_t.

Parameters:

  • self_ (::FFI::Pointer, #to_ptr)

Returns:

  • (Boolean)


344
345
346
347
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 344

def self.is(self_)
  result = ::CZMQ::FFI.zosc_is(self_)
  result
end

.new(address) ⇒ CZMQ::Zosc

Create a new empty OSC message with the specified address string.

Parameters:

  • address (String, #to_s, nil)

Returns:

  • (CZMQ::Zosc)


101
102
103
104
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 101

def self.new(address)
  ptr = ::CZMQ::FFI.zosc_new(address)
  __new ptr
end

.packx(self_p) ⇒ Zframe

Transform zosc into a zframe that can be sent in a message. Take ownership of the chunk.

Parameters:

Returns:



301
302
303
304
305
306
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 301

def self.packx(self_p)
  self_p = self_p.__ptr_give_ref
  result = ::CZMQ::FFI.zosc_packx(self_p)
  result = Zframe.__new result, true
  result
end

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class.

Parameters:

  • verbose (Boolean)


496
497
498
499
500
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 496

def self.test(verbose)
  verbose = !(0==verbose||!verbose) # boolean
  result = ::CZMQ::FFI.zosc_test(verbose)
  result
end

.unpack(frame) ⇒ Zosc

Transform a zframe into a zosc.

Parameters:

Returns:



312
313
314
315
316
317
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 312

def self.unpack(frame)
  frame = frame.__ptr if frame
  result = ::CZMQ::FFI.zosc_unpack(frame)
  result = Zosc.__new result, true
  result
end

Instance Method Details

#__ptr::FFI::Pointer Also known as: to_ptr

Return internal pointer

Returns:

  • (::FFI::Pointer)

Raises:



70
71
72
73
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 70

def __ptr
  raise DestroyedError unless @ptr
  @ptr
end

#__ptr_give_ref::FFI::MemoryPointer

Note:

This detaches the current instance from the native object and thus makes it unusable.

Nullify internal pointer and return pointer pointer.

Returns:

  • (::FFI::MemoryPointer)

    the pointer pointing to a pointer pointing to the native object

Raises:



81
82
83
84
85
86
87
88
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 81

def __ptr_give_ref
  raise DestroyedError unless @ptr
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
  ptr_ptr.write_pointer @ptr
  __undef_finalizer if @finalizer
  @ptr = nil
  ptr_ptr
end

#__undef_finalizervoid

Note:

Only use this if you need to and can guarantee that the native object will be freed by other means.

This method returns an undefined value.

Undefines the finalizer for this object.



93
94
95
96
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 93

def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end

#addressString

Return the OSC address string

Returns:

  • (String)

Raises:



194
195
196
197
198
199
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 194

def address()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_address(self_p)
  result
end

#append(format, *args) ⇒ Integer

Append data to the osc message. The format describes the data that needs to be appended in the message. This essentially relocates all data! The format type tags are as follows:

i - 32bit integer
h - 64bit integer
f - 32bit floating point number (IEEE)
d - 64bit (double) floating point number
s - string (NULL terminated)
t = timetag: an OSC timetag in NTP format (uint64_t)
S - symbol
c - char
m - 4 byte midi packet (8 digits hexadecimal)
T - TRUE (no value required)
F - FALSE (no value required)
N - NIL (no value required)
I - Impulse (for triggers) or INFINITUM (no value required)
b - binary blob

Parameters:

Returns:

  • (Integer)

Raises:



247
248
249
250
251
252
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 247

def append(format, *args)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_append(self_p, format, *args)
  result
end

#data::FFI::Pointer

Return OSC chunk data. Caller does not own the data!

Returns:

  • (::FFI::Pointer)

Raises:



184
185
186
187
188
189
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 184

def data()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_data(self_p)
  result
end

#destroyvoid

This method returns an undefined value.

Destroy an OSC message



164
165
166
167
168
169
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 164

def destroy()
  return unless @ptr
  self_p = __ptr_give_ref
  result = ::CZMQ::FFI.zosc_destroy(self_p)
  result
end

#dump::FFI::AutoPointer

Return a string describing the the OSC message. The returned string must be freed by the caller.

Returns:

  • (::FFI::AutoPointer)

Raises:



322
323
324
325
326
327
328
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 322

def dump()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_dump(self_p)
  result = ::FFI::AutoPointer.new(result, LibC.method(:free))
  result
end

#dupZosc

Create copy of the message, as new chunk object. Returns a fresh zosc_t object, or null if there was not enough heap memory. If chunk is null, returns null.

Returns:

Raises:



277
278
279
280
281
282
283
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 277

def dup()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_dup(self_p)
  result = Zosc.__new result, true
  result
end

#first(type) ⇒ ::FFI::Pointer

Return a pointer to the item at the head of the OSC data. Sets the given char argument to the type tag of the data. If the message is empty, returns NULL and the sets the given char to NULL.

Parameters:

  • type (::FFI::Pointer, #to_ptr)

Returns:

  • (::FFI::Pointer)

Raises:



356
357
358
359
360
361
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 356

def first(type)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_first(self_p, type)
  result
end

#formatString

Return the OSC format of the message.

i - 32bit integer
h - 64bit integer
f - 32bit floating point number (IEEE)
d - 64bit (double) floating point number
s - string (NULL terminated)
t = timetag: an OSC timetag in NTP format (uint64_t)
S - symbol
c - char
m - 4 byte midi packet (8 digits hexadecimal)
T - TRUE (no value required)
F - FALSE (no value required)
N - NIL (no value required)
I - Impulse (for triggers) or INFINITUM (no value required)
b - binary blob

Returns:

  • (String)

Raises:



218
219
220
221
222
223
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 218

def format()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_format(self_p)
  result
end

#last(type) ⇒ ::FFI::Pointer

Return a pointer to the item at the tail of the OSC message. Sets the given char argument to the type tag of the data. If the message is empty, returns NULL.

Parameters:

  • type (::FFI::Pointer, #to_ptr)

Returns:

  • (::FFI::Pointer)

Raises:



381
382
383
384
385
386
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 381

def last(type)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_last(self_p, type)
  result
end

#next(type) ⇒ ::FFI::Pointer

Return the next item of the OSC message. If the list is empty, returns NULL. To move to the start of the OSC message call zosc_first ().

Parameters:

  • type (::FFI::Pointer, #to_ptr)

Returns:

  • (::FFI::Pointer)

Raises:



368
369
370
371
372
373
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 368

def next(type)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_next(self_p, type)
  result
end

#null?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 65

def null?
  !@ptr or @ptr.null?
end

#packZframe

Transform zosc into a zframe that can be sent in a message.

Returns:

Raises:



288
289
290
291
292
293
294
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 288

def pack()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_pack(self_p)
  result = Zframe.__new result, true
  result
end

#pop_bool(val) ⇒ Integer

Set the provided boolean from the type tag in the message. Booleans are not represented in the data in the message, only in the type tag. If the type tag at the current position does not correspond it will fail and return -1. Returns 0 on success.

Parameters:

  • val (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



472
473
474
475
476
477
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 472

def pop_bool(val)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_pop_bool(self_p, val)
  result
end

#pop_char(val) ⇒ Integer

Set the provided char from the value at the current cursor position in the message. If the type tag at the current position does not correspond it will fail and return -1. Returns 0 on success.

Parameters:

  • val (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



459
460
461
462
463
464
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 459

def pop_char(val)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_pop_char(self_p, val)
  result
end

#pop_double(val) ⇒ Integer

Set the provided double from the value at the current cursor position in the message. If the type tag at the current position does not correspond it will fail and return -1. Returns 0 on success.

Parameters:

  • val (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



433
434
435
436
437
438
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 433

def pop_double(val)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_pop_double(self_p, val)
  result
end

#pop_float(val) ⇒ Integer

Set the provided float from the value at the current cursor position in the message. If the type tag at the current position does not correspond it will fail and return -1. Returns 0 on success.

Parameters:

  • val (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



420
421
422
423
424
425
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 420

def pop_float(val)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_pop_float(self_p, val)
  result
end

#pop_int32(val) ⇒ Integer

Set the provided 32 bit integer from value at the current cursor position in the message. If the type tag at the current position does not correspond it will fail and return -1. Returns 0 on success.

Parameters:

  • val (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



394
395
396
397
398
399
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 394

def pop_int32(val)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_pop_int32(self_p, val)
  result
end

#pop_int64(val) ⇒ Integer

Set the provided 64 bit integer from the value at the current cursor position in the message. If the type tag at the current position does not correspond it will fail and return -1. Returns 0 on success.

Parameters:

  • val (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



407
408
409
410
411
412
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 407

def pop_int64(val)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_pop_int64(self_p, val)
  result
end

#pop_midi(val) ⇒ Integer

Set the provided 4 bytes (unsigned 32bit int) from the value at the current cursor position in the message. If the type tag at the current position does not correspond it will fail and return -1. Returns 0 on success.

Parameters:

  • val (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



485
486
487
488
489
490
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 485

def pop_midi(val)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_pop_midi(self_p, val)
  result
end

#pop_string(val) ⇒ Integer

Set the provided string from the value at the current cursor position in the message. If the type tag at the current position does not correspond it will fail and return -1. Returns 0 on success. Caller owns the string!

Parameters:

  • val (::FFI::Pointer, #to_ptr)

Returns:

  • (Integer)

Raises:



446
447
448
449
450
451
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 446

def pop_string(val)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_pop_string(self_p, val)
  result
end

This method returns an undefined value.

Dump OSC message to stdout, for debugging and tracing.

Raises:



333
334
335
336
337
338
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 333

def print()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_print(self_p)
  result
end

#retr(format, *args) ⇒ Integer

Retrieve the values provided by the given format. Note that zosc_retr creates the objects and the caller must destroy them when finished. The supplied pointers do not need to be initialized. Returns 0 if successful, or -1 if it failed to retrieve a value in which case the pointers are not modified. If an argument pointer is NULL is skips the value. See the format method for a detailed list op type tags for the format string.

Parameters:

Returns:

  • (Integer)

Raises:



265
266
267
268
269
270
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 265

def retr(format, *args)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_retr(self_p, format, *args)
  result
end

#sizeInteger

Return chunk data size

Returns:

  • (Integer)

Raises:



174
175
176
177
178
179
# File 'lib/czmq-ffi-gen/czmq/ffi/zosc.rb', line 174

def size()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zosc_size(self_p)
  result
end