Skip to content

Commit

Permalink
Be less strict about coalescing when merging scales
Browse files Browse the repository at this point in the history
  • Loading branch information
frostburn committed Jun 7, 2024
1 parent ca3e096 commit 529b7ad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/__tests__/scale.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,34 @@ describe('Scale', () => {
expect(lines).toBe('1 9/8 5/4 4/3 3/2 5/3 15/8 2');
});

it('can merge similar offsets without duplicates', () => {
let scale = Scale.fromIntervalArray([
new Interval(
ExtendedMonzo.fromEqualTemperament(new Fraction(7, 12)),
'equal temperament'
),
new Interval(
ExtendedMonzo.fromEqualTemperament(new Fraction(12, 12)),
'equal temperament'
),
]);
scale = scale.merge(
scale.transpose(
new Interval(
ExtendedMonzo.fromEqualTemperament(new Fraction(1, 12)),
'equal temperament'
)
)
);
scale = scale.merge(
scale.transpose(new Interval(ExtendedMonzo.fromCents(100, 1), 'cents'))
);
expect(scale.size).toBe(6);
expect([...Array(7).keys()].map(i => scale.getCents(i).toFixed(1))).toEqual(
['0.0', '100.0', '200.0', '700.0', '800.0', '900.0', '1200.0']
);
});

it('can be reverse parsed', () => {
const scale = Scale.fromIntervalArray([
new Interval(
Expand Down
2 changes: 1 addition & 1 deletion src/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ export class Scale {
let i = 1;
while (i < this.intervals.length) {
for (let j = 0; j < i; ++j) {
if (this.intervals[i].strictEquals(this.intervals[j])) {
if (this.intervals[i].equals(this.intervals[j])) {
this.intervals.splice(i, 1);
i--;
break;
Expand Down

0 comments on commit 529b7ad

Please sign in to comment.