-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: (Edo) cycle option on Lattice tab
ref #678
- Loading branch information
Showing
6 changed files
with
171 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<script setup lang="ts"> | ||
import { useGridStore } from '@/stores/grid' | ||
import { type MultiVertex } from 'ji-lattice' | ||
import { type Interval } from 'sonic-weave' | ||
import { computed, ref } from 'vue' | ||
import { mmod } from 'xen-dev-utils' | ||
const store = useGridStore() | ||
const props = defineProps<{ | ||
relativeIntervals: Interval[] | ||
labels: string[] | ||
colors: string[] | ||
heldNotes: Set<number> | ||
}>() | ||
const svgElement = ref<SVGSVGElement | null>(null) | ||
const steps = computed(() => { | ||
const result: number[] = [] | ||
for (const interval of props.relativeIntervals) { | ||
result.push(interval.dot(store.val).valueOf()) | ||
} | ||
return result | ||
}) | ||
// Multi-label offsets | ||
function lx(n: number, num: number) { | ||
if (num < 3) { | ||
return 0 | ||
} | ||
if (num & 1) { | ||
// Odd counts exploit a different starting angle. | ||
return store.labelOffset * store.size * Math.cos((2 * Math.PI * n) / num) | ||
} | ||
// Text tends to extend horizontally so we draw an ellipse. | ||
return 1.5 * store.labelOffset * store.size * Math.sin((2 * Math.PI * n) / num) | ||
} | ||
function ly(n: number, num: number) { | ||
if (num === 1) { | ||
return -store.labelOffset * store.size | ||
} | ||
if (num & 1) { | ||
// Odd counts exploit a different starting angle. | ||
return store.labelOffset * store.size * Math.sin((2 * Math.PI * n) / num) | ||
} | ||
return -store.labelOffset * store.size * Math.cos((2 * Math.PI * n) / num) | ||
} | ||
const vertices = computed(() => { | ||
const m = store.modulus; | ||
const n = store.numEdoCycles; | ||
const gpi = store.generatorPseudoInverse; | ||
const result = new Map<number, MultiVertex>(); | ||
const dt = 2 * Math.PI / m; | ||
for (let i = 0; i < steps.value.length; ++i) { | ||
const s = steps.value[i]; | ||
const c = mmod(s, n) | ||
const j = mmod((s - c) * gpi, m) + c | ||
const vertex = result.get(j) ?? { | ||
x: Math.sin(dt * j), | ||
y: -Math.cos(dt * j), | ||
indices: [] | ||
} | ||
vertex.indices.push(i) | ||
result.set(j, vertex) | ||
} | ||
return Array.from(result.values()) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<svg | ||
ref="svgElement" | ||
class="lattice" | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="-2 -2 4 4" | ||
preserveAspectRatio="xMidYMid meet" | ||
> | ||
<circle | ||
v-for="(v, i) of vertices" | ||
:key="i" | ||
:class="{ node: true, held: v.indices.some((idx) => heldNotes.has(idx)) }" | ||
:cx="v.x" | ||
:cy="v.y" | ||
:r="0.5 * store.size" | ||
:fill="colors[v.indices[0]] ?? 'none'" | ||
:stroke="colors[v.indices[0]] ?? 'none'" | ||
:stroke-width="store.size * 0.1" | ||
/> | ||
<template v-if="store.showLabels"> | ||
<template v-for="(v, i) of vertices" :key="i"> | ||
<text | ||
v-for="(idx, j) of v.indices" | ||
:key="idx" | ||
class="node-label" | ||
:x="v.x + lx(j, v.indices.length)" | ||
:y="v.y + ly(j, v.indices.length)" | ||
:font-size="`${1.1 * store.size}px`" | ||
:stroke-width="store.size * 0.01" | ||
dominant-baseline="middle" | ||
> | ||
{{ labels[idx] }} | ||
</text> | ||
</template> | ||
</template> | ||
</svg> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters