Skip to content

Commit

Permalink
Merge branch 'main' of github.com:noearc/xi
Browse files Browse the repository at this point in the history
  • Loading branch information
n451 committed Mar 28, 2024
2 parents ffe214b + 5eed201 commit 90482a7
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 141 deletions.
55 changes: 52 additions & 3 deletions src/core/control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,56 @@ local aliasParams = {
vcoegint = "vco",
voice = "voi"
}
return {
genericParams = genericParams,
aliasParams = aliasParams
local reify, stack
do
local _obj_0 = require("xi.pattern")
reify, stack = _obj_0.reify, _obj_0.stack
end
local parseChord
parseChord = require("xi.chords").parseChord
local C = { }
local create
create = function(name)
local withVal
withVal = function(v)
return {
[name] = v
}
end
local func
func = function(args)
return reify(args):fmap(withVal)
end
C[name] = func
end
for _index_0 = 1, #genericParams do
local name = genericParams[_index_0]
local param = name[2]
create(param)
if aliasParams[param] ~= nil then
local alias = aliasParams[param]
C[alias] = C[param]
end
end
local notemt = {
__add = function(self, other)
return {
note = self.note + other.note
}
end
}
C.note = function(args)
args = reify(args)
local chordToStack
chordToStack = function(thing)
return stack(parseChord(thing))
end
local withVal
withVal = function(v)
return setmetatable({
note = v
}, notemt)
end
return reify(args):fmap(chordToStack):outerJoin():fmap(withVal)
end
return C
30 changes: 29 additions & 1 deletion src/core/control.moon
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

genericParams = {
{ "s", "sound"}
{ "s", "toArg", "for internal sound routing" },
Expand Down Expand Up @@ -226,4 +227,31 @@ aliasParams = {
voice: "voi"
}

return { :genericParams, :aliasParams }
import reify, stack from require "xi.pattern"
import parseChord from require "xi.chords"

C = {}

create = (name) ->
withVal = (v) -> { [name]: v }
func = (args) -> reify(args)\fmap(withVal)
C[name] = func

for name in *genericParams
param = name[2]
create param
if aliasParams[param] != nil
alias = aliasParams[param]
C[alias] = C[param]

notemt =
__add: (other) =>
{ note: @note + other.note }

C.note = (args) ->
args = reify(args)
chordToStack = (thing) -> stack(parseChord thing)
withVal = (v) -> setmetatable { note: v }, notemt
return reify(args)\fmap(chordToStack)\outerJoin!\fmap(withVal)

return C
84 changes: 9 additions & 75 deletions src/core/pattern.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
local map, filter, reduce, id, flatten, totable, dump, concat, rotate, union, timeToRand, curry, type
local map, filter, string_lambda, reduce, id, flatten, totable, dump, concat, rotate, union, timeToRand, curry, type
do
local _obj_0 = require("xi.utils")
map, filter, reduce, id, flatten, totable, dump, concat, rotate, union, timeToRand, curry, type = _obj_0.map, _obj_0.filter, _obj_0.reduce, _obj_0.id, _obj_0.flatten, _obj_0.totable, _obj_0.dump, _obj_0.concat, _obj_0.rotate, _obj_0.union, _obj_0.timeToRand, _obj_0.curry, _obj_0.type
map, filter, string_lambda, reduce, id, flatten, totable, dump, concat, rotate, union, timeToRand, curry, type = _obj_0.map, _obj_0.filter, _obj_0.string_lambda, _obj_0.reduce, _obj_0.id, _obj_0.flatten, _obj_0.totable, _obj_0.dump, _obj_0.concat, _obj_0.rotate, _obj_0.union, _obj_0.timeToRand, _obj_0.curry, _obj_0.type
end
local bjork
bjork = require("xi.euclid").bjork
local parseChord
parseChord = require("xi.chords").parseChord
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
end
local genericParams, aliasParams
do
local _obj_0 = require("xi.control")
genericParams, aliasParams = _obj_0.genericParams, _obj_0.aliasParams
Fraction, tofrac = _obj_0.Fraction, _obj_0.tofrac
end
local Event, Span, State
do
Expand All @@ -26,68 +19,14 @@ do
end
local visit
visit = require("xi.mini.visitor").visit
local op
op = require("xi.fun").op
local string_lambda
string_lambda = require("pl.utils").string_lambda
local fun = require("xi.fun")
local sin, min, max, pi, floor, tinsert, p, C, create, notemt, Interpreter, Pattern, silence, pure, mini, reify, _patternify, _patternify_p_p, _patternify_p_p_p, stack, slowcatPrime, slowcat, fastcat, timecat, _cpm, cpm, _fast, fast, _slow, slow, _early, early, _late, late, _inside, inside, _outside, outside, _ply, ply, _fastgap, fastgap, _compress, compress, _focus, focusSpan, focus, _zoom, zoom, run, scan, waveform, steady, toBipolar, fromBipolar, sine2, sine, cosine2, cosine, square, square2, isaw, isaw2, saw, saw2, tri, tri2, time, rand, _irand, irand, _chooseWith, chooseWith, choose, chooseCycles, randcat, polyrhythm, _degradeByWith, _degradeBy, degradeBy, undegradeBy, _undegradeBy, degrade, undegrade, sometimesBy, sometimes, struct, _euclid, euclid, rev, palindrome, _iter, iter, _reviter, reviter, _segment, segment, _range, range, superimpose, layer, _off, off, _echoWith, echoWith, _when, when_, _firstOf, firstOf, every, _lastOf, lastOf, _jux, jux, _juxBy, juxBy, _striate, striate, _chop, chop, slice, splice, _loopAt, loopAt, fit, _legato, legato, _scale, scale, apply, sl
local sin, min, max, pi, floor, tinsert, Interpreter, Pattern, silence, pure, mini, reify, _patternify, _patternify_p_p, _patternify_p_p_p, stack, slowcatPrime, slowcat, fastcat, timecat, _cpm, cpm, _fast, fast, _slow, slow, _early, early, _late, late, _inside, inside, _outside, outside, _ply, ply, _fastgap, fastgap, _compress, compress, _focus, focusSpan, focus, _zoom, zoom, run, scan, waveform, steady, toBipolar, fromBipolar, sine2, sine, cosine2, cosine, square, square2, isaw, isaw2, saw, saw2, tri, tri2, time, rand, _irand, irand, _chooseWith, chooseWith, choose, chooseCycles, randcat, polyrhythm, _degradeByWith, _degradeBy, degradeBy, undegradeBy, _undegradeBy, degrade, undegrade, sometimesBy, sometimes, struct, _euclid, euclid, rev, palindrome, _iter, iter, _reviter, reviter, _segment, segment, _range, range, superimpose, layer, _off, off, _echoWith, echoWith, _when, when_, _firstOf, firstOf, every, _lastOf, lastOf, _jux, jux, _juxBy, juxBy, _striate, striate, _chop, chop, slice, splice, _loopAt, loopAt, fit, _legato, legato, _scale, scale, apply, sl
sin = math.sin
min = math.min
max = math.max
pi = math.pi
floor = math.floor
tinsert = table.insert
p = function(evs)
for _index_0 = 1, #evs do
local ev = evs[_index_0]
print(ev)
end
end
C = { }
create = function(name)
local withVal
withVal = function(v)
return {
[name] = v
}
end
local func
func = function(args)
return reify(args):fmap(withVal)
end
C[name] = func
end
for _index_0 = 1, #genericParams do
local name = genericParams[_index_0]
local param = name[2]
create(param)
if aliasParams[param] ~= nil then
local alias = aliasParams[param]
C[alias] = C[param]
end
end
notemt = {
__add = function(self, other)
return {
note = self.note + other.note
}
end
}
C.note = function(args)
args = reify(args)
local chordToStack
chordToStack = function(thing)
return stack(parseChord(thing))
end
local withVal
withVal = function(v)
return setmetatable({
note = v
}, notemt)
end
return reify(args):fmap(chordToStack):outerJoin():fmap(withVal)
end
do
local _class_0
local _base_0 = {
Expand Down Expand Up @@ -728,11 +667,7 @@ end
reify = function(thing)
local _exp_0 = type(thing)
if "string" == _exp_0 then
if string_lambda(thing) then
return string_lambda(thing)
else
return mini(thing)
end
return mini(thing)
elseif "pattern" == _exp_0 then
return thing
else
Expand Down Expand Up @@ -842,7 +777,7 @@ timecat = function(tuples)
local times = map((function(x)
return x[1]
end), tuples)
local total = reduce(op.add, Fraction(0), times)
local total = reduce(fun.op.add, Fraction(0), times)
local accum = Fraction(0)
for _index_0 = 1, #tuples do
local tup = tuples[_index_0]
Expand Down Expand Up @@ -1192,15 +1127,15 @@ _range = function(min, max, pat)
end
range = _patternify_p_p(_range)
superimpose = function(f, pat)
return stack(pat, f(pat))
return stack(pat, sl(f)(pat))
end
layer = function(table, pat)
return stack((function()
local _accum_0 = { }
local _len_0 = 1
for _index_0 = 1, #table do
local f = table[_index_0]
_accum_0[_len_0] = f(reify(pat))
_accum_0[_len_0] = sl(f)(reify(pat))
_len_0 = _len_0 + 1
end
return _accum_0
Expand Down Expand Up @@ -1425,7 +1360,6 @@ apply = function(x, pat)
end
sl = string_lambda
return {
C = C,
Pattern = Pattern,
id = id,
pure = pure,
Expand Down
52 changes: 9 additions & 43 deletions src/core/pattern.moon
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
--- Core pattern representation
-- @module xi.pattern
import map, filter, reduce, id, flatten, totable, dump, concat, rotate, union, timeToRand, curry, type from require "xi.utils"
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 parseChord from require "xi.chords"
import getScale from require "xi.scales"
import Fraction, tofrac, tofloat from require "xi.fraction"
import genericParams, aliasParams from require "xi.control"
import Fraction, tofrac from require "xi.fraction"
import Event, Span, State from require "xi.types"
import visit from require "xi.mini.visitor"
import op from require "xi.fun"
import string_lambda from require("pl.utils")
fun = require "xi.fun"
local *

Expand All @@ -20,34 +16,6 @@ pi = math.pi
floor = math.floor
tinsert = table.insert

p = (evs) ->
for ev in *evs
print ev

C = {}

create = (name) ->
withVal = (v) -> { [name]: v }
func = (args) -> reify(args)\fmap(withVal)
C[name] = func

for name in *genericParams
param = name[2]
create param
if aliasParams[param] != nil
alias = aliasParams[param]
C[alias] = C[param]

notemt =
__add: (other) =>
{ note: @note + other.note }

C.note = (args) ->
args = reify(args)
chordToStack = (thing) -> stack(parseChord thing)
withVal = (v) -> setmetatable { note: v }, notemt
return reify(args)\fmap(chordToStack)\outerJoin!\fmap(withVal)

class Interpreter
eval:(node) =>
tag = node.type
Expand Down Expand Up @@ -357,11 +325,7 @@ mini = (string) ->
-- @return pattern
reify = (thing) ->
switch type thing
when "string" then
if string_lambda thing
return string_lambda thing
else
return mini thing
when "string" then mini thing
when "pattern" then thing
else pure thing

Expand Down Expand Up @@ -448,7 +412,7 @@ fastcat = (...) ->
timecat = (tuples) ->
pats = {}
times = map ((x) -> x[1]), tuples
total = reduce op.add, Fraction(0), times
total = reduce fun.op.add, Fraction(0), times
accum = Fraction(0)
for tup in *tuples
{ time, pat } = tup
Expand Down Expand Up @@ -710,9 +674,12 @@ _range = (min, max, pat) -> pat\fmap((x) -> x * (max - min) + min)
range = _patternify_p_p _range

-- @section higher order functions
superimpose = (f, pat) -> stack(pat, f(pat))
-- HACK: limited because mini does not turn stirng to number yet
-- p superimpose "|x| x+7", "0 7"
superimpose = (f, pat) ->
stack(pat, sl(f)(pat))

layer = (table, pat) -> stack [f reify pat for f in *table]
layer = (table, pat) -> stack [sl(f) reify pat for f in *table]

_off = (time_pat, f, pat) -> stack(pat, f late(time_pat, pat))
off = _patternify_p_p _off
Expand Down Expand Up @@ -837,7 +804,6 @@ sl = string_lambda
-- TODO: wchoose, tests for the new functions

return {
:C
:Pattern
:id, :pure, :silence
:mini, :reify
Expand Down
8 changes: 3 additions & 5 deletions src/core/pattern_factory.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/core/pattern_factory.moon
Original file line number Diff line number Diff line change
@@ -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!
Expand Down
5 changes: 2 additions & 3 deletions src/init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local pattern = require("xi.pattern")
local pattern_factory = require("xi.pattern_factory")
local C
C = require("xi.pattern").C
local C = require("xi.control")
local drawline
drawline = require("xi.drawline").drawline
local xi = {
Expand All @@ -11,7 +10,7 @@ local xi = {
}
xi.drawline = drawline
for name, func in pairs(pattern) do
if name ~= "C" and name ~= "Pattern" then
if name ~= "Pattern" then
xi[name] = func
end
end
Expand Down
Loading

0 comments on commit 90482a7

Please sign in to comment.