Module:Infobox MOS: Difference between revisions

Ganaram inukshuk (talk | contribs)
Fixed wrong args being passed
Ganaram inukshuk (talk | contribs)
Moved categories to helper function
Line 43: Line 43:
   local mult = 10^(numDecimalPlaces or 0)
   local mult = 10^(numDecimalPlaces or 0)
   return math.floor(num * mult + 0.5) / mult
   return math.floor(num * mult + 0.5) / mult
end
-- Helper function
-- Adds categories
function p.categorize(tuning)
local tuning = tuning or "5L 2s"
local input_mos = MOS.parse(tuning)
-- Add to category of abstact mosses
local categories = "[[Category:Abstract MOS patterns]]"
-- Add tuning category
categories = categories .. "\n" .. string.format('[[Category:%s]]', tuning)
-- Add notecount category if the notecount is greater than 3
local notecount = input_mos.nL + input_mos.ns
if notecount > 3 then
categories = categories .. "\n" .. string.format('[[Category:%d-tone scales]]', notecount)
end
-- Add to nonoctave category if the equave is nonoctave
if not rat.eq(input_mos.equave, rat.new(2)) then
categories = categories .. "\n" .. '[[Category:Nonoctave]]'
end
return categories
end
end


Line 52: Line 78:
local other_names = other_names or nil
local other_names = other_names or nil
local mos = MOS.parse(tuning)
local mos = MOS.parse(tuning)
-- category of the main article
local categories = '[[Category:' .. tuning .. ']]\n'
-- Add to abstract mos pattern category
categories = categories .. '[[Category:Abstract MOS patterns]]\n'
-- Add to approprite category of scales by note count, except if it's 3 or less
local note_count = mos.nL+mos.ns
if note_count > 3 then
categories = categories .. '[[Category:' .. note_count .. '-tone scales]]\n'
end
local equave = mos.equave
local equave = mos.equave
Line 266: Line 280:
)
)
if not debug_mode then
if not debug_mode then
result = result .. "\n" .. categories
result = result .. "\n\n" .. p.categorize(tuning)
end
end
return result
return result