Skip to content

Commit

Permalink
Merge 1326759 into c3b55d3
Browse files Browse the repository at this point in the history
  • Loading branch information
Jussi Utunen committed Sep 26, 2019
2 parents c3b55d3 + 1326759 commit 75e86f3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs-src/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

<div class="output">
<div data-output="normalized">-</div>
<div data-output="pianokeys"></div>
</div>

<div class="output-details hidden">
Expand Down
34 changes: 34 additions & 0 deletions docs-src/src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/*eslint complexity: ["error", 12]*/

import { parseChord, chordRendererFactory } from '../../src/index';
import 'custom-piano-keys';

const renderChordNormalized = chordRendererFactory();
const renderChordShort = chordRendererFactory({ useShortNamings: true });

const chordInput = document.getElementById('chordInput');

const normalized = document.querySelector('[data-output="normalized"]');
const pianokeysDiv = document.querySelector('[data-output="pianokeys"]');
const normalizedShort = document.querySelector('[data-output="normalizedShort"]');
const intervals = document.querySelector('[data-output="intervals"]');
const json = document.querySelector('[data-output="json"]');
Expand All @@ -15,10 +19,40 @@ let input;
let chord;
let symbolNormalized;
let symbolShort;
let mappedNotes;
let markedKeys;
let pianokeys;
let rootNotes = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B'];
let rootNoteIndex;
let octaveCount;

function myReducer(total, item) {
return total + ' ' + item;
}

chordInput.addEventListener('keyup', () => {

if(pianokeysDiv.firstChild) {
pianokeysDiv.firstChild.remove();
}

input = chordInput.value;
chord = parseChord(input);
if(chord) {
rootNoteIndex = rootNotes.indexOf(chord.normalized.rootNote);
if(rootNoteIndex !== -1) {
mappedNotes = chord.normalized.semitones.map(x => x + 1 + rootNoteIndex);
octaveCount = 1;
if(mappedNotes.some(x => x > 12)) {
octaveCount = 2;
}
markedKeys = mappedNotes.reduce(myReducer,'').trim();
pianokeys = document.createElement('custom-piano-keys');
pianokeys.setAttribute('marked-keys', markedKeys);
pianokeys.setAttribute('oct-count', octaveCount);
pianokeysDiv.appendChild(pianokeys);
}
}

symbolNormalized = (!chord) ? '' : renderChordNormalized(chord);
symbolShort = (!chord) ? '' : renderChordShort(chord);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"dependencies": {
"core-js": "^3.2.1",
"custom-piano-keys": "0.0.10",
"lodash": "^4.17.15"
},
"scripts": {
Expand Down

0 comments on commit 75e86f3

Please sign in to comment.