Skip to content

Commit

Permalink
rename music
Browse files Browse the repository at this point in the history
  • Loading branch information
idris-maps committed May 18, 2023
1 parent c758402 commit 3268037
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 0 deletions.
1 change: 1 addition & 0 deletions sheet-music/example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions sheet-music/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import renderAbc from './vendor/abc/mod.ts'

export const renderFromString = (d: string) => renderAbc(d)
25 changes: 25 additions & 0 deletions sheet-music/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# sheet music

```ts
import {
renderFromString,
} from "https://deno.land/x/serea/sheet-music/mod.ts";
```

## renderFromString

```ts
const svg = renderFromString(`
X: 1
T: Cooley's
M: 4/4
L: 1/8
K: Emin
|:D2|"Em"EB{c}BA B2 EB|~B2 AB dBAG| "D"FDAD BDAD|FDAD dAFD|
"Em"EBBA B2 EB|B2 AB defg| "D"afe^c dBAF|"Em"DEFD E2:|
|:gf|"Em"eB B2 efge|eB B2 gedB| "D"A2 FA DAFA|A2 FA defg|
"Em"eB B2 eBgB|eB B2 defg| "D"afe^c dBAF|"Em"DEFD E2:|
`);
```

returns an SVG, see the [example](./example.svg)
13 changes: 13 additions & 0 deletions sheet-music/try.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { renderFromString } from './mod.ts'

console.log(await renderFromString(`
X: 1
T: Cooley's
M: 4/4
L: 1/8
K: Emin
|:D2|"Em"EB{c}BA B2 EB|~B2 AB dBAG| "D"FDAD BDAD|FDAD dAFD|
"Em"EBBA B2 EB|B2 AB defg| "D"afe^c dBAF|"Em"DEFD E2:|
|:gf|"Em"eB B2 efge|eB B2 gedB| "D"A2 FA DAFA|A2 FA defg|
"Em"eB B2 eBgB|eB B2 defg| "D"afe^c dBAF|"Em"DEFD E2:|
`))
65 changes: 65 additions & 0 deletions sheet-music/vendor/abc/abc.js

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions sheet-music/vendor/abc/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// deno-fmt-ignore-file

const { parseHTML } = require('linkedom')
const renderAbc = require('abcjs/src/api/abc_tunebook_svg')

const toSvg = async abc => {
const html = '<!DOCTYPE html>\n<html><body><div id="sheet"></div></body></html>'
const { document } = parseHTML(html)
const el = document.getElementById('sheet')

globalThis.document = document
await renderAbc(el, abc)

const svg = el.getElementsByTagName('svg')[0]
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg')

const viewBox = `0 0 ${svg.getAttribute('width')} ${svg.getAttribute('height')}`
svg.setAttribute('viewBox', viewBox)
svg.removeAttribute('height')
svg.removeAttribute('width')
svg.removeAttribute('style')

const style = svg.getElementsByTagName('style')[0]
if (style) {
svg.removeChild(style)
}

return svg.outerHTML
}

module.exports = toSvg
10 changes: 10 additions & 0 deletions sheet-music/vendor/abc/lib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"scripts": {
"build": "esbuild index.js --bundle --minify --format=esm --outfile=abc.js"
},
"dependencies": {
"abcjs": "^6.0.2",
"esbuild": "^0.14.38",
"linkedom": "^0.14.9"
}
}
7 changes: 7 additions & 0 deletions sheet-music/vendor/abc/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { default as abcToSvg } from "./abc.js";

/**
* @param {string} abc music notation https://paulrosen.github.io/abcjs/overview/abc-notation.html
* @returns {Promise<string>} svg string
*/
export default (abc: string): Promise<string> => abcToSvg(abc);
13 changes: 13 additions & 0 deletions sheet-music/vendor/abc/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# abc

https://paulrosen.github.io/abcjs/ https://github.com/WebReflection/linkedom

License: [MIT](https://github.com/paulrosen/abcjs/blob/main/license.js)

## How to build

```
cd lib
npm install
npm run build
```

0 comments on commit 3268037

Please sign in to comment.