<commit_before>use v6;

BEGIN { push @*INC, "lib" }
use ABC;

regex between { \v+ }
regex file { \s* <ABC::tune> ** <between> }

my $abcs = $*IN.lines.join("\n");
my @matches = $abcs.comb(m/ <ABC::tune> /, :match);

for @matches {
    my %header = header_hash(.<ABC::tune><header>);
    say %header<T>;
}

# 
# my @notes = gather for $match<ABC::tune><music><line_of_music> -> $line
# {
#     for $line<bar> -> $bar
#     {
#         for $bar<element>
#         {
#             when .<broken_rhythm> { take .<broken_rhythm><note>[0]; take .<broken_rhythm><note>[1]; }
#             when .<note>          { take .<note>; }
#         }
#     }
# }
# 
# my %header = header_hash($match<ABC::tune><header>);
# my %key_signature = key_signature(%header<K>);
# 
# @notes.map({say .<pitch> ~ " => " ~ apply_key_signature(%key_signature, .<pitch>)});
<commit_msg>Simplify input, work old note handling code into new match loop.<commit_after>use v6;

BEGIN { push @*INC, "lib" }
use ABC;

my @matches = $*IN.lines.join("\n").comb(m/ <ABC::tune> /, :match);

for @matches {
    my %header = header_hash(.<ABC::tune><header>);
    say %header<T> ~ ":";

    my @notes = gather for .<ABC::tune><music><line_of_music> -> $line
    {
        for $line<bar> -> $bar
        {
            for $bar<element>
            {
                when .<broken_rhythm> { take .<broken_rhythm><note>[0]; take .<broken_rhythm><note>[1]; }
                when .<note>          { take .<note>; }
            }
        }
    }

    my %header = header_hash(.<ABC::tune><header>);
    my %key_signature = key_signature(%header<K>);

    @notes.map({say .<pitch> ~ " => " ~ apply_key_signature(%key_signature, .<pitch>)});
}

{'fraction_non_alphanumeric': 0.20968694624926165, 'fraction_numerical': 0.0035440047253396337, 'mean_word_length': 2.6351931330472103, 'pattern_counts': {'":': 1, '<': 47, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3768552', 'n_tokens_mistral': 668, 'n_tokens_neox': 629, 'n_words': 123}