Skip to content

Commit

Permalink
Merge pull request #71 from subvertnormality/refactor
Browse files Browse the repository at this point in the history
More performance improvements
  • Loading branch information
subvertnormality authored May 26, 2024
2 parents 4714aed + 347134d commit 271a1d8
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 90 deletions.
8 changes: 7 additions & 1 deletion lib/clock_controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,19 @@ function clock_controller:start()
end

clock_controller.set_playing()
midi_controller.start()

for i = 1, 16 do
step_handler.process_params(i, 1)
end

clock_lattice:start()

clock.run(function()
clock.sync(1/32)
midi_controller.start()
end)


end

function clock_controller:stop()
Expand Down
2 changes: 0 additions & 2 deletions lib/controls/sequencer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ function sequencer:draw(channel, draw_func)
end
end
end
fn.dirty_grid(true)
fn.dirty_screen(true)
end

function sequencer:press(x, y)
Expand Down
13 changes: 6 additions & 7 deletions lib/midi_controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,13 @@ function midi_controller:program_change(program_id, channel, device)
end

function midi_controller.start()
clock.run(function()
clock.sleep(0.0075)
for id = 1, #midi.vports do
if midi_devices[id].device ~= nil then
midi_devices[id]:start()
end

for id = 1, #midi.vports do
if midi_devices[id].device ~= nil then
midi_devices[id]:start()
end
end)
end

end

function midi_controller.stop()
Expand Down
30 changes: 13 additions & 17 deletions lib/pages/channel_edit_page/channel_edit_page_controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function channel_edit_page_controller.init()
elseif i == program.get().selected_scale and program.get_selected_channel().number == 17 then
grid_abstraction.led(i, y, 4)
end

end
end
)
Expand Down Expand Up @@ -179,7 +180,6 @@ function channel_edit_page_controller.register_press_handlers()
if program.get().selected_channel ~= 17 and is_key3_down then
channel_edit_page_sequencer:press(x, y)
program.toggle_step_trig_mask(program.get().selected_channel, fn.calc_grid_count(x, y))
pattern_controller.ui_throttled_update_working_patterns()
end
end
end
Expand All @@ -191,7 +191,6 @@ function channel_edit_page_controller.register_press_handlers()
if program.get().selected_channel ~= 17 and is_key3_down then
program.clear_step_trig_mask(program.get().selected_channel, fn.calc_grid_count(x, y))
channel_edit_page_ui_controller.refresh_notes()
pattern_controller.ui_throttled_update_working_patterns()
end
end
end
Expand All @@ -203,21 +202,19 @@ function channel_edit_page_controller.register_press_handlers()
channel_edit_page_ui_controller.refresh_trig_locks()
channel_edit_page_ui_controller.refresh_notes()
channel_edit_page_controller.refresh_faders()
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()
end
end
)
press_handler:register(
"channel_edit_page",
function(x, y)
channel_select_fader:press(x, y)
if channel_select_fader:is_this(x, y) then
channel_select_fader:press(x, y)
program.get().selected_channel = channel_select_fader:get_value()
pattern_controller.ui_throttled_update_working_patterns()
tooltip:show("Channel " .. program.get().selected_channel .. " selected")
channel_edit_page_controller.refresh()
channel_edit_page_ui_controller.refresh()
channel_edit_page_ui_controller.refresh_trig_lock_values()
end
end
)
Expand Down Expand Up @@ -248,7 +245,6 @@ function channel_edit_page_controller.register_press_handlers()
local selected_sequencer_pattern = program.get().selected_sequencer_pattern
channel_edit_page_sequencer:dual_press(x, y, x2, y2)
if channel_edit_page_sequencer:is_this(x2, y2) then
pattern_controller.ui_throttled_update_working_patterns()
program.get_selected_sequencer_pattern().active = true
tooltip:show("Channel " .. program.get().selected_channel .. " length changed")
end
Expand Down Expand Up @@ -335,9 +331,9 @@ function channel_edit_page_controller.register_press_handlers()
press_handler:register(
"channel_edit_page",
function(x, y)
local selected_sequencer_pattern = program.get().selected_sequencer_pattern
pattern_buttons["step" .. s .. "_pattern_button"]:press(x, y)
if pattern_buttons["step" .. s .. "_pattern_button"]:is_this(x, y) then
local selected_sequencer_pattern = program.get().selected_sequencer_pattern
pattern_buttons["step" .. s .. "_pattern_button"]:press(x, y)
if pattern_buttons["step" .. s .. "_pattern_button"]:get_state() == 2 then
fn.add_to_set(program.get_selected_channel().selected_patterns, x)
program.get_selected_sequencer_pattern().active = true
Expand All @@ -347,7 +343,7 @@ function channel_edit_page_controller.register_press_handlers()
program.get_selected_sequencer_pattern().active = true
tooltip:show("Pattern " .. x .. " removed from ch. " .. program.get().selected_channel)
end
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()
program.get_selected_sequencer_pattern().active = true
end
end
Expand Down Expand Up @@ -383,7 +379,7 @@ function channel_edit_page_controller.register_press_handlers()
end

program.get_selected_sequencer_pattern().active = true
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()

end
end
Expand Down Expand Up @@ -421,7 +417,7 @@ function channel_edit_page_controller.register_press_handlers()
end

program.get_selected_sequencer_pattern().active = true
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()

end
end
Expand Down Expand Up @@ -458,7 +454,7 @@ function channel_edit_page_controller.register_press_handlers()
end

program.get_selected_sequencer_pattern().active = true
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()

end
end
Expand Down Expand Up @@ -495,7 +491,7 @@ function channel_edit_page_controller.register_press_handlers()
end

program.get_selected_sequencer_pattern().active = true
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()
end
end
end
Expand All @@ -522,7 +518,7 @@ function channel_edit_page_controller.register_press_handlers()
program.get_selected_channel().note_merge_mode = "pattern_number_" .. x2
note_merge_mode_button:set_state(4)
program.get_selected_sequencer_pattern().active = true
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()
tooltip:show(
"Note merge mode pattern " ..x2
)
Expand All @@ -531,7 +527,7 @@ function channel_edit_page_controller.register_press_handlers()
program.get_selected_channel().velocity_merge_mode = "pattern_number_" .. x2
velocity_merge_mode_button:set_state(4)
program.get_selected_sequencer_pattern().active = true
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()
tooltip:show(
"Velocity merge mode pattern " ..x2
)
Expand All @@ -540,7 +536,7 @@ function channel_edit_page_controller.register_press_handlers()
program.get_selected_channel().length_merge_mode = "pattern_number_" .. x2
length_merge_mode_button:set_state(4)
program.get_selected_sequencer_pattern().active = true
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()
tooltip:show(
"Length merge mode pattern " ..x2
)
Expand Down
26 changes: 3 additions & 23 deletions lib/pages/channel_edit_page/channel_edit_page_ui_controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ local scales_page_to_index = {["Quantizer"] = 1, ["Clock Mods"] = 2}

-- Helper variables
local refresh_timer_id = nil
local throttle_time = 0.1
local throttle_time = 0.2

-- Utility functions
local function print_no_scale_selected_message_to_screen()
Expand Down Expand Up @@ -391,7 +391,7 @@ function channel_edit_page_ui_controller.enc(n, d)
elseif channel_pages:get_selected_page() == channel_page_to_index["Midi Config"] and program.get().selected_channel ~= 17 then
channel_edit_page_ui_controller.handle_midi_config_page_increment()
elseif channel_pages:get_selected_page() == channel_page_to_index["Trig Locks"] and program.get().selected_channel ~= 17 then
channel_edit_page_ui_controller.handle_trig_locks_page_increment(d)
channel_edit_page_ui_handlers.handle_trig_locks_page_change(d, trig_lock_page, param_select_vertical_scroll_selector, dials)
end
else
if channel_pages:get_selected_page() == channel_page_to_index["Notes"] and program.get().selected_channel ~= 17 then
Expand All @@ -405,7 +405,7 @@ function channel_edit_page_ui_controller.enc(n, d)
elseif channel_pages:get_selected_page() == channel_page_to_index["Midi Config"] and program.get().selected_channel ~= 17 then
channel_edit_page_ui_controller.handle_midi_config_page_decrement()
elseif channel_pages:get_selected_page() == channel_page_to_index["Trig Locks"] and program.get().selected_channel ~= 17 then
channel_edit_page_ui_controller.handle_trig_locks_page_decrement(d)
channel_edit_page_ui_handlers.handle_trig_locks_page_change(d, trig_lock_page, param_select_vertical_scroll_selector, dials)
end
end
end
Expand Down Expand Up @@ -471,10 +471,6 @@ function channel_edit_page_ui_controller.refresh_trig_lock_values()
end
end

function channel_edit_page_ui_controller.refresh_trig_lock(i)
channel_edit_page_ui_refreshers.refresh_trig_lock(i, m_params)
end

function channel_edit_page_ui_controller.refresh_trig_locks()
channel_edit_page_ui_refreshers.refresh_trig_locks(m_params)
end
Expand Down Expand Up @@ -711,22 +707,6 @@ function channel_edit_page_ui_controller.handle_midi_config_page_decrement()
end)
end

function channel_edit_page_ui_controller.handle_trig_locks_page_increment(d)
channel_edit_page_ui_handlers.handle_trig_locks_page_change(d, trig_lock_page, param_select_vertical_scroll_selector, dials)
end

function channel_edit_page_ui_controller.handle_trig_locks_page_decrement(d)
channel_edit_page_ui_handlers.handle_trig_locks_page_change(d, trig_lock_page, param_select_vertical_scroll_selector, dials)
end

function channel_edit_page_ui_controller.handle_encoder_two_positive()
channel_edit_page_ui_handlers.handle_encoder_two_positive(channel_pages, channel_page_to_index, scales_pages, scales_page_to_index, mask_selectors, quantizer_vertical_scroll_selector, romans_vertical_scroll_selector, notes_vertical_scroll_selector, rotation_vertical_scroll_selector, clock_mod_list_selector, clock_swing_value_selector, midi_device_vertical_scroll_selector, midi_channel_vertical_scroll_selector, device_map_vertical_scroll_selector, dials, trig_lock_page)
end

function channel_edit_page_ui_controller.handle_encoder_two_negative()
channel_edit_page_ui_handlers.handle_encoder_two_negative(channel_pages, channel_page_to_index, scales_pages, scales_page_to_index, mask_selectors, quantizer_vertical_scroll_selector, romans_vertical_scroll_selector, notes_vertical_scroll_selector, rotation_vertical_scroll_selector, clock_mod_list_selector, clock_swing_value_selector, midi_device_vertical_scroll_selector, midi_channel_vertical_scroll_selector, device_map_vertical_scroll_selector, dials, trig_lock_page)
end

function channel_edit_page_ui_controller.handle_encoder_one_positive()
if program.get().selected_channel ~= 17 then
channel_pages:next_page()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function channel_sequencer_page_controller.register_draw_handlers()
refresh_button[s] = false
end
channel_pattern_buttons["step" .. s .. "_sequencer_pattern_button"]:draw()
clock.sleep(0.0001)
end
end
)
Expand Down
6 changes: 4 additions & 2 deletions lib/pages/note_edit_page/note_edit_page_controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function note_edit_page_controller.register_press_handlers()
tooltip:show("Steps " .. steps_tip .. "set to " .. note)
end

pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()
end
)
end
Expand Down Expand Up @@ -265,11 +265,13 @@ function note_edit_page_controller.refresh_fader(s)
end

function note_edit_page_controller.refresh()



for s = 1, 64 do
note_edit_page_controller.refresh_fader(s)
end
note_edit_page_controller.refresh_buttons()

end

return note_edit_page_controller
8 changes: 4 additions & 4 deletions lib/pages/trigger_edit_page/trigger_edit_page_controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ local function save_paint_pattern(p)
end
program.get_selected_sequencer_pattern().patterns[selected_pattern].trig_values = trigs
program.get_selected_sequencer_pattern().patterns[selected_pattern].lengths = lengths
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()
program.get_selected_sequencer_pattern().active = true
end

Expand All @@ -205,7 +205,7 @@ function trigger_edit_page_controller.register_press_handlers()
function(x, y)
if pattern_trigger_edit_page_sequencer:is_this(x, y) then
pattern_trigger_edit_page_sequencer:press(x, y)
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()
end
end
)
Expand Down Expand Up @@ -358,7 +358,7 @@ function trigger_edit_page_controller.register_press_handlers()
function(x, y, x2, y2)
pattern_trigger_edit_page_sequencer:dual_press(x, y, x2, y2)
if pattern_trigger_edit_page_sequencer:is_this(x2, y2) then
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()
tooltip:show("Note length set")
end
end
Expand All @@ -368,7 +368,7 @@ function trigger_edit_page_controller.register_press_handlers()
function(x, y)
if pattern_trigger_edit_page_sequencer:is_this(x, y) then
pattern_trigger_edit_page_sequencer:long_press(x, y)
pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()
tooltip:show("Note length reset")
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function velocity_edit_page_controller.register_press_handlers()
tooltip:show("Steps " .. steps_tip .. "set to " .. velocity)
end

pattern_controller.ui_throttled_update_working_patterns()
pattern_controller.update_working_patterns()
end
end
)
Expand Down Expand Up @@ -289,10 +289,13 @@ function velocity_edit_page_controller.refresh_fader(s)
end

function velocity_edit_page_controller.refresh()

for s = 1, 64 do
velocity_edit_page_controller.refresh_fader(s)

end
velocity_edit_page_controller.refresh_buttons()

end

return velocity_edit_page_controller
Loading

0 comments on commit 271a1d8

Please sign in to comment.