Index: trunk/extensions/Score/Score.i18n.php |
— | — | @@ -38,6 +38,7 @@ |
39 | 39 | 'score-getcwderr' => 'Unable to obtain current working directory', |
40 | 40 | 'score-invalidlang' => 'Invalid score language lang="<nowiki>$1</nowiki>". Currently recognised languages are lang="lilypond" (the default) and lang="ABC".', |
41 | 41 | 'score-invalidoggoverride' => 'The file "<nowiki>$1</nowiki>" you specified with override_ogg is invalid. Please specify the file name only, omit <nowiki>[[…]]</nowiki> and the "{{ns:file}}:" prefix.', |
| 42 | + 'score-midioverridenotfound' => 'The file "<nowiki>$1</nowiki>" you specified with override_midi could not be found. Please specify the file name only, omit <nowiki>[[…]]</nowiki> and the "{{ns:file}}:" prefix.', |
42 | 43 | 'score-noabcinput' => 'ABC source file $1 could not be created.', |
43 | 44 | 'score-noimages' => 'No score images were generated. Please check your score code.', |
44 | 45 | 'score-noinput' => 'Failed to create LilyPond input file $1.', |
— | — | @@ -73,6 +74,7 @@ |
74 | 75 | 'score-getcwderr' => 'Displayed if the extension cannot obtain the current working directory.', |
75 | 76 | 'score-invalidlang' => 'Displayed if the lang="…" attribute contains an unrecognised score language. $1 is the unrecognised language.', |
76 | 77 | 'score-invalidoggoverride' => 'Displayed if the file specified with the override_ogg="…" attribute is invalid. $1 is the value of the override_ogg attribute.', |
| 78 | + 'score-midioverridenotfound' => 'Displayed if the file specified with the override_midi="…" attribute could not be found. $1 is the value of the override_midi attribute.', |
77 | 79 | 'score-noabcinput' => 'Displayed if an ABC source file could not be created for lang="ABC". $1 is the path to the file that could not be created.', |
78 | 80 | 'score-noimages' => 'Displayed if no score images were rendered.', |
79 | 81 | 'score-noinput' => 'Displayed if the LilyPond input file cannot be created. $1 is the path to the input file.', |
Index: trunk/extensions/Score/Score.body.php |
— | — | @@ -212,6 +212,24 @@ |
213 | 213 | throw new ScoreException( wfMessage( 'score-invalidlang', htmlspecialchars( $options['lang'] ) ) ); |
214 | 214 | } |
215 | 215 | |
| 216 | + /* Override MIDI file? */ |
| 217 | + if ( array_key_exists( 'override_midi', $args ) ) { |
| 218 | + $file = wfFindFile( $args['override_midi'] ); |
| 219 | + if ( $file === false ) { |
| 220 | + throw new ScoreException( wfMessage( 'score-midioverridenotfound', htmlspecialchars( $args['override_midi'] ) ) ); |
| 221 | + } |
| 222 | + $options['override_midi'] = true; |
| 223 | + $options['midi_file'] = $file; |
| 224 | + $options['midi_path'] = $file->getLocalRefPath(); |
| 225 | + /* Set OGG stuff in case Vorbis rendering is requested */ |
| 226 | + $sha1 = $file->getSha1(); |
| 227 | + $oggRel = self::LILYPOND_DIR_NAME . "/{$sha1[0]}/{$sha1[0]}{$sha1[1]}/$sha1.ogg"; |
| 228 | + $options['ogg_path'] = "$wgUploadDirectory/$oggRel"; |
| 229 | + $options['ogg_url'] = "$wgUploadPath/$oggRel"; |
| 230 | + } else { |
| 231 | + $options['override_midi'] = false; |
| 232 | + } |
| 233 | + |
216 | 234 | /* image file path and URL prefixes */ |
217 | 235 | $imageCacheName = wfBaseConvert( sha1( $code ), 16, 36, 31 ); |
218 | 236 | $imagePrefixEnd = self::LILYPOND_DIR_NAME . '/' |
— | — | @@ -226,8 +244,11 @@ |
227 | 245 | $options['link_midi'] = false; |
228 | 246 | } |
229 | 247 | if ( $options['link_midi'] ) { |
230 | | - $options['midi_path'] = "{$options['image_path_prefix']}.midi"; |
231 | | - $options['midi_url'] = "{$options['image_url_prefix']}.midi"; |
| 248 | + if ( $options['override_midi'] ) { |
| 249 | + $options['midi_url'] = $options['midi_file']->getUrl(); |
| 250 | + } else { |
| 251 | + $options['midi_url'] = "{$options['image_url_prefix']}.midi"; |
| 252 | + } |
232 | 253 | } |
233 | 254 | |
234 | 255 | /* Override OGG file? */ |
— | — | @@ -257,11 +278,17 @@ |
258 | 279 | if ( $options['generate_vorbis'] && ( $options['override_ogg'] !== false ) ) { |
259 | 280 | throw new ScoreException( wfMessage( 'score-vorbisoverrideogg' ) ); |
260 | 281 | } |
261 | | - if ( $options['generate_vorbis'] ) { |
| 282 | + if ( $options['generate_vorbis'] && !$options['override_midi'] ) { |
262 | 283 | $options['ogg_path'] = "{$options['image_path_prefix']}.ogg"; |
263 | 284 | $options['ogg_url'] = "{$options['image_url_prefix']}.ogg"; |
264 | 285 | } |
265 | 286 | |
| 287 | + /* Generate MIDI? */ |
| 288 | + $options['generate_midi'] = ( $options['override_midi'] === false ) && ( $options['link_midi'] || $options['generate_vorbis'] ); |
| 289 | + if ( $options['generate_midi'] && !array_key_exists( 'midi_path', $options ) ) { |
| 290 | + $options['midi_path'] = "{$options['image_path_prefix']}.midi"; |
| 291 | + } |
| 292 | + |
266 | 293 | /* Raw rendering? */ |
267 | 294 | if ( array_key_exists( 'raw', $args ) ) { |
268 | 295 | $options['raw'] = $args['raw']; |
— | — | @@ -287,6 +314,9 @@ |
288 | 315 | * * factory_directory: string Path to directory in which files |
289 | 316 | * may be generated without stepping on someone else's |
290 | 317 | * toes. The directory may not exist yet. Required. |
| 318 | + * * generate_midi: bool Whether to create a MIDI file, either |
| 319 | + * to subsequently generate a vorbis file, or to provide |
| 320 | + * a link to the MIDI file. Required. |
291 | 321 | * * generate_vorbis: bool Whether to create an Ogg/Vorbis file in |
292 | 322 | * an OggHandler. If set to true, the override_ogg option |
293 | 323 | * must be set to false. Required. |
— | — | @@ -295,8 +325,10 @@ |
296 | 326 | * * image_url_prefix: string Prefix to the image URL. Required. |
297 | 327 | * * lang: string Score language. Required. |
298 | 328 | * * link_midi: bool Whether to link to a MIDI file. Required. |
299 | | - * * midi_path: string Local MIDI path. Required if the link_midi |
300 | | - * option is set to true, ignored otherwise. |
| 329 | + * * midi_file: MIDI file object. |
| 330 | + * * midi_path: string Local MIDI path. Required if the link_midi, |
| 331 | + * override_midi, or the generate_vorbis option is set to |
| 332 | + * true, ignored otherwise. |
301 | 333 | * * midi_url: string MIDI URL. Required if the link_midi option |
302 | 334 | * is set to true, ignored otherwise. |
303 | 335 | * * ogg_name: string Name of the OGG file. Required if the |
— | — | @@ -307,6 +339,8 @@ |
308 | 340 | * * ogg_url: string Ogg/Vorbis URL. Required if the |
309 | 341 | * generate_vorbis option is set to true, ignored |
310 | 342 | * otherwise. |
| 343 | + * * override_midi: bool Whether to use a user-provided MIDI file. |
| 344 | + * Required. |
311 | 345 | * * override_ogg: bool Whether to generate a wikilink to a |
312 | 346 | * user-provided OGG file. If set to true, the vorbis |
313 | 347 | * option must be set to false. Required. |
— | — | @@ -326,10 +360,6 @@ |
327 | 361 | /* Generate PNG and MIDI files if necessary */ |
328 | 362 | $imagePath = "{$options['image_path_prefix']}.png"; |
329 | 363 | $multi1Path = "{$options['image_path_prefix']}-1.png"; |
330 | | - if ( !$options['link_midi'] && $options['generate_vorbis'] && !file_exists( $options['ogg_path'] ) ) { |
331 | | - /* We need a MIDI file to generate a Vorbis file */ |
332 | | - $options['midi_path'] = "{$options['factory_directory']}/file.midi"; |
333 | | - } |
334 | 364 | if ( ( !file_exists( $imagePath ) && !file_exists( $multi1Path ) ) |
335 | 365 | || ( array_key_exists( 'midi_path', $options ) && !file_exists( $options['midi_path'] ) ) ) { |
336 | 366 | self::generatePngAndMidi( $code, $options ); |
— | — | @@ -401,9 +431,9 @@ |
402 | 432 | * |
403 | 433 | * @param $code string Score code. |
404 | 434 | * @param $options array Rendering options. They are the same as for |
405 | | - * Score::generateHTML() with the exception that the link_midi |
406 | | - * option is ignored and the midi file is generated if the |
407 | | - * midi_path option is present. |
| 435 | + * Score::generateHTML(). The MIDI file specified by the midi_path |
| 436 | + * option is generated if and only if the generate_midi option |
| 437 | + * evaluates to true. |
408 | 438 | * |
409 | 439 | * @throws ScoreException on error. |
410 | 440 | */ |
— | — | @@ -417,7 +447,7 @@ |
418 | 448 | $multiFormat = "{$options['image_path_prefix']}-%d.png"; |
419 | 449 | |
420 | 450 | /* delete old files if necessary */ |
421 | | - if ( array_key_exists( 'midi_path', $options ) ) { |
| 451 | + if ( $options['generate_midi'] ) { |
422 | 452 | self::cleanupFile( $options['midi_path'] ); |
423 | 453 | } |
424 | 454 | self::cleanupFile( $image ); |
— | — | @@ -477,7 +507,7 @@ |
478 | 508 | if ( $rc2 != 0 ) { |
479 | 509 | self::throwCallException( wfMessage( 'score-compilererr' ), $output ); |
480 | 510 | } |
481 | | - if ( array_key_exists( 'midi_path', $options ) && !file_exists( $factoryMidi ) ) { |
| 511 | + if ( $options['generate_midi'] && !file_exists( $factoryMidi ) ) { |
482 | 512 | throw new ScoreException( wfMessage( 'score-nomidi' ) ); |
483 | 513 | } |
484 | 514 | |
— | — | @@ -496,7 +526,7 @@ |
497 | 527 | |
498 | 528 | /* move files to proper places */ |
499 | 529 | $rc = true; |
500 | | - if ( array_key_exists( 'midi_path', $options ) ) { |
| 530 | + if ( $options['generate_midi'] ) { |
501 | 531 | self::renameFile( $factoryMidi, $options['midi_path'] ); |
502 | 532 | } |
503 | 533 | if ( file_exists( $factoryImageTrimmed ) ) { |
— | — | @@ -512,9 +542,8 @@ |
513 | 543 | * |
514 | 544 | * @param $lilypondCode string Simple LilyPond code. |
515 | 545 | * @param $options array Rendering options. The are the same as for |
516 | | - * Score::generateHTML() except that the link_midi option is |
517 | | - * ignored and a MIDI block is embedded if and only if the |
518 | | - * midi_path option is present. |
| 546 | + * Score::generateHTML(). A MIDI block is embedded if and only if |
| 547 | + * the generate_midi option evaluates to true. |
519 | 548 | * |
520 | 549 | * @return string Raw lilypond code. |
521 | 550 | * |
— | — | @@ -540,7 +569,7 @@ |
541 | 570 | . "\\score {\n" |
542 | 571 | . $lilypondCode |
543 | 572 | . "\t\\layout { }\n" |
544 | | - . ( array_key_exists( 'midi_path', $options ) ? "\t\\midi { }\n" : "" ) |
| 573 | + . ( $options['generate_midi'] ? "\t\\midi { }\n" : '' ) |
545 | 574 | . "}\n"; |
546 | 575 | return $raw; |
547 | 576 | } |