Skip to content

Commit

Permalink
Merge pull request #161 from dac514/grid-pie-indicators
Browse files Browse the repository at this point in the history
Gridpie: New indicator lights, bugfixes
  • Loading branch information
emuell committed Apr 19, 2024
2 parents 1456683 + 499cf9c commit 7f77c81
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 45 deletions.
99 changes: 74 additions & 25 deletions Tools/com.renoise.GridPie.xrnx/main.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
require "toolbox"

--[[ Globals, capitalized for easier recognition ]]--
--[[ Globals, capitalized for easier recognition, alphabetical order ]]--

local DBUG_MODE = false
local DISABLE_POLYRHYTHMS = false
local GRIDPIE_IDX = nil
local INDICATORS = table.create()
local MATRIX_CELLS = table.create()
local MATRIX_HEIGHT = 8
local MATRIX_WIDTH = 8
local MY_INTERFACE = nil
local POLY_COUNTER = table.create()
local REVERT_PM_SLOT = table.create()
local SPECIAL_PATTERN_NAME = "__GRID_PIE__"
local VB = nil
local X_POS = 1
local Y_POS = 1
Expand Down Expand Up @@ -47,12 +49,11 @@ end


--------------------------------------------------------------------------------
-- Is garbage PM position?
-- Is garbage Pattern Matrix position?
--------------------------------------------------------------------------------

function is_garbage_pos(x, y)

-- Garbage position?
local sequencer = renoise.song().sequencer
local total_sequence = #sequencer.pattern_sequence

Expand Down Expand Up @@ -91,7 +92,7 @@ end
-- Toggle all slot mutes in Pattern Matrix
--------------------------------------------------------------------------------

function init_pm_slots_to(val)
function init_pm_slots_to(muted)

local rns = renoise.song()
local tracks = rns.tracks
Expand All @@ -106,13 +107,13 @@ function init_pm_slots_to(val)
then
for y = 1, total_sequence do
local tmp = x .. ',' .. y
if val and rns.sequencer:track_sequence_slot_is_muted(x, y) then
if muted and rns.sequencer:track_sequence_slot_is_muted(x, y) then
-- Store original state
REVERT_PM_SLOT[tmp] = true
end
rns.sequencer:set_track_sequence_slot_is_muted(x , y, val)
if not val and REVERT_PM_SLOT ~= nil and REVERT_PM_SLOT[tmp] ~= nil then
-- Revert to original state
rns.sequencer:set_track_sequence_slot_is_muted(x , y, muted)
if not muted and REVERT_PM_SLOT ~= nil and REVERT_PM_SLOT[tmp] ~= nil then
-- Revert to original state
rns.sequencer:set_track_sequence_slot_is_muted(x , y, true)
end
end
Expand All @@ -135,27 +136,29 @@ function init_gp_pattern()
local total_sequence = #sequencer.pattern_sequence
local last_pattern = rns.sequencer:pattern(total_sequence)

if rns.patterns[last_pattern].name ~= "__GRID_PIE__" then
if rns.patterns[last_pattern].name ~= SPECIAL_PATTERN_NAME then
-- Create new pattern
local new_pattern = rns.sequencer:insert_new_pattern_at(total_sequence + 1)
rns.patterns[new_pattern].name = "__GRID_PIE__"
rns.patterns[new_pattern]:clear()
rns.patterns[new_pattern].name = SPECIAL_PATTERN_NAME
GRIDPIE_IDX = new_pattern
total_sequence = total_sequence + 1
else
-- Clear pattern, unmute slot
rns.patterns[last_pattern]:clear()
rns.patterns[last_pattern].name = "__GRID_PIE__"
rns.patterns[last_pattern].name = SPECIAL_PATTERN_NAME
for x = 1, total_tracks do
rns.sequencer:set_track_sequence_slot_is_muted(x , total_sequence, false)
end
GRIDPIE_IDX = last_pattern
end


-- Cleanup any other pattern named __GRID_PIE__
for x = 1, total_sequence - 1 do
local tmp = rns.sequencer:pattern(x)

if rns.patterns[tmp].name:find("__GRID_PIE__") ~= nil then
if rns.patterns[tmp].name:find(SPECIAL_PATTERN_NAME) ~= nil then
rns.patterns[tmp].name = ""
end
end
Expand All @@ -176,21 +179,32 @@ end

function adjust_grid()

local cell = nil
local rns = renoise.song()
for x = X_POS, MATRIX_WIDTH + X_POS - 1 do
local mtx_x = x - X_POS + 1
for y = Y_POS, MATRIX_HEIGHT + Y_POS - 1 do
cell = matrix_cell(x - X_POS + 1, y - Y_POS + 1)
-- Cell
local cell = matrix_cell(mtx_x, y - Y_POS + 1)
if cell ~= nil and not is_garbage_pos(x, y) then
local val = renoise.song().sequencer:track_sequence_slot_is_muted(x, y)
if val then cell.color = { 0, 0, 0 }
local slot_is_muted = rns.sequencer:track_sequence_slot_is_muted(x, y)
if slot_is_muted then cell.color = { 0, 0, 0 }
else cell.color = { 0, 255, 0 } end
elseif cell ~= nil then
cell.color = { 0, 0, 0 }
end
end
-- Indicator
local indicator = INDICATORS[mtx_x]
if indicator ~= nil and not is_garbage_pos(x, Y_POS) then
local track_is_empty = rns.patterns[GRIDPIE_IDX].tracks[x].is_empty
if track_is_empty then indicator.color = { 0, 0, 0 }
else indicator.color = { 255, 255, 0 } end
elseif indicator ~= nil then
indicator.color = { 0, 0, 0 }
end
end
renoise.song().selected_track_index = X_POS
renoise.song().selected_sequence_index = Y_POS
rns.selected_track_index = X_POS
rns.selected_sequence_index = Y_POS

end

Expand Down Expand Up @@ -268,6 +282,10 @@ function toggler(x, y)
local rns = renoise.song()
local source = rns.patterns[rns.sequencer:pattern(y)]
local dest = rns.patterns[GRIDPIE_IDX]
if dest == nil then
abort()
return
end
local lc = least_common(dest.number_of_lines, source.number_of_lines)
local toc = 0

Expand Down Expand Up @@ -403,7 +421,7 @@ function build_interface()
},
}

-- Checkmark Matrix
-- Matrix
local matrix_view = VB:row { }
for x = 1, MATRIX_WIDTH do
local column = VB:column { margin = 2, spacing = 2, }
Expand All @@ -422,7 +440,17 @@ function build_interface()
matrix_view:add_child(column)
end

-- Racks
-- Indicators
local indicators_view = VB:row { spacing = 29, margin = 2 }
for x = 1, MATRIX_WIDTH do
INDICATORS[x] = VB:button {
width = 10,
height = 10,
}
indicators_view:add_child(INDICATORS[x])
end

-- Assmble all the racks
local rack = VB:column {
uniform = true,
margin = renoise.ViewBuilder.DEFAULT_DIALOG_MARGIN,
Expand All @@ -444,6 +472,14 @@ function build_interface()
},
},

VB:column {
VB:horizontal_aligner {
mode = "center",
indicators_view,
},
},


}

-- Show dialog
Expand All @@ -463,13 +499,16 @@ function main(x, y)
x ~= MATRIX_WIDTH or
y ~= MATRIX_HEIGHT
then
if MY_INTERFACE and MY_INTERFACE.visible then
init_pm_slots_to(false)
MY_INTERFACE:close()
end
MATRIX_WIDTH = x
MATRIX_HEIGHT = y
REVERT_PM_SLOT = table.create()
POLY_COUNTER = table.create()
init_pm_slots_to(true)
init_gp_pattern()
if MY_INTERFACE and MY_INTERFACE.visible then MY_INTERFACE:close() end
build_interface()
end
run()
Expand All @@ -482,10 +521,10 @@ end
-- Abort
--------------------------------------------------------------------------------

function abort(notification)
function abort()

renoise.app():show_message(
"You dun goofed! Grid Pie needs to be restarted."
"Unexpected problem! Usually triggered by moving or deleting the special Grid Pie pattern, and Grid Pie needs to be restarted."
)
if MY_INTERFACE and MY_INTERFACE.visible then MY_INTERFACE:close() end

Expand Down Expand Up @@ -548,7 +587,7 @@ function idler(notification)
end

local last_pattern = renoise.song().sequencer:pattern(#renoise.song().sequencer.pattern_sequence)
if renoise.song().patterns[last_pattern].name ~= "__GRID_PIE__" then
if renoise.song().patterns[last_pattern].name ~= SPECIAL_PATTERN_NAME then
abort()
else

Expand Down Expand Up @@ -705,7 +744,17 @@ renoise.tool():add_menu_entry {
invoke = function() main(4, 4) end
}

renoise.tool():add_menu_entry {
name = "Main Menu:Tools:Grid Pie:8x2...",
invoke = function() main(8, 2) end
}

renoise.tool():add_menu_entry {
name = "Main Menu:Tools:Grid Pie:8x5...",
invoke = function() main(8, 5) end
}

renoise.tool():add_menu_entry {
name = "Main Menu:Tools:Grid Pie:8x8...",
invoke = function() main(8, 8) end
}
}
6 changes: 3 additions & 3 deletions Tools/com.renoise.GridPie.xrnx/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<RenoiseScriptingTool doc_version="0">
<ApiVersion>5</ApiVersion>
<ApiVersion>6.1</ApiVersion>
<Id>com.renoise.GridPie</Id>
<Version>0.92</Version>
<Version>1.0</Version>
<Author>Dac Chartrand [dac@renoise.com]</Author>
<Name>Grid Pie</Name>
<Description>Renoise cut and pastry. Live sequence recombinator.</Description>
</RenoiseScriptingTool>
</RenoiseScriptingTool>
17 changes: 0 additions & 17 deletions Tools/com.renoise.GridPie.xrnx/toolbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,6 @@ function least_common(...)
end


--------------------------------------------------------------------------------
-- PHP style exlpode()
--------------------------------------------------------------------------------

function explode(div,str)
if (div=='') then return false end
local pos,arr = 0,table.create()
-- for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
pos = sp + 1 -- Jump past current divider
end
table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
return arr
end


--------------------------------------------------------------------------------
-- OneShotIdle Class
--------------------------------------------------------------------------------
Expand Down

0 comments on commit 7f77c81

Please sign in to comment.