Skip to content

Commit

Permalink
🎉 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TilBlechschmidt committed Nov 21, 2020
0 parents commit 09ce655
Show file tree
Hide file tree
Showing 11 changed files with 471 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Intellij
*.iml
.idea

# npm
node_modules
package-lock.json

# build
main.js
*.js.map
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Obsidian ABC.JS plugin

This plugin renders music sheets from code blocks using the `abc` language. Under the hood it uses [abc.js](https://paulrosen.github.io/abcjs/) and supports everything the library does.

## Examples

### Simple song

```abc
X:1
T:The Legacy Jig
M:6/8
L:1/8
R:jig
K:G
GFG BAB | gfg gab | GFG BAB | d2A AFD |
GFG BAB | gfg gab | age edB |1 dBA AFD :|2 dBA ABd |:
efe edB | dBA ABd | efe edB | gdB ABd |
efe edB | d2d def | gfe edB |1 dBA ABd :|2 dBA AFD |]
```

### Chorus music

```abc
X: 1
T: Chorus
V: T1 clef=treble name="Soprano"
V: T2 clef=treble name="Alto"
V: B1 clef=bass name="Tenor"
V: B2 clef=bass name="Bass"
L:1/8
K:G
P:First Part
[V: T1]"C"ed"Am"ed "F"cd"G7"gf |
[V: T2]GGAA- A2BB |
[V: B1]C3D- DF,3 |
[V: B2]C,2A,,2 F,,2G,,2 |
```
33 changes: 33 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { App, MarkdownPostProcessor, MarkdownPostProcessorContext, MarkdownPreviewRenderer, MarkdownRenderer, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { signature, renderAbc } from 'abcjs';

export default class MusicPlugin extends Plugin {
static postprocessor: MarkdownPostProcessor = (el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
// Assumption: One section always contains only the code block

const blockToReplace = el.querySelector('pre')
if (!blockToReplace) return

const musicBlock = blockToReplace.querySelector('code.language-abc')
if (!musicBlock) return

const source = musicBlock.textContent
const destination = document.createElement('div')
renderAbc(destination, source, {
add_classes: true,
responsive: 'resize'
})

el.replaceChild(destination, blockToReplace)
}

onload() {
console.log('loading abcjs plugin');
MarkdownPreviewRenderer.registerPostProcessor(MusicPlugin.postprocessor)
}

onunload() {
console.log('unloading abcjs plugin');
MarkdownPreviewRenderer.unregisterPostProcessor(MusicPlugin.postprocessor)
}
}
10 changes: 10 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "obsidian-plugin-abcjs",
"name": "Music notation",
"version": "1.0.0",
"minAppVersion": "0.9.15",
"description": "Plugin which renders music notation from code blocks. Uses the `abc` language.",
"author": "Til Blechschmidt",
"authorUrl": "https://github.com/TilBlechschmidt/obsidian-plugin-abcjs",
"isDesktopOnly": false
}
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "obsidian-sample-plugin",
"version": "0.9.7",
"description": "Plugin which renders music notation from code blocks. Uses the `abc` language.",
"main": "main.js",
"scripts": {
"dev": "rollup --config rollup.config.js -w",
"build": "rollup --config rollup.config.js"
},
"keywords": [],
"author": "",
"license": "MIT",
"devDependencies": {
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"@types/node": "^14.14.2",
"obsidian": "https://github.com/obsidianmd/obsidian-api/tarball/master",
"rollup": "^2.32.1",
"tslib": "^2.0.3",
"typescript": "^4.0.3"
},
"dependencies": {
"abcjs": "^5.12.0"
}
}
19 changes: 19 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import typescript from '@rollup/plugin-typescript';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

export default {
input: 'main.ts',
output: {
dir: '.',
sourcemap: 'inline',
format: 'cjs',
exports: 'default'
},
external: ['obsidian'],
plugins: [
typescript(),
nodeResolve({browser: true}),
commonjs(),
]
};
1 change: 1 addition & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Nothing to do here really, default abcjs styles look good */
26 changes: 26 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"baseUrl": ".",
"inlineSourceMap": true,
"inlineSources": true,
"module": "ESNext",
"target": "es5",
"allowJs": true,
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"lib": [
"dom",
"es5",
"scripthost",
"es2015"
],
"typeRoots": [
"node_modules/@types",
"typeDefs"
]
},
"include": [
"**/*.ts"
]
}
10 changes: 10 additions & 0 deletions typeDefs/abcjs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type Params = {
add_classes: boolean,
responsive: 'resize' | undefined
}

declare module 'abcjs' {
const signature: string

const renderAbc: (output: HTMLElement, abc: string, parameters: Params) => void
}
3 changes: 3 additions & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"1.0.0": "0.9.15"
}
Loading

0 comments on commit 09ce655

Please sign in to comment.