aboutsummaryrefslogtreecommitdiff
path: root/chimaera_osc-midi_bridge/chimaera_osc-midi_bridge-oscmidi.lua
blob: 246f9e7269695bc649b7f02f0973d3ce9603c1e1 (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
--[[
-- Copyright (c) 2014 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_server, err = renoise.Socket.create_server(4444, 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    
})

-- 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

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

osc_false = oscarg.i(0)
osc_true = oscarg.i(1)

N = 160
offset = (3.0*12.0 - 0.5 - (N % 18 / 6.0))
range = N / 3.0

-- 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(), osc_false }) )
conf_client:send( OscMessage('/engines/enabled', { uuid(), osc_false }) )
conf_client:send( OscMessage('/engines/address', { uuid(), oscarg.s(conf_client.local_address .. ':8000') }) )
conf_client:send( OscMessage('/engines/server', { uuid(), osc_false }) )
conf_client:send( OscMessage('/engines/mode', { uuid(), oscarg.s('osc.udp') }) )
conf_client:send( OscMessage('/engines/enabled', { uuid(), osc_true }) )

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', { uuid(), oscarg.f(0.0), oscarg.f(1.0), oscarg.i(0), oscarg.i(1), oscarg.i(0) }) )
conf_client:send( OscMessage('/sensors/group/attributes/1', { uuid(), oscarg.f(0.0), oscarg.f(1.0), oscarg.i(1), oscarg.i(0), oscarg.i(0) }) )
conf_client:send( OscMessage('/sensors/number', { uuid() }) )
		
conf_client:send( OscMessage('/engines/oscmidi/enabled', { uuid(), osc_true }) )
conf_client:send( OscMessage('/engines/oscmidi/multi', { uuid(), osc_false }) )
conf_client:send( OscMessage('/engines/oscmidi/path', { uuid(), oscarg.s('/renoise/trigger/midi') }) )
conf_client:send( OscMessage('/engines/oscmidi/format', { uuid(), oscarg.s('int32') }) )
conf_client:send( OscMessage('/engines/oscmidi/reset', { uuid() }) )
conf_client:send( OscMessage('/engines/oscmidi/attributes/0', { uuid(), oscarg.s('control_change'), oscarg.f(offset), oscarg.f(range), oscarg.i(0x07) }) )
conf_client:send( OscMessage('/engines/oscmidi/attributes/1', { uuid(), oscarg.s('note_pressure'), oscarg.f(offset), oscarg.f(range), oscarg.i(0x07) }) )