'abcm2ps', 'gs' => 'gs', 'ppmtogif' => 'pnmcrop | ppmtogif', 'abc2midi' => '')); SDV($PubCacheDir,"pub/cache"); SDV($PubCacheUrl,"$PubDirUrl/cache"); ## command to create .ps file if ($ABCProgs['abcm2ps']) SDV($ABCPSCmdFmt, "{$ABCProgs['abcm2ps']} -O\$ABCFile.ps \$ABCFile.abc"); ## command to create .gif file if ($ABCProgs['gs'] && $ABCProgs['ppmtogif']) { SDV($ABCGifCmdFmt, "{$ABCProgs['gs']} -sDEVICE=ppmraw -sOutputFile=- -q -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r96x96 \$ABCFile.ps | {$ABCProgs['ppmtogif']} >\$ABCFile.gif"); } ## command to create .mid file if ($ABCProgs['abc2midi']) SDV($ABCMidiCmdFmt, "{$ABCProgs['abc2midi']} \$ABCFile.abc -o \$ABCFile.mid"); ## (:music:) markup Markup('music', 'fulltext', '/\\(:music:\\)(.*?)\\(:musicend:\\)/eis', "Keep(AbcMusic(\$pagename, PSS('$1')))"); ## This is the function that does all of the work. :-) ## It just creates a suitable basename for the music files, ## calls each of the external programs to produce the corresponding ## output, and returns an HTML string with links to the ## appropriate files. function AbcMusic($pagename, $text) { global $FmtV, $PubCacheDir, $PubCacheUrl, $ABCProgs, $ABCPSCmdFmt, $ABCGifCmdFmt, $ABCMidiCmdFmt; $text = trim($text); $text = str_replace(array('<', '>', '&'), array('<', '>', '&'), $text); ## build a suitable filename from the music title (T:) if (preg_match('/^T:(.*)/m', $text, $match)) { $abctitle = $match[1]; $abcname = preg_replace('/\\s+/', '_', $abctitle); $abcname = preg_replace('/\\W+/', '', $abcname); $abcname .= '_' . substr(md5($text), 0, 6); } else $abcname = md5($text); $abcfile = "$PubCacheDir/$abcname"; $FmtV['$ABCName'] = $abcname; $FmtV['$ABCFile'] = $abcfile; ## Create the cache directory to hold the files mkdirp($PubCacheDir); fixperms($PubCacheDir); ## Create the "abc" file if (!file_exists("$abcfile.abc")) { $fp = fopen("$abcfile.abc", "w"); if ($fp) { fputs($fp, "$text\n"); fclose($fp); } else return "abcmusic failed to create $abcfile.abc\n"; } ## Create the "ps" file if (!file_exists("$abcfile.ps")) { $pscmd = FmtPageName($ABCPSCmdFmt, $pagename); if (system($pscmd) === false) return "abcmusic failed to create $abcfile.ps\n"; } ## Create the image file if (!file_exists("$abcfile.gif")) { $gifcmd = FmtPageName($ABCGifCmdFmt, $pagename); if (system($gifcmd) === false) return "abcmusic failed to create $abcfile.gif\n"; } ## Create the midi file if ($ABCMidiCmdFmt && !file_exists("$abcfile.mid")) { $midicmd = FmtPageName($ABCMidiCmdFmt, $pagename); system($midicmd); } ## Return the image and output $out = "
"; if (file_exists("$abcfile.gif")) $out .= "$abctitle
"; if (file_exists("$abcfile.abc")) $out .= " abc"; if (file_exists("$abcfile.ps")) $out .= " ps"; if (file_exists("$abcfile.mid")) $out .= " midi"; $out .= "
"; return $out; }