Skip to content

Commit

Permalink
Fix tactus marking in mininotation (#1144)
Browse files Browse the repository at this point in the history
* more tactus tweaks
* format
  • Loading branch information
yaxu authored Jul 24, 2024
1 parent f514cd8 commit 4c34574
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
16 changes: 13 additions & 3 deletions packages/core/pattern.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,9 @@ export function fastcat(...pats) {
result = result._fast(pats.length);
result.tactus = pats.length;
}
if (pats.length == 1 && pats[0].__tactus_source) {
pats.tactus = pats[0].tactus;
}
return result;
}

Expand Down Expand Up @@ -1566,7 +1569,11 @@ export function register(name, func, patternify = true, preserveTactus = false,
// There are patternified args, so lets make an unpatternified
// version, prefixed by '_'
Pattern.prototype['_' + name] = function (...args) {
return func(...args, this);
const result = func(...args, this);
if (preserveTactus) {
result.setTactus(this.tactus);
}
return result;
};
}

Expand Down Expand Up @@ -2612,8 +2619,7 @@ export function s_cat(...timepats) {
}
if (timepats.length == 1) {
const result = reify(timepats[0][1]);
result.tactus = timepats[0][0];
return result;
return result.withTactus((_) => timepats[0][0]);
}

const total = timepats.map((a) => a[0]).reduce((a, b) => a.add(b), Fraction(0));
Expand Down Expand Up @@ -2706,6 +2712,10 @@ export const s_sub = stepRegister('s_sub', function (i, pat) {
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) {
return pat.withTactus((t) => t.mul(Fraction(factor)));
});
Expand Down
5 changes: 3 additions & 2 deletions packages/mini/mini.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const applyOptions = (parent, enter) => (pat, i) => {
const ast = parent.source_[i];
const options = ast.options_;
const ops = options?.ops;

const tactus_source = pat.__tactus_source;
if (ops) {
for (const op of ops) {
switch (op.type_) {
Expand All @@ -39,6 +39,7 @@ const applyOptions = (parent, enter) => (pat, i) => {
} else {
pat = pat.euclid(enter(op.arguments_.pulse), enter(op.arguments_.step));
}
console.log(op.arguments_.step);
break;
}
case 'degradeBy': {
Expand Down Expand Up @@ -69,7 +70,7 @@ const applyOptions = (parent, enter) => (pat, i) => {
}
}
}

pat.__tactus_source = pat.__tactus_source || tactus_source;
return pat;
};

Expand Down
2 changes: 2 additions & 0 deletions packages/mini/test/mini.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,14 @@ describe('mini', () => {
});
it('supports ^ tactus marking', () => {
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(8));
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(24));
expect(mini('[^a b c d e]').tactus).toEqual(Fraction(5));
});
});

Expand Down

0 comments on commit 4c34574

Please sign in to comment.