-
Notifications
You must be signed in to change notification settings - Fork 0
/
musicparser.export.text.php
118 lines (94 loc) · 2.92 KB
/
musicparser.export.text.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/* Text EXPORT */
namespace MusicParser\Export\Text{
const SONGPART_MARGIN = 6;
abstract class SongObject implements \MusicParser\IExport{
public static function export(&$el){
if(!$el->children) return $el->text;
$o = "";
foreach($el->children as $child) $o .= $child->__toString();
return $o;
}
}
class Song extends SongObject{
}
class Section extends SongObject{}
class Column extends SongObject{
public static function export(&$el){
//!!! $width = floor(100/count($el->getClosest("Section")->columns));
return join("\n\n",$el->children);
}
}
abstract class SongPart extends SongObject{
public static function export(&$el){
$i = 0;
$children = &$el->children;
$firstline = true;
$lines = array();
while(@$children[$i]){
$text = "";
$chords = "";
if($firstline){
$text .= str_repeat(" ",SONGPART_MARGIN - mb_strlen($el->label.$el->delimiter));
$text .= $el->label.$el->delimiter." ";
$firstline = false;
}else{
$text .= str_repeat(" ",SONGPART_MARGIN)." ";
}
while(@$children[$i]){
if($children[$i] instanceof \MusicParser\Structure\Chord){
if(mb_strlen($chords) < mb_strlen($text)){
$chords .= str_repeat(" ",mb_strlen($text) - mb_strlen($chords));
$chords .= $children[$i]->__toString();
}
else{
$text .= str_repeat(" ",mb_strlen($chords) - mb_strlen($text) + 1);
$chords .= " ".$children[$i]->__toString();
}
}
if($children[$i] instanceof \MusicParser\Structure\Text){
$text .= $children[$i]->__toString();
}
if($children[$i] instanceof \MusicParser\Structure\EOL){
$i++;
break;
}
$i++;
}
if(trim($chords)) $lines[] = $chords;
$lines[] = $text;
}
return join("\n",$lines);
}
}
class Verse extends SongPart{}
class Chorus extends SongPart{}
class Part extends SongPart{}
class BlockTab extends SongPart{}
class TextBlock extends SongPart{}
/* INLINE BLOCKS */
abstract class SongInline extends SongObject{}
class Text extends SongInline{}
class InlineTab extends SongInline{}
class Diagram extends SongInline{
/*public static function export(&$el){
$chord = $el->chord;
$template = $el->template;
$size = 100;
ob_start();
include __DIR__."/diagram-svg.php";
return ob_get_clean();
}*/
}
class Chord extends SongInline{
public static function export(&$el){
return join(" ",$el->chords);
}
}
class EOL extends SongInline{
public static function export(&$el){
return "\n";
}
}
}
?>