Index: trunk/extensions/ABC/ABC.php |
— | — | @@ -41,6 +41,12 @@ |
42 | 42 | # specification or your TiMidity++ patch description for others. |
43 | 43 | $abcMIDIvoice = 1; |
44 | 44 | |
| 45 | +# If you have the OggHandler extension installed, set this to |
| 46 | +# 'true' to embed the OggHandler below the music. This will |
| 47 | +# allow users to listen to the music on the page. To use this, |
| 48 | +# you must enable Ogg Vorbis rendering. |
| 49 | +$abcOggHandler = false; |
| 50 | + |
45 | 51 | $wgExtensionCredits['parserhooks'][] = array( |
46 | 52 | 'name' => 'ABC', |
47 | 53 | 'author' => 'River Tarnell', |
— | — | @@ -58,15 +64,21 @@ |
59 | 65 | |
60 | 66 | function |
61 | 67 | efABCInit() { |
62 | | -global $wgParser; |
| 68 | +global $wgParser, $wgOut, $abcOggHandler; |
63 | 69 | wfLoadExtensionMessages('ABC'); |
64 | 70 | $wgParser->setHook( 'abc', 'efABCRender' ); |
| 71 | + |
| 72 | + if ($abcOggHandler) { |
| 73 | + $oh = new OggHandler(); |
| 74 | + $oh->setHeaders($wgOut); |
| 75 | + } |
| 76 | + |
65 | 77 | return true; |
66 | 78 | } |
67 | 79 | |
68 | 80 | function |
69 | 81 | efABCRender($input, $args, $parser) { |
70 | | -global $abcPath, $abcURL, $abc2midi, $abctimidity; |
| 82 | +global $abcPath, $abcURL, $abc2midi, $abctimidity, $abcOggHandler; |
71 | 83 | if ($abcPath == false || $abcURL == false) |
72 | 84 | return 'Error: $abcPath and $abcURL must be set to use the ABC extension.'; |
73 | 85 | |
— | — | @@ -106,7 +118,7 @@ |
107 | 119 | if ($abc2midi && $abctimidity) |
108 | 120 | if (!abcCreateVorbis($abc, $hash, $error)) |
109 | 121 | return str_replace("\n", "<br />", htmlspecialchars($error)); |
110 | | - |
| 122 | + |
111 | 123 | /* |
112 | 124 | * Succeeded to create all the output formats, return the |
113 | 125 | * output. We produce an image from the PNG, and include |
— | — | @@ -131,12 +143,24 @@ |
132 | 144 | |
133 | 145 | $e_dllinks = wfMsg('abcdownload') . " " . |
134 | 146 | join(" " . wfMsg('abcsep') . " ", $links); |
135 | | - |
| 147 | + |
| 148 | + $ogghtml = ""; |
| 149 | + |
| 150 | + if ($abcOggHandler) { |
| 151 | + $oh = new OggTransformOutput(null, |
| 152 | + "$abcURL/$hash.ogg", false, |
| 153 | + 250, 0, 0, false, |
| 154 | + "$abcPath/$hash.ogg", false); |
| 155 | + $ogghtml = $oh->toHtml(array('alt' => $title)); |
| 156 | + } |
| 157 | + |
136 | 158 | $output = <<<EOF |
137 | 159 | <div style="float: $float; border: solid 1px #aaaaaa; margin: 0.2em;" class="abc-music"> |
138 | 160 | <img src="$e_imgpath" alt="$e_title" /> |
139 | 161 | <div style="text-align: center"> |
140 | 162 | $e_dllinks |
| 163 | + <br /> |
| 164 | + $ogghtml |
141 | 165 | </div> |
142 | 166 | </div> |
143 | 167 | EOF; |
— | — | @@ -153,6 +177,9 @@ |
154 | 178 | } |
155 | 179 | |
156 | 180 | $filename = "$abcPath/$hash.abc"; |
| 181 | + if (file_exists($filename)) |
| 182 | + return true; |
| 183 | + |
157 | 184 | if (($f = @fopen($filename, "w")) === false) { |
158 | 185 | $last = error_get_last(); |
159 | 186 | $msg = $last['msg']; |
— | — | @@ -190,6 +217,9 @@ |
191 | 218 | |
192 | 219 | $input = "$abcPath/$hash.abc"; |
193 | 220 | $output = "$abcPath/$hash.ps"; |
| 221 | + |
| 222 | + if (file_exists($output)) |
| 223 | + return true; |
194 | 224 | |
195 | 225 | $cmd = "$abcm2ps -E $input -O $abcPath/$hash"; |
196 | 226 | @exec($cmd, $cmd_out, $ret); |
— | — | @@ -218,7 +248,10 @@ |
219 | 249 | |
220 | 250 | $input = "$abcPath/$hash.ps"; |
221 | 251 | $output = "$abcPath/$hash.pdf"; |
222 | | - |
| 252 | + |
| 253 | + if (file_exists($output)) |
| 254 | + return true; |
| 255 | + |
223 | 256 | $cmd = "$abcps2pdf $input $output"; |
224 | 257 | @exec($cmd, $cmd_out, $ret); |
225 | 258 | if ($ret != 0 || !@file_exists("$abcPath/$hash.pdf")) { |
— | — | @@ -241,7 +274,10 @@ |
242 | 275 | |
243 | 276 | $input = "$abcPath/$hash.ps"; |
244 | 277 | $output = "$abcPath/$hash.png"; |
245 | | - |
| 278 | + |
| 279 | + if (file_exists($output)) |
| 280 | + return true; |
| 281 | + |
246 | 282 | $cmd = "$wgImageMagickConvertCommand $input $output"; |
247 | 283 | @exec($cmd, $cmd_out, $ret); |
248 | 284 | if ($ret != 0 || !@file_exists($output)) { |
— | — | @@ -264,7 +300,10 @@ |
265 | 301 | |
266 | 302 | $input = "$abcPath/$hash.abc"; |
267 | 303 | $output = "$abcPath/$hash.mid"; |
268 | | - |
| 304 | + |
| 305 | + if (file_exists($output)) |
| 306 | + return true; |
| 307 | + |
269 | 308 | $cmd = "$abc2midi $input -o $output"; |
270 | 309 | @exec($cmd, $cmd_out, $ret); |
271 | 310 | if ($ret != 0 || !@file_exists($output)) { |
— | — | @@ -287,7 +326,10 @@ |
288 | 327 | |
289 | 328 | $input = "$abcPath/$hash.mid"; |
290 | 329 | $output = "$abcPath/$hash.ogg"; |
291 | | - |
| 330 | + |
| 331 | + if (file_exists($output)) |
| 332 | + return true; |
| 333 | + |
292 | 334 | $cmd = "$abctimidity -Ei$abcMIDIvoice -Ov -id $input"; |
293 | 335 | @exec($cmd, $cmd_out, $ret); |
294 | 336 | if ($ret != 0 || !@file_exists($output)) { |