Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,12 @@ https://www.instagram.com/p/CS4JRtonRD7/
4. Open **code/toga/lib/togaarc.lua** file and repeat the step 2 and 3.
5. Reload the script on norns. Now **toga** will automatically connect to the TouchOSC controller when the script is loaded.

## Orientation

The orientation button says which round the grid should be oriented.
Any change here only updates after clicking the connection button,
so if you set or change the orientation on the grid, touch the connection
button to register that.

## Forum
https://llllllll.co/t/toga-touchosc-grid-and-arc-controller-for-monome-norns/47902
29 changes: 29 additions & 0 deletions design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Design notes

## Notes for `toga.tosc`

The orientation of the grid is the orientation of the connect button.
The script attached to the orientation button will change the orientation
of the connect button, as well as changing the orientation lights.

The OSC message `/toga_connection` has a send variant and a receive variant.
When sent from the norns and received by TouchOSC the argument is the
connect button's `x` value.
When sent from TouchOSC and received by the norns the argument is the
connect button's orientation.

## Notes for `lib/togagrid.lua`

`old_buffer` is what's been sent to the grid; `new_buffer` is the old buffer
with any changes. This allows only changes to be sent on a refresh.

`dest` is a list of tables, mapping IP address to port number, one for each
connected grid.

`orientation` is what the grid says its orientation is. 0 = north, 1 = east,
2 = south, 3 = west. This is the orientation enumeration in TouchOSC.
Regardless of how many grids are connected, there is only one orientation
for all of them. Beware that the semantics is different from that used by
`grid:rotation(val)` which is used to tell a (real)
grid what orientation it should assume. There, the argument is
0 = 0 degrees (east), 1 = 90 degrees (north), etc.
80 changes: 75 additions & 5 deletions lib/togagrid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ local togagrid = {
old_grid = nil,
old_osc_in = nil,
old_cleanup = nil,
key = nil -- key event callback
key = nil, -- key event callback
orientation = 0, -- As TouchOSC, clockwise from 0 = north
}

function togagrid:connect()
Expand Down Expand Up @@ -83,13 +84,13 @@ function togagrid.osc_in(path, args, from)
table.insert(togagrid.dest, from)
togagrid:refresh(true, from)
end
local orientation_changed = togagrid:set_orientation(args[1])
-- echo back anyway to update connection button value
togagrid:send_connected(from, true)
-- do not consume the event so togaarc can also add the new touchosc client.
elseif string.starts(path, "/togagrid/") then
i = tonumber(string.sub(path,11))
x = ((i-1) % 16) + 1
y = (i-1) // 16 + 1
x, y = togagrid:i_to_xy(i)
z = args[1] // 1
--print("togagrid_osc_in togagrid", i, x, y, z)
if togagrid.key then
Expand All @@ -109,6 +110,55 @@ function togagrid.osc_in(path, args, from)
end
end

function togagrid:set_orientation(orientation)
local changed = false
if orientation then
if self.orientation ~= orientation then
self.orientation = orientation
changed = true
end
end
if changed then
if orientation % 2 == 0 then
-- North or south
self.cols = 16
self.rows = 8
else
-- East or west
self.cols = 8
self.rows = 16
end
self.old_buffer = create_buffer(self.cols, self.rows)
self.new_buffer = create_buffer(self.cols, self.rows)
self:refresh(true)
end
return changed
end

function togagrid:i_to_xy(i)
local x, y
if togagrid.orientation == 0 then
-- North
x = ((i-1) % 16) + 1
y = (i-1) // 16 + 1
elseif togagrid.orientation == 1 then
-- East
x = (i-1) // 16 + 1
y = 16 - ((i-1) % 16)
elseif togagrid.orientation == 2 then
-- South
i = 129 - i
x = ((i-1) % 16) + 1
y = (i-1) // 16 + 1
else
-- West
i = 129 - i
x = (i-1) // 16 + 1
y = 16 - ((i-1) % 16)
end
return x, y
end

function togagrid:hook_osc_in()
if self.old_osc_in ~= nil then return end
--print("togagrid: hook old osc_in")
Expand Down Expand Up @@ -190,7 +240,7 @@ end

function togagrid:update_led(c, r, target_dest)
local z = self.new_buffer[c][r]
local i = c + (r-1) * self.cols
local i = self:cr_to_i(c, r)
local addr = string.format("/togagrid/%d", i)
--print("togagrid osc.send", addr, z)
for d, dest in pairs(self.dest) do
Expand All @@ -202,6 +252,26 @@ function togagrid:update_led(c, r, target_dest)
end
end

function togagrid:cr_to_i(c, r)
local i
if togagrid.orientation == 0 then
-- North
i = c + (r-1) * self.cols
elseif togagrid.orientation == 1 then
-- East
i = c*16 - (r-1)
elseif togagrid.orientation == 2 then
-- Sound
i = c + (r-1) * self.cols
i = 129 - i
else
-- West
i = c*16 - (r-1)
i = 129 - i
end
return i
end

function togagrid:send_connected(target_dest, connected)
for d, dest in pairs(self.dest) do
if target_dest and (target_dest[1] ~= dest[1] or target_dest[2] ~= dest[2]) then
Expand All @@ -212,4 +282,4 @@ function togagrid:send_connected(target_dest, connected)
end
end

return togagrid
return togagrid
Binary file modified toga.tosc
Binary file not shown.