Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 196 lines (166 sloc) 5.082 kb
ee2c5f6 @colomon Add ABC::Header.is-valid and ABC::Actions.
authored
1 use v6;
2
23bdd44 @colomon Start to sketch in ABC::Duration.
authored
3 use ABC::Header;
4 use ABC::Tune;
1c1e94d @colomon Start to sketch in ABC::Duration and ABC::Note.
authored
5 use ABC::Duration;
6 use ABC::Note;
f69a112 @colomon Try adding ABC::Rest, some Str methods.
authored
7 use ABC::Rest;
0aae3f4 @colomon Add tuplet action and tests, fix typo in ABC::Tuplet.
authored
8 use ABC::Tuplet;
73cd8b2 @colomon Basic support for broken rhythms (at the library level) in place.
authored
9 use ABC::BrokenRhythm;
c55e48a @colomon Add ABC::Chord and adjust actions to handle it.
authored
10 use ABC::Chord;
bfee93a @colomon Support for multi-measure rests.
authored
11 use ABC::LongRest;
aceaec7 @colomon Add grace notes.
authored
12 use ABC::GraceNotes;
23bdd44 @colomon Start to sketch in ABC::Duration.
authored
13
ee2c5f6 @colomon Add ABC::Header.is-valid and ABC::Actions.
authored
14 class ABC::Actions {
15 method header_field($/) {
41c04b4 @colomon Be smarter about extraneous end-slur marks. (To deal with Gerry Strong'...
authored
16 if $<header_field_name> eq "T" {
17 $*ERR.say: "Parsing " ~ $<header_field_data>;
18 }
19
ee2c5f6 @colomon Add ABC::Header.is-valid and ABC::Actions.
authored
20 make ~$<header_field_name> => ~$<header_field_data>;
21 }
22
23 method header($/) {
24 my $header = ABC::Header.new;
25 for @( $<header_field> ) -> $field {
26 $header.add-line($field.ast.key, $field.ast.value);
27 }
28 make $header;
29 }
b350309 @colomon Add simple actions for element, barline, and bar.
authored
30
1c1e94d @colomon Start to sketch in ABC::Duration and ABC::Note.
authored
31 method note_length($/) {
32 if $<note_length_denominator> {
9bffd79 @colomon All tests now pass on both Rakuod and Niecza.
authored
33 make duration-from-parse($<top>, $<note_length_denominator>[0]<bottom>);
1c1e94d @colomon Start to sketch in ABC::Duration and ABC::Note.
authored
34 } else {
9bffd79 @colomon All tests now pass on both Rakuod and Niecza.
authored
35 make duration-from-parse($<top>);
1c1e94d @colomon Start to sketch in ABC::Duration and ABC::Note.
authored
36 }
37 }
38
39 method mnote($/) {
40 make ABC::Note.new(~$<pitch>,
0c5c68f @colomon Clean up things a tad, add ABC::Stem.
authored
41 $<note_length>.ast,
641cd1d @colomon More fixes for NIecza support.
authored
42 ?$<tie>);
1c1e94d @colomon Start to sketch in ABC::Duration and ABC::Note.
authored
43 }
44
0c5c68f @colomon Clean up things a tad, add ABC::Stem.
authored
45 method stem($/) {
46 if @( $<mnote> ) == 1 {
47 make $<mnote>[0].ast;
48 } else {
83d7ac7 @colomon Allow [ABC] chords to have durations and "is tied" flags. This goes aga...
authored
49 make ABC::Stem.new(@( $<mnote> )>>.ast, $<note_length>.ast, ?$<tie>);
0c5c68f @colomon Clean up things a tad, add ABC::Stem.
authored
50 }
51 }
1c1e94d @colomon Start to sketch in ABC::Duration and ABC::Note.
authored
52
0eda2ba @colomon Fix glitch in ABC::Rest, turn it back on.
authored
53 method rest($/) {
54 make ABC::Rest.new(~$<rest_type>, $<note_length>.ast);
55 }
bfee93a @colomon Support for multi-measure rests.
authored
56
57 method multi_measure_rest($/) {
58 make ABC::LongRest.new(~$<number>);
59 }
f69a112 @colomon Try adding ABC::Rest, some Str methods.
authored
60
1221bde @colomon Get triplets working.
authored
61 method tuplet($/) {
ea8c786 @colomon Support sixteenth note as a note length, and better (though note yet ful...
authored
62 make ABC::Tuplet.new(+@( $<stem> ), @( $<stem> )>>.ast);
0aae3f4 @colomon Add tuplet action and tests, fix typo in ABC::Tuplet.
authored
63 }
64
73cd8b2 @colomon Basic support for broken rhythms (at the library level) in place.
authored
65 method broken_rhythm($/) {
66 make ABC::BrokenRhythm.new($<stem>[0].ast,
67 ~$<g1>,
68 ~$<broken_rhythm_bracket>,
69 ~$<g2>,
70 $<stem>[1].ast);
71 }
b561dfc @colomon Refactor key signature handling a bit.
authored
72
aceaec7 @colomon Add grace notes.
authored
73 method grace_note($/) {
74 make ABC::Note.new(~$<pitch>,
75 $<note_length>.ast,
76 False);
77 }
78
79 method grace_note_stem($/) {
80 if @( $<grace_note> ) == 1 {
81 make $<grace_note>[0].ast;
82 } else {
83 make ABC::Stem.new(@( $<grace_note> )>>.ast);
84 }
85 }
86
87 method grace_notes($/) {
88 make ABC::GraceNotes.new(?$<acciaccatura>, @( $<grace_note_stem> )>>.ast);
89 }
90
91
8d09a3e @colomon Get in-line key changes working.
authored
92 method inline_field($/) {
084141b @colomon Change inline_field to use a different sort of capture, to avoid a nom b...
authored
93 make ~$/<alpha> => ~$/<value>;
8d09a3e @colomon Get in-line key changes working.
authored
94 }
95
ebe9e75 @colomon Long gracing ast is just the Str of the text of the long gracing.
authored
96 method long_gracing($/) {
447e573 @colomon Get gracing action working correctly as well.
authored
97 make ~$/<long_gracing_text>;
ebe9e75 @colomon Long gracing ast is just the Str of the text of the long gracing.
authored
98 }
447e573 @colomon Get gracing action working correctly as well.
authored
99
100 method gracing($/) {
101 make $/<long_gracing> ?? $/<long_gracing>.ast !! ~$/;
102 }
c55e48a @colomon Add ABC::Chord and adjust actions to handle it.
authored
103
a63e6e6 @colomon Support slurs, too.
authored
104 method slur_begin($/) {
bfee93a @colomon Support for multi-measure rests.
authored
105 make ~$/;
a63e6e6 @colomon Support slurs, too.
authored
106 }
107
108 method slur_end($/) {
bfee93a @colomon Support for multi-measure rests.
authored
109 make ~$/;
a63e6e6 @colomon Support slurs, too.
authored
110 }
111
c55e48a @colomon Add ABC::Chord and adjust actions to handle it.
authored
112 method chord($/) {
113 # say "hello?";
114 # say $/<chord_accidental>[0].WHAT;
115 # say $/<chord_accidental>[0].perl;
2f242a8 @colomon Make the chord action Niecza-friendly.
authored
116 make ABC::Chord.new(~$/<mainnote>, ~($/<mainaccidental> // ""), ~($/<maintype> // ""),
117 ~($/<bassnote> // ""), ~($/<bass_accidental> // ""));
c55e48a @colomon Add ABC::Chord and adjust actions to handle it.
authored
118 }
119
120 method chord_or_text($/) {
9d0218e @colomon Handle parsing / action for text_expressions, too.
authored
121 my @chords = $/<chord>.map({ $_.ast });
122 my @texts = $/<text_expression>.map({ ~$_ });
123 make (@chords, @texts).flat;
c55e48a @colomon Add ABC::Chord and adjust actions to handle it.
authored
124 }
125
b350309 @colomon Add simple actions for element, barline, and bar.
authored
126 method element($/) {
127 my $type;
ed6dc7a @colomon Fix up long_gracing so that it works without breaking tests.
authored
128 for <broken_rhythm stem rest slur_begin slur_end multi_measure_rest gracing grace_notes nth_repeat end_nth_repeat spacing tuplet inline_field chord_or_text> {
b350309 @colomon Add simple actions for element, barline, and bar.
authored
129 $type = $_ if $/{$_};
130 }
c55e48a @colomon Add ABC::Chord and adjust actions to handle it.
authored
131 # say $type ~ " => " ~ $/{$type}.ast.WHAT;
1c1e94d @colomon Start to sketch in ABC::Duration and ABC::Note.
authored
132
133 my $ast = $type => ~$/{$type};
1221bde @colomon Get triplets working.
authored
134 # say :$ast.perl;
135 # say $/{$type}.ast.perl;
8d09a3e @colomon Get in-line key changes working.
authored
136 # say $/{$type}.ast.WHAT;
aceaec7 @colomon Add grace notes.
authored
137 if $/{$type}.ast ~~ ABC::Duration | ABC::LongRest | ABC::GraceNotes | Pair | Str | List {
7edf476 @colomon Fix element action to return component's AST value (sometimes) and fix c...
authored
138 $ast = $type => $/{$type}.ast;
139 }
1c1e94d @colomon Start to sketch in ABC::Duration and ABC::Note.
authored
140 make $ast;
b350309 @colomon Add simple actions for element, barline, and bar.
authored
141 }
142
143 method barline($/) {
144 make "barline" => ~$/;
145 }
146
147 method bar($/) {
d24480f @colomon Ugly but successful actions for bar, line_of_music, and music.
authored
148 my @bar = @( $<element> )>>.ast;
641cd1d @colomon More fixes for NIecza support.
authored
149 if $<barline> {
150 @bar.push($<barline>>>.ast);
151 }
d24480f @colomon Ugly but successful actions for bar, line_of_music, and music.
authored
152 make @bar;
b350309 @colomon Add simple actions for element, barline, and bar.
authored
153 }
154
d24480f @colomon Ugly but successful actions for bar, line_of_music, and music.
authored
155 method line_of_music($/) {
641cd1d @colomon More fixes for NIecza support.
authored
156 my @line;
157 if $<barline> {
158 @line.push($<barline>>>.ast);
159 }
d24480f @colomon Ugly but successful actions for bar, line_of_music, and music.
authored
160 my @bars = @( $<bar> )>>.ast;
161 for @bars -> $bar {
162 for $bar.list {
163 @line.push($_);
164 }
165 }
166 @line.push("endline" => "");
167 make @line;
168 }
169
170 method music($/) {
171 my @music;
363a3dc @colomon Improved handling of music action, additional tests.
authored
172 # $*ERR.say: "Started music action";
173 for @( $/.caps ) {
174 # $*ERR.say: ~$_.key ~ " => " ~ ~$_.value;
175 when *.key eq "line_of_music" {
176 for $_.value.ast.list {
177 @music.push($_);
178 }
179 }
180 when *.key eq "header_field" {
181 @music.push("inline_field" => $_.value.ast);
d24480f @colomon Ugly but successful actions for bar, line_of_music, and music.
authored
182 }
183 }
363a3dc @colomon Improved handling of music action, additional tests.
authored
184 # state $count = 0;
185 # die if ++$count == 10;
d24480f @colomon Ugly but successful actions for bar, line_of_music, and music.
authored
186 make @music;
187 }
6524784 @colomon Add ABC::Tune and have the <tune> action create one.
authored
188
189 method tune($/) {
190 make ABC::Tune.new($<header>.ast, $<music>.ast);
191 }
264e7f8 @colomon tune_file action added, though it's a little weird at the moment.
authored
192
193 method tune_file($/) {
194 make @( $<tune> )>>.ast;
195 }
ee2c5f6 @colomon Add ABC::Header.is-valid and ABC::Actions.
authored
196 }
Something went wrong with that request. Please try again.