aboutsummaryrefslogtreecommitdiff
path: root/chimaera_osc-midi_bridge/chimaera_osc-midi_bridge-custom.lua
blob: 0472c75c7e46524b2d625a0bca15e4f508854dab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
--[[
-- Copyright (c) 2015 Hanspeter Portner (dev@open-music-kontrollers.ch)
-- 
-- This software is provided 'as-is', without any express or implied
-- warranty. In no event will the authors be held liable for any damages
-- arising from the use of this software.
-- 
-- Permission is granted to anyone to use this software for any purpose,
-- including commercial applications, and to alter it and redistribute it
-- freely, subject to the following restrictions:
-- 
--     1. The origin of this software must not be misrepresented; you must not
--     claim that you wrote the original software. If you use this software
--     in a product, an acknowledgment in the product documentation would be
--     appreciated but is not required.
-- 
--     2. Altered source versions must be plainly marked as such, and must not be
--     misrepresented as being the original software.
-- 
--     3. This notice may not be removed or altered from any source
--     distribution.
--]]

-- create some handy shortcuts
OscMessage = renoise.Osc.Message

-- open a socket connection to the server
conf_client, err = renoise.Socket.create_client('chimaera.local', 4444, renoise.Socket.PROTOCOL_UDP)
if err then
  renoise.app():show_warning(('Failed to start the OSC client. Error: %s'):format(err))
  return
end

print(conf_client.local_address)
print(conf_client.local_port)
print(conf_client.peer_address)
print(conf_client.peer_port)

-- open a socket connection to the server
conf_server, err = renoise.Socket.create_server(conf_client.local_port, renoise.Socket.PROTOCOL_UDP)
if err then 
	renoise.app():show_warning(('Failed to start the OSC server. Error: %s'):format(err))
  return
end

conf_methods = {
	['/success'] = function(args)
		local uuid = args[1].value
		local path = args[2].value
		print('success', uuid, path)
	end,

	['/fail'] = function(args)
		local uuid = args[1].value
		local path = args[2].value
		local err = args[3].value
		print('fail', uuid, path, err)
	end
}

conf_server:run({
  socket_message = function(socket, data)
    -- decode the data to Osc
    local osc, err = renoise.Osc.from_binary_data(data)
    
    -- show what we've got
    if osc then
			local meth = conf_methods[osc.pattern]
			if meth then
				meth(osc.arguments)
			end
    else
      print(('Got invalid OSC data, or data which is not OSC data at all. Error: %s'):format(err))
    end
	end
})

oscarg = {}
setmetatable(oscarg, {
	__index = function(self, k)
		return function(v)
			return { tag=k, value=v }
		end
	end
})

uuid = function()
	local rand = math.random
	return oscarg.i(rand(1024))
end

-- construct and send messages
conf_client:send( OscMessage('/engines/reset', { uuid() }) )
conf_client:send( OscMessage('/engines/offset', { uuid(), oscarg.f(0.0025) }) )
conf_client:send( OscMessage('/engines/parallel', { uuid(), oscarg.i(0) }) )
conf_client:send( OscMessage('/engines/enabled', { uuid(), oscarg.i(0) }) )
conf_client:send( OscMessage('/engines/address', { uuid(), oscarg.s(conf_client.local_address .. ':8000') }) )
conf_client:send( OscMessage('/engines/server', { uuid(), oscarg.i(0) }) )
conf_client:send( OscMessage('/engines/mode', { uuid(), oscarg.s('osc.udp') }) )
conf_client:send( OscMessage('/engines/enabled', { uuid(), oscarg.i(1) }) )

conf_client:send( OscMessage('/sensors/rate', { uuid(), oscarg.i(2000) }) )
conf_client:send( OscMessage('/sensors/group/reset', { uuid() }) )
conf_client:send( OscMessage("/sensors/group/attributes/0/min", { uuid(), oscarg.f(0.0) }) )
conf_client:send( OscMessage("/sensors/group/attributes/0/max", { uuid(), oscarg.f(1.0) }) )
conf_client:send( OscMessage("/sensors/group/attributes/0/north", { uuid(), oscarg.i(0) }) )
conf_client:send( OscMessage("/sensors/group/attributes/0/south", { uuid(), oscarg.i(1) }) )
conf_client:send( OscMessage("/sensors/group/attributes/0/scale", { uuid(), oscarg.i(0) }) )
conf_client:send( OscMessage("/sensors/group/attributes/1/min", { uuid(), oscarg.f(0.0) }) )
conf_client:send( OscMessage("/sensors/group/attributes/1/max", { uuid(), oscarg.f(1.0) }) )
conf_client:send( OscMessage("/sensors/group/attributes/1/north", { uuid(), oscarg.i(1) }) )
conf_client:send( OscMessage("/sensors/group/attributes/1/south", { uuid(), oscarg.i(0) }) )
conf_client:send( OscMessage("/sensors/group/attributes/1/scale", { uuid(), oscarg.i(0) }) )
conf_client:send( OscMessage('/sensors/number', { uuid() }) )
		
dest  = oscarg.s('/renoise/trigger/midi')
conf_client:send( OscMessage('/engines/custom/enabled', { uuid(), oscarg.i(1) }) )
conf_client:send( OscMessage('/engines/custom/reset', { uuid() }) )
conf_client:send( OscMessage('/engines/custom/append/on', { uuid(),
	oscarg.s(dest .. ' i(0x7f0090 $g| 35.5 $n 18% 6/- $n 3/ $x @@ $g[*+ 8<<|)') }) );
conf_client:send( OscMessage('/engines/custom/append/off', { uuid(),
	oscarg.s(dest .. ' i(0x7f0080 $g| 35.5 $n 18% 6/- $n 3/ $g]*+ 8<<|)') }) );
conf_client:send( OscMessage('/engines/custom/append/set', { uuid(),
	oscarg.s(dest .. ' i(0xe0 $g| $x $g]- 0x2000* 0x1fff+ @@ 7>> 16<< # 0x7f& 8<<| |)') }) );
conf_client:send( OscMessage('/engines/custom/append/set', { uuid(),
	oscarg.s(dest .. ' i(0x27b0 $g| $z 0x3fff* 0x7f& 16<<|)') }) );
conf_client:send( OscMessage('/engines/custom/append/set', { uuid(),
	oscarg.s(dest .. ' i(0x07b0 $g| $z 0x3fff* 7>> 16<<|)') }) );