Index: trunk/extensions/ABC/ABC.i18n.php |
— | — | @@ -18,4 +18,5 @@ |
19 | 19 | 'abcpdf' => 'PDF', |
20 | 20 | 'abcps' => 'PostScript', |
21 | 21 | 'abcmidi' => 'MIDI', |
| 22 | + 'abcvorbis' => 'Ogg Vorbis', |
22 | 23 | ); |
Index: trunk/extensions/ABC/ABC.php |
— | — | @@ -31,6 +31,16 @@ |
32 | 32 | #$abc2midi = "/usr/bin/abc2midi"; |
33 | 33 | $abc2midi = false; |
34 | 34 | |
| 35 | +# Path to the TiMidity++ executable. Optional; set this if you |
| 36 | +# want Ogg Vorbis rendering. Requires MIDI rendering. |
| 37 | +#$abctimidity = "/usr/bin/timidity"; |
| 38 | +$abctimidity = false; |
| 39 | + |
| 40 | +# Default instrument number for Vorbis. |
| 41 | +# 0 = Piano, 40 = Violin, 73 = Flute. See General MIDI |
| 42 | +# specification or your TiMidity++ patch description for others. |
| 43 | +$abcMIDIvoice = 1; |
| 44 | + |
35 | 45 | $wgExtensionCredits['parserhooks'][] = array( |
36 | 46 | 'name' => 'ABC', |
37 | 47 | 'author' => 'River Tarnell', |
— | — | @@ -56,7 +66,7 @@ |
57 | 67 | |
58 | 68 | function |
59 | 69 | efABCRender($input, $args, $parser) { |
60 | | -global $abcPath, $abcURL; |
| 70 | +global $abcPath, $abcURL, $abc2midi, $abctimidity; |
61 | 71 | if ($abcPath == false || $abcURL == false) |
62 | 72 | return 'Error: $abcPath and $abcURL must be set to use the ABC extension.'; |
63 | 73 | |
— | — | @@ -93,7 +103,10 @@ |
94 | 104 | if ($abc2midi) |
95 | 105 | if (!abcCreateMIDI($abc, $hash, $error)) |
96 | 106 | return str_replace("\n", "<br />", htmlspecialchars($error)); |
97 | | - |
| 107 | + if ($abc2midi && $abctimidity) |
| 108 | + if (!abcCreateVorbis($abc, $hash, $error)) |
| 109 | + return str_replace("\n", "<br />", htmlspecialchars($error)); |
| 110 | + |
98 | 111 | /* |
99 | 112 | * Succeeded to create all the output formats, return the |
100 | 113 | * output. We produce an image from the PNG, and include |
— | — | @@ -105,6 +118,7 @@ |
106 | 119 | $e_pspath = htmlspecialchars("$abcURL/$hash.ps"); |
107 | 120 | $e_pdfpath = htmlspecialchars("$abcURL/$hash.pdf"); |
108 | 121 | $e_midipath = htmlspecialchars("$abcURL/$hash.mid"); |
| 122 | + $e_vorbispath = htmlspecialchars("$abcURL/$hash.ogg"); |
109 | 123 | |
110 | 124 | $links = array(); |
111 | 125 | $links[] = "<a href=\"$e_abcpath\">" . wfMsg('abcabc') . "</a>"; |
— | — | @@ -112,7 +126,9 @@ |
113 | 127 | $links[] = "<a href=\"$e_pdfpath\">" . wfMsg('abcpdf') . "</a>"; |
114 | 128 | if ($abc2midi) |
115 | 129 | $links[] = "<a href=\"$e_midipath\">" . wfMsg('abcmidi') . "</a>"; |
116 | | - |
| 130 | + if ($abctimidity) |
| 131 | + $links[] = "<a href=\"$e_vorbispath\">" . wfMsg('abcvorbis') . "</a>"; |
| 132 | + |
117 | 133 | $e_dllinks = wfMsg('abcdownload') . " " . |
118 | 134 | join(" " . wfMsg('abcsep') . " ", $links); |
119 | 135 | |
— | — | @@ -259,3 +275,26 @@ |
260 | 276 | |
261 | 277 | return true; |
262 | 278 | } |
| 279 | + |
| 280 | +function |
| 281 | +abcCreateVorbis($abc, $hash, &$error) |
| 282 | +{ |
| 283 | +global $abctimidity, $abcMIDIvoice, $abcPath; |
| 284 | + if (!@file_exists($abctimidity)) { |
| 285 | + $error = "Error: TiMidity++ not enabled."; |
| 286 | + return false; |
| 287 | + } |
| 288 | + |
| 289 | + $input = "$abcPath/$hash.mid"; |
| 290 | + $output = "$abcPath/$hash.ogg"; |
| 291 | + |
| 292 | + $cmd = "$abctimidity -Ei$abcMIDIvoice -Ov -id $input"; |
| 293 | + @exec($cmd, $cmd_out, $ret); |
| 294 | + if ($ret != 0 || !@file_exists($output)) { |
| 295 | + $error = "Error: TiMidity++ failed to convert input [$output] (ret: $ret)."; |
| 296 | + $error .= "Output: " . join("\n", $cmd_out); |
| 297 | + return false; |
| 298 | + } |
| 299 | + |
| 300 | + return true; |
| 301 | +} |