-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update from
bettermusic
fork (#1559)
Co-authored-by: isaiahdahl <isaiahdahl@me.com>
- Loading branch information
1 parent
52eecb1
commit 14d2055
Showing
22 changed files
with
1,439 additions
and
72 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...chord_sheet/chord_pro/chord_definition.ts → src/chord_definition/chord_definition.ts
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,51 @@ | ||
import ChordDefinition from './chord_definition'; | ||
import chordDefinitions from './defaults.json'; | ||
|
||
export type DefinitionSet = Record<string, ChordDefinition>; | ||
|
||
class ChordDefinitionSet { | ||
definitions: DefinitionSet; | ||
|
||
constructor(definitions?: DefinitionSet) { | ||
this.definitions = definitions || {}; | ||
} | ||
|
||
get(chord: string): ChordDefinition | null { | ||
return this.definitions[chord] || null; | ||
} | ||
|
||
withDefaults() { | ||
const defaultDefinitions: Record<string, string> = chordDefinitions; | ||
const clone = this.clone(); | ||
|
||
Object.keys(defaultDefinitions).forEach((chord: string) => { | ||
const definition = ChordDefinition.parse(defaultDefinitions[chord]); | ||
|
||
if (!clone.has(chord)) { | ||
clone.add(chord, definition); | ||
} | ||
}); | ||
|
||
return clone; | ||
} | ||
|
||
add(chord: string, definition: ChordDefinition) { | ||
this.definitions[chord] = definition; | ||
} | ||
|
||
has(chord: string): boolean { | ||
return chord in this.definitions; | ||
} | ||
|
||
clone(): ChordDefinitionSet { | ||
const clone = new ChordDefinitionSet(); | ||
|
||
Object.keys(this.definitions).forEach((chord: string) => { | ||
clone.add(chord, this.definitions[chord].clone()); | ||
}); | ||
|
||
return clone; | ||
} | ||
} | ||
|
||
export default ChordDefinitionSet; |
Large diffs are not rendered by default.
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
Oops, something went wrong.