-
-
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.
Implement SonicWeave Interchange exporter
ref #34
- Loading branch information
Showing
7 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { describe, it, expect } from 'vitest' | ||
|
||
import SonicWeaveInterchangeExporter from '../xen-devs' | ||
|
||
import { getTestData } from './test-data' | ||
|
||
describe('SonicWeave Interchange exporter', () => { | ||
it('can handle all line types', () => { | ||
const params = getTestData('SWI exporter unit test v0.0.0') | ||
const exporter = new SonicWeaveInterchangeExporter(params) | ||
expect(exporter.getFileContents()).toBe(`(* Created using SWI exporter unit test v0.0.0 *) | ||
"Test Scale" | ||
[1/12> "" niente | ||
[1 1 -1> "" niente | ||
[4/5> "" niente | ||
[0 -1 1> "" niente | ||
[531.234049066756>@rc "" niente | ||
[-20 20 -5> "" niente | ||
[1> "" niente | ||
`) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { APP_TITLE } from '@/constants' | ||
import { BaseExporter, type ExporterParams } from '@/exporters/base' | ||
import { literalToString } from 'sonic-weave' | ||
|
||
// Specs: https://github.com/xenharmonic-devs/sonic-weave/blob/main/documentation/interchange.md | ||
export default class SonicWeaveInterchangeExporter extends BaseExporter { | ||
constructor(params: ExporterParams) { | ||
super(params) | ||
} | ||
|
||
getFileContents() { | ||
const params = this.params | ||
const lines = [`(* Created using ${params.appTitle ?? APP_TITLE} *)`, ''] | ||
lines.push(JSON.stringify(params.scale.title)) | ||
if (params.unisonFrequency) { | ||
const unisonFrequency = literalToString(params.unisonFrequency.asInterchangeLiteral()) | ||
lines.push(`1 = ${unisonFrequency}`) | ||
lines.push('') | ||
} | ||
const intervals = params.rawIntervals ?? params.relativeIntervals | ||
for (const interval of intervals) { | ||
const universal = interval.shallowClone() | ||
universal.node = universal.asMonzoLiteral(true) | ||
let line = universal.toString(undefined, true) | ||
if (line.startsWith('(') && line.endsWith(')')) { | ||
line = line.slice(1, -1) | ||
} | ||
lines.push(line) | ||
} | ||
lines.push('') | ||
return lines.join('\n') | ||
} | ||
|
||
saveFile() { | ||
super.saveFile(this.params.filename + '.swi', this.getFileContents()) | ||
} | ||
} |
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