| 1 | #! perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 92 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 92 | ▶ | use feature qw( signatures ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 92 | ▶ | no warnings qw( experimental::signatures ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 92 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | package ChordPro::Symbols; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 92 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 92 | our @EXPORT; | |||||||||||||||||||||||||||
| 13 | 92 | our @EXPORT_OK; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 92 | my $symbols; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 92 | ▶ | use List::Util qw( any ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 92 | ▶ | use Ref::Util qw( is_arrayref ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 196 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 21 | 196 | ▶ | $symbols || _build(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 196 | goto &Exporter::import; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 92 | ▶ | sub _build { | ||||||||||||||||||||||||||
|
Subroutine
_build: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 92 | my @a = split( /\s+/, <<EOD ); | |||||||||||||||||||||||||||
| 28 | u \x{2190} arrow-up | ||||||||||||||||||||||||||||
| 29 | up \x{2190} arrow-up | ||||||||||||||||||||||||||||
| 30 | ua \x{2191} arrow-up-with-arpeggio | ||||||||||||||||||||||||||||
| 31 | us \x{2192} arrow-up-with-staccato | ||||||||||||||||||||||||||||
| 32 | u+ \x{2193} arrow-up-with-accent | ||||||||||||||||||||||||||||
| 33 | up+ \x{2193} arrow-up-with-accent | ||||||||||||||||||||||||||||
| 34 | ua+ \x{2194} arrow-up-with-accent-and-arpeggio | ||||||||||||||||||||||||||||
| 35 | us+ \x{2195} arrow-up-with-accent-and-staccato | ||||||||||||||||||||||||||||
| 36 | ux \x{2196} arrow-up-muted | ||||||||||||||||||||||||||||
| 37 | uxa \x{2197} arrow-up-muted-with-arpeggio | ||||||||||||||||||||||||||||
| 38 | uxs \x{2198} arrow-up-muted-with-staccato | ||||||||||||||||||||||||||||
| 39 | ux+ \x{2199} arrow-up-muted-with-accent | ||||||||||||||||||||||||||||
| 40 | uxa+ \x{219a} arrow-up-muted-with-accent-and-arpeggio | ||||||||||||||||||||||||||||
| 41 | uxs+ \x{219b} arrow-up-muted-with-accent-and-staccato | ||||||||||||||||||||||||||||
| 42 | uxa+ \x{219a} arrow-up-muted-with-accent-and-arpeggio | ||||||||||||||||||||||||||||
| 43 | uxs+ \x{219b} arrow-up-muted-with-accent-and-staccato | ||||||||||||||||||||||||||||
| 44 | d \x{21a0} arrow-down | ||||||||||||||||||||||||||||
| 45 | dn \x{21a0} arrow-down | ||||||||||||||||||||||||||||
| 46 | da \x{21a1} arrow-down-with-arpeggio | ||||||||||||||||||||||||||||
| 47 | ds \x{21a2} arrow-down-with-staccato | ||||||||||||||||||||||||||||
| 48 | d+ \x{21a3} arrow-down-with-accent | ||||||||||||||||||||||||||||
| 49 | dn+ \x{21a3} arrow-down-with-accent | ||||||||||||||||||||||||||||
| 50 | da+ \x{21a4} arrow-down-with-accent-and-arpeggio | ||||||||||||||||||||||||||||
| 51 | ds+ \x{21a5} arrow-down-with-accent-and-staccato | ||||||||||||||||||||||||||||
| 52 | dx \x{21a6} arrow-down-muted | ||||||||||||||||||||||||||||
| 53 | dxa \x{21a7} arrow-down-muted-with-arpeggio | ||||||||||||||||||||||||||||
| 54 | dxs \x{21a8} arrow-down-muted-with-staccato | ||||||||||||||||||||||||||||
| 55 | dx+ \x{21a9} arrow-down-muted-with-accent | ||||||||||||||||||||||||||||
| 56 | dxa+ \x{21aa} arrow-down-muted-with-accent-and-arpeggio | ||||||||||||||||||||||||||||
| 57 | dxs+ \x{21ab} arrow-down-muted-with-accent-and-staccato | ||||||||||||||||||||||||||||
| 58 | dxa+ \x{21aa} arrow-down-muted-with-accent-and-arpeggio | ||||||||||||||||||||||||||||
| 59 | dxs+ \x{21ab} arrow-down-muted-with-accent-and-staccato | ||||||||||||||||||||||||||||
| 60 | x \x{21b0} arrow-mute | ||||||||||||||||||||||||||||
| 61 | EOD | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 92 | ▶ | while ( @a ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 3036 | my $code = shift(@a); | |||||||||||||||||||||||||||
| 65 | 3036 | my $glyph = shift(@a); | |||||||||||||||||||||||||||
| 66 | 3036 | my $name = shift(@a); | |||||||||||||||||||||||||||
| 67 | 3036 | $symbols->{"strum_$code"} = $glyph; | |||||||||||||||||||||||||||
| 68 | 3036 | $symbols->{$name} = $glyph; | |||||||||||||||||||||||||||
| 69 | 3036 | $name =~ s/muted/mut/; | |||||||||||||||||||||||||||
| 70 | 3036 | $name =~ s/accent/acc/; | |||||||||||||||||||||||||||
| 71 | 3036 | $name =~ s/arpeggio/arp/; | |||||||||||||||||||||||||||
| 72 | 3036 | $name =~ s/staccato/stc/; | |||||||||||||||||||||||||||
| 73 | 3036 | $name =~ s/-(and|with)-/-/g; | |||||||||||||||||||||||||||
| 74 | 3036 | $symbols->{$name} = $glyph; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 92 | my $start = ord("!"); | |||||||||||||||||||||||||||
| 78 | # Something peculiar happening here... | ||||||||||||||||||||||||||||
| 79 | # If repeat-end-start1 maps to ' it cannot be used (comes out as undefined glyph). | ||||||||||||||||||||||||||||
| 80 | $symbols->{$_} = sprintf("%c", $start++ ) | ||||||||||||||||||||||||||||
| 81 | 92 | for qw( flat natural sharp delta | |||||||||||||||||||||||||||
| 82 | repeat-start repeat-end repeat-end-start1 repeat-colon repeat1 repeat2 repeat-end-start ); | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 92 | $start = ord(":"); | |||||||||||||||||||||||||||
| 85 | $symbols->{$_} = sprintf("%c", $start++ ) | ||||||||||||||||||||||||||||
| 86 | 92 | for qw( bar double-bar end-bar start-bar thick-bar double-thick-bar ); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 92 | $symbols->{"circle-$_"} = $_ for "0".."9"; | |||||||||||||||||||||||||||
| 89 | 92 | $symbols->{"circle-$_"} = $_ for "A".."Z"; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 80 | ▶ | sub symbols() { | ||||||||||||||||||||||||||
|
Subroutine
symbols: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | 80 | $symbols; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 92 | push( @EXPORT_OK, qw( symbols ) ); | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub symbol($sym) { | ||||||||||||||||||||||||||
|
Subroutine
symbol: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 0 | $symbols->{$sym}; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 92 | push( @EXPORT_OK, qw( symbol ) ); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub is_symbol( $name ) { | ||||||||||||||||||||||||||
|
Subroutine
is_symbol: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 106 | 0 | exists( $symbols->{$name} ); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 92 | push( @EXPORT, qw( is_symbol ) ); | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub strum( $code ) { | ||||||||||||||||||||||||||
|
Subroutine
strum: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 112 | # Allow override by config. | ||||||||||||||||||||||||||||
| 113 | exists($::config->{gridstrum}->{symbols}->{$code}) | ||||||||||||||||||||||||||||
| 114 | ? $::config->{gridstrum}->{symbols}->{$code} | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | : $symbols->{"strum_$code"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 92 | push( @EXPORT, qw( strum ) ); | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub is_strum( $code ) { | ||||||||||||||||||||||||||
|
Subroutine
is_strum: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 121 | # In case of settings.notenames, prevent arrow codes from hiding | ||||||||||||||||||||||||||||
| 122 | # lowercase note names. | ||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ( $::config->{settings}->{notenames} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | return | ||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if any { $_ eq $code } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | map { is_arrayref($_) ? ( map{lc}@$_ ) : lc($_) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | @{ $::config->{notes}->{flat} }, | |||||||||||||||||||||||||||
| 128 | 0 | ▶ | @{ $::config->{notes}->{sharp} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | exists( $symbols->{"strum_$code"} ); | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 92 | push( @EXPORT, qw( is_strum ) ); | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub as_json() { | ||||||||||||||||||||||||||
|
Subroutine
as_json: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 137 | 0 | my $ret = "{\n"; | |||||||||||||||||||||||||||
| 138 | 0 | for ( sort keys %$symbols ) { | |||||||||||||||||||||||||||
| 139 | 0 | $ret .= qq{ "$_" : }; | |||||||||||||||||||||||||||
| 140 | 0 | my $s = $symbols->{$_}; | |||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ( $s ge "!" && $s le "}" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$s ge "!" and $s le "}"
MC/DC0%0/2
$s ge "!" and $s le "}"
$s ge "!"
$s le "}"
Truth table0%0/3
A and B
A= $s ge "!"B= $s le "}"
| |||||||||||||||||||||||||||||
| 142 | 0 | $ret .= qq{"$s"}; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | else { | ||||||||||||||||||||||||||||
| 145 | 0 | $ret .= sprintf(qq{"\\u%04x"}, ord($s) ); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | 0 | $ret .= ",\n"; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 0 | $ret =~ s/,\n$/\n/; | |||||||||||||||||||||||||||
| 150 | 0 | $ret .= "}\n"; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 92 | push( @EXPORT_OK, qw( as_json ) ); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 92 | 1; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 92 | ▶ | unless ( caller ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | $symbols || _build(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | print as_json(); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||