| 1 | package MIDI::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:GENE'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: MIDI and music utilities | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.1310'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use File::Slurper qw(write_text); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use MIDI (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use MIDI::Simple (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Music::Tempo qw(bpm_to_ms); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Music::Scales qw(%original_modes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use constant TICKS => 96; # nb: used internally when a score is not given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | midi_dump | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | reverse_dump | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | midi_format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | set_chan_patch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | set_time_signature | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | setup_score | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | dura_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ticks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | timidity_conf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | play_timidity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | play_fluidsynth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | get_microseconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | score2events | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | scale_names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | TICKS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub setup_score { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup_score: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my %args = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | lead_in => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | volume => 120, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | bpm => 100, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | channel => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | patch => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | octave => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | signature => '4/4', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | @_, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | my $score = MIDI::Simple->new_score(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | set_time_signature($score, $args{signature}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | $score->set_tempo( bpm_to_ms($args{bpm}) * 1000 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | $score->Channel(9); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | $score->n( 'qn', 42 ) for 1 .. $args{lead_in}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | $score->Volume($args{volume}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | $score->Channel($args{channel}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | $score->Octave($args{octave}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | $score->patch_change( $args{channel}, $args{patch} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | return $score; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | sub set_chan_patch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_chan_patch: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | my ( $score, $channel, $patch ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | $channel //= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$channel //= 0
MC/DC0%0/1
$channel //= 0
$channel
Truth table50%1/2
A
A= $channel
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | $score->patch_change( $channel, $patch ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | if defined $patch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | $score->noop( 'c' . $channel ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 15 | ▶ | sub midi_dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
midi_dump: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 15 | my ($key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 15 | ▶ | if ( lc $key eq 'volume' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 15 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 10 | map { $_ => $MIDI::Simple::Volume{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | sort { $MIDI::Simple::Volume{$a} <=> $MIDI::Simple::Volume{$b} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | keys %MIDI::Simple::Volume | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | elsif ( lc $key eq 'length' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 20 | map { $_ => $MIDI::Simple::Length{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | sort { $MIDI::Simple::Length{$a} <=> $MIDI::Simple::Length{$b} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | keys %MIDI::Simple::Length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | elsif ( lc $key eq 'ticks' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 20 | map { $_ => $MIDI::Simple::Length{$_} * TICKS } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | sort { $MIDI::Simple::Length{$a} <=> $MIDI::Simple::Length{$b} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | keys %MIDI::Simple::Length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | elsif ( lc $key eq 'note' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 27 | map { $_ => $MIDI::Simple::Note{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | sort { $MIDI::Simple::Note{$a} <=> $MIDI::Simple::Note{$b} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | keys %MIDI::Simple::Note | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | elsif ( lc $key eq 'note2number' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 128 | map { $_ => $MIDI::note2number{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | sort { $MIDI::note2number{$a} <=> $MIDI::note2number{$b} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | keys %MIDI::note2number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | elsif ( lc $key eq 'number2note' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 128 | map { $_ => $MIDI::number2note{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | sort { $a <=> $b } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | keys %MIDI::number2note | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | elsif ( lc $key eq 'patch2number' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 128 | map { $_ => $MIDI::patch2number{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | sort { $MIDI::patch2number{$a} <=> $MIDI::patch2number{$b} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | keys %MIDI::patch2number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | elsif ( lc $key eq 'number2patch' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 128 | map { $_ => $MIDI::number2patch{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | sort { $a <=> $b } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | keys %MIDI::number2patch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | elsif ( lc $key eq 'notenum2percussion' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 47 | map { $_ => $MIDI::notenum2percussion{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | sort { $a <=> $b } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | keys %MIDI::notenum2percussion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | elsif ( lc $key eq 'percussion2notenum' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 47 | map { $_ => $MIDI::percussion2notenum{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | sort { $MIDI::percussion2notenum{$a} <=> $MIDI::percussion2notenum{$b} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | keys %MIDI::percussion2notenum | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | elsif ( lc $key eq 'all_events' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | return \@MIDI::Event::All_events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | elsif ( lc $key eq 'midi_events' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | return \@MIDI::Event::MIDI_events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | elsif ( lc $key eq 'meta_events' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | return \@MIDI::Event::Meta_events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | elsif ( lc $key eq 'text_events' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | return \@MIDI::Event::Text_events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | elsif ( lc $key eq 'nontext_meta_events' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | return \@MIDI::Event::Nontext_meta_events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub reverse_dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reverse_dump: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my ($name, $precision) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | $precision //= -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$precision //= -1
MC/DC0%0/1
$precision //= -1
$precision
Truth table0%0/2
A
A= $precision
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my %by_value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my $dump = midi_dump($name); # dumps an arrayref | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | for my $key (keys %$dump) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | my $val = $name eq 'length' && $precision >= 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | ? sprintf('%.*f', $precision, $dump->{$key}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | : $dump->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name eq "length" and $precision >= 0
MC/DC0%0/2
$name eq "length" and $precision >= 0
$name eq "length"
$precision >= 0
Truth table0%0/3
A and B
A= $name eq "length"B= $precision >= 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $by_value{$val} = $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | return \%by_value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | sub midi_format { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
midi_format: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | my (@notes) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | my $flag = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | ▶ | if ($notes[0] =~ /^(\d)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $flag = shift @notes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | my @formatted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | for my $note (@notes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 4 | $note =~ s/C##/D/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 4 | $note =~ s/D##/E/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 4 | $note =~ s/F##/G/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 4 | $note =~ s/G##/A/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 4 | $note =~ s/Dbb/C/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 4 | $note =~ s/Ebb/D/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 4 | $note =~ s/Abb/G/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 4 | $note =~ s/Bbb/A/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 4 | $note =~ s/E#/F/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | $note =~ s/B#/C/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | $note =~ s/Cb/B/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 4 | $note =~ s/Fb/E/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 4 | ▶ | if ($flag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 4 | $note =~ s/#/s/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 4 | $note =~ s/b/f/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | push @formatted, $note; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | return @formatted; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | ▶ | sub set_time_signature { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_time_signature: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | my ($score, $signature) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 1 | my ($beats, $divisions) = split /\//, $signature; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | ▶ | $score->time_signature( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | $beats, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | ($divisions == 8 ? 3 : 2), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | ($divisions == 8 ? 24 : 18 ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | ▶ | sub dura_size { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dura_size: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | my ($duration, $ppqn) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 4 | ▶ | $ppqn ||= TICKS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ppqn ||= 96
MC/DC0%0/1
$ppqn ||= 96
$ppqn
Truth table50%1/2
A
A= $ppqn
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 4 | my $size = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 4 | ▶ | if ($duration =~ /^d(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | $size = sprintf '%0.f', $1 / $ppqn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | $size = $MIDI::Simple::Length{$duration}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | return $size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | ▶ | sub ticks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ticks: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | my ($score) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | return ${ $score->{Tempo} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 2 | ▶ | sub timidity_conf { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
timidity_conf: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | my ($soundfont, $config_file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 2 | my $config = "soundfont $soundfont\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | ▶ | write_text($config_file, $config) if $config_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | return $config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | sub play_timidity { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play_timidity: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my ($score, $midi, $soundfont, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $score->write_score($midi); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my @cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ($soundfont) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | $config ||= 'timidity-midi-util.cfg'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config ||= "timidity-midi-util.cfg"
MC/DC0%0/1
$config ||= "timidity-midi-util.cfg"
$config
Truth table0%0/2
A
A= $config
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | timidity_conf($soundfont, $config); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | @cmd = ('timidity', '-c', $config, '-Od', $midi); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | @cmd = ('timidity', '-Od', $midi); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | system(@cmd) == 0 or die "system(@cmd) failed: $?"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | sub play_fluidsynth { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play_fluidsynth: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my ($score, $midi, $soundfont, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $score->write_score($midi); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if (!$config && $^O eq 'darwin') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
not $config and $^O eq "darwin"
MC/DC0%0/2
not $config and $^O eq "darwin"
not $config
$^O eq "darwin"
Truth table0%0/3
not(A) and B
A= not $configB= $^O eq "darwin"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $config = [qw(-a coreaudio -m coremidi -i)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | ▶ | elsif (!$config && $^O eq 'MSWin32') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
not $config and $^O eq "MSWin32"
MC/DC0%0/2
not $config and $^O eq "MSWin32"
not $config
$^O eq "MSWin32"
Truth table0%0/3
not(A) and B
A= not $configB= $^O eq "MSWin32"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $config = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | elsif (!$config) { # linux | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $config = [qw(-a alsa -m alsa_seq -i)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my @cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | @cmd = ('fluidsynth', @$config, $soundfont, $midi); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | system(@cmd) == 0 or die "system(@cmd) failed: $?"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 1 | ▶ | sub get_microseconds { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_microseconds: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | my ($score) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | ▶ | my $tempo = first { $_->[0] eq 'set_tempo' } @{ $score->{Score} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 1 | return $tempo->[2] / ${ $score->{Tempo} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | ▶ | sub score2events { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
score2events: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | my ($score) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | return MIDI::Score::score_r_to_events_r($score->{Score}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | ▶ | sub scale_names { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
scale_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | return [ sort keys %original_modes ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||