Skip to content

Commit

Permalink
Fix stepjoin (#1067)
Browse files Browse the repository at this point in the history
* sort fractions properly - fixes #1066
  • Loading branch information
yaxu authored Apr 23, 2024
1 parent 6a1fa7e commit a189626
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/core/pattern.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Pattern {
constructor(query, tactus = undefined) {
this.query = query;
this._Pattern = true; // this property is used to detect if a pattern that fails instanceof Pattern is an instance of another Pattern
this.__tactus = tactus; // in terms of number of beats per cycle
this.__tactus = Fraction(tactus); // in terms of number of steps per cycle
}

get tactus() {
Expand Down
11 changes: 10 additions & 1 deletion packages/core/test/pattern.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ describe('Pattern', () => {
expect(sameFirst(sequence(0, 1, 2, 3, 4).s_taper(-1, 5), sequence(0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4)));
});
});
describe('s_add and s_sub, left', () => {
describe('s_add and s_sub', () => {
it('can add from the left', () => {
expect(sameFirst(sequence(0, 1, 2, 3, 4).s_add(2), sequence(0, 1)));
});
Expand All @@ -1159,5 +1159,14 @@ describe('Pattern', () => {
it('can sub to the right', () => {
expect(sameFirst(sequence(0, 1, 2, 3, 4).s_sub(-2), sequence(2, 3, 4)));
});
it('can subtract nothing', () => {
expect(sameFirst(pure('a').s_sub(0), pure('a')));
});
it('can subtract nothing, repeatedly', () => {
expect(sameFirst(pure('a').s_sub(0, 0), fastcat('a', 'a')));
for (var i = 0; i < 100; ++i) {
expect(sameFirst(pure('a').s_sub(...Array(i).fill(0)), fastcat(...Array(i).fill('a'))));
}
});
});
});
8 changes: 5 additions & 3 deletions packages/core/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,11 @@ export function uniqsort(a) {

// rational version
export function uniqsortr(a) {
return a.sort().filter(function (item, pos, ary) {
return !pos || item.ne(ary[pos - 1]);
});
return a
.sort((x, y) => x.compare(y))
.filter(function (item, pos, ary) {
return !pos || item.ne(ary[pos - 1]);
});
}

// code hashing helpers
Expand Down

0 comments on commit a189626

Please sign in to comment.