Skip to content

Commit

Permalink
mini for eculids
Browse files Browse the repository at this point in the history
  • Loading branch information
n451 committed Mar 18, 2024
1 parent 6ddaf76 commit f9af53e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
9 changes: 7 additions & 2 deletions spec/mini_spec.moon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import describe, it from require "busted"
-- import Span from require "xi.types"
import parse from require "xi.mini.grammar"
import mini, pure, silence, slowcat, fastcat, timecat, randcat, fast, slow, degrade, stack, C from require "xi.pattern"
import mini, pure, silence, euclid, slowcat, fastcat, timecat, randcat, fast, slow, degrade, stack, C from require "xi.pattern"
local *

same = (name) -> assert.same visitor_targets[name], parse name
Expand Down Expand Up @@ -100,6 +100,10 @@ describe "Mini Interpreter for", ->
-- eval "bd hh@2"
-- -- eval "bd hh@3 sd@2"
-- eval "bd! hh? ~ sd/2 cp*3"

describe "euclidian rhythm", ->
it "should pass", ->
eval "bd(3,8,1)"
--
-- describe "repeat", ->
-- it "should pass", ->
Expand All @@ -112,7 +116,7 @@ describe "Mini Interpreter for", ->
-- describe "weight", ->
-- it "should pass", ->
-- eval "hh@2"
--

describe "fast&slow", ->
it "should pass", ->
eval "bd*2"
Expand Down Expand Up @@ -166,6 +170,7 @@ interpreter_targets = {
-- sequences
"bd sd": fastcat "bd", "sd"
"bd hh sd": fastcat "bd", "hh", "sd"
"bd(3,8,1)": euclid 3, 8, 1, pure"bd"
-- "hh@2": pure "hh"
-- "bd hh@2": timecat { { 1, mini"bd" }, { 2, mini"hh" } }
-- -- "bd hh@3 sd@2": timecat { { 1, "bd" }, { 3, "hh" }, { 2, "sd" } }
Expand Down
8 changes: 5 additions & 3 deletions src/core/pattern.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ applyOptions = function(parent, enter)
else
print("mini: stretch: type must be one of fast of slow")
end
return pat
elseif "euclid" == _exp_0 then
local steps, pulse, rotation = op.arguments.steps, op.arguments.pulse, op.arguments.rotation
pat = euclid(enter(pulse), enter(steps), enter(rotation), pat)
end
end
end
Expand Down Expand Up @@ -898,7 +900,7 @@ sometimes = function(func, pat)
return sometimesBy(0.5, func, pat)
end
struct = function(boolpat, pat)
return boolpat:fmap(function(b)
return (fastcat(boolpat)):fmap(function(b)
return function(val)
if b then
return val
Expand Down Expand Up @@ -1202,7 +1204,7 @@ apply = function(x, pat)
return pat .. x
end
sl = string_lambda
print(mini("bd/3"))
print(mini("bd(3,8,1)"))
return {
C = C,
Pattern = Pattern,
Expand Down
8 changes: 5 additions & 3 deletions src/core/pattern.moon
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ applyOptions = (parent, enter) ->
pat = slow enter(amount), pat
else
print("mini: stretch: type must be one of fast of slow")
return pat
when "euclid"
steps, pulse, rotation = op.arguments.steps, op.arguments.pulse, op.arguments.rotation
pat = euclid(enter(pulse), enter(steps), enter(rotation), pat)
return pat

resolveReplications = id
Expand Down Expand Up @@ -624,7 +626,7 @@ sometimes = (func, pat) -> sometimesBy(0.5, func, pat)

-- @section manipulating structure
struct = (boolpat, pat) ->
boolpat\fmap((b) -> (val) -> if b return val else nil)\appLeft(pat)\removeNils!
(fastcat boolpat)\fmap((b) -> (val) -> if b return val else nil)\appLeft(pat)\removeNils!

_euclid = (n, k, offset, pat) -> struct bjork(n, k, offset), reify(pat)
euclid = _patternify_p_p_p _euclid
Expand Down Expand Up @@ -779,7 +781,7 @@ scale = _patternify _scale
apply = (x, pat) -> pat .. x
sl = string_lambda

-- print mini "bd/3"
print mini "bd(3,8,1)"

-- TODO: wchoose, tests for the new functions
return {
Expand Down

0 comments on commit f9af53e

Please sign in to comment.