-
-
Notifications
You must be signed in to change notification settings - Fork 12
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 importer
Update sonic-weave dependency. Update moment-of-symmetry dependency. ref #34
- Loading branch information
Showing
6 changed files
with
82 additions
and
25 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
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,35 @@ | ||
import { describe, it, expect } from 'vitest' | ||
|
||
import { SonicWeaveInterchangeImporter } from '../xen-devs' | ||
|
||
describe('SonicWeave Interchange importer', () => { | ||
it('can parse text', () => { | ||
const importer = new SonicWeaveInterchangeImporter() | ||
const { sourceText, name } = importer.parseText(` | ||
(* Created using SWI exporter unit test v0.0.0 *) | ||
"Unit Test Scale" | ||
1 = [1 3 1 1>@Hz.2.5.11 | ||
[1/12> "" niente | ||
[1 1 -1> "" niente | ||
[4/5> "" niente | ||
[0 -1 1> "" niente | ||
[531.234049066756>@rc "" niente | ||
[-20 20 -5> "" niente | ||
[1> "" niente | ||
`) | ||
|
||
expect(name).toBe('Unit Test Scale') | ||
expect(sourceText).toBe(`"Unit Test Scale" | ||
1/1 = 440 Hz | ||
1\\12 | ||
6/5 | ||
4\\5 | ||
5/3 | ||
531.2340490667464r¢ | ||
3486784401/3276800000 | ||
2`) | ||
}) | ||
}) |
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 { TextImporter, type ImportResult } from '@/importers/base' | ||
import { RootContext, getSourceVisitor, parseAST } from 'sonic-weave' | ||
|
||
// Specs: https://github.com/xenharmonic-devs/sonic-weave/blob/main/documentation/interchange.md | ||
export class SonicWeaveInterchangeImporter extends TextImporter { | ||
parseText(input: string): ImportResult { | ||
const ast = parseAST(input) | ||
const visitor = getSourceVisitor(false) | ||
visitor.executeProgram(ast) | ||
for (const interval of visitor.currentScale) { | ||
// Strip interchange format | ||
interval.node = undefined | ||
if (interval.isRelative() && interval.value.isFractional()) { | ||
interval.domain = 'linear' | ||
} | ||
} | ||
const result = { | ||
name: visitor.rootContext?.title, | ||
sourceText: visitor.expand(new RootContext()) | ||
} | ||
return result | ||
} | ||
} |