Skip to content
Newer
Older
100644 169 lines (136 sloc) 5.56 KB
2dafe43 @LastOfTheCarelessMen Feeble first stab at some ABC classes.
LastOfTheCarelessMen authored Dec 11, 2009
1 use v6;
084141b @colomon Change inline_field to use a different sort of capture, to avoid a no…
authored Nov 29, 2011
2 # use Grammar::Tracer;
2dafe43 @LastOfTheCarelessMen Feeble first stab at some ABC classes.
LastOfTheCarelessMen authored Dec 12, 2009
3
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored Sep 16, 2010
4 grammar ABC::Grammar
c08cd27 @LastOfTheCarelessMen Move the grammar to the ABC.pm file.
LastOfTheCarelessMen authored Dec 16, 2009
5 {
6 regex header_field_name { \w }
7 regex header_field_data { \N* }
8 regex header_field { ^^ <header_field_name> ':' \s* <header_field_data> $$ }
18ef0e8 @colomon Tweak the header grammar so that it will work with CR LF line endings.
authored Mar 11, 2011
9 regex header { [<header_field> \v+]+ }
c08cd27 @LastOfTheCarelessMen Move the grammar to the ABC.pm file.
LastOfTheCarelessMen authored Dec 16, 2009
10
11 regex basenote { <[a..g]+[A..G]> }
d74ea6a @colomon Tweak octave regex to make it easier to read.
authored Dec 18, 2010
12 regex octave { "'"+ | ","+ }
4f997d9 @colomon Workaround the nom LTM bug by putting the longest first.
authored Nov 29, 2011
13 regex accidental { '^^' | '^' | '__' | '_' | '=' }
c08cd27 @LastOfTheCarelessMen Move the grammar to the ABC.pm file.
LastOfTheCarelessMen authored Dec 16, 2009
14 regex pitch { <accidental>? <basenote> <octave>? }
15
16 regex tie { '-' }
23bdd44 @colomon Start to sketch in ABC::Duration.
authored Sep 30, 2010
17 regex number { <digit>+ }
1c1e94d @colomon Start to sketch in ABC::Duration and ABC::Note.
authored Sep 30, 2010
18 regex note_length_denominator { '/' <bottom=number>? }
19 regex note_length { <top=number>? <note_length_denominator>? }
0c5c68f @colomon Clean up things a tad, add ABC::Stem.
authored Oct 1, 2010
20 regex mnote { <pitch> <note_length> <tie>? }
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored Sep 16, 2010
21 regex stem { <mnote> | [ '[' <mnote>+ ']' ] }
af6d791 @LastOfTheCarelessMen Handle and test rests.
LastOfTheCarelessMen authored Dec 16, 2009
22
23 regex rest_type { <[x..z]> }
f69a112 @colomon Try adding ABC::Rest, some Str methods.
authored Oct 1, 2010
24 regex rest { <rest_type> <note_length> }
57b26ee @LastOfTheCarelessMen Add gracing type, element which can be note, rest, or gracing.
LastOfTheCarelessMen authored Dec 16, 2009
25
82ca886 @colomon Add very basic support for slurs in the grammar.
authored Mar 11, 2011
26 regex slur_begin { '(' }
27 regex slur_end { ')' }
28
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored Sep 16, 2010
29 regex grace_note { <pitch> <note_length>? } # as mnote, but without tie
fb0b7d2 @LastOfTheCarelessMen Add staccato and roll gracings, and basic grace note support.
LastOfTheCarelessMen authored Jan 16, 2010
30 regex grace_note_stem { <grace_note> | [ '[' <grace_note>+ ']' ] }
31 regex acciaccatura { '/' }
32 regex grace_notes { '{' <acciaccatura>? <grace_note_stem>+ '}' }
33
447e573 @colomon Get gracing action working correctly as well.
authored Nov 25, 2010
34 regex long_gracing_text { [<alpha> | '.']+ }
35 regex long_gracing { '+' <long_gracing_text> '+' }
fb0b7d2 @LastOfTheCarelessMen Add staccato and roll gracings, and basic grace note support.
LastOfTheCarelessMen authored Jan 16, 2010
36 regex gracing { '.' | '~' | <long_gracing> }
57b26ee @LastOfTheCarelessMen Add gracing type, element which can be note, rest, or gracing.
LastOfTheCarelessMen authored Dec 16, 2009
37
97a6ca1 @LastOfTheCarelessMen Make <spacing> do horizontal spacing everywhere. Add <music>.
LastOfTheCarelessMen authored Dec 20, 2009
38 regex spacing { \h+ }
702bdff @LastOfTheCarelessMen Get white space working.
LastOfTheCarelessMen authored Dec 20, 2009
39
1b40656 @LastOfTheCarelessMen Add broken_rhythm.
LastOfTheCarelessMen authored Dec 16, 2009
40 regex broken_rhythm_bracket { ['<'+ | '>'+] }
05ca634 @colomon Add b_elem and t_elem as per the ABC BNF.
authored Mar 11, 2011
41 regex b_elem { <gracing> | <grace_notes> | <slur_begin> | <slur_end> }
42 regex broken_rhythm { <stem> <g1=b_elem>* <broken_rhythm_bracket> <g2=b_elem>* <stem> }
1b40656 @LastOfTheCarelessMen Add broken_rhythm.
LastOfTheCarelessMen authored Dec 16, 2009
43
05ca634 @colomon Add b_elem and t_elem as per the ABC BNF.
authored Mar 12, 2011
44 regex t_elem { <gracing> | <grace_notes> | <broken_rhythm> | <slur_begin> | <slur_end> }
7f72e30 @colomon Very weak implementation of tuple that works for the common triplet c…
authored Sep 26, 2010
45 # next line should work, but is NYI in Rakudo
05ca634 @colomon Add b_elem and t_elem as per the ABC BNF.
authored Mar 12, 2011
46 # regex tuple { '('(<digit>+) [<t_elem>* <stem>] ** { $0 } }
7f72e30 @colomon Very weak implementation of tuple that works for the common triplet c…
authored Sep 26, 2010
47 # next block makes the most common case work
05ca634 @colomon Add b_elem and t_elem as per the ABC BNF.
authored Mar 12, 2011
48 regex tuplet { '(3' [<t_elem>* <stem>] ** 3 }
7f72e30 @colomon Very weak implementation of tuple that works for the common triplet c…
authored Sep 26, 2010
49
0f17a26 @LastOfTheCarelessMen Add nth repeat regexes.
LastOfTheCarelessMen authored Jan 16, 2010
50 regex nth_repeat_num { <digit>+ [[',' | '-'] <digit>+]* }
51 regex nth_repeat_text { '"' .*? '"' }
52 regex nth_repeat { '[' [ <nth_repeat_num> | <nth_repeat_text> ] }
53 regex end_nth_repeat { ']' }
54
084141b @colomon Change inline_field to use a different sort of capture, to avoid a no…
authored Nov 29, 2011
55 regex inline_field { '[' <alpha> ':' $<value>=[.*?] ']' }
98189f2 @colomon Add inline_field to the grammar, plus some tests for it.
authored Oct 29, 2010
56
e01b96b @colomon Add chords to the grammar.
authored Dec 5, 2011
57 regex chord_accidental { '#' | 'b' | '=' }
58 regex chord_type { [ <alpha> | <digit> | '+' | '-' ]+ }
59 regex chord_newline { '\n' | ';' }
c55e48a @colomon Add ABC::Chord and adjust actions to handle it.
authored Dec 12, 2011
60 regex chord { <mainnote=basenote> <mainaccidental=chord_accidental>? <maintype=chord_type>?
61 [ '/' <bassnote=basenote> <bass_accidental=chord_accidental>? ]? <non_quote>* }
e01b96b @colomon Add chords to the grammar.
authored Dec 6, 2011
62 regex non_quote { <-["]> }
63 regex text_expression { [ '^' | '<' | '>' | '_' | '@' ] <non_quote>+ }
64 regex chord_or_text { '"' [ <chord> | <text_expression> ] [ <chord_newline> [ <chord> | <text_expression> ] ]* '"' }
65
82ca886 @colomon Add very basic support for slurs in the grammar.
authored Mar 11, 2011
66 regex element { <broken_rhythm> | <stem> | <rest> | <tuplet> | <slur_begin> | <slur_end>
058df8a @colomon Rename tuple to tuplet (to match ABC grammar).
authored Oct 8, 2010
67 | <gracing> | <grace_notes> | <nth_repeat> | <end_nth_repeat>
e01b96b @colomon Add chords to the grammar.
authored Dec 6, 2011
68 | <spacing> | <inline_field> | <chord_or_text> }
57b26ee @LastOfTheCarelessMen Add gracing type, element which can be note, rest, or gracing.
LastOfTheCarelessMen authored Dec 16, 2009
69
56c09ce @colomon Support length field and proper final bar line.
authored Dec 17, 2010
70 regex barline { '||' | '|]' | ':|:' | '|:' | '|' | ':|' | '::' }
479f3de @LastOfTheCarelessMen Use an alias to distinguish between the first and second <gracing> ca…
LastOfTheCarelessMen authored Dec 17, 2009
71
925e301 @LastOfTheCarelessMen Add regex bar, working test for bar (without whitespaces).
LastOfTheCarelessMen authored Dec 20, 2009
72 regex bar { <element>+ <barline>? }
73
8cf49a2 @LastOfTheCarelessMen Line of music working, with tests.
LastOfTheCarelessMen authored Dec 20, 2009
74 regex line_of_music { <barline>? <bar>+ }
97a6ca1 @LastOfTheCarelessMen Make <spacing> do horizontal spacing everywhere. Add <music>.
LastOfTheCarelessMen authored Dec 20, 2009
75
d84f024 @LastOfTheCarelessMen Change to \v instead of \n. Add regex tune.
LastOfTheCarelessMen authored Dec 20, 2009
76 regex music { [<line_of_music> \s*\v?]+ }
77
78 regex tune { <header> <music> }
3407b9b @colomon Get 02-key.t working.
authored Sep 1, 2010
79
c2fe3ce @colomon Add tune_file regex, tests for it.
authored Sep 14, 2010
80 regex tune_file { \s* [<tune> \s*]+ }
81
3407b9b @colomon Get 02-key.t working.
authored Sep 2, 2010
82 regex key_sig { <basenote> ('#' | 'b')? \h* (\w*) }
83
945131a @colomon Get the key signature correct (at least for simple key signatures) bu…
authored Oct 2, 2010
84 our sub key_signature($key_signature_name) is export
a326b88 @LastOfTheCarelessMen Working early key signature framework.
LastOfTheCarelessMen authored Dec 30, 2009
85 {
3407b9b @colomon Get 02-key.t working.
authored Sep 2, 2010
86 my %keys = (
87 'C' => 0,
88 'G' => 1,
89 'D' => 2,
90 'A' => 3,
91 'E' => 4,
92 'B' => 5,
93 'F#' => 6,
94 'C#' => 7,
95 'F' => -1,
96 'Bb' => -2,
97 'Eb' => -3,
98 'Ab' => -4,
99 'Db' => -5,
100 'Gb' => -6,
101 'Cb' => -7
102 );
103
104 # say :$key_signature_name.perl;
a326b88 @LastOfTheCarelessMen Working early key signature framework.
LastOfTheCarelessMen authored Dec 30, 2009
105
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored Sep 16, 2010
106 my $match = ABC::Grammar.parse($key_signature_name, :rule<key_sig>);
3407b9b @colomon Get 02-key.t working.
authored Sep 2, 2010
107 # say :$match.perl;
5138ef2 @colomon Bit of cleanup in key_signature.
authored Nov 29, 2011
108 die "Illegal key signature\n" unless $match;
3407b9b @colomon Get 02-key.t working.
authored Sep 2, 2010
109 my $lookup = [~] $match<basenote>.uc, $match[0];
110 # say :$lookup.perl;
111 my $sharps = %keys{$lookup};
112
113 # say :$sharps.perl;
114
115 if ($match[1].defined) {
116 given ~($match[1]) {
117 when "" { }
118 when /^maj/ { }
119 when /^ion/ { }
120 when /^mix/ { $sharps -= 1; }
121 when /^dor/ { $sharps -= 2; }
122 when /^m/ { $sharps -= 3; }
123 when /^aeo/ { $sharps -= 3; }
124 when /^phr/ { $sharps -= 4; }
125 when /^loc/ { $sharps -= 5; }
126 when /^lyd/ { $sharps += 1; }
127 default { die "Unknown mode {$match[1]} requested"; }
128 }
325c475 @LastOfTheCarelessMen Move key_signature to ABC.pm and start tests for it.
LastOfTheCarelessMen authored Dec 30, 2009
129 }
3407b9b @colomon Get 02-key.t working.
authored Sep 2, 2010
130
131 my @sharp_notes = <F C G D A E B>;
132 my %hash;
133
134 given $sharps {
135 when 1..7 { for ^$sharps -> $i { %hash{@sharp_notes[$i]} = "^"; } }
136 when -7..-1 { for ^(-$sharps) -> $i { %hash{@sharp_notes[6-$i]} = "_"; } }
137 }
138
139 return %hash;
325c475 @LastOfTheCarelessMen Move key_signature to ABC.pm and start tests for it.
LastOfTheCarelessMen authored Dec 30, 2009
140 }
141
3407b9b @colomon Get 02-key.t working.
authored Sep 2, 2010
142 our sub apply_key_signature(%key_signature, $pitch)
143 {
144 my $resulting_note = "";
145 if $pitch<accidental>
146 {
147 $resulting_note ~= $pitch<accidental>.Str;
148 }
149 else
150 {
9f0d6d5 @colomon Tweak for Niecza.
authored Aug 23, 2011
151 if %key_signature.exists($pitch<basenote>.uc) {
152 $resulting_note ~= %key_signature{$pitch<basenote>.uc};
153 }
3407b9b @colomon Get 02-key.t working.
authored Sep 2, 2010
154 }
155 $resulting_note ~= $pitch<basenote>.Str;
156 $resulting_note ~= $pitch<octave>.Str if $pitch<octave>;
157 return $resulting_note;
158 }
325c475 @LastOfTheCarelessMen Move key_signature to ABC.pm and start tests for it.
LastOfTheCarelessMen authored Dec 30, 2009
159 }
160
3407b9b @colomon Get 02-key.t working.
authored Sep 2, 2010
161 sub header_hash($header_match)
fe6fa09 @LastOfTheCarelessMen Move apply_key_signature to ABC.pm.
LastOfTheCarelessMen authored Jan 6, 2010
162 {
3407b9b @colomon Get 02-key.t working.
authored Sep 2, 2010
163 gather for $header_match<header_field>
fe6fa09 @LastOfTheCarelessMen Move apply_key_signature to ABC.pm.
LastOfTheCarelessMen authored Jan 6, 2010
164 {
3407b9b @colomon Get 02-key.t working.
authored Sep 2, 2010
165 take $_.<header_field_name>.Str => $_.<header_field_data>.Str;
fe6fa09 @LastOfTheCarelessMen Move apply_key_signature to ABC.pm.
LastOfTheCarelessMen authored Jan 6, 2010
166 }
167 }
168
Something went wrong with that request. Please try again.