fast_osc 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +48 -0
- data/README.md +95 -0
- data/Rakefile +5 -0
- data/ext/fast_osc/extconf.rb +28 -0
- data/ext/fast_osc/fast_osc_wrapper.c +155 -0
- data/ext/fast_osc/rtosc.c +781 -0
- data/ext/fast_osc/rtosc.h +269 -0
- data/fast_osc.gemspec +26 -0
- data/lib/fast_osc/version.rb +3 -0
- data/lib/fast_osc.rb +6 -0
- metadata +100 -0
@@ -0,0 +1,269 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2012 Mark McCurry
|
3
|
+
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
5
|
+
* copy of this software and associated documentation files (the "Software"),
|
6
|
+
* to deal in the Software without restriction, including without limitation
|
7
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
8
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
9
|
+
* Software is furnished to do so, subject to the following conditions:
|
10
|
+
*
|
11
|
+
* The above copyright notice and this permission notice (including the next
|
12
|
+
* paragraph) shall be included in all copies or substantial portions of the
|
13
|
+
* Software.
|
14
|
+
*
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
22
|
+
* DEALINGS IN THE SOFTWARE.
|
23
|
+
*
|
24
|
+
* @file rtosc.h
|
25
|
+
*/
|
26
|
+
#ifndef RTOSC_H
|
27
|
+
#define RTOSC_H
|
28
|
+
#include <stdarg.h>
|
29
|
+
#include <stdint.h>
|
30
|
+
#include <stddef.h>
|
31
|
+
#include <stdbool.h>
|
32
|
+
|
33
|
+
#ifdef __cplusplus
|
34
|
+
extern "C" {
|
35
|
+
#endif
|
36
|
+
|
37
|
+
typedef struct {
|
38
|
+
int32_t len;
|
39
|
+
uint8_t *data;
|
40
|
+
} rtosc_blob_t;
|
41
|
+
|
42
|
+
typedef union {
|
43
|
+
int32_t i; //i,c,r
|
44
|
+
char T; //I,T,F,N
|
45
|
+
float f; //f
|
46
|
+
double d; //d
|
47
|
+
int64_t h; //h
|
48
|
+
uint64_t t; //t
|
49
|
+
uint8_t m[4];//m
|
50
|
+
const char *s; //s,S
|
51
|
+
rtosc_blob_t b; //b
|
52
|
+
} rtosc_arg_t;
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Write OSC message to fixed length buffer
|
56
|
+
*
|
57
|
+
* On error, buffer will be zeroed.
|
58
|
+
* When buffer is NULL, the function returns the size of the buffer required to
|
59
|
+
* store the message
|
60
|
+
*
|
61
|
+
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
62
|
+
* //Example messages
|
63
|
+
* char buffer[128];
|
64
|
+
* rtosc_message(buffer,128,"/path","TFI");
|
65
|
+
* rtosc_message(buffer,128,"/path","s","foobar");
|
66
|
+
* rtosc_message(buffer,128,"/path","i",128);
|
67
|
+
* rtosc_message(buffer,128,"/path","f",128.0);
|
68
|
+
* const char blob[4] = {'a','b','c','d'};
|
69
|
+
* rtosc_message(buffer,128,"/path","b",4,blob);
|
70
|
+
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
71
|
+
*
|
72
|
+
* @param buffer Memory to write to
|
73
|
+
* @param len Length of buffer
|
74
|
+
* @param address OSC pattern to send message to
|
75
|
+
* @param arguments String consisting of the types of the following arguments
|
76
|
+
* @param ... OSC arguments to pass forward
|
77
|
+
* @returns length of resulting message or zero if bounds exceeded
|
78
|
+
*/
|
79
|
+
size_t rtosc_message(char *buffer,
|
80
|
+
size_t len,
|
81
|
+
const char *address,
|
82
|
+
const char *arguments,
|
83
|
+
...);
|
84
|
+
|
85
|
+
/**
|
86
|
+
* @see rtosc_message()
|
87
|
+
*/
|
88
|
+
size_t rtosc_vmessage(char *buffer,
|
89
|
+
size_t len,
|
90
|
+
const char *address,
|
91
|
+
const char *arguments,
|
92
|
+
va_list va);
|
93
|
+
|
94
|
+
/**
|
95
|
+
* @see rtosc_message()
|
96
|
+
*/
|
97
|
+
size_t rtosc_amessage(char *buffer,
|
98
|
+
size_t len,
|
99
|
+
const char *address,
|
100
|
+
const char *arguments,
|
101
|
+
const rtosc_arg_t *args);
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Returns the number of arguments found in a given message
|
105
|
+
*
|
106
|
+
* @param msg well formed OSC message
|
107
|
+
* @returns number of arguments in message
|
108
|
+
*/
|
109
|
+
unsigned rtosc_narguments(const char *msg);
|
110
|
+
|
111
|
+
/**
|
112
|
+
* @param msg well formed OSC message
|
113
|
+
* @param i index of argument
|
114
|
+
* @returns the type of the ith argument in msg
|
115
|
+
*/
|
116
|
+
char rtosc_type(const char *msg, unsigned i);
|
117
|
+
|
118
|
+
typedef struct {
|
119
|
+
const char *type_pos;
|
120
|
+
const uint8_t *value_pos;
|
121
|
+
} rtosc_arg_itr_t;
|
122
|
+
|
123
|
+
typedef struct {
|
124
|
+
char type;
|
125
|
+
rtosc_arg_t val;
|
126
|
+
} rtosc_arg_val_t;
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Create an argument iterator for a message
|
130
|
+
* @param msg OSC message
|
131
|
+
* @returns an initialized iterator
|
132
|
+
*/
|
133
|
+
rtosc_arg_itr_t rtosc_itr_begin(const char *msg);
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Gets the next argument in a message
|
137
|
+
* @param itr OSC message iterator
|
138
|
+
* @returns a type value pair from the message
|
139
|
+
*/
|
140
|
+
rtosc_arg_val_t rtosc_itr_next(rtosc_arg_itr_t *itr);
|
141
|
+
|
142
|
+
/**
|
143
|
+
* Determines if the iterator is at the end of the argument list
|
144
|
+
* @param itr OSC message iterator
|
145
|
+
* @returns 1 if there are no more elements, 0 otherwise
|
146
|
+
*/
|
147
|
+
int rtosc_itr_end(rtosc_arg_itr_t itr);
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Blob data may be safely written to
|
151
|
+
* @param msg OSC message
|
152
|
+
* @param i index of argument
|
153
|
+
* @returns an argument by value via the rtosc_arg_t union
|
154
|
+
*/
|
155
|
+
rtosc_arg_t rtosc_argument(const char *msg, unsigned i);
|
156
|
+
|
157
|
+
/**
|
158
|
+
* @param msg OSC message
|
159
|
+
* @param len Message length upper bound
|
160
|
+
* @returns the size of a message given a chunk of memory.
|
161
|
+
*/
|
162
|
+
size_t rtosc_message_length(const char *msg, size_t len);
|
163
|
+
|
164
|
+
typedef struct {
|
165
|
+
char *data;
|
166
|
+
size_t len;
|
167
|
+
} ring_t;
|
168
|
+
|
169
|
+
/**
|
170
|
+
* Finds the length of the next message inside a ringbuffer structure.
|
171
|
+
*
|
172
|
+
* @param ring The addresses and lengths of the split buffer, in a compatible
|
173
|
+
* format to jack's ringbuffer
|
174
|
+
* @returns size of message stored in ring datastructure
|
175
|
+
*/
|
176
|
+
size_t rtosc_message_ring_length(ring_t *ring);
|
177
|
+
|
178
|
+
|
179
|
+
/**
|
180
|
+
* Validate if an arbitrary byte sequence is an OSC message.
|
181
|
+
* @param msg pointer to memory buffer
|
182
|
+
* @param len length of buffer
|
183
|
+
*/
|
184
|
+
bool rtosc_valid_message_p(const char *msg, size_t len);
|
185
|
+
|
186
|
+
/**
|
187
|
+
* @param OSC message
|
188
|
+
* @returns the argument string of a given message
|
189
|
+
*/
|
190
|
+
const char *rtosc_argument_string(const char *msg);
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Generate a bundle from sub-messages
|
194
|
+
*
|
195
|
+
* @param buffer Destination buffer
|
196
|
+
* @param len Length of buffer
|
197
|
+
* @param tt OSC time tag
|
198
|
+
* @param elms Number of sub messages
|
199
|
+
* @param ... Messages
|
200
|
+
* @returns legnth of generated bundle or zero on failure
|
201
|
+
*/
|
202
|
+
size_t rtosc_bundle(char *buffer, size_t len, uint64_t tt, int elms, ...);
|
203
|
+
|
204
|
+
/**
|
205
|
+
* Find the elements in a bundle
|
206
|
+
*
|
207
|
+
* @param msg OSC bundle
|
208
|
+
* @param len Upper bound on the length of the bundle
|
209
|
+
* @returns The number of messages contained within the bundle
|
210
|
+
*/
|
211
|
+
size_t rtosc_bundle_elements(const char *msg, size_t len);
|
212
|
+
|
213
|
+
/**
|
214
|
+
* Fetch a message within the bundle
|
215
|
+
*
|
216
|
+
* @param msg OSC bundle
|
217
|
+
* @param i index of sub-message
|
218
|
+
* @returns The ith message within the bundle
|
219
|
+
*/
|
220
|
+
const char *rtosc_bundle_fetch(const char *msg, unsigned i);
|
221
|
+
|
222
|
+
/**
|
223
|
+
* Get the size of a particular bundle element
|
224
|
+
*
|
225
|
+
* @param msg OSC bundle
|
226
|
+
* @param i Index of sub-message
|
227
|
+
* @returns The size of the ith sub-message in bytes
|
228
|
+
*/
|
229
|
+
size_t rtosc_bundle_size(const char *msg, unsigned i);
|
230
|
+
|
231
|
+
/**
|
232
|
+
* Test if the buffer contains a bundle
|
233
|
+
*
|
234
|
+
* @param msg OSC message
|
235
|
+
* @returns true if message is a bundle
|
236
|
+
*/
|
237
|
+
int rtosc_bundle_p(const char *msg);
|
238
|
+
|
239
|
+
/**
|
240
|
+
* @returns Time Tag for a bundle
|
241
|
+
*/
|
242
|
+
uint64_t rtosc_bundle_timetag(const char *msg);
|
243
|
+
|
244
|
+
|
245
|
+
/**
|
246
|
+
* This is a non-compliant pattern matcher for dispatching OSC messages
|
247
|
+
*
|
248
|
+
* Overall the pattern specification is
|
249
|
+
* (normal-path)(\#digit-specifier)?(/)?(:argument-restrictor)*
|
250
|
+
*
|
251
|
+
* @param pattern The pattern string stored in the Port
|
252
|
+
* @param msg The OSC message to be matched
|
253
|
+
* @returns true if a normal match and false if unmatched
|
254
|
+
*/
|
255
|
+
bool rtosc_match(const char *pattern, const char *msg);
|
256
|
+
|
257
|
+
|
258
|
+
/**
|
259
|
+
* Attempt to match a rtosc style path while ignoring arguments
|
260
|
+
*
|
261
|
+
* @param pattern rtosc pattern
|
262
|
+
* @param msg a normal C string or a rtosc message
|
263
|
+
*/
|
264
|
+
const char *rtosc_match_path(const char *pattern, const char *msg);
|
265
|
+
|
266
|
+
#ifdef __cplusplus
|
267
|
+
};
|
268
|
+
#endif
|
269
|
+
#endif
|
data/fast_osc.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fast_osc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fast_osc"
|
8
|
+
spec.version = FastOsc::VERSION
|
9
|
+
spec.authors = ["Xavier Riley"]
|
10
|
+
spec.email = ["xavriley@hotmail.com"]
|
11
|
+
spec.summary = %q{Serialize and deserialize Open Sound Control messages}
|
12
|
+
spec.description = %q{Serialize and deserialize Open Sound Control messages using rtosc}
|
13
|
+
spec.homepage = "https://github.com/xavriley/fast_osc"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib", "ext"]
|
20
|
+
|
21
|
+
spec.extensions << "ext/fast_osc/extconf.rb"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rake-compiler"
|
26
|
+
end
|
data/lib/fast_osc.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast_osc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Xavier Riley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake-compiler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Serialize and deserialize Open Sound Control messages using rtosc
|
56
|
+
email:
|
57
|
+
- xavriley@hotmail.com
|
58
|
+
executables: []
|
59
|
+
extensions:
|
60
|
+
- ext/fast_osc/extconf.rb
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- ext/fast_osc/extconf.rb
|
69
|
+
- ext/fast_osc/fast_osc_wrapper.c
|
70
|
+
- ext/fast_osc/rtosc.c
|
71
|
+
- ext/fast_osc/rtosc.h
|
72
|
+
- fast_osc.gemspec
|
73
|
+
- lib/fast_osc.rb
|
74
|
+
- lib/fast_osc/version.rb
|
75
|
+
homepage: https://github.com/xavriley/fast_osc
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
- ext
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.6
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Serialize and deserialize Open Sound Control messages
|
100
|
+
test_files: []
|