コード例 #1
0
ファイル: Typeset.php プロジェクト: ludviki/tlac
 protected function typesetLine(Line $line)
 {
     $this->startLine();
     foreach ($line->getLineParts() as $linePart) {
         if ($linePart->hasChord()) {
             $this->typesetChord($linePart->getChord());
         }
         $this->typesetLyrics($linePart->getLyrics());
     }
     $this->endLine();
 }
コード例 #2
0
ファイル: Parser.php プロジェクト: ludviki/tlac
 protected function splitToLines($rawBlock)
 {
     $rawLines = preg_split("/\n/", $rawBlock['rawLines']);
     $lines = array();
     foreach ($rawLines as $rawLine) {
         $line = new Line();
         # get lyrics up till first chord
         preg_match('%
             (?:                 # (do not capture)
               (.*?)             # $1 capture all ...
                 (?=             # ... up till ...
                 (?:             # (do not capture)
                     \\+?\\{       # chord begin
                       [^\\} \\s]+ # ... first chord ...
                     \\}\\+?       # chord end
                 )
                 |$              # ... or end
                 )
             )
             %xs', $rawLine, $part1);
         if ($lyrics = $part1[1]) {
             $line->addLinePart(new LinePart($lyrics));
         }
         # get chord and lyrics till next chord
         $countMatches = preg_match_all('%
             (?:                 # do not capture
               (\\+?)             # $1 optional left margin, + before {
               \\{                # chord begins
                 ([^\\} \\s]+)     # $2 chord (no whitespace)
               \\}                # chord ends
               (\\+?)             # $3 optional right margin, + after }
               (.*?)             # $4 all up till ...
                 (?=\\+?\\{|$)     # ... next chord or end
             )
             %xs', $rawLine, $parts, PREG_SET_ORDER);
         foreach ($parts as $part) {
             $lyrics = $part[4];
             # each $part contains a chord in the beginning
             $leftMargin = $part[1] === '' ? false : true;
             $rightMargin = $part[3] === '' ? false : true;
             $bound = false;
             if (substr($lyrics, 0, 1) !== ' ' && $rightMargin === false) {
                 $bound = true;
             }
             $chord = new Chord($part[2], $bound, $leftMargin, $rightMargin);
             $line->addLinePart(new LinePart($lyrics, $chord));
         }
         $lines[] = $line;
     }
     return $lines;
 }