Skip to content

Commit

Permalink
First commit!
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
Brun0oO committed Sep 16, 2021
0 parents commit 73360f4
Show file tree
Hide file tree
Showing 20 changed files with 2,119 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Defold Protocol Buffer Text Files (https://github.com/github/linguist/issues/5091)
*.animationset linguist-language=JSON5
*.atlas linguist-language=JSON5
*.camera linguist-language=JSON5
*.collection linguist-language=JSON5
*.collectionfactory linguist-language=JSON5
*.collectionproxy linguist-language=JSON5
*.collisionobject linguist-language=JSON5
*.cubemap linguist-language=JSON5
*.display_profiles linguist-language=JSON5
*.factory linguist-language=JSON5
*.font linguist-language=JSON5
*.gamepads linguist-language=JSON5
*.go linguist-language=JSON5
*.gui linguist-language=JSON5
*.input_binding linguist-language=JSON5
*.label linguist-language=JSON5
*.material linguist-language=JSON5
*.mesh linguist-language=JSON5
*.model linguist-language=JSON5
*.particlefx linguist-language=JSON5
*.render linguist-language=JSON5
*.sound linguist-language=JSON5
*.sprite linguist-language=JSON5
*.spinemodel linguist-language=JSON5
*.spinescene linguist-language=JSON5
*.texture_profiles linguist-language=JSON5
*.tilemap linguist-language=JSON5
*.tilesource linguist-language=JSON5

# Defold JSON Files
*.buffer linguist-language=JSON

# Defold GLSL Shaders
*.fp linguist-language=GLSL
*.vp linguist-language=GLSL

# Defold Lua Files
*.editor_script linguist-language=Lua
*.render_script linguist-language=Lua
*.script linguist-language=Lua
*.gui_script linguist-language=Lua
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.internal
/build
.externalToolBuilders
.DS_Store
Thumbs.db
.lock-wscript
*.pyc
.project
.cproject
builtins
7 changes: 7 additions & 0 deletions CONTRIBUTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Contribution guide

If you have some improvements to bring the project, feel free to open a pull request.

Please stick to the indentation style used throughout the project (K&R-like).


21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Bruno Plantier

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 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.
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
![osc](./docs/osc_logo.png)

# Open Sound Control Library

## Overview


Open Sound Control (OSC) is an open, transport-independent, message-based protocol developed for communication among computers, sound synthesizers and other multimedia devices.

This library aims to provide the [OSC 1.0](http://opensoundcontrol.org/spec-1_0.html) protocol to any defold application.
It's a pure lua implementation, there's no platform dependent librarie.



## Installation

You can use OSC in your own project by adding this project as a [Defold Library dependency](https://defold.com/manuals/libraries/). Open your **game.project** file and in the **dependencies** field under **project** add:

https://github.com/Brun0oO/defold-osc/archive/master.zip

Or point to the ZIP file of a [specific OSC release](https://github.com/Brun0oO/defold-osc/releases).


## Basic usage
### Receiving of messages
Create a script with the following code, add it to a game object:

```lua
local osc = require('osc.init')
local plugin = require('osc.plugins.udp-socket-non-blocking')

function init(self)
-- Initialize the osc mechanism
local udp = plugin.new {
recvAddr = 'localhost',
recvPort = 9000,
ignore_late = true, -- ignore late bundles
}
self.osc = osc.new {plugin = udp}

-- Bind the receipt of a message to a dedicated callback
self.osc:add_handler('/foo/bar', function(data)
local msg = data.message
print('Received OscMessage => address: ' .. msg.address, 'timestamp: ' .. data.timestamp)
for index, argument in ipairs(msg) do
print(' arg index: ' .. index, ' value: ' .. argument)
end
end)

self.osc:open()
end

-- Very important call to handle sockect reading and the receipt of messages !!
function update(self, dt)
self.osc:update()
end

```

Have a look to the example folder !o)

### Sending of messages
Create a script with the following code, add it to a game object:

```lua
local osc = require('osc.init')
local plugin = require('osc.plugins.udp-socket-non-blocking')

function init(self)
-- Initialize the osc mechanism
local udp = plugin.new {
recvAddr = 'localhost',
recvPort = 9000,
ignore_late = true, -- ignore late bundles
}
self.osc = osc.new {plugin = udp}

-- Create a message
local message = osc.new_message {
address = '/foo/bar',
types = 'ifsb',
123, 1.234, 'hi', 'blobdata'
}

-- Send it over UDP
self.osc:send(message)
end


```

## Contributing
There are probably bugs. Please report them!
Did you improve some of the code? Have a look to [CONTRIBUTE.md](./CONTRIBUTE.md) for details about how to contribute to this project.

## Credits

* OSC 1.0 implementation for lua and luajit from [davidgranstrom/losc](https://github.com/davidgranstrom/losc)
Binary file added docs/osc_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions example/main.collection
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "main"
scale_along_z: 0
embedded_instances {
id: "go"
data: "components {\n"
" id: \"main\"\n"
" component: \"/example/main.script\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
58 changes: 58 additions & 0 deletions example/main.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
local osc = require('osc.init')
local plugin = require('osc.plugins.udp-socket-non-blocking')



local function print_data(data)
local msg = data.message
print('Received OscMessage => address: ' .. msg.address, 'timestamp: ' .. data.timestamp)
if #msg ~=0 then
for index, argument in ipairs(msg) do
print(' arg index: ' .. index, 'value: ' .. argument)
end
else
print(' no arg provided')
end
end

function init(self)
local udp = plugin.new {
recvAddr = 'localhost',
recvPort = 9000,
ignore_late = true, -- ignore late bundles
}
self.osc = osc.new {plugin = udp}



local _self = self
self.osc:add_handler('/test', function(data)
test(_self, data)
end)
self.osc:add_handler('/param/{x,y,z}', function(data)
param(_self, data)
end)


host, port, error = self.osc:open()
if error ~= nil then
print("Failed to start OSC server, error: " .. error)
else
print("UDP OSC server started on address "..host.." (port:"..port..")")
end
end

function update(self, dt)
self.osc:update() -- This call is very important to handle socket reading !!!
end

function test(self, data)
print_data(data)
end

function param(self, data)
print_data(data)
end



19 changes: 19 additions & 0 deletions game.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[bootstrap]
main_collection = /example/main.collectionc

[script]
shared_state = 1

[display]
width = 960
height = 640

[android]
input_method = HiddenInputField

[project]
title = defold-osc

[library]
include_dirs = osc

4 changes: 4 additions & 0 deletions input/game.input_binding
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mouse_trigger {
input: MOUSE_BUTTON_1
action: "touch"
}
Loading

0 comments on commit 73360f4

Please sign in to comment.