Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add midigrid and animation toggle button in toolbar #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
42 changes: 42 additions & 0 deletions gridstep.lua
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ local textentry = require 'textentry'



local grid = util.file_exists(_path.code .. "midigrid") and include "midigrid/lib/mg_128" or grid
local g = grid.connect()

local gridType_none = 0
Expand Down Expand Up @@ -212,6 +213,7 @@ local shift_down = false
local track = 1

local is_playing = false
local animation = true

local edit_steps_9_16 = false -- for 64x64 grids

Expand Down Expand Up @@ -695,6 +697,20 @@ function toggle_playback()
end
end

function toggle_animation()
for i, gKey in pairs(all_gridKeys) do
if gKey.animation then
gKey.animation = false
animation = false
show_temporary_notification("Animation Off")
else
gKey.animation = true
animation = true
show_temporary_notification("Animation On")
end
end
end

function clock.transport.start()
-- print("we begin")
-- position = 16
Expand Down Expand Up @@ -1202,6 +1218,9 @@ function grid_key_toolbar_128( x, y, z)
change_grid_page("GridSeq")
grid_dirty = true
end
elseif x == 6 then -- Toggle animation
toggle_animation()
grid_dirty = true
end
end
else -- key released
Expand Down Expand Up @@ -1235,6 +1254,9 @@ function grid_key_toolbar_64( x, y, z)
local new_page = (config.grid_page_index % 3) + 1
change_grid_page(grid_page_names[new_page])
grid_dirty = true
elseif x == 4 then -- Toggle animation
toggle_animation()
grid_dirty = true
elseif x == 7 then -- edit steps 1-8
edit_steps_9_16 = false
show_temporary_notification("Edit 1-8")
Expand Down Expand Up @@ -2738,8 +2760,18 @@ function grid_draw_toolbar()
g:led(3,toolY, config.grid_page_index == 1 and mode_on_brightness or mode_off_brightness) -- play mode active
g:led(4,toolY, config.grid_page_index == 2 and mode_on_brightness or mode_off_brightness) -- pat launch mode not active
g:led(5,toolY, config.grid_page_index == 3 and mode_on_brightness or mode_off_brightness) -- step mode not active
if animation then
g:led(6, toolY, mode_on_brightness) -- animation active
else
g:led(6, toolY, mode_off_brightness) -- animation inactive
end
elseif gridType == gridType_64 then
g:led(3,toolY, mode_on_brightness)
if animation then
g:led(4, toolY, mode_on_brightness) -- animation active
else
g:led(4, toolY, mode_off_brightness) -- animation inactive
end

g:led(7,toolY, edit_steps_9_16 and mode_off_brightness or mode_on_brightness)
g:led(8,toolY, edit_steps_9_16 and mode_on_brightness or mode_off_brightness)
Expand Down Expand Up @@ -3023,9 +3055,19 @@ function grid_draw_param_edit(edit_type)
g:led(3,toolY,edit_type == 1 and mode_on_brightness or mode_off_brightness)
g:led(4,toolY,edit_type == 2 and mode_on_brightness or mode_off_brightness)
g:led(5,toolY,edit_type == 3 and mode_on_brightness or mode_off_brightness)
if animation then
g:led(6, toolY, mode_on_brightness) -- animation active
else
g:led(6, toolY, mode_off_brightness) -- animation inactive
end
elseif gridType == gridType_64 then
g:led(1,toolY,mode_off_brightness)
g:led(3,toolY,mode_on_brightness)
if animation then
g:led(4, toolY, mode_on_brightness) -- animation active
else
g:led(4, toolY, mode_off_brightness) -- animation inactive
end

g:led(7,toolY, edit_steps_9_16 and mode_off_brightness or mode_on_brightness)
g:led(8,toolY, edit_steps_9_16 and mode_on_brightness or mode_off_brightness)
Expand Down
21 changes: 12 additions & 9 deletions lib/Q7GridKeys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function Q7GridKeys.new(width,height)

gk.enable_note_highlighting = true
gk.enable_key_playback = true
gk.animation = true

gk.lit_keys = {}

Expand Down Expand Up @@ -351,15 +352,17 @@ function Q7GridKeys:animate()
end

function Q7GridKeys:anim_set_leds(step_position, x, y)
local pixels = ripple_anim[step_position]
local brightness = math.floor(util.linlin(1,8,5,1,step_position))

for i=1,#pixels do
local pixel = pixels[i]
self:set_anim_grid(x + pixel[1], y + pixel[2], brightness)
self:set_anim_grid(x - pixel[1], y + pixel[2], brightness)
self:set_anim_grid(x - pixel[1], y - pixel[2], brightness)
self:set_anim_grid(x + pixel[1], y - pixel[2], brightness)
if self.animation then
local pixels = ripple_anim[step_position]
local brightness = math.floor(util.linlin(1,8,5,1,step_position))

for i=1,#pixels do
local pixel = pixels[i]
self:set_anim_grid(x + pixel[1], y + pixel[2], brightness)
self:set_anim_grid(x - pixel[1], y + pixel[2], brightness)
self:set_anim_grid(x - pixel[1], y - pixel[2], brightness)
self:set_anim_grid(x + pixel[1], y - pixel[2], brightness)
end
end
end

Expand Down