diff --git a/lib/clock_controller.lua b/lib/clock_controller.lua index bcd22ce..a422b3d 100644 --- a/lib/clock_controller.lua +++ b/lib/clock_controller.lua @@ -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() diff --git a/lib/controls/sequencer.lua b/lib/controls/sequencer.lua index 5bdd708..be38d69 100644 --- a/lib/controls/sequencer.lua +++ b/lib/controls/sequencer.lua @@ -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) diff --git a/lib/midi_controller.lua b/lib/midi_controller.lua index bbf6683..8539dac 100644 --- a/lib/midi_controller.lua +++ b/lib/midi_controller.lua @@ -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() diff --git a/lib/pages/channel_edit_page/channel_edit_page_controller.lua b/lib/pages/channel_edit_page/channel_edit_page_controller.lua index 9a74ab8..ab19bc9 100644 --- a/lib/pages/channel_edit_page/channel_edit_page_controller.lua +++ b/lib/pages/channel_edit_page/channel_edit_page_controller.lua @@ -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 ) @@ -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 @@ -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 @@ -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 ) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 ) @@ -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 ) @@ -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 ) diff --git a/lib/pages/channel_edit_page/channel_edit_page_ui_controller.lua b/lib/pages/channel_edit_page/channel_edit_page_ui_controller.lua index 217fcf5..b68c0a6 100644 --- a/lib/pages/channel_edit_page/channel_edit_page_ui_controller.lua +++ b/lib/pages/channel_edit_page/channel_edit_page_ui_controller.lua @@ -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() @@ -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 @@ -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 @@ -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 @@ -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() diff --git a/lib/pages/channel_sequencer_page/channel_sequencer_page_controller.lua b/lib/pages/channel_sequencer_page/channel_sequencer_page_controller.lua index c5c3a63..efb8fcf 100644 --- a/lib/pages/channel_sequencer_page/channel_sequencer_page_controller.lua +++ b/lib/pages/channel_sequencer_page/channel_sequencer_page_controller.lua @@ -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 ) diff --git a/lib/pages/note_edit_page/note_edit_page_controller.lua b/lib/pages/note_edit_page/note_edit_page_controller.lua index 32e4b1d..e76bf87 100644 --- a/lib/pages/note_edit_page/note_edit_page_controller.lua +++ b/lib/pages/note_edit_page/note_edit_page_controller.lua @@ -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 @@ -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 diff --git a/lib/pages/trigger_edit_page/trigger_edit_page_controller.lua b/lib/pages/trigger_edit_page/trigger_edit_page_controller.lua index 0267e10..5c91da4 100644 --- a/lib/pages/trigger_edit_page/trigger_edit_page_controller.lua +++ b/lib/pages/trigger_edit_page/trigger_edit_page_controller.lua @@ -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 @@ -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 ) @@ -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 @@ -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 diff --git a/lib/pages/velocity_edit_page/velocity_edit_page_controller.lua b/lib/pages/velocity_edit_page/velocity_edit_page_controller.lua index 172bb94..31427a8 100644 --- a/lib/pages/velocity_edit_page/velocity_edit_page_controller.lua +++ b/lib/pages/velocity_edit_page/velocity_edit_page_controller.lua @@ -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 ) @@ -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 diff --git a/lib/pattern_controller.lua b/lib/pattern_controller.lua index 74f5bd5..e356fd2 100644 --- a/lib/pattern_controller.lua +++ b/lib/pattern_controller.lua @@ -9,8 +9,8 @@ local velocities = program.initialise_64_table({}) -- Helper variables local update_timer_id = nil -local throttle_time = 0.05 -local long_throttle_time = 0.1 +local throttle_time = 0.0005 +local currently_processing = false local function sync_pattern_values(merged_pattern, pattern, s) @@ -176,47 +176,28 @@ function pattern_controller.get_and_merge_patterns(channel, trig_merge_mode, not return merged_pattern end -function pattern_controller.throttled_update_working_patterns() - -- Must throttle to stop multiple quick inputs from slowing the sequencer down - if update_timer_id then - clock.cancel(update_timer_id) - end - update_timer_id = clock.run(function() - clock.sleep(throttle_time) - for c = 1, 16 do - pattern_controller.update_working_pattern(c) - clock.sleep(throttle_time) - end - clock.cancel(update_timer_id) - update_timer_id = nil - end) -end -function pattern_controller.ui_throttled_update_working_patterns() +function pattern_controller.update_working_patterns() -- Must throttle to stop multiple quick inputs from slowing the sequencer down if update_timer_id then clock.cancel(update_timer_id) end update_timer_id = clock.run(function() - if clock_controller.is_playing() then - clock.sleep(long_throttle_time) - end - for c = 1, 16 do - pattern_controller.update_working_pattern(c) + while currently_processing do clock.sleep(throttle_time) end - clock.cancel(update_timer_id) - update_timer_id = nil + currently_processing = true + clock.run(function() + for c = 1, 16 do + pattern_controller.update_working_pattern(c) + clock.sleep(throttle_time) + end + currently_processing = false + end) end) end -function pattern_controller.update_working_patterns() - for c = 1, 16 do - pattern_controller.update_working_pattern(c) - end -end - function pattern_controller.update_working_pattern(c) local selected_sequencer_pattern = program.get_selected_sequencer_pattern() local sequencer_patterns = selected_sequencer_pattern.channels diff --git a/lib/step_handler.lua b/lib/step_handler.lua index a63ff43..cdb564e 100644 --- a/lib/step_handler.lua +++ b/lib/step_handler.lua @@ -583,7 +583,7 @@ function step_handler.process_song_sequencer_patterns() step_handler.reset_pattern() end end - pattern_controller.throttled_update_working_patterns() + pattern_controller.update_working_patterns() end end diff --git a/mosaic.lua b/mosaic.lua index d9f9fb8..fbf4143 100644 --- a/mosaic.lua +++ b/mosaic.lua @@ -186,7 +186,7 @@ function init() redraw_clock = clock.run( function() while true do - clock.sleep(1/20) + clock.sleep(1/30) if fn.dirty_screen() then redraw() end