Fix More 0.4 Bitrot
This commit is contained in:
parent
687d7a4fc8
commit
9a607f4312
51
src/OSC.jl
51
src/OSC.jl
|
@ -17,6 +17,7 @@
|
||||||
module OSC
|
module OSC
|
||||||
import Base.show
|
import Base.show
|
||||||
export OscMsg, path
|
export OscMsg, path
|
||||||
|
|
||||||
macro incfp(x) quote begin
|
macro incfp(x) quote begin
|
||||||
local gensym_ = $(esc(x))
|
local gensym_ = $(esc(x))
|
||||||
$(esc(x)) = $(esc(x))+1
|
$(esc(x)) = $(esc(x))+1
|
||||||
|
@ -32,11 +33,11 @@ path(msg::OscMsg) = stringify(msg.data)
|
||||||
function stringify(data::Array{Uint8})
|
function stringify(data::Array{Uint8})
|
||||||
zeroInd = find(data.== 0)
|
zeroInd = find(data.== 0)
|
||||||
if(length(zeroInd) == 0)
|
if(length(zeroInd) == 0)
|
||||||
return string(map(char, data)...)
|
return string(map(Char, data)...)
|
||||||
elseif(zeroInd[1] == 0)
|
elseif(zeroInd[1] == 0)
|
||||||
return nothing
|
return nothing
|
||||||
else
|
else
|
||||||
return string(map(char, data[1:zeroInd[1]-1])...)
|
return string(map(Char, data[1:zeroInd[1]-1])...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ function names(msg::OscMsg)#::ASCIIString
|
||||||
return stringify(msg.data[pos+1:end]); #skip comma
|
return stringify(msg.data[pos+1:end]); #skip comma
|
||||||
end
|
end
|
||||||
|
|
||||||
strip_args(args::ASCIIString) = replace(replace(args,"]",""),"[","")
|
strip_args(args::AbstractString) = replace(replace(args,"]",""),"[","")
|
||||||
|
|
||||||
function narguments(msg::OscMsg)
|
function narguments(msg::OscMsg)
|
||||||
length(strip_args(names(msg)))
|
length(strip_args(names(msg)))
|
||||||
|
@ -207,7 +208,7 @@ function rtosc_amessage(buffer::Array{Uint8},
|
||||||
buffer[@incfp(pos)] = ((i>>8) & 0xff);
|
buffer[@incfp(pos)] = ((i>>8) & 0xff);
|
||||||
buffer[@incfp(pos)] = (i & 0xff);
|
buffer[@incfp(pos)] = (i & 0xff);
|
||||||
for(U = b)
|
for(U = b)
|
||||||
buffer[@incfp(pos)] = uint8(U);
|
buffer[@incfp(pos)] = Uint8(U);
|
||||||
end
|
end
|
||||||
pos = align(pos)
|
pos = align(pos)
|
||||||
end
|
end
|
||||||
|
@ -241,14 +242,14 @@ function rtosc_argument(msg::OscMsg, idx::Int)
|
||||||
|
|
||||||
if(typeChar in "htd")
|
if(typeChar in "htd")
|
||||||
t::Uint64 = 0
|
t::Uint64 = 0
|
||||||
t |= (uint64(msg.data[@incfp(arg_pos)]) << 56);
|
t |= (Uint64(msg.data[@incfp(arg_pos)]) << 56);
|
||||||
t |= (uint64(msg.data[@incfp(arg_pos)]) << 48);
|
t |= (Uint64(msg.data[@incfp(arg_pos)]) << 48);
|
||||||
t |= (uint64(msg.data[@incfp(arg_pos)]) << 40);
|
t |= (Uint64(msg.data[@incfp(arg_pos)]) << 40);
|
||||||
t |= (uint64(msg.data[@incfp(arg_pos)]) << 32);
|
t |= (Uint64(msg.data[@incfp(arg_pos)]) << 32);
|
||||||
t |= (uint64(msg.data[@incfp(arg_pos)]) << 24);
|
t |= (Uint64(msg.data[@incfp(arg_pos)]) << 24);
|
||||||
t |= (uint64(msg.data[@incfp(arg_pos)]) << 16);
|
t |= (Uint64(msg.data[@incfp(arg_pos)]) << 16);
|
||||||
t |= (uint64(msg.data[@incfp(arg_pos)]) << 8);
|
t |= (Uint64(msg.data[@incfp(arg_pos)]) << 8);
|
||||||
t |= (uint64(msg.data[@incfp(arg_pos)]));
|
t |= (Uint64(msg.data[@incfp(arg_pos)]));
|
||||||
if(typeChar == 'h')
|
if(typeChar == 'h')
|
||||||
return reinterpret(Int64, t)
|
return reinterpret(Int64, t)
|
||||||
elseif(typeChar == 'd')
|
elseif(typeChar == 'd')
|
||||||
|
@ -260,16 +261,16 @@ function rtosc_argument(msg::OscMsg, idx::Int)
|
||||||
return reinterpret(Float32,msg.data[arg_pos+(3:-1:0)])[1]
|
return reinterpret(Float32,msg.data[arg_pos+(3:-1:0)])[1]
|
||||||
elseif(typeChar in "rci")
|
elseif(typeChar in "rci")
|
||||||
i::Uint32 = 0
|
i::Uint32 = 0
|
||||||
i |= (uint32(msg.data[@incfp(arg_pos)]) << 24);
|
i |= (Uint32(msg.data[@incfp(arg_pos)]) << 24);
|
||||||
i |= (uint32(msg.data[@incfp(arg_pos)]) << 16);
|
i |= (Uint32(msg.data[@incfp(arg_pos)]) << 16);
|
||||||
i |= (uint32(msg.data[@incfp(arg_pos)]) << 8);
|
i |= (Uint32(msg.data[@incfp(arg_pos)]) << 8);
|
||||||
i |= (uint32(msg.data[@incfp(arg_pos)]));
|
i |= (Uint32(msg.data[@incfp(arg_pos)]));
|
||||||
if(typeChar == 'r')
|
if(typeChar == 'r')
|
||||||
return uint32(i)
|
return Uint32(i)
|
||||||
elseif(typeChar == 'c')
|
elseif(typeChar == 'c')
|
||||||
return char(i)
|
return Char(i)
|
||||||
else
|
else
|
||||||
return reinterpret(Int32, i)
|
return reinterpret(Int32, i);
|
||||||
end
|
end
|
||||||
elseif(typeChar in "m")
|
elseif(typeChar in "m")
|
||||||
m = Array(Uint8, 4)
|
m = Array(Uint8, 4)
|
||||||
|
@ -279,7 +280,7 @@ function rtosc_argument(msg::OscMsg, idx::Int)
|
||||||
m[4] = msg.data[@incfp(arg_pos)]
|
m[4] = msg.data[@incfp(arg_pos)]
|
||||||
return m
|
return m
|
||||||
elseif(typeChar in "b")
|
elseif(typeChar in "b")
|
||||||
len::Uint32 = 0
|
len::Int32 = 0
|
||||||
len |= (msg.data[@incfp(arg_pos)] << 24);
|
len |= (msg.data[@incfp(arg_pos)] << 24);
|
||||||
len |= (msg.data[@incfp(arg_pos)] << 16);
|
len |= (msg.data[@incfp(arg_pos)] << 16);
|
||||||
len |= (msg.data[@incfp(arg_pos)] << 8);
|
len |= (msg.data[@incfp(arg_pos)] << 8);
|
||||||
|
@ -307,21 +308,15 @@ function showField(io::IO, msg::OscMsg, arg_id)
|
||||||
map = ['i' Int32; 'f' Float32; 's' String; 'b' :Blob; 'h' Int32; 't' Uint64;
|
map = ['i' Int32; 'f' Float32; 's' String; 'b' :Blob; 'h' Int32; 't' Uint64;
|
||||||
'd' Float64; 'S' Symbol; 'c' Char; 'r' :RBG; 'm' :Midi; 'T' true;
|
'd' Float64; 'S' Symbol; 'c' Char; 'r' :RBG; 'm' :Midi; 'T' true;
|
||||||
'F' false; 'N' Nothing]
|
'F' false; 'N' Nothing]
|
||||||
dict = Dict{Char, Any}(map[:,1][:],map[:,2][:])
|
dict = Dict{Char, Any}(zip(Vector{Char}(map[:,1][:]),map[:,2][:]))
|
||||||
dict['I'] = Inf
|
dict['I'] = Inf
|
||||||
typeChar::Char = argType(msg, arg_id)
|
typeChar::Char = argType(msg, arg_id)
|
||||||
value = msg[arg_id]
|
value = msg[arg_id]
|
||||||
if(issubtype(typeof(value), Array))
|
if(issubtype(typeof(value), Array))
|
||||||
value = value'
|
value = value'
|
||||||
end
|
end
|
||||||
fieldClass = dict[typeChar]
|
|
||||||
if(fieldClass == true)
|
|
||||||
fieldClass = 'T'
|
|
||||||
elseif(fieldClass == false)
|
|
||||||
fieldClass = 'F'
|
|
||||||
end
|
|
||||||
@printf(io, " #%2d %c:", arg_id, typeChar);
|
@printf(io, " #%2d %c:", arg_id, typeChar);
|
||||||
println(fieldClass," - '", value,"'")
|
println(dict[typeChar]," - ", value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -104,28 +104,28 @@ function test_it_osc_spec()
|
||||||
0x40, 0xb5, 0xb2, 0x2d, #40
|
0x40, 0xb5, 0xb2, 0x2d, #40
|
||||||
];
|
];
|
||||||
|
|
||||||
osc=OscMsg("/oscillator/4/frequency", "f", float32(440.0))
|
osc=OscMsg("/oscillator/4/frequency", "f", Float32(440.0))
|
||||||
|
|
||||||
println(string(map(x->(hex(x,2)), osc.data)...))
|
println(string(map(x->(hex(x,2)), osc.data)...))
|
||||||
println(string(map(x->(hex(x,2)), message_one)...))
|
println(string(map(x->(hex(x,2)), message_one)...))
|
||||||
println(string(map(x->(isprint(char(x&0x7f)) ? string(char(x&0x7f)," ") : ". "), osc.data)...))
|
println(string(map(x->(isprint(Char(x&0x7f)) ? string(Char(x&0x7f)," ") : ". "), osc.data)...))
|
||||||
println(string(map(x->(isprint(char(x&0x7f)) ? string(char(x&0x7f)," ") : ". "), message_one)...))
|
println(string(map(x->(isprint(Char(x&0x7f)) ? string(Char(x&0x7f)," ") : ". "), message_one)...))
|
||||||
@test length(osc.data) == length(message_one)
|
@test length(osc.data) == length(message_one)
|
||||||
@test osc.data == message_one
|
@test osc.data == message_one
|
||||||
show(osc)
|
show(osc)
|
||||||
|
|
||||||
osc = OscMsg("/foo", "iisff", int32(1000), int32(-1), "hello", float32(1.234), float32(5.678))
|
osc = OscMsg("/foo", "iisff", Int32(1000), Int32(-1), "hello", Float32(1.234), Float32(5.678))
|
||||||
println(string(map(x->(hex(x,2)), osc.data)...))
|
println(string(map(x->(hex(x,2)), osc.data)...))
|
||||||
println(string(map(x->(hex(x,2)), message_two)...))
|
println(string(map(x->(hex(x,2)), message_two)...))
|
||||||
println(string(map(x->(isprint(char(x&0x7f)) ? string(char(x&0x7f)," ") : ". "), osc.data)...))
|
println(string(map(x->(isprint(Char(x&0x7f)) ? string(Char(x&0x7f)," ") : ". "), osc.data)...))
|
||||||
println(string(map(x->(isprint(char(x&0x7f)) ? string(char(x&0x7f)," ") : ". "), message_two)...))
|
println(string(map(x->(isprint(Char(x&0x7f)) ? string(Char(x&0x7f)," ") : ". "), message_two)...))
|
||||||
@test length(osc.data) == length(message_two)
|
@test length(osc.data) == length(message_two)
|
||||||
@test osc.data == message_two
|
@test osc.data == message_two
|
||||||
show(osc)
|
show(osc)
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_path()
|
function test_path()
|
||||||
osc = OscMsg("/foo", "f", float32(1.234))
|
osc = OscMsg("/foo", "f", Float32(1.234))
|
||||||
@test path(osc) == "/foo"
|
@test path(osc) == "/foo"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue