Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 152 lines (121 sloc) 4.728 kB
2dafe43 @LastOfTheCarelessMen Feeble first stab at some ABC classes.
LastOfTheCarelessMen authored
1 use v6;
2
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
3 grammar ABC::Grammar
c08cd27 @LastOfTheCarelessMen Move the grammar to the ABC.pm file.
LastOfTheCarelessMen authored
4 {
5 regex header_field_name { \w }
6 regex header_field_data { \N* }
7 regex header_field { ^^ <header_field_name> ':' \s* <header_field_data> $$ }
d84f024 @LastOfTheCarelessMen Change to \v instead of \n. Add regex tune.
LastOfTheCarelessMen authored
8 regex header { [<header_field> \v]+ }
c08cd27 @LastOfTheCarelessMen Move the grammar to the ABC.pm file.
LastOfTheCarelessMen authored
9
10 regex basenote { <[a..g]+[A..G]> }
11 regex octave { \'+ | \,+ }
12 regex accidental { '^' | '^^' | '_' | '__' | '=' }
13 regex pitch { <accidental>? <basenote> <octave>? }
14
15 regex tie { '-' }
23bdd44 @colomon Start to sketch in ABC::Duration.
authored
16 regex number { <digit>+ }
1c1e94d @colomon Start to sketch in ABC::Duration and ABC::Note.
authored
17 regex note_length_denominator { '/' <bottom=number>? }
18 regex note_length { <top=number>? <note_length_denominator>? }
0c5c68f @colomon Clean up things a tad, add ABC::Stem.
authored
19 regex mnote { <pitch> <note_length> <tie>? }
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
20 regex stem { <mnote> | [ '[' <mnote>+ ']' ] }
af6d791 @LastOfTheCarelessMen Handle and test rests.
LastOfTheCarelessMen authored
21
22 regex rest_type { <[x..z]> }
f69a112 @colomon Try adding ABC::Rest, some Str methods.
authored
23 regex rest { <rest_type> <note_length> }
57b26ee @LastOfTheCarelessMen Add gracing type, element which can be note, rest, or gracing.
LastOfTheCarelessMen authored
24
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
25 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
26 regex grace_note_stem { <grace_note> | [ '[' <grace_note>+ ']' ] }
27 regex acciaccatura { '/' }
28 regex grace_notes { '{' <acciaccatura>? <grace_note_stem>+ '}' }
29
30 regex long_gracing { '+' <alpha>+ '+' }
31 regex gracing { '.' | '~' | <long_gracing> }
57b26ee @LastOfTheCarelessMen Add gracing type, element which can be note, rest, or gracing.
LastOfTheCarelessMen authored
32
97a6ca1 @LastOfTheCarelessMen Make <spacing> do horizontal spacing everywhere. Add <music>.
LastOfTheCarelessMen authored
33 regex spacing { \h+ }
702bdff @LastOfTheCarelessMen Get white space working.
LastOfTheCarelessMen authored
34
1b40656 @LastOfTheCarelessMen Add broken_rhythm.
LastOfTheCarelessMen authored
35 regex broken_rhythm_bracket { ['<'+ | '>'+] }
c78d0e2 @LastOfTheCarelessMen Add chords by supporting the "stem" element.
LastOfTheCarelessMen authored
36 regex broken_rhythm { <stem> <g1=gracing>* <broken_rhythm_bracket> <g2=gracing>* <stem> }
1b40656 @LastOfTheCarelessMen Add broken_rhythm.
LastOfTheCarelessMen authored
37
7f72e30 @colomon Very weak implementation of tuple that works for the common triplet c…
authored
38 # next line should work, but is NYI in Rakudo
39 # regex tuple { '('(<digit>+) [<gracing>* <stem>] ** { $0 } }
40 # next block makes the most common case work
058df8a @colomon Rename tuple to tuplet (to match ABC grammar).
authored
41 regex tuplet { '(3' [<gracing>* <stem>] ** 3 }
7f72e30 @colomon Very weak implementation of tuple that works for the common triplet c…
authored
42
0f17a26 @LastOfTheCarelessMen Add nth repeat regexes.
LastOfTheCarelessMen authored
43 regex nth_repeat_num { <digit>+ [[',' | '-'] <digit>+]* }
44 regex nth_repeat_text { '"' .*? '"' }
45 regex nth_repeat { '[' [ <nth_repeat_num> | <nth_repeat_text> ] }
46 regex end_nth_repeat { ']' }
47
058df8a @colomon Rename tuple to tuplet (to match ABC grammar).
authored
48 regex element { <broken_rhythm> | <stem> | <rest> | <tuplet>
49 | <gracing> | <grace_notes> | <nth_repeat> | <end_nth_repeat>
50 | <spacing> }
57b26ee @LastOfTheCarelessMen Add gracing type, element which can be note, rest, or gracing.
LastOfTheCarelessMen authored
51
3d558f6 @LastOfTheCarelessMen Implement Moritz's suggestions, more or less.
LastOfTheCarelessMen authored
52 regex barline { ':|:' | '|:' | '|' | ':|' | '::' }
479f3de @LastOfTheCarelessMen Use an alias to distinguish between the first and second <gracing> ca…
LastOfTheCarelessMen authored
53
925e301 @LastOfTheCarelessMen Add regex bar, working test for bar (without whitespaces).
LastOfTheCarelessMen authored
54 regex bar { <element>+ <barline>? }
55
8cf49a2 @LastOfTheCarelessMen Line of music working, with tests.
LastOfTheCarelessMen authored
56 regex line_of_music { <barline>? <bar>+ }
97a6ca1 @LastOfTheCarelessMen Make <spacing> do horizontal spacing everywhere. Add <music>.
LastOfTheCarelessMen authored
57
d84f024 @LastOfTheCarelessMen Change to \v instead of \n. Add regex tune.
LastOfTheCarelessMen authored
58 regex music { [<line_of_music> \s*\v?]+ }
59
60 regex tune { <header> <music> }
3407b9b @colomon Get 02-key.t working.
authored
61
c2fe3ce @colomon Add tune_file regex, tests for it.
authored
62 regex tune_file { \s* [<tune> \s*]+ }
63
3407b9b @colomon Get 02-key.t working.
authored
64 regex key_sig { <basenote> ('#' | 'b')? \h* (\w*) }
65
945131a @colomon Get the key signature correct (at least for simple key signatures) bu…
authored
66 our sub key_signature($key_signature_name) is export
a326b88 @LastOfTheCarelessMen Working early key signature framework.
LastOfTheCarelessMen authored
67 {
3407b9b @colomon Get 02-key.t working.
authored
68 my %keys = (
69 'C' => 0,
70 'G' => 1,
71 'D' => 2,
72 'A' => 3,
73 'E' => 4,
74 'B' => 5,
75 'F#' => 6,
76 'C#' => 7,
77 'F' => -1,
78 'Bb' => -2,
79 'Eb' => -3,
80 'Ab' => -4,
81 'Db' => -5,
82 'Gb' => -6,
83 'Cb' => -7
84 );
85
86 # say :$key_signature_name.perl;
a326b88 @LastOfTheCarelessMen Working early key signature framework.
LastOfTheCarelessMen authored
87
3407b9b @colomon Get 02-key.t working.
authored
88 # <[a..g]+[A..G]> should be <ABC::basenote
89
9613195 @colomon Switch from ABC to ABC::Grammar in preparation for further goodness.
authored
90 my $match = ABC::Grammar.parse($key_signature_name, :rule<key_sig>);
3407b9b @colomon Get 02-key.t working.
authored
91 # say :$match.perl;
92 die "Illegal key signature\n" unless $match ~~ Match;
93 my $lookup = [~] $match<basenote>.uc, $match[0];
94 # say :$lookup.perl;
95 my $sharps = %keys{$lookup};
96
97 # say :$sharps.perl;
98
99 if ($match[1].defined) {
100 given ~($match[1]) {
101 when "" { }
102 when /^maj/ { }
103 when /^ion/ { }
104 when /^mix/ { $sharps -= 1; }
105 when /^dor/ { $sharps -= 2; }
106 when /^m/ { $sharps -= 3; }
107 when /^aeo/ { $sharps -= 3; }
108 when /^phr/ { $sharps -= 4; }
109 when /^loc/ { $sharps -= 5; }
110 when /^lyd/ { $sharps += 1; }
111 default { die "Unknown mode {$match[1]} requested"; }
112 }
325c475 @LastOfTheCarelessMen Move key_signature to ABC.pm and start tests for it.
LastOfTheCarelessMen authored
113 }
3407b9b @colomon Get 02-key.t working.
authored
114
115 my @sharp_notes = <F C G D A E B>;
116 my %hash;
117
118 given $sharps {
119 when 1..7 { for ^$sharps -> $i { %hash{@sharp_notes[$i]} = "^"; } }
120 when -7..-1 { for ^(-$sharps) -> $i { %hash{@sharp_notes[6-$i]} = "_"; } }
121 }
122
123 return %hash;
325c475 @LastOfTheCarelessMen Move key_signature to ABC.pm and start tests for it.
LastOfTheCarelessMen authored
124 }
125
3407b9b @colomon Get 02-key.t working.
authored
126 our sub apply_key_signature(%key_signature, $pitch)
127 {
128 my $resulting_note = "";
129 if $pitch<accidental>
130 {
131 $resulting_note ~= $pitch<accidental>.Str;
132 }
133 else
134 {
135 $resulting_note ~= %key_signature{$pitch<basenote>.uc}
136 if (%key_signature.exists($pitch<basenote>.uc));
137 }
138 $resulting_note ~= $pitch<basenote>.Str;
139 $resulting_note ~= $pitch<octave>.Str if $pitch<octave>;
140 return $resulting_note;
141 }
325c475 @LastOfTheCarelessMen Move key_signature to ABC.pm and start tests for it.
LastOfTheCarelessMen authored
142 }
143
3407b9b @colomon Get 02-key.t working.
authored
144 sub header_hash($header_match)
fe6fa09 @LastOfTheCarelessMen Move apply_key_signature to ABC.pm.
LastOfTheCarelessMen authored
145 {
3407b9b @colomon Get 02-key.t working.
authored
146 gather for $header_match<header_field>
fe6fa09 @LastOfTheCarelessMen Move apply_key_signature to ABC.pm.
LastOfTheCarelessMen authored
147 {
3407b9b @colomon Get 02-key.t working.
authored
148 take $_.<header_field_name>.Str => $_.<header_field_data>.Str;
fe6fa09 @LastOfTheCarelessMen Move apply_key_signature to ABC.pm.
LastOfTheCarelessMen authored
149 }
150 }
151
Something went wrong with that request. Please try again.