diff --git a/src/core/pattern.lua b/src/core/pattern.lua index 8b1ac3b..7fa527b 100644 --- a/src/core/pattern.lua +++ b/src/core/pattern.lua @@ -7,10 +7,10 @@ local bjork bjork = require("xi.euclid").bjork local getScale getScale = require("xi.scales").getScale -local Fraction, tofrac, tofloat +local Fraction, tofrac do local _obj_0 = require("xi.fraction") - Fraction, tofrac, tofloat = _obj_0.Fraction, _obj_0.tofrac, _obj_0.tofloat + Fraction, tofrac = _obj_0.Fraction, _obj_0.tofrac end local Event, Span, State do diff --git a/src/core/pattern.moon b/src/core/pattern.moon index f6247aa..f4fa4fd 100644 --- a/src/core/pattern.moon +++ b/src/core/pattern.moon @@ -3,7 +3,7 @@ import map, filter, string_lambda, reduce, id, flatten, totable, dump, concat, rotate, union, timeToRand, curry, type from require "xi.utils" import bjork from require "xi.euclid" import getScale from require "xi.scales" -import Fraction, tofrac, tofloat from require "xi.fraction" +import Fraction, tofrac from require "xi.fraction" import Event, Span, State from require "xi.types" import visit from require "xi.mini.visitor" fun = require "xi.fun" diff --git a/src/core/pattern_factory.lua b/src/core/pattern_factory.lua index 63d508f..59bc3c6 100644 --- a/src/core/pattern_factory.lua +++ b/src/core/pattern_factory.lua @@ -1,12 +1,10 @@ -local C, cpm -do - local _obj_0 = require("xi.pattern") - C, cpm = _obj_0.C, _obj_0.cpm -end +local cpm +cpm = require("xi.pattern").cpm local Stream Stream = require("xi.stream").Stream local Clock Clock = require("xi.clock").Clock +local C = require("xi.control") local Streams = { } local DefaultClock = Clock() local p diff --git a/src/core/pattern_factory.moon b/src/core/pattern_factory.moon index 61dc5f7..14593da 100644 --- a/src/core/pattern_factory.moon +++ b/src/core/pattern_factory.moon @@ -1,6 +1,7 @@ -import C, cpm from require "xi.pattern" +import cpm from require "xi.pattern" import Stream from require "xi.stream" import Clock from require "xi.clock" +C = require"xi.control" Streams = {} DefaultClock = Clock! diff --git a/src/utils/fraction.moon b/src/utils/fraction.moon index 69a3fa5..b6b4548 100644 --- a/src/utils/fraction.moon +++ b/src/utils/fraction.moon @@ -5,10 +5,33 @@ local * abs = math.abs floor = math.floor +-- decimaltofraction1 = (x, N) -> +-- N = N or 1000000 +-- a, b = 0, 1 +-- c, d = 1, 1 +-- while b <= N and d <= N +-- mediant = (a+c)/(b+d) +-- if x == mediant +-- if b + d <= N +-- return a + c, b + d +-- elseif d > b +-- return c, d +-- else +-- return a, b +-- elseif x > mediant +-- a, b = a + c, b + d +-- else +-- c, d = a + c, b + d +-- +-- if b > N +-- return c, d +-- else +-- return a, b + decimaltofraction = (x0, err) -> err = err or 0.0000000001 local num, den - g = abs x0 -- or x0:abs() + g = abs x0 sign = x0 / g a, b, c, d = 0, 1, 1, 0 local s @@ -25,7 +48,7 @@ decimaltofraction = (x0, err) -> return sign * num, den error "Fraction: failed to find a fraction for " .. x0 - 0, 1 + return 0, 1 gcd = (a, b) -> (b == 0) and a or gcd(b, a % b) @@ -205,10 +228,4 @@ tofrac = (x) -> else return x -tofloat = (x) -> - if type(x) == "fraction" - return x\asFloat! - else - return x - return { :Fraction, :gcd_reduce, :tofrac, :tofloat }