This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStupidHarpTab.php
211 lines (172 loc) · 6.21 KB
/
StupidHarpTab.php
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
<?php
//======================================================================
// StupidHarpTab V.1
// Made by Uhtoom
// https://github.com/uhtoom/StupidHarpTab
// Released under GNU General Public License v3.0
//======================================================================
function StupidHarpTab($file, $style){ // Main function, gets the file, spits it and sends it on its way
$myfile = fopen($file, "r") or die("Unable to open file!"); //open the file
while(!feof($myfile)) { //go throu the file until end
$line = fgets($myfile); // read a line
if(substr( $line, 0, 1 ) == "#"){ //if line begins with # print it
$line = substr($line, 1);
echo "<div class='title'>" . $line . "</div>"; //Set class and echos Title
}else{
$lineArr = explode(" ", trim($line)); // explode the line at blank space and trim trailing \n added by fgets
parseTab($lineArr, $style); // send the array to the parser
} // end else
} //end while loop
fclose($myfile); // Close the file
} // end StupidHarpTab()
function parseTab(array $score, $style){ //function to get everything in right order and echo som divs
echo "<div class='rad'>";
genScore($score, $style); // get the score
echo "<div class='mellan' style='width:100%; height:1px; clear:both;'></div>"; // echo seperation between score and tab
genTab($score); // get the tabs
echo "</div>";
} //end parseTab
function genTab(array $score){
foreach ($score as $singleNot) { // go through expressions
$singleChar = str_split($singleNot); // split a single expression in to characters
echo "<div class='tab'>";
foreach ($singleChar as $char) { // go through every single character
if($char == "(" || $char == ")"){echo $char;} //write out parantheses
if(is_numeric($char)){echo $char;} //write out number
if($char == "r" || $char == "R"){echo " ";} //echo empty for rests
if($char == "d" || $char == "D"){echo " ";} //echo empty for repeat
} //end foreach $singleNot
echo "</div>";
} //end forech $score
} //end genTab
function genScore(array $score, $style){ //resive score as array of expressions like "(4)."
foreach ($score as $singleNot) { // go through expressions
if(substr( $singleNot, 0, 1 ) == "r"){getNot("r",0,$style);} // If we have "r" generate rest
elseif(substr( $singleNot, 0, 1 ) == "R"){getNot("R",0,$style);}
elseif(substr( $singleNot, 0, 1 ) == "d" ){getNot("d",0,$style);} // If we have "d" generate repeat
elseif(substr( $singleNot, 0, 1 ) == "D" ){getNot("D",0,$style);}
else{ // if we have "R" generate rest, if no rests continue
if(substr( $singleNot, -1 ) == ")" || is_numeric(substr( $singleNot, -1 )) ){ //if last sign is ")" or numeric
if(substr( $singleNot, 0, 1 ) == "("){getNot(4,0,$style);} //if first sign is "(" then both first and last is () thus a 4 note
elseif(is_numeric(substr( $singleNot, 0, 1 ))){getNot(4,0,$style);} // if first is numeric then both first and last is numeric, thus 4 note
elseif(substr( $singleNot, 0, 1 ) == "."){ getNot(8,0,$style); } // if dot infront its 8th
elseif(substr( $singleNot, 0, 1 ) == ":"){ getNot(16,0,$style); } // if ":" in front then its 16th
}else{ //if last sign isnt numeric or ")" it must be a longer note
if(substr( $singleNot, -1 ) == "."){getNot(2,0,$style);} // if last sign is "." its a halfnote
elseif(substr( $singleNot, -1 ) == ":"){getNot(1,0,$style);} // if last sign is a ":" its a fullnote
} //end esle
}//end else from rests
} //end forech $score
} //end genScore
function getNot($length,$dot,$style){ //generate div with right class for diffrent length
if($style=="div"){
switch($length)
{
case "1":
echo "<div class='not full' >";
if($dot == "1"){echo " <b>.</b>";}
echo "</div>";
break;
case "2":
echo "<div class='not half' >";
if($dot == "1"){echo " <b>.</b>";}
echo "</div>";
break;
case "4":
echo "<div class='not forth' >";
if($dot == "1"){echo " <b>.</b>";}
echo "</div>";
break;
case "8":
echo "<div class='not eighth' >";
if($dot == "1"){echo " <b>.</b>";}
echo "</div>";
break;
case "16":
echo "<div class='not sixteenth' >";
if($dot == "1"){echo " <b>.</b>";}
echo "</div>";
break;
case "r":
echo "<div class='not eighth' >";
echo "<b>R</b>";
if($dot == "1"){echo " <b>.</b>";}
echo "</div>";
break;
case "R":
echo "<div class='not forth' >";
echo "<b>R</b>";
if($dot == "1"){echo " <b>.</b>";}
echo "</div>";
break;
case "d":
echo "<div class='not empty' >";
echo "<b>:|</b>";
if($dot == "1"){echo " <b>.</b>";}
echo "</div>";
break;
case "D":
echo "<div class='not empty' >";
echo "<b>|:</b>";
if($dot == "1"){echo " <b>.</b>";}
echo "</div>";
break;
case "":
case NULL:
break;
} //end switch
}elseif($style == "unicode"){ //if style is unicode echo the right character
switch($length)
{
case "1":
echo "<div class='not unicodeN' >";
echo "𝅝";
echo "</div>";
break;
case "2":
echo "<div class='not unicodeN' >";
echo "𝅗𝅥";
echo "</div>";
break;
case "4":
echo "<div class='not unicodeN' >";
echo "𝅘𝅥";
echo "</div>";
break;
case "8":
echo "<div class='not unicodeN' >";
echo "𝅘𝅥𝅮";
echo "</div>";
break;
case "16":
echo "<div class='not unicodeN' >";
echo "𝅘𝅥𝅯";
echo "</div>";
break;
case "r":
echo "<div class='not unicodeN' >";
echo "𝄾";
echo "</div>";
break;
case "R":
echo "<div class='not unicodeN' >";
echo "𝄽";
echo "</div>";
break;
case "d":
echo "<div class='not unicodeN' >";
echo "𝄇";
echo "</div>";
break;
case "D":
echo "<div class='not unicodeN' >";
echo "𝄆";
echo "</div>";
break;
case "":
case NULL:
break;
} //end switch
}//end elseif
} //end getNot
?>