Module:MOS tunings: Difference between revisions

Ganaram inukshuk (talk | contribs)
Step ratios are now sorted by hardness, except for simple step ratios (2/1, 3/1, and 3/2)
Ganaram inukshuk (talk | contribs)
bugfix sorting algorithm
Line 27: Line 27:
-- Sorts step ratios L:s by their hardnesses
-- Sorts step ratios L:s by their hardnesses
function p.sort_step_ratios(step_ratios)
function p.sort_step_ratios(step_ratios)
if #step_ratios > 2 then
if #step_ratios < 2 then
return step_ratios
return step_ratios
end
end
Line 34: Line 34:
for i = 1, #step_ratios - 1 do
for i = 1, #step_ratios - 1 do
local index_of_current = i
local index_of_smallest = i
local current_val = step_ratios[i][1] / step_ratios[i][2]
local current_val = step_ratios[i][1] / step_ratios[i][2]
Line 40: Line 40:
for j = i + 1, #step_ratios do
for j = i + 1, #step_ratios do
if (step_ratios[j][1] / step_ratios[j][2] < current_val) then
if (step_ratios[j][1] / step_ratios[j][2] < current_val) then
index_of_current = j
index_of_smallest = j
end
end
end
end
if index_of_current ~= j then
if index_of_smallest ~= i then
local temp = step_ratios[index_of_current]
local temp = step_ratios[index_of_smallest]
step_ratios[index_of_current] = step_ratios[j]
step_ratios[index_of_smallest] = step_ratios[i]
step_ratios[j] = temp
step_ratios[i] = temp
end
end
end
end
Line 60: Line 60:
local step_ratio_range = ""
local step_ratio_range = ""
-- If the step ratios are 2/1, 3/1, and 3/2 in that order, then they are
-- If the step ratios are 3/2, 2/1, and 3/1 in that order, then they are
-- the simple step ratios: basic, hard, and soft.
-- the simple step ratios: basic, hard, and soft.
-- These should not be sorted, since the basic-hard-soft sorting is a little
-- These should not be sorted, since the basic-hard-soft sorting is a little
Line 182: Line 182:


function p.tester()
function p.tester()
return p._mos_tunings()
return p.sort_step_ratios({ {2,1}, {3,1}, {3,2} })
end
end


return p
return p