Skip to content
This repository was archived by the owner on Dec 28, 2025. It is now read-only.

Commit 93135dd

Browse files
committed
Scale builder polish
1 parent c1246a1 commit 93135dd

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

src/scale-builder/script.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ function ratios(limit: number): Ratio[] {
2727
return a;
2828
}
2929

30-
const ratioPool = ratios(27);
30+
const limit = 27;
31+
const ratioPool = ratios(limit);
3132
let edo = edoInput.valueAsNumber;
3233

33-
function tenneyHeight(r: Ratio): number {
34-
return Math.log2(r[0] * r[1]);
34+
function height(r: Ratio): number {
35+
return r[0] * r[1];
3536
}
3637

3738
function bestMapping(r: Ratio, et: number): number {
@@ -50,16 +51,16 @@ function detemper(n: number): Ratio | null {
5051
}
5152
const matchedRatios = ratioPool
5253
.filter(r => bestMapping(r, edo) == n && approximates(n, edo, r));
53-
matchedRatios.sort((a, b) => tenneyHeight(a) - tenneyHeight(b));
54+
matchedRatios.sort((a, b) => height(a) - height(b));
5455
return matchedRatios[0]; // TODO
5556
}
5657

5758
function stepScore(n: number): number {
5859
const r = detemper(n);
5960
if (r) {
60-
return tenneyHeight(r);
61+
return height(r);
6162
} else {
62-
return 100;
63+
return limit * limit;
6364
}
6465
}
6566

@@ -73,18 +74,25 @@ function simplify(r: Ratio): Ratio {
7374
return [r[0] / f, r[1] / f];
7475
}
7576

77+
let relative = 0;
78+
79+
function viewRelative(n: number) {
80+
relative = n;
81+
renderScale();
82+
}
83+
7684
function addInterval(n: number) {
7785
scaleIntervals.push(n);
7886
scaleIntervals.sort((a, b) => a - b);
79-
renderScale();
87+
viewRelative(0);
8088
renderNonScale();
8189
updateDiagnostics();
8290
}
8391

8492
function removeInterval(n: number) {
8593
if (n == 0) return;
8694
scaleIntervals = scaleIntervals.filter(x => x != n);
87-
renderScale();
95+
viewRelative(0);
8896
renderNonScale();
8997
updateDiagnostics();
9098
}
@@ -94,7 +102,7 @@ function mean(xs: number[]): number {
94102
}
95103

96104
function complexity(n: number, scale: number[]): number {
97-
const result = mean(scale.map(x => Math.pow(stepScores[Math.abs(n - x)], 2)));
105+
const result = mean(scale.map(x => stepScores[Math.abs(n - x)], 2));
98106
return result;
99107
}
100108

@@ -106,13 +114,6 @@ function formatRatio(r: Ratio | null): string {
106114
}
107115
}
108116

109-
let relative = 0;
110-
111-
function viewRelative(n: number) {
112-
relative = n;
113-
renderScale();
114-
}
115-
116117
function renderScale() {
117118
render(html`${scaleIntervals.map(n => html`
118119
<button class="note" onClick=${() => removeInterval(n)}

0 commit comments

Comments
 (0)