-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
70 lines (65 loc) · 3.3 KB
/
index.html
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Chord-Draw">
<meta name="author" content="T-vK">
<title>Chord-Draw</title>
</head>
<body>
<input type="text" id="chord-input">
<select id="layout">
<option value="1" selected="selected">Layout 1</option>
<option value="2">Layout 2</option>
</select>
<div id="chord-output"></div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="ChordJS/chords.js"></script>
<script src="chord-collection/chords.js"></script>
<script>
function draw(){
var chordName = $("#chord-input").val()
var layout = $('#layout').val()
chordsHtml = getChordHtml(chordName,layout).join('')
$('#chord-output').html(chordsHtml)
ChordJS.replace()
}
$(function(){
$("#chord-input").on('change keydown paste input', draw)
draw()
})
function transposeChord(chord, amount) {
var scale = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
var normalizeMap = {"Cb":"B", "Db":"C#", "Eb":"D#", "Fb":"E", "Gb":"F#", "Ab":"G#", "Bb":"A#", "E#":"F", "B#":"C"}
return chord.replace(/[CDEFGAB](b|#)?/g, function(match) {
var i = (scale.indexOf((normalizeMap[match] ? normalizeMap[match] : match)) + amount) % scale.length
return scale[ i < 0 ? i + scale.length : i ]
})
}
function getChordHtml(chordName,layout,size) {
var size = size || 5
var chordsHtmlArr = [] //example: <chord name="D" positions="xx0232" fingers="---132" size="3" ></chord>
var chordVariations = []
if (CHORD_COLLECTION[chordName]) {
chordVariations = CHORD_COLLECTION[chordName]
} else {
chordVariations.push({positions:['x','x','x','x','x','x'],fingerings:[[0,0,0,0,0,0]]})
chordName = chordName + ' (N/A)'
}
chordVariations.forEach(function(variation,i){
var positionsStr = variation.positions.join('')
variation.fingerings.forEach(function(fingering,i){
var fingeringStr = fingering.join('').replace(/0/g,'-')
if (positionsStr.length===6 && fingeringStr.length===6 && positionsStr !== 'xxxxxx') {
var chordHtml = '<chord name="' + chordName + '" positions="' + positionsStr + '" fingers="' + fingeringStr + '" size="' + size + '" layout="' + layout + '" strings="EADGBe"></chord>'
chordsHtmlArr.push(chordHtml)
}
})
})
return chordsHtmlArr
}
</script>
</body>
</html>