Module:MOS notation: Difference between revisions

Ganaram inukshuk (talk | contribs)
Renaming/reorganizing functions for sake of documentation, keys are now capitalized (mossteps, quality, and chromas); will momentarily break modules mos gamut and mos degrees v2
ArrowHead294 (talk | contribs)
m Sort dependencies
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- This is a helper module that contains commonly used functions for:
-- - MOS degrees
-- - MOS gamut
local mos = require('Module:MOS')
local rat = require('Module:Rational')
local ord = require('Module:Ordinal')
local utils = require('Module:Utils')
local p = {}
local p = {}
local mos = require("Module:MOS")
local ord = require("Module:Ordinal")
local rat = require("Module:Rational")
local utils = require("Module:Utils")


-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
Line 24: Line 22:
local parsed = {}
local parsed = {}
for entry in string.gmatch(unparsed, '([^;]+)') do
for entry in string.gmatch(unparsed, "([^;]+)") do
local trimmed = entry:gsub("^%s*(.-)%s*$", "%1")
local trimmed = entry:gsub("^%s*(.-)%s*$", "%1")
table.insert(parsed, trimmed) -- Add to array
table.insert(parsed, trimmed) -- Add to array
end
end
local notation = { ['Naturals'] = parsed[1], ['Sharp'] = parsed[2], ['Flat'] = parsed[3] }
local notation = { ["Naturals"] = parsed[1], ["Sharp"] = parsed[2], ["Flat"] = parsed[3] }
if #parsed == 3 then
if #parsed == 3 then
return notation
return notation
Line 42: Line 40:
local parsed = {}
local parsed = {}
for entry in string.gmatch(unparsed, '([^/]+)') do
for entry in string.gmatch(unparsed, "([^/]+)") do
local trimmed = entry:gsub("^%s*(.-)%s*$", "%1")
local trimmed = entry:gsub("^%s*(.-)%s*$", "%1")
table.insert(parsed, trimmed) -- Add to array
table.insert(parsed, trimmed) -- Add to array
Line 73: Line 71:
local parsed = {}
local parsed = {}
for entry in string.gmatch(step_ratio_unparsed, '([^,]+)') do
for entry in string.gmatch(step_ratio_unparsed, "([^,]+)") do
local trimmed = entry:gsub("^%s*(.-)%s*$", "%1")
local trimmed = entry:gsub("^%s*(.-)%s*$", "%1")
table.insert(parsed, trimmed) -- Add to array
table.insert(parsed, trimmed) -- Add to array
Line 114: Line 112:
-- Get the mossteps and quality from the encoded mosstep
-- Get the mossteps and quality from the encoded mosstep
local mossteps = encoded_mosstep['Mossteps']
local mossteps = encoded_mosstep["Mossteps"]
local quality = encoded_mosstep['Quality']
local quality = encoded_mosstep["Quality"]
-- Notation options currently include:
-- Notation options currently include:
Line 247: Line 245:
-- Get the size of the generator in mossteps
-- Get the size of the generator in mossteps
local gen = mos.bright_gen(input_mos)
local gen = mos.bright_gen(input_mos)
local gen_in_mossteps = gen['L'] + gen['s']
local gen_in_mossteps = gen["L"] + gen["s"]
-- If the genchain is descending (ie, going_up is false), switch to
-- If the genchain is descending (ie, going_up is false), switch to
Line 288: Line 286:
-- Get the final note name
-- Get the final note name
local note_name = {}
local note_name = {}
note_name['Mossteps'] = index + root_offest -- Mossteps needed to reach a note
note_name["Mossteps"] = index + root_offest -- Mossteps needed to reach a note
note_name['Chromas'] = accidentals_to_add -- How many chromas
note_name["Chromas"] = accidentals_to_add -- How many chromas
-- Add the note name
-- Add the note name
Line 348: Line 346:
-- Get the number of mossteps for the generators
-- Get the number of mossteps for the generators
local bright_gen = mos.bright_gen(input_mos)
local bright_gen = mos.bright_gen(input_mos)
local mossteps_per_bright_gen = bright_gen['L'] + bright_gen['s']
local mossteps_per_bright_gen = bright_gen["L"] + bright_gen["s"]
local mossteps_per_dark_gen = mossteps_per_period - mossteps_per_bright_gen
local mossteps_per_dark_gen = mossteps_per_period - mossteps_per_bright_gen
Line 398: Line 396:
-- Put together the name
-- Put together the name
local degree = { ['Mossteps'] = mossteps, ['Quality'] = quality }
local degree = { ["Mossteps"] = mossteps, ["Quality"] = quality }
table.insert(chain_for_period, degree)
table.insert(chain_for_period, degree)
end
end