Merge pull request #332 from tidalcycles/fix-mini-multiply-floats
fix: can now multiply floats in mini notation
This commit is contained in:
commit
204f655d6d
3 changed files with 35 additions and 31 deletions
|
|
@ -32,7 +32,7 @@ function peg$padEnd(str, targetLength, padString) {
|
||||||
}
|
}
|
||||||
|
|
||||||
peg$SyntaxError.prototype.format = function(sources) {
|
peg$SyntaxError.prototype.format = function(sources) {
|
||||||
var str = "peg error: " + this.message;
|
var str = "Error: " + this.message;
|
||||||
if (this.location) {
|
if (this.location) {
|
||||||
var src = null;
|
var src = null;
|
||||||
var k;
|
var k;
|
||||||
|
|
@ -271,8 +271,8 @@ function peg$parse(input, options) {
|
||||||
var peg$f4 = function(a) { return { weight: a} };
|
var peg$f4 = function(a) { return { weight: a} };
|
||||||
var peg$f5 = function(a) { return { replicate: a } };
|
var peg$f5 = function(a) { return { replicate: a } };
|
||||||
var peg$f6 = function(p, s, r) { return { operator : { type_: "bjorklund", arguments_ :{ pulse: p, step:s, rotation:r || 0 } } } };
|
var peg$f6 = function(p, s, r) { return { operator : { type_: "bjorklund", arguments_ :{ pulse: p, step:s, rotation:r || 0 } } } };
|
||||||
var peg$f7 = function(a) { return { operator : { type_: "stretch", arguments_ :{ amount:a } } } };
|
var peg$f7 = function(a) { return { operator : { type_: "stretch", arguments_ :{ amount:a, type: 'slow' } } } };
|
||||||
var peg$f8 = function(a) { return { operator : { type_: "stretch", arguments_ :{ amount:"1/"+a } } } };
|
var peg$f8 = function(a) { return { operator : { type_: "stretch", arguments_ :{ amount:a, type: 'fast' } } } };
|
||||||
var peg$f9 = function(a) { return { operator : { type_: "fixed-step", arguments_ :{ amount:a } } } };
|
var peg$f9 = function(a) { return { operator : { type_: "fixed-step", arguments_ :{ amount:a } } } };
|
||||||
var peg$f10 = function(a) { return { operator : { type_: "degradeBy", arguments_ :{ amount:(a? a : 0.5) } } } };
|
var peg$f10 = function(a) { return { operator : { type_: "degradeBy", arguments_ :{ amount:(a? a : 0.5) } } } };
|
||||||
var peg$f11 = function(s, o) { return new ElementStub(s, o);};
|
var peg$f11 = function(s, o) { return new ElementStub(s, o);};
|
||||||
|
|
|
||||||
|
|
@ -116,10 +116,10 @@ slice_bjorklund = "(" ws p:number ws comma ws s:number ws comma? ws r:number? ws
|
||||||
{ return { operator : { type_: "bjorklund", arguments_ :{ pulse: p, step:s, rotation:r || 0 } } } }
|
{ return { operator : { type_: "bjorklund", arguments_ :{ pulse: p, step:s, rotation:r || 0 } } } }
|
||||||
|
|
||||||
slice_slow = "/"a:number
|
slice_slow = "/"a:number
|
||||||
{ return { operator : { type_: "stretch", arguments_ :{ amount:a } } } }
|
{ return { operator : { type_: "stretch", arguments_ :{ amount:a, type: 'slow' } } } }
|
||||||
|
|
||||||
slice_fast = "*"a:number
|
slice_fast = "*"a:number
|
||||||
{ return { operator : { type_: "stretch", arguments_ :{ amount:"1/"+a } } } }
|
{ return { operator : { type_: "stretch", arguments_ :{ amount:a, type: 'fast' } } } }
|
||||||
|
|
||||||
slice_fixed_step = "%"a:number
|
slice_fixed_step = "%"a:number
|
||||||
{ return { operator : { type_: "fixed-step", arguments_ :{ amount:a } } } }
|
{ return { operator : { type_: "fixed-step", arguments_ :{ amount:a } } } }
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,12 @@ const applyOptions = (parent) => (pat, i) => {
|
||||||
if (operator) {
|
if (operator) {
|
||||||
switch (operator.type_) {
|
switch (operator.type_) {
|
||||||
case 'stretch': {
|
case 'stretch': {
|
||||||
const speed = Fraction(operator.arguments_.amount).inverse();
|
const legalTypes = ['fast', 'slow'];
|
||||||
return reify(pat).fast(speed);
|
const { type, amount } = operator.arguments_;
|
||||||
|
if (!legalTypes.includes(type)) {
|
||||||
|
throw new Error(`mini: stretch: type must be one of ${legalTypes.join('|')} but got ${type}`);
|
||||||
|
}
|
||||||
|
return reify(pat)[type](amount);
|
||||||
}
|
}
|
||||||
case 'bjorklund':
|
case 'bjorklund':
|
||||||
return pat.euclid(operator.arguments_.pulse, operator.arguments_.step, operator.arguments_.rotation);
|
return pat.euclid(operator.arguments_.pulse, operator.arguments_.step, operator.arguments_.rotation);
|
||||||
|
|
@ -74,32 +78,32 @@ function resolveReplications(ast) {
|
||||||
// could this be made easier?!
|
// could this be made easier?!
|
||||||
ast.source_ = ast.source_.map((child) => {
|
ast.source_ = ast.source_.map((child) => {
|
||||||
const { replicate, ...options } = child.options_ || {};
|
const { replicate, ...options } = child.options_ || {};
|
||||||
if (replicate) {
|
if (!replicate) {
|
||||||
return {
|
return child;
|
||||||
...child,
|
}
|
||||||
options_: { ...options, weight: replicate },
|
return {
|
||||||
source_: {
|
...child,
|
||||||
type_: 'pattern',
|
options_: { ...options, weight: replicate },
|
||||||
arguments_: {
|
source_: {
|
||||||
alignment: 'h',
|
type_: 'pattern',
|
||||||
},
|
arguments_: {
|
||||||
source_: [
|
alignment: 'h',
|
||||||
{
|
},
|
||||||
type_: 'element',
|
source_: [
|
||||||
source_: child.source_,
|
{
|
||||||
location_: child.location_,
|
type_: 'element',
|
||||||
options_: {
|
source_: child.source_,
|
||||||
operator: {
|
location_: child.location_,
|
||||||
type_: 'stretch',
|
options_: {
|
||||||
arguments_: { amount: Fraction(replicate).inverse().toString() },
|
operator: {
|
||||||
},
|
type_: 'stretch',
|
||||||
|
arguments_: { amount: replicate, type: 'fast' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
},
|
],
|
||||||
};
|
},
|
||||||
}
|
};
|
||||||
return child;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue