-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
106 lines (99 loc) · 3.01 KB
/
index.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
paper = require('paper');
Fret = require("./node_modules/fretboard/src/fretboard.js");
$ = require("jquery");
Raphael = require("raphael")
Chord = require("./node_modules/vexchords/js/chord.js")
function convertToInt(el) {
conv = parseInt(el)
if (isNaN(conv)) {
return el
}
else {
return parseInt(el)
}
}
function parseChord(str) {
var array = str.split(/\r?\n/);
var strings = []
var bars = []
var position = 0
var position_text = ''
for (i=0, len=array.length; i < len; i++) {
line = array[i].trim()
data = line.match(/[^\s]+/g)
if (line.search('string') >= 0) {
note = data.slice(1)
note = note.map(convertToInt)
strings.push(note)
}
else if (line.search('bar') >= 0) {
var struct = {}
struct['from_string'] = parseInt(data[1])
struct['to_string'] = parseInt(data[2])
struct['fret'] = parseInt(data[3])
bars.push(struct)
}
else if (line.search('position') >= 0) {
position = data[1]
}
else if (line.search('text') >= 0) {
position_text = data[1]
console.log("Position text: " + position_text)
}
}
return [strings, position, bars, position_text]
}
// Get all div elements with class vex-tabdiv
content_width = $("div#wikipage").width()
console.log("Width: " + content_width)
tabdivs = $("div.vex-tabdivinit");
tabdivs.each(function( index ) {
console.log("Div: " + index);
console.log(this);
console.log("Contents: " + $( this ).text());
this.setAttribute("width", content_width)
this.className = "vex-tabdiv"
// div = new Vex.Flow.FretboardDiv($('div.vex-fretdiv'));
});
// Get all div elements with class vex-tabdiv
fretdivs = $("div.vex-fretdiv");
console.log(fretdivs);
fretdivs.each(function( index ) {
console.log("Div: " + index);
console.log(this);
console.log("Contents: " + $( this ).text());
// div = new Vex.Flow.FretboardDiv($('div.vex-fretdiv'));
div = new Vex.Flow.FretboardDiv($(this), 'vex-fretdiv' + index)
div.build()
});
chorddivs = $("div.vex-chorddiv");
console.log(chorddivs);
chorddivs.each(function( index ) {
console.log("Div: " + index);
console.log(this);
console.log("Contents: " + $( this ).text());
res = parseChord($(this).text())
this.innerHTML = ''
strings = res[0]
position = res[1]
bars = res[2]
position_text = res[3]
var raphpaper = Raphael(this, 150, 140);
var chord = new ChordBox(raphpaper, 30, 30);
console.log(chord)
console.log(raphpaper)
console.log("Strings: ")
console.log(strings)
console.log("Position: ")
console.log(position)
console.log("Bars: ")
console.log(bars)
console.log("Position Text: ")
console.log(position_text)
if (position_text == '') {
chord.setChord(strings, position, bars)
} else {
chord.setChord(strings, position, bars, position_text)
}
chord.draw()
});