Skip to content

Commit

Permalink
WIP: some sort of now taking a Ruby string, running through rtosc, re…
Browse files Browse the repository at this point in the history
…turning a ruby array
  • Loading branch information
xavriley committed Mar 23, 2016
1 parent 14531ce commit 30f196d
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 49 deletions.
26 changes: 26 additions & 0 deletions LICENSE.txt
@@ -1,3 +1,29 @@
# rtosc licence

Copyright (c) 2012 Mark McCurry

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

# fast_osc gem wrapper licence

Copyright (c) 2016 Xavier Riley

MIT License
Expand Down
26 changes: 24 additions & 2 deletions README.md
@@ -1,6 +1,8 @@
# FastOsc

TODO: Write a gem description
`WARNING - Work in progress. Not working yet`

A Ruby wrapper around [rtosc](https://github.com/fundamental/rtosc/) to encode and decode OSC messages.

## Installation

Expand All @@ -16,9 +18,29 @@ Or install it yourself as:

$ gem install fast_osc

This will only work on a mac at the moment as that's what the `librtosc.a` was compiled on.

## Usage

TODO: Write usage instructions here
Planned API

```
FastOsc.serialise(["/aa", "foo", "bar"]) #=> "/aa\x00ss\x00\x00foo\x00bar\x00"
FastOsc.deserialise("/aa\x00ss\x00\x00foo\x00bar\x00") #=> ["foo", "bar"]
```

What currently works

```
[19:07:29] xavierriley:fast_osc git:(master*) $ ruby -r ./lib/fast_osc.bundle -e 'puts FastOsc.deserialize("/ab\x00ss\x00\x00foo\x00bar\x00").inspect'
["foo"]
```

It's a start...

## Development notes

https://gist.github.com/xavriley/507eff0a75d4552fa56e

## Contributing

Expand Down
20 changes: 19 additions & 1 deletion ext/fast_osc/extconf.rb
@@ -1,4 +1,22 @@
require 'mkmf'

LIBDIR = RbConfig::CONFIG['libdir']
INCLUDEDIR = RbConfig::CONFIG['includedir']

HEADER_DIRS = ["/Users/xavierriley/Projects/rtosc/include/rtosc", INCLUDEDIR]

# setup constant that is equal to that of the file path that holds that static libraries that will need to be compiled against
LIB_DIRS = [LIBDIR, File.expand_path(File.join(File.dirname(__FILE__), "lib"))]

# array of all libraries that the C extension should be compiled against
libs = ['-lrtosc']

extension_name = 'fast_osc'
dir_config(extension_name)
dir_config(extension_name, HEADER_DIRS, LIB_DIRS)

# iterate though the libs array, and append them to the $LOCAL_LIBS array used for the makefile creation
libs.each do |lib|
$LOCAL_LIBS << "#{lib} "
end

create_makefile(extension_name)
50 changes: 5 additions & 45 deletions ext/fast_osc/fast_osc.c
@@ -1,43 +1,6 @@
#include <ruby.h>
#include <rtosc.h>

typedef struct {
int32_t len;
uint8_t *data;
} rtosc_blob_t;

typedef union {
int32_t i; //i,c,r
char T; //I,T,F,N
float f; //f
double d; //d
int64_t h; //h
uint64_t t; //t
uint8_t m[4];//m
const char *s; //s,S
rtosc_blob_t b; //b
} rtosc_arg_t;

size_t rtosc_amessage(char *buffer,
size_t len,
const char *address,
const char *arguments,
const rtosc_arg_t *args);

typedef struct {
const char *type_pos;
const uint8_t *value_pos;
} rtosc_arg_itr_t;

typedef struct {
char type;
rtosc_arg_t val;
} rtosc_arg_val_t;

rtosc_arg_itr_t rtosc_itr_begin(const char *msg);
rtosc_arg_val_t rtosc_itr_next(rtosc_arg_itr_t *itr);
int rtosc_itr_end(rtosc_arg_itr_t itr);

// Allocate VALUE variables to hold the modules we'll create. Ruby values
// are all of type VALUE. Qnil is the C representation of Ruby's nil.
VALUE FastOsc = Qnil;
Expand All @@ -46,7 +9,7 @@ VALUE FastOsc = Qnil;
// when this file is loaded, and the second is the actual business logic we're
// implementing.
void Init_fast_osc();
VALUE method_fast_osc_deserialize(RString *msg);
VALUE method_fast_osc_deserialize(VALUE self, VALUE msg);

// Initial setup function, takes no arguments and returns nothing. Some API
// notes:
Expand Down Expand Up @@ -76,17 +39,14 @@ void Init_fast_osc() {
// * INT2NUM converts a C int to a Ruby Fixnum object
// * rb_ary_store(VALUE, int, VALUE) sets the nth element of a Ruby array
//
VALUE method_fast_osc_deserialize(VALUE *rb_string) {
VALUE method_fast_osc_deserialize(VALUE self, VALUE msg) {
rtosc_arg_itr_t itr;
itr = rtosc_itr_begin(*msg, RSTRING_LEN(*msg), )

VALUE output = rb_ary_new2(2);
itr = rtosc_itr_begin(StringValuePtr(msg));

int arg_count = 0;
VALUE output = rb_ary_new();

while(!rtosc_itr_end(itr)) {
rb_ary_store(output, arg_count, VALUE(rtosc_itr_next(itr)));
arg_count++;
rb_ary_push(output, rb_str_new2(rtosc_itr_next(&itr).val.s));
}

return output;
Expand Down
Binary file added ext/fast_osc/lib/librtosc.a
Binary file not shown.
2 changes: 1 addition & 1 deletion fast_osc.gemspec
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib", "ext"]

spec.extensions << "ext/faye_websocket/extconf.rb"
spec.extensions << "ext/fast_osc/extconf.rb"

spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake"
Expand Down
Binary file added lib/fast_osc.bundle
Binary file not shown.
1 change: 1 addition & 0 deletions lib/fast_osc.rb
@@ -1,4 +1,5 @@
require "fast_osc/version"
require File.expand_path('../../faye_websocket', __FILE__)

module FastOsc
# Your code goes here...
Expand Down

0 comments on commit 30f196d

Please sign in to comment.