Module:MOS intro: Difference between revisions

Ganaram inukshuk (talk | contribs)
Non-octave equaves now displays as a JI ratio and cent value
Ganaram inukshuk (talk | contribs)
Added TAMNAMS name lookup and support for entering names outside of TAMNAMS
Line 5: Line 5:
local utils = require('Module:Utils')
local utils = require('Module:Utils')
local p = {}
local p = {}
-- Helper function that parses entries from a semicolon-delimited string and returns them in an array
function p.parse_entries(unparsed)
local parsed = {}
for entry in string.gmatch(unparsed, '([^;]+)') do
table.insert(parsed, entry) -- Add to array
end
return parsed
end


-- Function that creates a mos intro sentence, given a mos
-- Function that creates a mos intro sentence, given a mos
function p.mos_intro_sentence(input_mos)
function p.mos_intro_sentence(input_mos, other_names)
local input_mos = input_mos or mos.new(4, 5, 3)
local input_mos = input_mos or mos.new(4, 5, 3)
local other_names = other_names or "name1; name2; name3"
-- Get the step counts and number of periods
-- Get the step counts and number of periods
Line 26: Line 36:
-- Get the scalesig
-- Get the scalesig
local scale_sig = mos.as_string(input_mos)
local scale_sig = mos.as_string(input_mos)
-- Get all the mos's names, starting with tamnams names if applicable
-- Some mosses have two tamnams names, so it's necessary to tokenize it
local tamnams_name = mos.tamnams_name[scale_sig] or ""
local mos_names = p.parse_entries(tamnams_name)
local other_names_tokenized = p.parse_entries(other_names)
-- Combine the two arrays
for i = 1, #other_names_tokenized do
mos_names[#mos_names + 1] = other_names_tokenized[i]
end
-- Get the eds (ets) corresponding to the collapsed and equalized mosses
-- Get the eds (ets) corresponding to the collapsed and equalized mosses
Line 43: Line 64:
local round = 3
local round = 3
-- Create the intro string
-- Create the intro string starting with the scale
local intro = "'''" .. scale_sig .. "''' is a"
local intro = "'''" .. scale_sig .. "'''"
-- Add the mos names, if any
if #mos_names == 1 then
intro = intro .. ", also called '''" .. mos_names[1] .. "''', is a"
elseif #mos_names == 2 then
intro = intro .. ", also called '''" .. mos_names[1] .. "''' or '''" .. mos_names[2] .. "''', is a"
elseif #mos_names > 2 then
intro = intro .. ", also called "
for i = 1, #mos_names - 1 do
intro = intro .. "'''" .. mos_names[i] .. "''', "
end
intro = intro .. "or '''" .. mos_names[#mos_names] .. "''', is a"
else
intro = intro .. " is a"
end
-- Add whether it's non-octave
-- Add whether it's non-octave
Line 115: Line 151:
-- Get and parse the the mos's scale signature, in the form xL ys or xL ys <p/q>
-- Get and parse the the mos's scale signature, in the form xL ys or xL ys <p/q>
local input_mos = mos.parse(frame.args['Scale Signature']) or mos.new(5, 2, 2)
local input_mos = mos.parse(frame.args['Scale Signature']) or mos.new(5, 2, 2)
local other_names = frame.args['Other Names'] or ""
return p.mos_intro_sentence(input_mos)
return p.mos_intro_sentence(input_mos, other_names)
end
end


return p
return p