Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preset golfing #670

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scale-workshop",
"version": "3.0.0-beta.19",
"version": "3.0.0-beta.20",
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
Expand All @@ -21,14 +21,14 @@
"moment-of-symmetry": "^0.4.2",
"pinia": "^2.1.7",
"qs": "^6.12.0",
"sonic-weave": "github:xenharmonic-devs/sonic-weave#v0.0.26",
"sonic-weave": "github:xenharmonic-devs/sonic-weave#v0.0.29",
"sw-synth": "^0.1.0",
"temperaments": "^0.5.3",
"values.js": "^2.1.1",
"vue": "^3.3.4",
"vue-router": "^4.3.0",
"webmidi": "^3.1.8",
"xen-dev-utils": "^0.3.0",
"xen-dev-utils": "^0.4.0",
"xen-midi": "^0.2.0"
},
"devDependencies": {
Expand Down
24 changes: 12 additions & 12 deletions src/components/modals/modification/EnumerateScale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const emit = defineEmits(['done', 'cancel'])
const scale = useScaleStore()

function overtonal() {
scale.sourceText += ';elevate();simplify;repr'
scale.sourceText += ';elevate();simplify;map(repr)'
const { visitor, defaults } = scale.getVisitors()
const overtones = visitor.mutables.get('$') as unknown as string[]
visitor.mutables.set('$', [])
const overtones = visitor.currentScale.map(i => i.label)
visitor.currentScale.length = 0
scale.sourceText = visitor.expand(defaults)
if (scale.sourceText) {
scale.sourceText += '\n'
Expand All @@ -21,10 +21,10 @@ function overtonal() {
}

function undertonal() {
scale.sourceText += ';reflect();elevate();simplify;repr'
scale.sourceText += ';reflect();elevate();simplify;map(repr)'
const { visitor, defaults } = scale.getVisitors()
const undertones = visitor.mutables.get('$') as unknown as string[]
visitor.mutables.set('$', [])
const undertones = visitor.currentScale.map(i => i.label)
visitor.currentScale.length = 0
scale.sourceText = visitor.expand(defaults)
if (scale.sourceText) {
scale.sourceText += '\n'
Expand All @@ -35,10 +35,10 @@ function undertonal() {
}

function retroversion() {
scale.sourceText += ';retrovert();elevate();simplify;repr'
scale.sourceText += ';retrovert();elevate();simplify;map(repr)'
const { visitor, defaults } = scale.getVisitors()
const tones = visitor.mutables.get('$') as unknown as string[]
visitor.mutables.set('$', [])
const tones = visitor.currentScale.map(i => i.label)
visitor.currentScale.length = 0
scale.sourceText = visitor.expand(defaults)
if (scale.sourceText) {
scale.sourceText += '\n'
Expand All @@ -49,10 +49,10 @@ function retroversion() {
}

function revposition() {
scale.sourceText += ';revpose();elevate();simplify;repr'
scale.sourceText += ';revpose();elevate();simplify;map(repr)'
const { visitor, defaults } = scale.getVisitors()
const tones = visitor.mutables.get('$') as unknown as string[]
visitor.mutables.set('$', [])
const tones = visitor.currentScale.map(i => i.label)
visitor.currentScale.length = 0
scale.sourceText = visitor.expand(defaults)
if (scale.sourceText) {
scale.sourceText += '\n'
Expand Down
47 changes: 26 additions & 21 deletions src/presets.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"ragatodi": {
"name": "Raga Todi",
"source": "rank2(3/2 white, 1, 5, 2/1 white)\n$[2] *~= 135/128 black\n$[5] *~= 135/128 black\n",
"source": "rank2(3/2 white, 1, 5, 2/1 white)\n$[[2, 5]] *~= 135/128 black\n",
"categories": ["traditional", "just intonation"]
},
"ragayaman": {
Expand Down Expand Up @@ -98,28 +98,28 @@
"5edo": {
"title": "Equal pentatonic",
"name": "Equal pentatonic (5edo)",
"source": "tet(5)\nlabel([white, white, white, white, gray])\n",
"source": "tet(5)\n[white, white, white, white, gray]\n",
"categories": ["traditional", "equal temperament"]
},
"7edo": {
"title": "Equal heptatonic",
"name": "Equal heptatonic (7edo)",
"source": "tet(7)\ni => i white\npop() gray\n",
"source": "tet(7) white\npop() gray\n",
"categories": ["traditional", "equal temperament"]
},
"archytasdiatonic": {
"name": "Archytas Diatonic",
"source": "3/2 white\n2/1 white\nmergeOffset([28/27 blue, 32/27 white, 4/3 white])\nsimplify\n",
"source": "(2::4) white\nmergeOffset([28/27 blue, 32/27 white, 4/3 white])\nsimplify\n",
"categories": ["traditional", "just intonation"]
},
"archytasenharmonic": {
"name": "Archytas Enharmonic",
"source": "3/2 white\n2/1 white\nmergeOffset([28/27 blue, 16/15 green, 4/3 white])\nsimplify\n",
"source": "(2::4) white\nmergeOffset([28/27 blue, 16/15 green, 4/3 white])\nsimplify\n",
"categories": ["traditional", "just intonation"]
},
"didymuschromatic": {
"name": "Didymus Chromatic",
"source": "3/2 white\n2/1 white\nmergeOffset([16/15 green, 10/9 yellow, 4/3 white])\nsimplify\n",
"source": "2 white::4\nmergeOffset([16/15 green, 10/9 yellow, 4/3 white])\nsimplify\n",
"categories": ["traditional", "just intonation"]
},
"ptolemydiatonicditoniaion": {
Expand All @@ -129,12 +129,12 @@
},
"ptolemydiatonichemiolion": {
"name": "Ptolemy Diatonic Hemiolion",
"source": "3/2 white\n2/1 white\nmergeOffset([12/11 black, 6/5 green, 4/3 white])\nsimplify\n",
"source": "2::4\nmergeOffset([12/11 black, 6/5 green, 4/3])\nwhite\nsimplify\n",
"categories": ["traditional", "just intonation"]
},
"pythagorean": {
"name": "Pythagorean",
"source": "labeled(['F', 'C', 'G', 'D', 'A', 'E', 'B'], [3^i rdc 2 white for i of [-2..4]])\nlabeled(['G♭', 'D♭', 'A♭', 'E♭', 'B♭'], [3^i rdc 2 black for i of [-7..-3]])\nsort()\n",
"source": "[3^i rdc 2 white for i of [-2..4]] ['F', 'C', 'G', 'D', 'A', 'E', 'B']\n[3^i rdc 2 black for i of [-7..-3]] ['G♭', 'D♭', 'A♭', 'E♭', 'B♭']\nsort()\n",
"categories": ["traditional", "just intonation"],
"baseMidiNote": 67,
"baseFrequency": 391
Expand All @@ -160,12 +160,12 @@
},
"partch43": {
"name": "Harry Partch 43-tone",
"source": "[\n n % d white\n for n of [1..11]\n for d of [1..11]\n]\n\n1 gray:15:21:27:33\n/1 black:15:21:27:33\n\n5 olive:21:27:81\n/5 gold:21:27:81\n\n2\nreduce()\nsort()\nkeepUnique()\n",
"source": "1 gray:15:21:27:33\n/1 black:15:21:27:33\n\n5 olive:21:27:81\n/5 gold:21:27:81\n\noddLimit(11) white\n\norganize()\n",
"categories": ["just intonation"]
},
"carlossuperjust": {
"name": "Wendy Carlos Super Just",
"source": "[3,5..17]\nlabel([white, yellow, blue, white, lavender, chocolate, yellow, indigo])\n1/3 white\n3/5 green\n5/3 yellow\n2 white\nreduce()\nsort()\n",
"source": "[3,5..17]\n[white, yellow, blue, white, lavender, chocolate, yellow, indigo]\n1/3 white\n3/5 green\n5/3 yellow\n2 white\norganize()\n",
"baseFrequency": 264,
"baseMidiNote": 60,
"categories": ["just intonation"]
Expand Down Expand Up @@ -206,7 +206,7 @@
},
"13oneirotonic": {
"name": "13edo oneirotonic (5L 3s)",
"source": "mos(5, 3)\nlabel([white, black, white, white, black, white, black, white])\n",
"source": "mos(5, 3)\n[white, black, white, white, black, white, black, white]",
"categories": ["MOS", "equal temperament"]
},
"15blackwood10": {
Expand All @@ -221,14 +221,14 @@
},
"17superpyth12": {
"name": "17edo superpyth[12]",
"source": "[3^i rdc 2 for i of concat([0 white..6], [7 black..11])]\nlabel(['F', 'C', 'G', 'D', 'A', 'E', 'B', 'F♯', 'C♯', 'G♯', 'D♯', 'A♯'])\nsort()\n17@",
"source": "[3^i rdc 2 for i of concat([0 white..6], [7 black..11])]\n['F', 'C', 'G', 'D', 'A', 'E', 'B', 'F♯', 'C♯', 'G♯', 'D♯', 'A♯']\nsort()\n17@",
"categories": ["MOS", "equal temperament"],
"baseMidiNote": 65,
"baseFrequency": 349
},
"17rast": {
"name": "17edo Rast",
"source": "M2 white\nn3 gray\nP4 white\nP5 white\nM6 white\nn7 gray\nP8 white\nlabel(map(str))\n17@\n",
"source": "M2 white\nn3 gray\nP4 white\nP5 white\nM6 white\nn7 gray\nP8 white\nmap(str)\n17@\n",
"categories": ["MOS", "equal temperament"]
},
"22porcupine8": {
Expand All @@ -253,19 +253,19 @@
},
"26flattone12": {
"name": "26edo flattone[12]",
"source": "C=4 = 265 Hz\nC#4 black\nD=4 white\nD#4 black\nE=4 white\nF=4 white\nF#4 black\nG=4 white\nG#4 black\nA=4 white\nBb4 black\nB=4 white\nC=5 white\nlabel(map(i => str(i)[..1]))\n26@\n",
"source": "rank2(3/2, 9, 2)\nlabelAbsoluteFJS\n26@\n",
"categories": ["MOS", "equal temperament"],
"baseMidiNote": 60,
"baseFrequency": 265
},
"31meantone19": {
"name": "31edo meantone[19]",
"source": "A♮4 = 440 Hz\nA♯4 navy\nB♭4 maroon\nB♮4 white\nC♭5 maroon\nC♮5 white\nC♯5 navy\nD♭5 maroon\nD♮5 white\nD♯5 navy\nE♭5 maroon\nE♮5 white\nE♯5 navy\nF♮5 white\nF♯5 navy\nG♭5 maroon\nG♮5 white\nG♯5 navy\nA♭5 maroon\nA♮5 white\nlabel(map(i => str(i)[..1]))\n31@\n",
"source": "A♮4 = 440 Hz\nA♯4 navy\nB♭4 maroon\nB♮4 white\nC♭5 maroon\nC♮5 white\nC♯5 navy\nD♭5 maroon\nD♮5 white\nD♯5 navy\nE♭5 maroon\nE♮5 white\nE♯5 navy\nF♮5 white\nF♯5 navy\nG♭5 maroon\nG♮5 white\nG♯5 navy\nA♭5 maroon\nA♮5 white\nmap(i => str(i)[..1])\n31@\n",
"categories": ["MOS", "equal temperament"]
},
"46sensi11": {
"name": "46edo sensi[11]",
"source": "rank2(9/7, 10)\nlabel([white, white, black, white, white, white, black, white, white, black, white])\n46@",
"source": "rank2(9/7, 10)\n[white, white, black, white, white, white, black, white, white, black, white]\n46@\n",
"categories": ["MOS", "equal temperament"]
},
"362barbados9": {
Expand All @@ -285,17 +285,17 @@
},
"carlosalpha": {
"name": "Wendy Carlos Alpha",
"source": "78.\nrepeat(9)\nlabel([black, black, black, white, white, black, black, black, white])\n",
"source": "78.\nrepeat(9)\n[black, black, black, white, white, black, black, black, white]\n",
"categories": ["non-octave", "equal temperament"]
},
"carlosbeta": {
"name": "Wendy Carlos Beta",
"source": "63.8\nrepeat(11)\nlabel([black, black, white, black, white, white, black, white, black, black, white])\n",
"source": "63.8\nrepeat(11)\n[black, black, white, black, white, white, black, white, black, black, white]\n",
"categories": ["non-octave", "equal temperament"]
},
"carlosgamma": {
"name": "Wendy Carlos Gamma",
"source": "35.1\nrepeat(20)\nlabel([black, black, gray, black, black, white, black, black, white, black, white, black, black, white, black, black, gray, black, black, white])\n",
"source": "35.1\nrepeat(20)\n[black, black, gray, black, black, white, black, black, white, black, white, black, black, white, black, black, gray, black, black, white]\n",
"categories": ["non-octave", "equal temperament"]
},
"65cet": {
Expand All @@ -308,6 +308,11 @@
"source": "88.0 white",
"categories": ["non-octave", "equal temperament"]
},
"otonalstacks": {
"name": "Sevish stacked otonal framents",
"source": "unstacked(24 white:27:30:32:36)\nunstacked(24 lightblue:27:28:32:36)\nunstacked(24 palegoldenrod:27:30:32:36)\nstack()\n",
"categories": ["non-octave", "just intonation"]
},
"blackdye": {
"title": "Blackdye GO",
"name": "Blackdye",
Expand All @@ -333,7 +338,7 @@
"superzarlino": {
"title": "Superzarlino MV3 GO",
"name": "Superzarlino",
"source": "gs([5/4, 6/5], 17)\nlabel([black, black, white, black, white, black, black, white, black, white, black, black, white, black, white, black, white])\n34@",
"source": "gs([5/4, 6/5], 17)\n[black, black, white, black, white, black, black, white, black, white, black, black, white, black, white, black, white]\n34@",
"categories": ["MV3", "GO", "equal temperament"]
},
"marveldene": {
Expand All @@ -345,7 +350,7 @@
"meantone": {
"title": "Meantone CTE",
"name": "Meantone[12], TE optimized with a 2/1 constraint.",
"source": "A♮4 = 440Hz\nB♭4 black\nB♮4 white\nC♮5 white\nC♯5 black\nD♮5 white\nE♭5 black\nE♮5 white\nF♮5 white\nF♯5 black\nG♮5 white\nG♯5 black\nA♮5 white\nlabel(map(i => str(i)[..1]))\nPrimeMapping(1200.000, 1897.214, 2788.857)\n",
"source": "A♮4 = 440Hz\nB♭4 black\nB♮4 white\nC♮5 white\nC♯5 black\nD♮5 white\nE♭5 black\nE♮5 white\nF♮5 white\nF♯5 black\nG♮5 white\nG♯5 black\nA♮5 white\nmap(i => str(i)[..1])\nPrimeMapping(1200.000, 1897.214, 2788.857)\n",
"categories": ["MOS", "CTE", "rank 2"]
},
"orgone": {
Expand Down
9 changes: 5 additions & 4 deletions src/stores/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const useScaleStore = defineStore('scale', () => {

// === Computed state ===
const sourcePrefix = computed(() => {
const base = `${JSON.stringify(name.value)}\nnumComponents(${DEFAULT_NUMBER_OF_COMPONENTS})\n`
const base = `numComponents(${DEFAULT_NUMBER_OF_COMPONENTS})\n`
const rootPitch = midiNoteNumberToName(baseMidiNote.value)
if (autoFrequency.value) {
return `${base}${rootPitch} = mtof(_) = 1/1`
Expand Down Expand Up @@ -339,6 +339,7 @@ export const useScaleStore = defineStore('scale', () => {
function getVisitors() {
const globalVisitor = getGlobalVisitor()
const visitor = new StatementVisitor(globalVisitor)
visitor.isUserRoot = true
const defaults = visitor.rootContext!.clone()
defaults.gas = gas.value

Expand Down Expand Up @@ -387,12 +388,12 @@ export const useScaleStore = defineStore('scale', () => {
visitorBaseFrequency = visitor.rootContext!.unisonFrequency.valueOf()
}
if (ratios.length) {
const name = str.bind(ev)
const evStr = str.bind(ev)
scale.value = new Scale(
ratios,
visitorBaseFrequency,
baseMidiNote.value,
ev.rootContext!.title
ev.rootContext!.title || name.value
)
if (autoColors.value === 'silver') {
colors.value = intervals.map(
Expand All @@ -408,7 +409,7 @@ export const useScaleStore = defineStore('scale', () => {
(interval) => interval.color?.value ?? factorColor.bind(ev)(interval).value
)
}
labels.value = intervals.map((interval) => interval.label || name(interval))
labels.value = intervals.map((interval) => interval.label || evStr(interval))
} else {
scale.value = new Scale(TET12, visitorBaseFrequency, baseMidiNote.value, name.value)
colors.value = defaultColors(baseMidiNote.value)
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function expandCode(source: string) {
const globalVisitor = getSourceVisitor()
const defaults = globalVisitor.rootContext!.clone()
const visitor = new StatementVisitor(globalVisitor)
visitor.isUserRoot = true
const ast = parseAST(source)
for (const statement of ast.body) {
const interupt = visitor.visit(statement)
Expand Down
Loading