Module:MOS gamut: Difference between revisions

Ganaram inukshuk (talk | contribs)
Updated to use parse_notation function from mos notation module
ArrowHead294 (talk | contribs)
mNo edit summary
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local mos = require('Module:MOS')
local rat = require('Module:Rational')
local mosm = require('Module:MOS modes')
local et = require('Module:ET')
local mosnot = require('Module:MOS notation')
local p = {}
local p = {}


-- Function that produces a gamut, a sequence of note names with accidentals, for an edo
local et = require("Module:ET")
local mos = require("Module:MOS")
local mosm = require("Module:MOS modes")
local mosnot = require("Module:MOS notation")
local rat = require("Module:Rational")
local utils = require("Module:Utils")
local yesno = require("Module:Yesno")
 
-- Helper function for the function that has "frame" as a parameter
-- Helper function for the function that has "frame" as a parameter
function p.mos_gamut(input_mos, udp, step_ratio, note_symbols, chroma_plus_symbol, chroma_minus_symbol)
function p.mos_gamut(input_mos, udp, step_ratio, note_symbols, chroma_plus_symbol, chroma_minus_symbol)
Line 15: Line 17:
-- Get the number of mossteps per period and equave
-- Get the number of mossteps per period and equave
local mossteps_per_equave = input_mos.nL + input_mos.ns
local mossteps_per_equave = input_mos.nL + input_mos.ns
local periods_per_equave = rat.gcd(input_mos.nL, input_mos.ns)
local periods_per_equave = utils._gcd(input_mos.nL, input_mos.ns)
local mossteps_per_period = mossteps_per_equave / periods_per_equave
local mossteps_per_period = mossteps_per_equave / periods_per_equave
Line 32: Line 34:
local generators_up = udp[1]
local generators_up = udp[1]
local generators_down = udp[2]
local generators_down = udp[2]
-- The natural note symbols are those that correspond to diamond-mos
-- (JKLMN...) unless the mos is 5L 2s, then it's CDEFGAB
-- If it's diamond-mos, gamut is limited to 17 note names
local note_symbols_main = "JKLMNOPQRSTUVWXYZ"
local note_symbols_default = string.sub(note_symbols_main, 1, mossteps_per_equave)
if scale_sig == "5L 2s" then
note_symbols_default = "CDEFGAB"
end
local note_symbols = note_symbols or note_symbols_default
-- Get notation: naturals (or nominals), sharp symbol, and flat symbol
-- The default accidentals are the amp and at (& and @)
local notation_default = { ['Naturals'] = string.sub("JKLMNOPQRSTUVWXYZ", 1, mossteps_per_equave), ['Sharp'] = "&", ['Flat'] = "@" }
-- unless the mos is 5L 2s, then it's sharp and flat (# and b)
local chroma_plus_default = "&"
local chroma_minus_default = "@"
if scale_sig == "5L 2s" then
if scale_sig == "5L 2s" then
notation_default['Naturals'] = "CDEFGAB"
chroma_plus_default = "#"
notation_default['Sharp'] = "#"
chroma_minus_default = "b"
notation_default['Flat'] = "b"
end
end
local notation = mosnot.parse_notation(frame.args['Notation']) or notation_default
local chroma_plus_symbol = chroma_plus_symbol or chroma_plus_default
local note_symbols = notation['Naturals']
local chroma_minus_symbol = chroma_minus_symbol or chroma_minus_default
local chroma_plus_symbol = notation['Sharp']
local chroma_minus_symbol = notation['Flat']
-- How long is the inital genchain for notes without accidentals?
-- How long is the inital genchain for notes without accidentals?
Line 52: Line 63:
local kp = step_ratio[1]
local kp = step_ratio[1]
local kq = step_ratio[2]
local kq = step_ratio[2]
local k = rat.gcd(kp, kq)
local k = utils._gcd(kp, kq)
local num = kp / k
local num = kp / k
local den = kq / k
local den = kq / k
Line 87: Line 98:
-- How long are the genchains? Length is per period
-- How long are the genchains? Length is per period
local ascending_genchain_length = gens_up_per_period + genchain_extend
-- Genchain length counts the root, hence the +1
local descending_genchain_length = gens_down_per_period + genchain_extend
local ascending_genchain_length = gens_up_per_period + genchain_extend + 1
local descending_genchain_length = gens_down_per_period + genchain_extend + 1
-- Get the ascending and descending genchains
-- Get the ascending and descending genchains
Line 103: Line 115:
-- How many esteps are the bright and dark generators?
-- How many esteps are the bright and dark generators?
local bright_gen = mos.bright_gen(input_mos)
local bright_gen = mos.bright_gen(input_mos)
local esteps_per_bright_gen = bright_gen['L'] * num + bright_gen['s'] * den
local esteps_per_bright_gen = bright_gen["L"] * num + bright_gen["s"] * den
local esteps_per_dark_gen = esteps_per_period - esteps_per_bright_gen
local esteps_per_dark_gen = esteps_per_period - esteps_per_bright_gen
Line 114: Line 126:
-- Convert the notationally agnostic form into a form that uses given notation
-- Convert the notationally agnostic form into a form that uses given notation
local note = ascending_genchain[j][i]
local note = ascending_genchain[j][i]
local note_symbol = string.sub(note_symbols, note['mossteps'] + 1, note['mossteps'] + 1)
local note_symbol = string.sub(note_symbols, note["Mossteps"] + 1, note["Mossteps"] + 1)
local chroma_count = note['chromas']
local chroma_count = note["Chromas"]
local note_name = note_symbol .. string.rep(chroma_plus_symbol, chroma_count)
local note_name = note_symbol .. string.rep(chroma_plus_symbol, chroma_count)
Line 127: Line 139:
-- Convert the notationally agnostic form into a form that uses given notation
-- Convert the notationally agnostic form into a form that uses given notation
local note = descending_genchain[j][i]
local note = descending_genchain[j][i]
local note_symbol = string.sub(note_symbols, note['mossteps'] + 1, note['mossteps'] + 1)
local note_symbol = string.sub(note_symbols, note["Mossteps"] + 1, note["Mossteps"] + 1)
local chroma_count = note['chromas'] * -1
local chroma_count = note["Chromas"] * -1
local note_name = note_symbol .. string.rep(chroma_minus_symbol, chroma_count)
local note_name = note_symbol .. string.rep(chroma_minus_symbol, chroma_count)
Line 150: Line 162:
function p.mos_gamut_frame(frame)
function p.mos_gamut_frame(frame)
-- Default parameters for input mos and step ratio (5L 2s and 2:1 step ratio)
-- Default parameters for input mos and step ratio (5L 2s and 2:1 step ratio)
local input_mos_unparsed = frame.args['Scale Signature']
local input_mos_unparsed = frame.args["Scale Signature"]
local input_mos = mos.parse(input_mos_unparsed) or mos.new(2, 5, 2)
local input_mos = mos.parse(input_mos_unparsed) or mos.new(2, 5, 2)
-- Step ratio
-- Step ratio
local step_ratio = { 2, 1 }
local step_ratio = { 2, 1 }
if string.len(frame.args['Step Ratio']) > 0 then
if string.len(frame.args["Step Ratio"]) > 0 then
step_ratio = mosnot.parse_step_ratio(frame.args['Step Ratio'])
step_ratio = mosnot.parse_step_ratio(frame.args["Step Ratio"])
end
end
-- Get the number of mossteps per period and equave
-- Get the number of mossteps per period and equave
local mossteps_per_equave = input_mos.nL + input_mos.ns
local mossteps_per_equave = input_mos.nL + input_mos.ns
local periods_per_equave = rat.gcd(input_mos.nL, input_mos.ns)
local periods_per_equave = utils._gcd(input_mos.nL, input_mos.ns)
local mossteps_per_period = mossteps_per_equave / periods_per_equave
local mossteps_per_period = mossteps_per_equave / periods_per_equave
Line 176: Line 188:
udp = { 5, 1 }
udp = { 5, 1 }
end
end
if string.len(frame.args['UDP']) > 0 then
if string.len(frame.args["UDP"]) > 0 then
udp = mosnot.parse_udp(frame.args['UDP'])
udp = mosnot.parse_udp(frame.args["UDP"])
end
end
local generators_up = udp[1]
local generators_up = udp[1]
local generators_down = udp[2]
local generators_down = udp[2]
-- Get notation: naturals (or nominals), sharp symbol, and flat symbol
-- Get note symbols
local notation_default = { ["Naturals"] = string.sub("JKLMNOPQRSTUVWXYZ", 1, mossteps_per_equave), ["Sharp"] = "&", ["Flat"] = "@" }
-- If this param was blank, default to diamond-mos; limited to 17 note names
-- But if it's blank and the scalesig is 5L 2s, default to standard notation
-- This order of operations allows for overriding standard notation for 5L 2s
local note_symbols_main = "JKLMNOPQRSTUVWXYZ"
local note_symbols = string.sub(note_symbols_main, 1, mossteps_per_equave)
if scale_sig == "5L 2s" then
if scale_sig == "5L 2s" then
note_symbols = "CDEFGAB"
notation_default["Naturals"] = "CDEFGAB"
end
notation_default["Sharp"] = "#"
-- If a value was entered, override the default value
notation_default["Flat"] = "b"
if string.len(frame.args['Note Symbols']) > 0 then
note_symbols = frame.args['Note Symbols']
end
-- Get accidental symbols
-- If this param was blank, default to diamond-mos symbols & and @
-- unless the mos is 5L 2s, then it's sharp and flat # and b
-- This order of operations allows for overriding standard notation for 5L 2s
local chroma_plus_symbol = "&"
local chroma_minus_symbol = "@"
if scale_sig == "5L 2s" then
chroma_plus_symbol = "#"
chroma_minus_symbol = "b"
end
-- If value(s) were entered, override the default values
if string.len(frame.args['Sharp Symbol']) > 0 then
chroma_plus_symbol = frame.args['Sharp Symbol']
end
if string.len(frame.args['Flat Symbol']) > 0 then
chroma_minus_symbol = frame.args['Flat Symbol']
end
end
local notation = mosnot.parse_notation(frame.args["Notation"]) or notation_default
local note_symbols = notation["Naturals"]
local chroma_plus_symbol = notation["Sharp"]
local chroma_minus_symbol = notation["Flat"]
-- Get the gamut
-- Get the gamut
Line 232: Line 223:
result = result .. "'''" .. gamut[#gamut] .. "'''"
result = result .. "'''" .. gamut[#gamut] .. "'''"
return result
-- Debugger option
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