Module:Temperament data: Difference between revisions
CompactStar (talk | contribs) No edit summary |
CompactStar (talk | contribs) No edit summary |
||
| Line 4: | Line 4: | ||
local function gcd(a,b) | local function gcd(a,b) | ||
if type(a) == | if type(a) == 'number' and type(b) == 'number' and | ||
a == math.floor(a) and b == math.floor(b) then | a == math.floor(a) and b == math.floor(b) then | ||
if b == 0 then | if b == 0 then | ||
| Line 12: | Line 12: | ||
end | end | ||
else | else | ||
error( | error('Invalid argument to gcd (' .. tostring(a) .. ',' .. | ||
tostring(b) .. | tostring(b) .. ')', 2) | ||
end | end | ||
end | end | ||
| Line 222: | Line 222: | ||
local function mysplit (inputstr, sep) | local function mysplit (inputstr, sep) | ||
if sep == nil then | if sep == nil then | ||
sep = | sep = '%s' | ||
end | end | ||
local t={} | local t={} | ||
for str in string.gmatch(inputstr, | for str in string.gmatch(inputstr, '([^'..sep..']+)') do | ||
table.insert(t, str) | table.insert(t, str) | ||
end | end | ||
| Line 233: | Line 233: | ||
local function trim(x) | local function trim(x) | ||
local str = x | local str = x | ||
str = str:gsub( | str = str:gsub('%s+', '') | ||
str = string.gsub(str, | str = string.gsub(str, '%s+', '') | ||
return str | return str | ||
end | end | ||
function p.temperament_data(frame) | function p.temperament_data(frame) | ||
local subgroup = mysplit(frame.args['subgroup'], | local subgroup = mysplit(frame.args['subgroup'], '.') | ||
for i = 1, #subgroup do | for i = 1, #subgroup do | ||
subgroup[i] = tonumber(subgroup[i]) | subgroup[i] = tonumber(subgroup[i]) | ||
end | end | ||
local comma_matrix = mysplit(frame.args['comma_list'], | local comma_matrix = mysplit(frame.args['comma_list'], ',') | ||
for i = 1, #comma_matrix do | for i = 1, #comma_matrix do | ||
comma_matrix[i] = rat.parse(comma_matrix[i]) | comma_matrix[i] = rat.parse(comma_matrix[i]) | ||
end | end | ||
comma_matrix = rat_list_to_matrix(subgroup, comma_matrix) | comma_matrix = rat_list_to_matrix(subgroup, comma_matrix) | ||
local unparsed_gens = mysplit(frame.args['generators'], | local unparsed_gens = mysplit(frame.args['generators'], ',') | ||
local generators = mysplit(frame.args['generators'], | local generators = mysplit(frame.args['generators'], ',') | ||
for i = 1, #generators do | for i = 1, #generators do | ||
generators[i] = rat.parse(generators[i]) | generators[i] = rat.parse(generators[i]) | ||
| Line 255: | Line 255: | ||
generators = rat_list_to_matrix(subgroup, generators) | generators = rat_list_to_matrix(subgroup, generators) | ||
local pote_generator = get_pote_generator(subgroup, comma_matrix, generators) | local pote_generator = get_pote_generator(subgroup, comma_matrix, generators) | ||
local result = | local result = '[[Subgroup]]: ' .. frame.args['subgroup'] | ||
result = result .. | result = result .. '\n\n[[Comma list]]: ' .. frame.args['comma_list'] | ||
result = result .. | result = result .. '\n\n: mapping generators: ' | ||
for i = 1, #unparsed_gens do | for i = 1, #unparsed_gens do | ||
result = result .. '~' .. trim(unparsed_gens[i]) .. | result = result .. '~' .. trim(unparsed_gens[i]) .. ', ' | ||
end | end | ||
result = result:sub(0,-3) | result = result:sub(0,-3) | ||
result = result .. | if subgroup[1] ~= 2 then | ||
result = result .. '\n\n[[Optimal tuning]]s:\n*[[POTE|Pure-' .. subgroup[1] .. '/1 TE]]' | |||
else | |||
result = result .. '\n\n[[Optimal tuning]]s:\n*[[POTE]]: ' | |||
end | |||
for i = 1, #(pote_generator[1]) do | for i = 1, #(pote_generator[1]) do | ||
if pote_generator[1][i] == 1 then | if pote_generator[1][i] == 1 then | ||