Module:MOS degrees: Difference between revisions

ArrowHead294 (talk | contribs)
mNo edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
local et = require("Module:ET")
--local jiraf = require("Module:JI ratio finder")
local mos = require("Module:MOS")
local mos = require("Module:MOS")
local mosnot = require("Module:MOS notation")
local rat = require("Module:Rational")
local rat = require("Module:Rational")
local tamnams = require("Module:TAMNAMS")
local utils = require("Module:Utils")
local utils = require("Module:Utils")
local mosnot = require("Module:MOS notation")
local yesno = require("Module:Yesno")
local et = require("Module:ET")
--local jiraf = require('Module:JI ratio finder')
local tamnams = require("Module:TAMNAMS")
local p = {}


-- Version 2 of the MOS degrees moudle (by ganaraminukshuk)
-- TODO:
-- This is based more off of the MOS intervals module and older, non-tempalte tables that feature JI ratios,
-- Rewrite "main function" into a underscore-prefixed function to be called by Lua code and a wrapper to be called by templates. (HIGH PRIORITY!!!)
-- and doesn't depend on genchains (except for note names) to calculate cent values or degree names.
-- Adopt MOS arithmetic function (MEDIUM-PRIORITY!!!)
-- Current TODO list:
-- Add support for double accidentals (low-priority)
-- - Rewrite "main function" into a underscore-prefixed function to be called
-- Move certain helper functions to helper modules (low-priority)
--  by lua code and a wrapper to be called by templates. (HIGH PRIORITY!!!)
-- - Adopt MOS arithmetic function (MEDIUM-PRIORITY!!!)
-- - Add support for double accidentals (low-priority)
-- - Move certain helper functions to helper modules (low-priority)


-- Helper function
-- Helper function
-- Parses entries from a semicolon-delimited string and returns them in an array
-- Parses entries from a semicolon-delimited string and returns them in an array
-- TODO: Separate this and related functions (parse_pair and parse_kv_pairs) into its own module, as they're included
-- TODO: Separate this and related functions (parse_pair and parse_kv_pairs) into its own module, as they're included
-- in various modules at this point, such as: scale tree, MOS mdoes
-- in various modules at this point, such as: scale tree, MOS modes
function p.parse_entries(unparsed)
function p.parse_entries(unparsed)
local parsed = {}
local parsed = {}
Line 148: Line 146:
if not is_root then
if not is_root then
for i = 1, number_of_alterations do
for i = 1, number_of_alterations do
table.insert(row_colors, "eaeaff")
table.insert(row_colors, "#eaeaff")
end
end
end
end
Line 154: Line 152:
-- Row colors for main mossetps (default row color)
-- Row colors for main mossetps (default row color)
if is_period then
if is_period then
table.insert(row_colors, "")
table.insert(row_colors, "none")
else
else
table.insert(row_colors, "")
table.insert(row_colors, "none")
table.insert(row_colors, "")
table.insert(row_colors, "none")
end
end
Line 164: Line 162:
if not is_equave then
if not is_equave then
for i = 1, number_of_alterations do
for i = 1, number_of_alterations do
table.insert(row_colors, "eaeaff")
table.insert(row_colors, "#eaeaff")
end
end
end
end
Line 576: Line 574:
-- Create the table, starting with the headers
-- Create the table, starting with the headers
local result = '{| class="wikitable sortable"\n'
local result = "{| class=\"wikitable sortable mw-collapsible mw-collapsed\"\n"
-- First row
-- First row
result = result .. string.format("|+ style=\"font-size: 105%;\" | Scale degree of %s\n", scale_sig)
result = result
result = result .. "! rowspan=\"2\" class=\"unsortable\" | Scale degree\n"
.. "|+ style=\"font-size: 105%%; white-space: nowrap;\" | " .. string.format("Scale degree of %s\n", scale_sig)
.. "|-\n"
.. "! rowspan=\"2\" class=\"unsortable\" | Scale degree\n"
-- Add column for abbreviations
-- Add column for abbreviations
Line 620: Line 620:
-- Add the step ratio name if there is one
-- Add the step ratio name if there is one
if step_ratio_name == nil then
if step_ratio_name == nil then
result = result .. "! colspan=\"2\" |" .. et_as_string .. " (L:s = " .. step_ratio_key .. ")\n"
result = result .. "! colspan=\"2\" | " .. et_as_string .. " (L:s = " .. step_ratio_key .. ")\n"
else
else
result = result .. "! colspan=\"2\" |" .. et_as_string .. " (" .. step_ratio_name .. ", L:s = " .. step_ratio_key .. ")\n"
result = result .. "! colspan=\"2\" | " .. et_as_string .. " (" .. step_ratio_name .. ", L:s = " .. step_ratio_key .. ")\n"
end
end
end
end
Line 646: Line 646:
result = result .. "|-\n"
result = result .. "|-\n"
else
else
result = result .. string.format("|- style=\"background-color: %s\"\n", row_color)
result = result .. string.format("|- style=\"background: %s\"\n", row_color)
end
end
Line 802: Line 802:
if #frame.args["Notation"] > 0 then
if #frame.args["Notation"] > 0 then
if frame.args["Notation"] == "Default" and scale_sig == "5L 2s" then
if frame.args["Notation"] == "Default" and scale_sig == "5L 2s" then
notation_parsed = { ['Naturals'] = "CDEFGAB", ['Sharp'] = "#", ['Flat'] = "b" }
notation_parsed = { ["Naturals"] = "CDEFGAB", ["Sharp"] = "#", ["Flat"] = "b" }
show_notation = 1
show_notation = 1
elseif frame.args["Notation"] == "Default" and scale_sig ~= "5L 2s" then
elseif frame.args["Notation"] == "Default" and scale_sig ~= "5L 2s" then
local default_nominals = "JKLMNOPQRSTUVWXYZ"
local default_nominals = "JKLMNOPQRSTUVWXYZ"
notation_parsed = { ["Naturals"] = string.sub(default_nominals, 1, mossteps_per_equave), ['Sharp'] = "&", ['Flat'] = "@" }
notation_parsed = { ["Naturals"] = string.sub(default_nominals, 1, mossteps_per_equave), ["Sharp"] = "&", ["Flat"] = "@" }
show_notation = 1
show_notation = 1
else
else
Line 817: Line 817:
result = p.mos_degrees(input_mos, step_ratios, mos_prefix, show_abbreviations, number_of_alterations, ji_ratios_parsed, udp_parsed, notation_parsed, show_notation)
result = p.mos_degrees(input_mos, step_ratios, mos_prefix, show_abbreviations, number_of_alterations, ji_ratios_parsed, udp_parsed, notation_parsed, show_notation)
 
return result
-- Debugger
local debugg = yesno(frame.args["debug"])
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
end


return p
return p