r42720 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42719‎ | r42720 | r42721 >
Date:08:50, 28 October 2008
Author:river
Status:old
Tags:
Comment:
allow rendering to Ogg Vorbis
Modified paths:
  • /trunk/extensions/ABC/ABC.i18n.php (modified) (history)
  • /trunk/extensions/ABC/ABC.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ABC/ABC.i18n.php
@@ -18,4 +18,5 @@
1919 'abcpdf' => 'PDF',
2020 'abcps' => 'PostScript',
2121 'abcmidi' => 'MIDI',
 22+ 'abcvorbis' => 'Ogg Vorbis',
2223 );
Index: trunk/extensions/ABC/ABC.php
@@ -31,6 +31,16 @@
3232 #$abc2midi = "/usr/bin/abc2midi";
3333 $abc2midi = false;
3434
 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+
3545 $wgExtensionCredits['parserhooks'][] = array(
3646 'name' => 'ABC',
3747 'author' => 'River Tarnell',
@@ -56,7 +66,7 @@
5767
5868 function
5969 efABCRender($input, $args, $parser) {
60 -global $abcPath, $abcURL;
 70+global $abcPath, $abcURL, $abc2midi, $abctimidity;
6171 if ($abcPath == false || $abcURL == false)
6272 return 'Error: $abcPath and $abcURL must be set to use the ABC extension.';
6373
@@ -93,7 +103,10 @@
94104 if ($abc2midi)
95105 if (!abcCreateMIDI($abc, $hash, $error))
96106 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+
98111 /*
99112 * Succeeded to create all the output formats, return the
100113 * output. We produce an image from the PNG, and include
@@ -105,6 +118,7 @@
106119 $e_pspath = htmlspecialchars("$abcURL/$hash.ps");
107120 $e_pdfpath = htmlspecialchars("$abcURL/$hash.pdf");
108121 $e_midipath = htmlspecialchars("$abcURL/$hash.mid");
 122+ $e_vorbispath = htmlspecialchars("$abcURL/$hash.ogg");
109123
110124 $links = array();
111125 $links[] = "<a href=\"$e_abcpath\">" . wfMsg('abcabc') . "</a>";
@@ -112,7 +126,9 @@
113127 $links[] = "<a href=\"$e_pdfpath\">" . wfMsg('abcpdf') . "</a>";
114128 if ($abc2midi)
115129 $links[] = "<a href=\"$e_midipath\">" . wfMsg('abcmidi') . "</a>";
116 -
 130+ if ($abctimidity)
 131+ $links[] = "<a href=\"$e_vorbispath\">" . wfMsg('abcvorbis') . "</a>";
 132+
117133 $e_dllinks = wfMsg('abcdownload') . " " .
118134 join(" " . wfMsg('abcsep') . " ", $links);
119135
@@ -259,3 +275,26 @@
260276
261277 return true;
262278 }
 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+}

Status & tagging log