-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
44 lines (37 loc) · 1.33 KB
/
Copy pathmain.ts
File metadata and controls
44 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Editor, MarkdownView, Plugin } from "obsidian";
import { parseSong } from "./src/parser";
import { renderSong } from "./src/renderer";
import { convertAbsoluteToDegrees } from "./src/converter";
import { TonicPromptModal } from "./src/custom_modal";
export default class Cancionero extends Plugin {
async onload() {
this.registerMarkdownCodeBlockProcessor("song", (src, el) => {
const parsed = parseSong(src);
console.log(JSON.stringify(parsed, null, 2));
const view = renderSong(parsed);
el.replaceWith(view);
});
this.addCommand({
id: "convert-chords-to-degrees",
name: "Convert chords to degrees",
editorCallback: (editor) => {
const selection = editor.getSelection() || editor.getValue();
new TonicPromptModal(this.app, (tonic) => {
if (!tonic) return;
const converted = convertAbsoluteToDegrees(selection, tonic);
if (editor.getSelection()) {
editor.replaceSelection(converted);
} else {
editor.setValue(converted);
}
}).open();
},
});
}
async promptForTonic(): Promise<string | null> {
return new Promise((resolve) => {
const tonic = window.prompt("Enter tonic (e.g. C, D, G#, Fm):", "D");
resolve(tonic ? tonic.trim() : null);
});
}
}