-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchordConverter.html
296 lines (267 loc) · 10.5 KB
/
chordConverter.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>akkord konverterings test</title
<style type="text/css">
<!--
A:link {text-decoration: none}
A:visited {text-decoration: none}
A:active {text-decoration: none}
A:hover {text-decoration: none}
-->
</style>
<script src='js/renderModPro.js' type="text/javascript"></script>
<script src='js/cursor.js' type="text/javascript"></script>
<script type="text/javascript">
<!--
minRows = 10;
numbLines = -1;
function getCaretPosition (ctrl) {
var CaretPos = 0;
// IE Support
if (document.selection) {
ctrl.focus ();
var Sel = document.selection.createRange ();
Sel.moveStart ('character', -ctrl.value.length);
CaretPos = Sel.text.length;
}
// Firefox support
else if (ctrl.selectionStart || ctrl.selectionStart == '0'){
CaretPos = ctrl.selectionStart;
}
return (CaretPos);
}
function setCaretPosition(ctrl, pos)
{
if(ctrl.setSelectionRange)
{
ctrl.focus();
ctrl.setSelectionRange(pos,pos);
}
else if (ctrl.createTextRange) {
var range = ctrl.createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
function getCurLine(area) {
// pos = getCaretPosition(area);
pos = cursorPosition(area);
lines = area.value.split("\n");
numLines = lines.length;
txtLen = area.value.length;
idx = 0;
i = 0;
while(idx < pos && i < numLines) {
idx += lines[i].length + 1;
i++;
}
return i;
}
// Update the ModPro lyrics
function update() {
var _mydiv = document.getElementById('protext');
var _oldtext = _mydiv.childNodes;
for (j=0; j < _oldtext.length; j++) {
_mydiv.removeChild(_oldtext[j]);
}
var newnode = document.createElement("div");
var protext = convertToPro(document.getElementById('sangtekst').value)
//alert(protext);
// Get the rendered protext.
newnode.innerHTML = RenderSong(protext, '', '', '', '');
_mydiv.appendChild(newnode);
}
function convertToPro(text) {
var proText = "";
var lines = text.split("\n");
var lineCount = lines.length;
var latestAccordLine ="";
for (i=0; i < lineCount; i++) {
var curLineStatus = document.getElementById("link"+i).innerHTML;
var curLineText = lines[i];
// pure text, no work needed
if (curLineStatus == "tekst") {
proText += curLineText + "\n";
// insert accords in the protext format
} else if (curLineStatus == "indsæt") {
var newLine = "";
var noMoreText = false;
m = 0;
for (j=0; j<=latestAccordLine.length; j++) {
if (j >= curLineText.length) noMoreText = true;
if ((latestAccordLine.charAt(j) == " ") || (latestAccordLine.charAt(j) == "\t")) {
if (noMoreText) newLine += " ";
else newLine += curLineText.charAt(m++);
} else {
// ignore special line breaks
if (latestAccordLine.charAt(j) == "\r") continue;
newLine += "[";
n = 1;
while (((latestAccordLine.charAt(j) != " ") && (latestAccordLine.charAt(j) != "\t")) && (latestAccordLine.length > j)) {
newLine += latestAccordLine.charAt(j);
j++;
n++;
}
newLine += "]";
if (!noMoreText) {
for(e=0; e<n; e++) {
newLine += curLineText.charAt(m++);
}
}
}
}// for-loop
newLine += curLineText.substr(m) + "\n";
proText += newLine;
// save accords for later, or insert accords in a line with no text
} else if (curLineStatus == "akkord") {
if ((i+1 == lineCount) || (document.getElementById("link"+(i+1)).innerHTML != "indsæt")) {
var newLine = "";
for (j=0; j<=curLineText.length; j++) {
if (curLineText.charAt(j) == " " || curLineText.charAt(j) == "\n") {
newLine += curLineText.charAt(j);
} else {
// ignore special line breaks
if (latestAccordLine.charAt(j) == "\r") continue;
newLine += "[";
while ((curLineText.charAt(j) != " ") && (curLineText.charAt(j) != "\t") && (curLineText.length > j)) {
newLine += curLineText.charAt(j);
j++;
}
newLine += "]";
}
} // for-loop
proText += newLine + "\n";
} else {
latestAccordLine = lines[i];
} // if
} // if
} // for-loop
return proText;
}
function checkStuff() {
area = document.getElementById("sangtekst");
text = area.value;
var textArr = text.split("\n");
var count = textArr.length;
//document.getElementById("count").innerHTML = count;
// If no changes we dont change anything
if (count == numbLines) return;
curLine = getCurLine(area);
//document.getElementById("curline").innerHTML = curLine;
// Init the page - first run
if (numbLines == -1) {
lines = "";
for (i = 0; i <= count-1; i++) {
lines += "<div id=\"line" + i + "\"><a id=\"link" + i + "\" href=\"javascript:tag('link" + i + "');\">tekst</a></div>";
}
document.getElementById("zeroes").innerHTML = lines;
// A line has been added
} else if (count > numbLines) {
lineDiff = count - numbLines;
// Insert new line(s) at the end
for (i = numbLines; i < count; i++) {
newdiv = document.createElement("div");
newdiv.setAttribute("id","line" + i);
newdiv.innerHTML = "<a id=\"link" + i + "\" href=\"javascript:tag('link" + i + "');\">tekst</a>";
document.getElementById("zeroes").appendChild(newdiv);
}
// Move labels from old positions to new positions
for (i=count-1; i >= curLine+1; i--) {
if ((i-lineDiff) < 0) break;
link1 = "link" + i;
link2 = "link" + (i-lineDiff);
document.getElementById(link1).innerHTML = document.getElementById(link2).innerHTML;
}
document.getElementById("link"+i).innerHTML = "tekst";
// A line has been deleted
} else {
lineDiff = numbLines - count;
// Move labels from old positions to new positions
for (i=curLine; i <= numbLines; i++) {
if ((i+lineDiff) > numbLines-1) break;
link1 = "link" + i;
link2 = "link" + (i+lineDiff);
document.getElementById(link1).innerHTML = document.getElementById(link2).innerHTML;
}
// Remove the excess label(s)
for (i=count; i<numbLines; i++) {
node2delete = document.getElementById("line" + i);
node2delete.parentNode.removeChild(node2delete);
}
}
numbLines = count;
if (count < 10) {
document.getElementById("sangtekst").rows = minRows+2;
} else {
document.getElementById("sangtekst").rows = count+2;
}
}
function tag(linkId) {
divContent = document.getElementById(linkId).innerHTML;
if (divContent.indexOf("tekst") != -1) {
document.getElementById(linkId).innerHTML = "akkord";
} else if (divContent.indexOf("akkord") != -1) {
document.getElementById(linkId).innerHTML = "indsæt";
} else if (divContent.indexOf("indsæt") != -1) {
document.getElementById(linkId).innerHTML = "tekst";
}
}
function importAndClose() {
ret = window.opener.insertNewChords(convertToPro(document.getElementById("sangtekst").value));
if (ret == 0) close();
}
function insertChords(chords) {
document.getElementById('sangtekst').value = chords;
}
-->
</script>
</head>
<body onload="javascript:window.opener.getChords();checkStuff();">
<!--[if lte IE 6]></p>
<style type="text/css">
#ie6msg{border:3px solid #090; margin:8px 0; background:#cfc; color:#000;}
#ie6msg h4{margin:8px; padding:0;}
#ie6msg p{margin:8px; padding:0;}
#ie6msg p a.getie7{font-weight:bold; color:#006;}
#ie6msg p a.ie6expl{font-weight:normal; color:#006;}
</style>
<div id="ie6msg">
<h4>OBS: Du har en ældre version af browseren Internet Explorer.</h4>
<p>
For at få en bedst mulig oplevelse af at bruge denne webside,<br />
kan du gratis <a class="getie7" href="http://www.microsoft.com/danmark/windows/downloads/ie/getitnow.mspx" target="_blank">hente en nyere version af Internet Explorer</a>,<br />
eller bruge en anden browser som <a class="getie7" href="http://getfirefox.com">Mozilla Firefox</a> eller <a class="getie7" href="http://www.google.com/chrome/?hl=da">Google Chrome</a>.<br/>
Bruger du en arbejds-PC bør du kontakte den IT-ansvarlige.
</p>
<p>
</p>
</div>
<p>< ![endif]-->
<h3>Akkord konvertør</h3>
<p>Her kan du konvertere akkorder fra rent tekst format til Pro formatet som er det musikteam bruger.
Du indsætter din tekst med akkorder i tekstfeltet nedenfor, retter evt. til så akkorderne står hvor de skal og giver hver linje den rette mærkat.
Der er 3 forskellige mærkater: "tekst", "akkord" og "indsæt". Mærkatet "tekst" er for linjer som hverken er akkorder, eller skal have nogen akkorder indsat.
Mærkatet "akkord" er for de linjer der er akkorder, og mærkatat "indsæt" er for de tekst linjer hvor akkorderne skal indsættes.
En linje med mærkatet "indsæt" <u>skal</u> være under en linje med mærkatet "akkord".
Du skifter mellem de tre mærkater ved at trykke på dem (ude til venstre).
Tryk på Opdater-knappen for at se hvordan resultatet bliver, og tryk på Importer-knappen for at importere de nye akkorder ind i sangen.</p>
<!--Antal linjer: <div id="count">0</div> <br/>
Aktiv linje: <div id="curline">0</div> <br/>-->
<button name="send" value="Opdatér forhåndsvisning" class="submit_btn_2" onClick="javascript:update();return false;"><img src="http://www.musikteam.dk/img/refresh_firefox.gif" alt="Opdatér" width="18" height="19" align="absmiddle"/> Opdatér forhåndsvisning </button>
<button name="send" value="Importer akkorder og luk dette vindue" class="submit_btn_2" onClick="javascript:importAndClose();return false;"> Importer akkorder og luk dette vindue </button>
<table>
<tr>
<td width="50px" style="font-size:10pt;font-family:monospace" valign="top" align="right"><div id="zeroes"></div></td>
<td width="500px" valign="top">
<textarea wrap="off" id="sangtekst" onkeyup="javascript:checkStuff();" cols="70" rows="10" style="font-size:10pt;border:0px;overflow-y:hidden;background-color:#CCCCCC;margin:0px">
Indsæt sangtekst
med akkorder her</textarea>
</td>
<td><div id="protext"></div></td>
</tr>
</table><br/>
</body>
</html>