Skip to content

Commit

Permalink
Merge pull request #79 from subvertnormality/shuffle_fix
Browse files Browse the repository at this point in the history
Fixing various bugs
  • Loading branch information
subvertnormality authored Jan 9, 2025
2 parents c7a09a6 + dc54ec9 commit 7232f1c
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 122 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@


## 1.2.1

- Fixed regression that stopped shuffle from being applied to channels on pattern reset.
- Added global option to disable honouring scale transpose when using midi input devices.
- Fixed regression that stopped scale degree and rotation from being honoured properly when using midi input devices.

## 1.2.0

- Added mute_root_note trig param to silence the root note of chords while allowing other chord notes to play.
- Added global option to fully quantize note masks (quantiser_fully_act_on_note_masks) to make note masks follow scale degree and rotation changes.
- Added fully_quantise_mask trig param to control whether note masks are fully quantised to the current scale, including scale degree and rotation on a per-channel or per-step basis.


## 1.1.2

- Chord masks now follow the root note after random note shifts have been applied.
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,10 @@ Similarly, "Lock merged to pent." is on by default and ensures notes modified by

"Honor scale degree" is off by default. Enabling this setting means the current scale's degree option will affect the MIDI keyboard mapping.

##### Honour Scale Transpose

"Honour scale transpose" is off by default. Enabling this setting means the current scale's transpose option will affect the MIDI keyboard mapping.

### Sinfonion Connect

You can sync up your Eurorack Sinfonion module to Mosaic using a DIY device called [norns2sinfonion](https://github.com/subvertnormality/norns2sinfonion).
Expand Down
22 changes: 11 additions & 11 deletions lib/clock/m_clock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ end
local function get_shuffle_values(channel)

local shuffle_values = {
swing = (channel.swing ~= -51) and channel.swing or params:get("global_swing") or 0,
swing_or_shuffle = (channel.swing_shuffle_type and channel.swing_shuffle_type > 0) and (channel.swing_shuffle_type) or params:get("global_swing_shuffle_type"),
shuffle_basis = (channel.shuffle_basis and channel.shuffle_basis > 0) and (channel.shuffle_basis) or params:get("global_shuffle_basis"),
shuffle_feel = (channel.shuffle_feel and channel.shuffle_feel > 0) and (channel.shuffle_feel) or params:get("global_shuffle_feel"),
shuffle_amount = channel.shuffle_amount or params:get("global_shuffle_amount")
swing = program.get_effective_swing(channel),
swing_or_shuffle = program.get_effective_swing_shuffle_type(channel),
shuffle_basis = program.get_effective_shuffle_basis(channel),
shuffle_feel = program.get_effective_shuffle_feel(channel),
shuffle_amount = program.get_effective_shuffle_amount(channel)
}

if channel.number == 17 then
Expand Down Expand Up @@ -480,8 +480,8 @@ end

function m_clock.set_swing_shuffle_type(channel_number, swing_or_shuffle)
local clock = m_clock["channel_" .. channel_number .. "_clock"]
clock:set_swing_or_shuffle((swing_or_shuffle or 2) - 1)
clock.end_of_clock_processor:set_swing_or_shuffle((swing_or_shuffle or 2) - 1)
clock:set_swing_or_shuffle((swing_or_shuffle or 0))
clock.end_of_clock_processor:set_swing_or_shuffle((swing_or_shuffle or 0))
end

function m_clock.set_channel_swing(channel_number, swing)
Expand All @@ -492,14 +492,14 @@ end

function m_clock.set_channel_shuffle_feel(channel_number, shuffle_feel)
local clock = m_clock["channel_" .. channel_number .. "_clock"]
clock:set_shuffle_feel((shuffle_feel or 2) - 1)
clock.end_of_clock_processor:set_shuffle_feel((shuffle_feel or 2) - 1)
clock:set_shuffle_feel((shuffle_feel or 0))
clock.end_of_clock_processor:set_shuffle_feel((shuffle_feel or 0))
end

function m_clock.set_channel_shuffle_basis(channel_number, shuffle_basis)
local clock = m_clock["channel_" .. channel_number .. "_clock"]
clock:set_shuffle_basis((shuffle_basis or 2) - 1)
clock.end_of_clock_processor:set_shuffle_basis((shuffle_basis or 2) - 1)
clock:set_shuffle_basis((shuffle_basis or 0))
clock.end_of_clock_processor:set_shuffle_basis((shuffle_basis or 0))
end

function m_clock.set_channel_shuffle_amount(channel_number, shuffle_amount)
Expand Down
18 changes: 6 additions & 12 deletions lib/clock/m_lattice.lua
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ function Lattice:new_sprocket(args)
args.delay = args.delay == nil and 0 or util.clamp(args.delay,0,1)
args.swing = args.swing == nil and 0 or util.clamp(args.swing,-50,50)
args.swing_or_shuffle = args.swing_or_shuffle == nil and 1 or util.clamp(args.swing_or_shuffle,1,2)
args.shuffle_basis = args.shuffle_basis and util.clamp(args.shuffle_basis, 0, 6) or 0
args.shuffle_feel = args.shuffle_feel and util.clamp(args.shuffle_feel, 0, 3) or 0
args.shuffle_basis = args.shuffle_basis and util.clamp(args.shuffle_basis, 1, 6) or 0
args.shuffle_feel = args.shuffle_feel and util.clamp(args.shuffle_feel, 1, 4) or 0
args.shuffle_amount = args.shuffle_amount and util.clamp(args.shuffle_amount, 0, 100) or 0
args.step = 1
args.lattice = self
Expand Down Expand Up @@ -297,8 +297,8 @@ function Sprocket:new(args)
p.phase = args.phase or 1
p.ppqn = args.ppqn
p.swing_or_shuffle = args.swing_or_shuffle
p.shuffle_basis = util.clamp(args.shuffle_basis, 0, 6)
p.shuffle_feel = util.clamp(args.shuffle_feel, 0, 3)
p.shuffle_basis = util.clamp(args.shuffle_basis, 1, 6)
p.shuffle_feel = util.clamp(args.shuffle_feel, 1, 4)
p.shuffle_amount = (args.shuffle_amount == nil) and 1.0 or util.clamp(args.shuffle_amount, 0, 100) / 100
p.current_ppqn = args.ppqn
p.ppqn_error = 0.5
Expand Down Expand Up @@ -389,18 +389,12 @@ function Sprocket:set_shuffle_amount(shuffle_amount)
end

function Sprocket:set_shuffle_basis(basis)
self.shuffle_basis = util.clamp(basis, 0, 6)
self.shuffle_basis = util.clamp(basis, 1, 6)
self:update_shuffle(self.step)
end

function Sprocket:set_shuffle_feel(feel)
self.shuffle_feel = util.clamp(feel, 0, 3)
self:update_shuffle(self.step)
end

function Sprocket:set_shuffle_or_swing(swing_or_shuffle)
self.swing_or_shuffle = util.clamp(swing_or_shuffle, 1, 2)
self:update_swing()
self.shuffle_feel = util.clamp(feel, 1, 4)
self:update_shuffle(self.step)
end

Expand Down
2 changes: 2 additions & 0 deletions lib/m_midi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ function handle_midi_event_data(data, midi_device)
s = fn.calc_grid_count(pressed_keys[1][1], pressed_keys[1][2])
step_scale_number = step.manually_calculate_step_scale_number(channel.number, s)
end
else
step_scale_number = step.manually_calculate_step_scale_number(channel.number, s)
end

local note = quantiser.process_with_global_params(midi_tables[data[2] + 1][1], midi_tables[data[2] + 1][2], transpose, step_scale_number)
Expand Down
24 changes: 16 additions & 8 deletions lib/models/program.lua
Original file line number Diff line number Diff line change
Expand Up @@ -761,34 +761,42 @@ function program.get_effective_swing_shuffle_type(channel)
end

function program.get_effective_swing(channel)
if channel.swing ~= nil then
if channel.swing ~= nil and channel.swing > -51 then
return channel.swing
else
elseif params:get("global_swing_shuffle_type") == 1 then
return params:get("global_swing")
else
return 0
end
end

function program.get_effective_shuffle_feel(channel)
if channel.shuffle_feel ~= nil then
if channel.shuffle_feel ~= nil and channel.shuffle_feel > 0 then
return channel.shuffle_feel
else
elseif params:get("global_swing_shuffle_type") == 2 then
return params:get("global_shuffle_feel")
else
return 0
end
end

function program.get_effective_shuffle_basis(channel)
if channel.shuffle_basis ~= nil then
if channel.shuffle_basis ~= nil and channel.shuffle_basis > 0 then
return channel.shuffle_basis
else
elseif params:get("global_swing_shuffle_type") == 2 then
return params:get("global_shuffle_basis")
else
return 0
end
end

function program.get_effective_shuffle_amount(channel)
if channel.shuffle_amount ~= nil then
if channel.shuffle_amount ~= nil and channel.shuffle_amount > 0 then
return channel.shuffle_amount
else
elseif params:get("global_swing_shuffle_type") == 2 then
return params:get("global_shuffle_amount")
else
return 0
end
end

Expand Down
104 changes: 48 additions & 56 deletions lib/pages/channel_edit_page/channel_edit_page_ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,34 @@ local shuffle_feel_selector = list_selector:new(0, 40, "Feel", {{name = "X", val
local shuffle_basis_selector = list_selector:new(40, 40, "Basis", {{name = "X", value = 1}, {name = "9", value = 2}, {name = "7", value = 3}, {name = "5", value = 4}, {name = "6", value = 5}, {name = "8??", value = 6}, {name = "9??", value = 7}})
local shuffle_amount_selector = value_selector:new(70, 40, "Amount", 0, 100)


local memory_state = {
events = {}
}

function channel_edit_page_ui.get_swing_shuffle_type_selector_value()
return swing_shuffle_type_selector:get_selected().value - 1
end

function channel_edit_page_ui.get_shuffle_feel_selector_value()
return shuffle_feel_selector:get_selected().value - 1
end

function channel_edit_page_ui.get_shuffle_basis_selector_value()
return shuffle_basis_selector:get_selected().value - 1
end

function channel_edit_page_ui.set_swing_shuffle_type_selector_value(value)
swing_shuffle_type_selector:set_selected_value(value + 1)
end

function channel_edit_page_ui.set_shuffle_feel_selector_value(value)
shuffle_feel_selector:set_selected_value(value + 1)
end

function channel_edit_page_ui.set_shuffle_basis_selector_value(value)
shuffle_basis_selector:set_selected_value(value + 1)
end

-- Value selectors with initial values
local mask_selectors = {
trig = value_selector:new(0 + (1 - 1) % 5 * 25, 18 + math.floor((1 - 1) / 5) * 22, "Trig", -1, 1),
Expand Down Expand Up @@ -219,13 +242,13 @@ end)

local clock_mods_page = page:new("Clocks", function()
swing_shuffle_type_selector:draw()
local value = swing_shuffle_type_selector:get_selected().value
if value == 1 then
value = params:get("global_swing_shuffle_type") + 1
local value = channel_edit_page_ui.get_swing_shuffle_type_selector_value()
if value == 0 then
value = params:get("global_swing_shuffle_type")
end
if value == 2 then
if value == 1 then
swing_selector:draw()
elseif value == 3 then
elseif value == 2 then
shuffle_feel_selector:draw()
shuffle_basis_selector:draw()
shuffle_amount_selector:draw()
Expand Down Expand Up @@ -344,10 +367,10 @@ function channel_edit_page_ui.init()
clock_mod_list_selector:select()
swing_selector:set_value(0)

swing_shuffle_type_selector:set_selected_value(params:get("global_swing_shuffle_type"))
channel_edit_page_ui.set_swing_shuffle_type_selector_value(params:get("global_swing_shuffle_type"))
swing_selector:set_value(params:get("global_swing"))
shuffle_feel_selector:set_selected_value(params:get("global_shuffle_feel"))
shuffle_basis_selector:set_selected_value(params:get("global_shuffle_basis"))
channel_edit_page_ui.set_shuffle_feel_selector_value(params:get("global_shuffle_feel"))
channel_edit_page_ui.set_shuffle_basis_selector_value(params:get("global_shuffle_basis"))
shuffle_amount_selector:set_value(params:get("global_shuffle_amount"))

memory_controls.navigator:set_event_state(memory_state)
Expand All @@ -368,11 +391,11 @@ end
-- Update functions
function channel_edit_page_ui.update_swing_shuffle_type()
local channel = program.get_selected_channel()
local value = swing_shuffle_type_selector:get_selected().value
local value = channel_edit_page_ui.get_swing_shuffle_type_selector_value()
channel.swing_shuffle_type = value

if value == 1 or nil then
value = params:get("global_swing_shuffle_type") + 1 or 1
if value == 0 or nil then
value = program.get_effective_swing_shuffle_type(channel)
end

if m_clock.is_playing() then
Expand All @@ -389,13 +412,7 @@ end

function channel_edit_page_ui.align_global_and_local_swing_shuffle_type_values(c)
local channel = program.get_channel(program.get().selected_song_pattern, c)
local channel_value = channel.swing_shuffle_type
local value = channel_value
if channel_value == 1 or nil then
value = params:get("global_swing_shuffle_type") + 1 or 1
end

m_clock.set_swing_shuffle_type(channel.number, value)
m_clock.set_swing_shuffle_type(channel.number, program.get_effective_swing_shuffle_type(channel))

end

Expand All @@ -405,7 +422,7 @@ function channel_edit_page_ui.update_swing()
local value = swing_selector:get_value()
channel.swing = value
if value == -51 or nil then
value = params:get("global_swing")
value = program.get_effective_swing(channel)
end

if m_clock.is_playing() then
Expand All @@ -421,22 +438,16 @@ end

function channel_edit_page_ui.align_global_and_local_swing_values(c)
local channel = program.get_channel(program.get().selected_song_pattern, c)
local channel_value = channel.swing
local value = channel_value
if channel_value == -51 or nil then
value = params:get("global_swing")
end

m_clock.set_channel_swing(channel.number, value)
m_clock.set_channel_swing(channel.number, program.get_effective_swing(channel))

end

function channel_edit_page_ui.update_shuffle_feel()
local channel = program.get_selected_channel()
local shuffle_feel = shuffle_feel_selector:get_selected().value
local shuffle_feel = channel_edit_page_ui.get_shuffle_feel_selector_value()
channel.shuffle_feel = shuffle_feel
if shuffle_feel == 1 or nil then
shuffle_feel = params:get("global_shuffle_feel") + 1 or 0
if shuffle_feel == 0 or nil then
shuffle_feel = program.get_effective_shuffle_feel(channel)
end

if m_clock.is_playing() then
Expand All @@ -452,24 +463,18 @@ end

function channel_edit_page_ui.align_global_and_local_shuffle_feel_values(c)
local channel = program.get_channel(program.get().selected_song_pattern, c)
local channel_value = channel.shuffle_feel
local value = channel_value
if channel_value == 1 or nil then
value = params:get("global_shuffle_feel") + 1 or 0
end

m_clock.set_channel_shuffle_feel(channel.number, value)
m_clock.set_channel_shuffle_feel(channel.number, program.get_effective_shuffle_feel(channel))

end

function channel_edit_page_ui.update_shuffle_basis()
local channel = program.get_selected_channel()

local shuffle_basis = shuffle_basis_selector:get_selected().value
local shuffle_basis = channel_edit_page_ui.get_shuffle_basis_selector_value()
channel.shuffle_basis = shuffle_basis

if shuffle_basis == 1 or nil then
shuffle_basis = params:get("global_shuffle_basis") + 1 or 0
if shuffle_basis == 0 or nil then
shuffle_basis = program.get_effective_shuffle_basis(channel)
end

if m_clock.is_playing() then
Expand All @@ -485,14 +490,7 @@ end

function channel_edit_page_ui.align_global_and_local_shuffle_basis_values(c)
local channel = program.get_channel(program.get().selected_song_pattern, c)
local channel_value = channel.shuffle_basis
local value = channel_value
if channel_value == 1 or nil then
value = params:get("global_shuffle_basis") + 1 or 0
end

m_clock.set_channel_shuffle_basis(channel.number, value)

m_clock.set_channel_shuffle_basis(channel.number, program.get_effective_shuffle_basis(channel))
end

function channel_edit_page_ui.update_shuffle_amount()
Expand All @@ -501,7 +499,7 @@ function channel_edit_page_ui.update_shuffle_amount()
channel.shuffle_amount = shuffle_amount

if shuffle_amount == 0 or nil then
shuffle_amount = params:get("global_shuffle_amount") or 0
shuffle_amount = program.get_effective_shuffle_amount(channel)
end

if m_clock.is_playing() then
Expand All @@ -517,13 +515,7 @@ end

function channel_edit_page_ui.align_global_and_local_shuffle_amount_values(c)
local channel = program.get_channel(program.get().selected_song_pattern, c)
local channel_value = channel.shuffle_amount
local value = channel_value
if channel_value == 0 or nil then
value = params:get("global_shuffle_amount") or 0
end

m_clock.set_channel_shuffle_amount(channel.number, value)
m_clock.set_channel_shuffle_amount(channel.number, program.get_effective_shuffle_amount(channel))

end

Expand Down
Loading

0 comments on commit 7232f1c

Please sign in to comment.