Skip to content

Commit

Permalink
add mandolin
Browse files Browse the repository at this point in the history
  • Loading branch information
olvidalo committed Mar 22, 2024
1 parent a31d6ac commit 2dc3cbe
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Render and work with chord sheets (**chords over lyrics**) in your vault. This plugin brings
UltimateGuitar-like functionality into Obsidian, featuring **chord diagrams**,
support for **guitar** and **ukulele**, **transposition**, and **autoscroll**. Works seamlessly in **edit / live preview**
support for **guitar**, **ukulele** and **mandolin**, **transposition**, and **autoscroll**. Works seamlessly in **edit / live preview**
and **reading** mode. It integrates with your **theme colors** and is **customizable** to your needs.

## Features
Expand All @@ -26,7 +26,7 @@ rendered locally, no API calls to an external service required.

### 🎸 Choose Your Instrument

Supports guitar and ukulele for rendering the chord diagrams. Instrument can be set globally or specified per chord block.
Includes chord diagrams for guitar, ukulele and mandolin. The instrument can be set globally or specified per chord block.

![change-instrument.gif](docs/change-instrument.gif)

Expand Down
1 change: 1 addition & 0 deletions src/chordSheetsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class ChordSheetsSettingTab extends PluginSettingTab {
.addDropdown(dropdown => dropdown
.addOption("guitar", "Guitar")
.addOption("ukulele", "Ukulele")
.addOption("mandolin", "Mandolin")
.setValue(this.plugin.settings.defaultInstrument)
.onChange(async (value: Instrument) => {
this.plugin.settings.defaultInstrument = value;
Expand Down
19 changes: 8 additions & 11 deletions src/editor-extension/chordBlockToolsWidget.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {EditorView, WidgetType} from "@codemirror/view";
import {Instrument} from "../chordsUtils";
import {chordBlocksStateField} from "./chordBlocksStateField";
import ChordsDB from "@tombatossals/chords-db";

export interface InstrumentChangeEventDetail {
selectedInstrument: string
Expand Down Expand Up @@ -86,17 +87,13 @@ export class ChordBlockToolsWidget extends WidgetType {
const el = document.createElement("select");
el.classList.add("dropdown", "chord-sheet-instrument-change");

const guitarOption = document.createElement("option");
guitarOption.value = "guitar";
guitarOption.text = "Guitar";
guitarOption.selected = this.instrument === "guitar";
el.append(guitarOption);

const ukuleleOption = document.createElement("option");
ukuleleOption.value = "ukulele";
ukuleleOption.selected = this.instrument === "ukulele";
ukuleleOption.text = "Ukulele";
el.append(ukuleleOption);
for (const instrument of Object.keys(ChordsDB)) {
const option = document.createElement("option");
option.value = instrument;
option.text = instrument.charAt(0).toUpperCase() + instrument.slice(1);
option.selected = this.instrument === instrument;
el.append(option);
}

el.addEventListener("change", event => {
const target = event.target as HTMLSelectElement;
Expand Down
3 changes: 2 additions & 1 deletion src/editor-extension/chordBlocksStateField.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ChordsDB, ChordToken, Instrument, isChordLine, tokenizeLine} from "../chordsUtils";
import {ChordToken, Instrument, isChordLine, tokenizeLine} from "../chordsUtils";
import {Decoration, DecorationSet, EditorView, ViewUpdate} from "@codemirror/view";
import {
Compartment,
Expand All @@ -18,6 +18,7 @@ import {Tree} from "@lezer/common";
import {ChordSheetsSettings} from "../chordSheetsSettings";
import {ChordOverviewWidget} from "./chordOverviewWidget";
import {ChordBlockToolsWidget} from "./chordBlockToolsWidget";
import ChordsDB from "@tombatossals/chords-db";

class ParsedUntilRangeValue extends RangeValue {
endSide: -1;
Expand Down
27 changes: 11 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {AutoscrollControl, SPEED_CHANGED_EVENT} from "./autoscrollControl";
import {ChordSheetsSettingTab} from "./chordSheetsSettingTab";
import {IChordSheetsPlugin} from "./chordSheetsPluginInterface";
import {chordSheetsEditorExtension} from "./editor-extension/chordSheetsEditorExtension";
import ChordsDB from "@tombatossals/chords-db";


const AUTOSCROLL_SPEED_PROPERTY = "autoscroll-speed";
Expand Down Expand Up @@ -120,21 +121,15 @@ export default class ChordSheetsPlugin extends Plugin implements IChordSheetsPlu
}
});

this.addCommand({
id: 'block-instrument-change-ukulele',
name: 'Change instrument for the current chord block to ukulele',
editorCheckCallback: (checking: boolean, _editor: Editor, view: MarkdownView) => {
return this.changeInstrumentCommand(view, this.editorPlugin, checking, "ukulele");
}
});

this.addCommand({
id: 'block-instrument-change-guitar',
name: 'Change instrument for the current chord block to guitar',
editorCheckCallback: (checking: boolean, _editor: Editor, view: MarkdownView) => {
return this.changeInstrumentCommand(view, this.editorPlugin, checking, "guitar");
}
});
for (const instrument of Object.keys(ChordsDB) as Instrument[]) {
this.addCommand({
id: `block-instrument-change-${instrument}`,
name: `Change instrument for the current chord block to ${instrument}`,
editorCheckCallback: (checking: boolean, _editor: Editor, view: MarkdownView) => {
return this.changeInstrumentCommand(view, this.editorPlugin, checking, instrument);
}
});
}

this.addCommand({
id: 'transpose-block-up',
Expand Down Expand Up @@ -198,7 +193,7 @@ export default class ChordSheetsPlugin extends Plugin implements IChordSheetsPlu

return true;
}
})
});


this.addSettingTab(new ChordSheetsSettingTab(this.app, this));
Expand Down

0 comments on commit 2dc3cbe

Please sign in to comment.