Skip to content

Commit

Permalink
Merge pull request #30 from davidgranstrom/topic/bugfixes-v1.0.1
Browse files Browse the repository at this point in the history
Bugfixes v1.0.1
  • Loading branch information
davidgranstrom authored Feb 1, 2021
2 parents a5d141e + 126c4bf commit 6f71db4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ local message = osc.new_message {
osc:send(message)
```

## Command line utilities

`losc` provides two command line tools, `loscsend`/`loscrecv` that can be used
to send and receive OSC data via UDP.

Note that both tools requires [`lua-socket`](https://luarocks.org/modules/luasocket/luasocket).

```shell
loscsend - Send an OSC message via UDP.

usage: loscsend ip port address [types [args]]
supported types: b, d, f, h, i, s, t
example: loscsend localhost 57120 /test ifs 1 2.3 "hi"
```
```shell
loscrecv - Dump incoming OSC data.

usage: loscsend port
example: loscrecv 9000
```
## API
The API is divided into two parts:
Expand Down
28 changes: 23 additions & 5 deletions bin/loscrecv
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,30 @@ local osc = losc.new {plugin = plugin.new()}

osc:add_handler('*', function(data)
local tt = Timetag.new_from_timestamp(data.timestamp)
local time = string.format('%04x.%04x', tt:seconds(), tt:fractions())
local time = string.format('%08x.%08x', tt:seconds(), tt:fractions())
local ok, message = pcall(osc.new_message, data.message)
if not ok then
print(message)
return
end
io.write(time .. ' ')
io.write(data.message.address .. ' ')
io.write(data.message.types .. ' ')
for _, a in ipairs(data.message) do
io.write(tostring(a) .. ' ')
io.write(message:address() .. ' ')
io.write(message:types() .. ' ')
for i, type_, arg_ in message:iter() do
if type_ == 's' then
io.write(string.format('"%s" ', arg_))
elseif type_ == 'b' then
io.write(string.format('[%d byte blob] ', #arg_))
elseif type_ == 'f' or type_ == 'd' then
io.write(string.format('%06f ', arg_))
elseif type_ == 'i' or type_ 'h' then
io.write(string.format('%d ', arg_))
elseif type_ == 't' then
local tmp = Timetag.new_from_timestamp(arg_)
string.format('%08x.%08x', tmp:seconds(), tmp:fractions())
else
io.write(tostring(arg_) .. ' ')
end
end
io.write('\n')
end)
Expand Down
2 changes: 1 addition & 1 deletion src/losc/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ local Timetag = require(relpath .. '.timetag')
local Pattern = require(relpath .. '.pattern')

local losc = {
_VERSION = 'losc v1.0.0',
_VERSION = 'losc v1.0.1',
_URL = 'https://github.com/davidgranstrom/losc',
_DESCRIPTION = 'Open Sound Control (OSC) library for lua/luajit.',
_LICENSE = [[
Expand Down
2 changes: 1 addition & 1 deletion src/losc/plugins/udp-libuv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function M:send(packet, address, port)
address = address or self.options.sendAddr
port = port or self.options.sendPort
packet = assert(Packet.pack(packet))
self.handle:udp_try_send(packet, address, port)
self.handle:try_send(packet, address, port)
end

return M

0 comments on commit 6f71db4

Please sign in to comment.