Module:Xenpaper: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Ganaram inukshuk (talk | contribs)
Changed format for mos-to-xenpaper function
ArrowHead294 (talk | contribs)
mNo edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local rat = require('Module:Rational')
local p = {}
local p = {}
local mos = require("Module:MOS")
local rat = require("Module:Rational")


-- TODO:
-- TODO:
Line 8: Line 10:
function p.step_pattern_to_xenpaper_link(step_pattern, equave)
function p.step_pattern_to_xenpaper_link(step_pattern, equave)
local step_pattern = step_pattern or { 2, 2, 2, 1, 2, 2, 1 }
local step_pattern = step_pattern or { 2, 2, 2, 1, 2, 2, 1 }
local equave = equave or rat.new(2)
local equave = equave or rat.new(3)
local ed = 0
local ed = 0
Line 18: Line 20:
if equave_as_text == "2%2F1" then
if equave_as_text == "2%2F1" then
equave_as_text = "o"
equave_as_text = "o"
elseif equave_as_text == "3%2F1" then
equave_as_text = "3"
end
end
Line 33: Line 33:
for i = 1, #step_pattern + 1 do
for i = 1, #step_pattern + 1 do
if i ~= #step_pattern + 1 then
if i ~= #step_pattern + 1 then
text = text .. string.format('%d--_', i - 1)
text = text .. string.format("%d--_", i - 1)
else
else
text = text .. string.format('%d---', i - 1)
text = text .. string.format("%d---", i - 1)
end
end
end
end
text = "https://www.xenpaper.com/#" .. text
text = "https://www.luphoria.com/xenpaper/#" .. text
return text
return text
Line 45: Line 45:


-- Create a Xenpaper link for a mode of a mos
-- Create a Xenpaper link for a mode of a mos
-- The step pattern, step ratio, and equave (default is 2/1) are entered, so
-- no input mos is necessary; this allows for entering modmosses.
-- TODO: support step sizes of c (L-s), A (L+c), and d (s-c) for modmosses
-- TODO: support step sizes of c (L-s), A (L+c), and d (s-c) for modmosses
function p.mosstep_pattern_to_xenpaper_link(abstract_step_pattern, step_ratio, equave)
function p.mosstep_pattern_to_xenpaper_link(abstract_step_pattern, step_ratio, equave)
local abstract_step_pattern = abstract_step_pattern or "LLLsLLs"
local abstract_step_pattern = abstract_step_pattern or "LLLsLLs"
local step_ratio = step_ratio or { 2, 1 }
local step_ratio = step_ratio or { 2, 1 }
local equave = equave or rat.new(2, 1)
local equave = equave or 2
local L_size = step_ratio[1]
local L_size = step_ratio[1]
Line 66: Line 64:
end
end
return rat.new(equave)
return p.step_pattern_to_xenpaper_link(step_pattern, equave)
end
end


Line 86: Line 85:
local ratio_as_text = rat.as_ratio(ratios[i], "%2F")
local ratio_as_text = rat.as_ratio(ratios[i], "%2F")
if i ~= #ratios then
if i ~= #ratios then
text = text .. string.format('%d--_', i - 1)
text = text .. string.format("%d--_", i - 1)
else
else
text = text .. string.format('%d---', i - 1)
text = text .. string.format("%d---", i - 1)
end
end
end
end
text = "https://www.xenpaper.com/#" .. text
text = "https://www.luphoria.com/xenpaper/#" .. text
return text
return text
end
end
return p
return p

Latest revision as of 18:25, 19 May 2025

Module documentation[view] [edit] [history] [purge]
Todo: add documentation

local p = {}

local mos = require("Module:MOS")
local rat = require("Module:Rational")

-- TODO:
-- - Add support for ascending and descending scales

-- Create a Xenpaper link for a step pattern of arbitrary step sizes
function p.step_pattern_to_xenpaper_link(step_pattern, equave)
	local step_pattern = step_pattern or { 2, 2, 2, 1, 2, 2, 1 }
	local equave = equave or rat.new(3)
	
	local ed = 0
	for i = 1, #step_pattern do
		ed = ed + step_pattern[i]
	end
	
	local equave_as_text = rat.as_ratio(equave, "%2F")
	if equave_as_text == "2%2F1" then
		equave_as_text = "o"
	end
	
	local text = ""
	text = text .. "%7B" .. ed .. "ed" .. equave_as_text .. "%7D%0A"
	
	text = text .. "%7Bm"
	for i = 1, #step_pattern do
		text = text .. "_" .. step_pattern[i]
	end
	text = text .. "%7D%0A"
	
	for i = 1, #step_pattern + 1 do
		if i ~= #step_pattern + 1 then
			text = text .. string.format("%d--_", i - 1)
		else
			text = text .. string.format("%d---", i - 1)
		end
	end
	
	text = "https://www.luphoria.com/xenpaper/#" .. text
	return text
	
end

-- Create a Xenpaper link for a mode of a mos
-- TODO: support step sizes of c (L-s), A (L+c), and d (s-c) for modmosses
function p.mosstep_pattern_to_xenpaper_link(abstract_step_pattern, step_ratio, equave)
	local abstract_step_pattern = abstract_step_pattern or "LLLsLLs"
	local step_ratio = step_ratio or { 2, 1 }
	local equave = equave or 2
	
	local L_size = step_ratio[1]
	local s_size = step_ratio[2]
	
	local step_pattern = {}
	for i = 1, #abstract_step_pattern do
		local step = abstract_step_pattern:sub(i, i)
		if step == "L" then
			table.insert(step_pattern, L_size)
		elseif step == "s" then
			table.insert(step_pattern, s_size)
		end
	end
	
	return p.step_pattern_to_xenpaper_link(step_pattern, equave)
	
end

-- Create a xenpaper link for a scale whose degrees are defined as JI ratios
function p.ji_scale_to_xenpaper_link(ratios)
	local ratios = ratios or { rat.new(1, 1), rat.new(10, 9), rat.new(5, 4), rat.new(4, 3), rat.new(3, 2), rat.new(5, 3), rat.new(15, 8), rat.new(2, 1)}

	local text = "%7B"
	for i = 1, #ratios do
		local ratio_as_text = rat.as_ratio(ratios[i], "%2F")
		if i ~= #ratios then
			text = text .. ratio_as_text .. "_"
		else
			text = text .. ratio_as_text .. "%7D%0A"
		end
	end
	
	for i = 1, #ratios do
		local ratio_as_text = rat.as_ratio(ratios[i], "%2F")
		if i ~= #ratios then
			text = text .. string.format("%d--_", i - 1)
		else
			text = text .. string.format("%d---", i - 1)
		end
	end
	
	text = "https://www.luphoria.com/xenpaper/#" .. text
	return text
end
	
return p