Fix tactus marking in mininotation (#1144)

* more tactus tweaks
* format
This commit is contained in:
Alex McLean 2024-07-24 10:40:28 +01:00 committed by GitHub
parent f514cd85b1
commit 4c3457438d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 5 deletions

View file

@ -1423,6 +1423,9 @@ export function fastcat(...pats) {
result = result._fast(pats.length); result = result._fast(pats.length);
result.tactus = pats.length; result.tactus = pats.length;
} }
if (pats.length == 1 && pats[0].__tactus_source) {
pats.tactus = pats[0].tactus;
}
return result; return result;
} }
@ -1566,7 +1569,11 @@ export function register(name, func, patternify = true, preserveTactus = false,
// There are patternified args, so lets make an unpatternified // There are patternified args, so lets make an unpatternified
// version, prefixed by '_' // version, prefixed by '_'
Pattern.prototype['_' + name] = function (...args) { Pattern.prototype['_' + name] = function (...args) {
return func(...args, this); const result = func(...args, this);
if (preserveTactus) {
result.setTactus(this.tactus);
}
return result;
}; };
} }
@ -2612,8 +2619,7 @@ export function s_cat(...timepats) {
} }
if (timepats.length == 1) { if (timepats.length == 1) {
const result = reify(timepats[0][1]); const result = reify(timepats[0][1]);
result.tactus = timepats[0][0]; return result.withTactus((_) => timepats[0][0]);
return result;
} }
const total = timepats.map((a) => a[0]).reduce((a, b) => a.add(b), Fraction(0)); const total = timepats.map((a) => a[0]).reduce((a, b) => a.add(b), Fraction(0));
@ -2706,6 +2712,10 @@ export const s_sub = stepRegister('s_sub', function (i, pat) {
return pat.s_add(pat.tactus.sub(i)); return pat.s_add(pat.tactus.sub(i));
}); });
export const s_cycles = stepRegister('s_extend', function (factor, pat) {
return pat.fast(factor).s_expand(factor);
});
export const s_expand = stepRegister('s_expand', function (factor, pat) { export const s_expand = stepRegister('s_expand', function (factor, pat) {
return pat.withTactus((t) => t.mul(Fraction(factor))); return pat.withTactus((t) => t.mul(Fraction(factor)));
}); });

View file

@ -14,7 +14,7 @@ const applyOptions = (parent, enter) => (pat, i) => {
const ast = parent.source_[i]; const ast = parent.source_[i];
const options = ast.options_; const options = ast.options_;
const ops = options?.ops; const ops = options?.ops;
const tactus_source = pat.__tactus_source;
if (ops) { if (ops) {
for (const op of ops) { for (const op of ops) {
switch (op.type_) { switch (op.type_) {
@ -39,6 +39,7 @@ const applyOptions = (parent, enter) => (pat, i) => {
} else { } else {
pat = pat.euclid(enter(op.arguments_.pulse), enter(op.arguments_.step)); pat = pat.euclid(enter(op.arguments_.pulse), enter(op.arguments_.step));
} }
console.log(op.arguments_.step);
break; break;
} }
case 'degradeBy': { case 'degradeBy': {
@ -69,7 +70,7 @@ const applyOptions = (parent, enter) => (pat, i) => {
} }
} }
} }
pat.__tactus_source = pat.__tactus_source || tactus_source;
return pat; return pat;
}; };

View file

@ -210,12 +210,14 @@ describe('mini', () => {
}); });
it('supports ^ tactus marking', () => { it('supports ^ tactus marking', () => {
expect(mini('a [^b c]').tactus).toEqual(Fraction(4)); expect(mini('a [^b c]').tactus).toEqual(Fraction(4));
expect(mini('[^b c]!3').tactus).toEqual(Fraction(6));
expect(mini('[a b c] [d [e f]]').tactus).toEqual(Fraction(2)); expect(mini('[a b c] [d [e f]]').tactus).toEqual(Fraction(2));
expect(mini('^[a b c] [d [e f]]').tactus).toEqual(Fraction(2)); expect(mini('^[a b c] [d [e f]]').tactus).toEqual(Fraction(2));
expect(mini('[a b c] [d [^e f]]').tactus).toEqual(Fraction(8)); expect(mini('[a b c] [d [^e f]]').tactus).toEqual(Fraction(8));
expect(mini('[a b c] [^d [e f]]').tactus).toEqual(Fraction(4)); expect(mini('[a b c] [^d [e f]]').tactus).toEqual(Fraction(4));
expect(mini('[^a b c] [^d [e f]]').tactus).toEqual(Fraction(12)); expect(mini('[^a b c] [^d [e f]]').tactus).toEqual(Fraction(12));
expect(mini('[^a b c] [d [^e f]]').tactus).toEqual(Fraction(24)); expect(mini('[^a b c] [d [^e f]]').tactus).toEqual(Fraction(24));
expect(mini('[^a b c d e]').tactus).toEqual(Fraction(5));
}); });
}); });