| 1 | package Peta::Synth::Arpeggiator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: the keys held, played one after another in a pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # An arpeggiator: the keys held on a channel played one after another, in a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # pattern, in time, as hardware synthesizers have it. It hears the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # channel's keys (press, release) and gives the notes to play as events at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # sample times (events): a note on at each step, its note off a gate later. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # The patterns are those of Music::MelodicDevice::Arpeggiation (up, down, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # updown, random, converge, diverge, pedal_up, pedal_down, pedal_updown), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # and besides downup, played (in the order the keys came) and chord (every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # key at each step). Over more octaves the keys are repeated an octave up, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # and again. Latched, the keys go on after they are let go, until the next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # chord is pressed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # on 0 or 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # mode the pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # rate steps a beat: 1/4, 1/8, 1/8T (triplets), 1/16, 1/16T, 1/32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # tempo beats a minute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # octaves 1 .. 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # gate a note's length, a share of its step | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # swing every second step later by this share of a step (0 .. 0.5), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # the first longer as much | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # latch 0 or 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 16 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 16 | our $VERSION = '0.2610180'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 16 | my @MODES = qw(up down updown downup random played chord converge diverge pedal_up pedal_down pedal_updown); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 16 | my %RATE = ('1/4' => 1, '1/8' => 2, '1/8T' => 3, '1/16' => 4, '1/16T' => 6, '1/32' => 8); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 16 | my @RATES = ('1/4', '1/8', '1/8T', '1/16', '1/16T', '1/32'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # The settings an editor shows: name, min, max, scale (lin, int, choice), its choices. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 16 | my @FIELDS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | [ on => 0, 1, 'int' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | [ mode => 'up', 'pedal_updown', 'choice', [@MODES] ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | [ rate => '1/4', '1/32', 'choice', [@RATES] ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | [ tempo => 30, 300, 'lin' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | [ octaves => 1, 4, 'int' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | [ gate => 0.05, 1, 'lin' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | [ swing => 0, 0.5, 'lin' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | [ latch => 0, 1, 'int' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 16 | my %DEFAULT = (on => 0, mode => 'up', rate => '1/16', tempo => 120, octaves => 1, gate => 0.5, swing => 0, latch => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 7 | ▶ | sub field_info () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
field_info: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | return [ map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 7 | my ($name, $min, $max, $scale, $choices) = @$_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 56 | ▶ | +{ name => $name, min => $min, max => $max, scale => $scale, $choices ? (choices => $choices) : () }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } @FIELDS ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 112 | ▶ | sub defaults () { return {%DEFAULT} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # Steered by MIDI: NRPN 0x7D (125), its LSB the setting, data entry its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # value (CC6, and CC38 for tempo's low seven bits): 0 on (64 and up), 1 the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # pattern (0 .. 11, as @MODES has them), 2 the rate (0 .. 5, as @RATES), 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # the tempo (beats a minute, 14 bits), 4 octaves, 5 gate (0 .. 127 of a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # step), 6 swing (0 .. 127 of half a step), 7 latch (64 and up). A setting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # as (name => value); none for what is out of range. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 16 | ▶ | use constant NRPN => 0x7d; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 12 | ▶ | sub nrpn ($setting, $msb, $lsb = 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nrpn: called CC=14 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 12 | ▶ | my $clamp = sub ($v, $lo, $hi) { $v < $lo ? $lo : $v > $hi ? $hi : $v }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 12 | ▶ | return (on => $msb >= 64 ? 1 : 0) if $setting == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 11 | ▶ | return $MODES[$msb] ? (mode => $MODES[$msb]) : () if $setting == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 7 | ▶ | return $RATES[$msb] ? (rate => $RATES[$msb]) : () if $setting == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | ▶ | return (tempo => $clamp->(128 * $msb + $lsb, 30, 300)) if $setting == 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | ▶ | return (octaves => $clamp->($msb, 1, 4)) if $setting == 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | return (gate => $clamp->($msb / 127, 0.05, 1)) if $setting == 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | return (swing => $msb / 127 * 0.5) if $setting == 6; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return (latch => $msb >= 64 ? 1 : 0) if $setting == 7; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # new(rate => samples a second, channel => 0 .. 15, settings => {...}). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 57 | ▶ | sub new ($class, %arg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | srate => $arg{rate} // 48000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 57 | ▶ | channel => $arg{channel} // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
$arg{"rate"} // 48000
$arg{"channel"} // 0
MC/DC0%0/1
$arg{"rate"} // 48000
$arg{"rate"}
MC/DC100%1/1
$arg{"channel"} // 0
$arg{"channel"}
Truth table50%1/2
A
A= $arg{"rate"}
Truth table100%2/2
A
A= $arg{"channel"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | set => {%DEFAULT}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | held => [], # the keys held (or latched): [key, velocity, held down], in the order pressed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | pattern => undef, # the steps, made again when the keys change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | step => 0, # the next step's place in the pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | count => 0, # steps played since the keys began (for the swing) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | next => undef, # the next step's sample; undef: stopped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | offs => [], # the notes sounding: [sample of their off, key] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | seed => 12345, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 57 | ▶ | $self->set(%{ $arg{settings} // {} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"settings"} // {}
MC/DC0%0/1
$arg{"settings"} // {}
$arg{"settings"}
Truth table50%1/2
A
A= $arg{"settings"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 56 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 4425 | ▶ | sub on ($self) { return $self->{set}{on} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1056 | ▶ | sub params ($self) { return { %{ $self->{set} } } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
params: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Settings changed; an unknown one dies. Turned off, what it plays is let | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # go (see stop); the latch let go, the keys no longer held down are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # forgotten. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 187 | ▶ | sub set ($self, %fields) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 187 | for my $name (keys %fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 909 | ▶ | die "the arpeggiator has no '$name'\n" if !exists $DEFAULT{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 909 | my $value = $fields{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 909 | ▶ | die "'$value' is no arpeggiator mode\n" if $name eq 'mode' && !grep { $_ eq $value } @MODES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$name eq "mode" and not grep({$_ eq $value;} @MODES)
MC/DC100%2/2
$name eq "mode" and not grep({$_ eq $value;} @MODES)
$name eq "mode"
not grep({$_ eq $value;} @MODES)
Truth table100%3/3
A and not(B)
A= $name eq "mode"B= not grep({$_ eq $value;} @MODES)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 908 | ▶ | die "'$value' is no arpeggiator rate\n" if $name eq 'rate' && !$RATE{$value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name eq "rate" and not $RATE{$value}
MC/DC0%0/2
$name eq "rate" and not $RATE{$value}
$name eq "rate"
not $RATE{$value}
Truth table66%2/3
A and not(B)
A= $name eq "rate"B= not $RATE{$value}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 908 | $self->{set}{$name} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 186 | ▶ | @{ $self->{held} } = grep { $_->[2] } @{ $self->{held} } if exists $fields{latch} && !$fields{latch}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $fields{"latch"} and not $fields{"latch"}
MC/DC100%2/2
exists $fields{"latch"} and not $fields{"latch"}
exists $fields{"latch"}
not $fields{"latch"}
Truth table100%3/3
A and not(B)
A= exists $fields{"latch"}B= not $fields{"latch"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 186 | $self->{pattern} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 186 | ▶ | $self->{step} = 0 if exists $fields{mode} || exists $fields{octaves}; # a new pattern from its start | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $fields{"mode"} or exists $fields{"octaves"}
MC/DC100%2/2
exists $fields{"mode"} or exists $fields{"octaves"}
exists $fields{"mode"}
exists $fields{"octaves"}
Truth table100%3/3
A or B
A= exists $fields{"mode"}B= exists $fields{"octaves"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 186 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # How long the first step waits for the other keys of a chord (seconds). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 16 | ▶ | use constant CHORD => 0.01; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # A key pressed: into the chord (a latched chord let go is replaced by the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # next one pressed); the first starts the steps, 10 ms after it (the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # chord's other keys). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 56 | ▶ | sub press ($self, $key, $velocity, $at) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
press: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 56 | ▶ | $self->{held} = [] if $self->{set}{latch} && !grep { $_->[2] } @{ $self->{held} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"set"}{"latch"} and not grep({$_->[2];} @{$$self{"held"};})
MC/DC100%2/2
$self->{"set"}{"latch"} and not grep({$_->[2];} @{$$self{"held"};})
$self->{"set"}{"latch"}
not grep({$_->[2];} @{$$self{"held"};})
Truth table100%3/3
A and not(B)
A= $self->{"set"}{"latch"}B= not grep({$_->[2];} @{$$self{"held"};})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 56 | @{ $self->{held} } = grep { $_->[0] != $key } @{ $self->{held} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 56 | push @{ $self->{held} }, [ $key, $velocity, 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 56 | $self->{pattern} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 56 | ▶ | if (!defined $self->{next}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 19 | @$self{qw(next step count)} = ($at + int(CHORD * $self->{srate}), 0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 56 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # A key let go: out of the chord, unless latched. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 9 | ▶ | sub release ($self, $key, $at) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
release: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 9 | ▶ | my ($note) = grep { $_->[0] == $key } @{ $self->{held} } or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 9 | $note->[2] = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 9 | ▶ | return if $self->{set}{latch}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | @{ $self->{held} } = grep { $_->[0] != $key } @{ $self->{held} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | $self->{pattern} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # Every key forgotten and what sounds let go now: [sample, event] for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # note offs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 231 | ▶ | sub stop ($self, $at) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: called CC=1 SCAR=0.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my @events = map { [ $at, $self->_off($_->[1]) ] } @{ $self->{offs} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 231 | @$self{qw(held pattern next offs marked)} = ([], undef, undef, [], 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 231 | return @events; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # What is due in [$from, $to) (samples): the note offs, and a mark for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # next step ({ type => 'arp_step', channel }), whose notes are chosen when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # it comes (step), of the keys held then. [sample, event], in time order. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 242 | ▶ | sub events ($self, $from, $to) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
events: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 242 | my @events = $self->_due_offs($to, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 242 | ▶ | if (defined $self->{next} && !$self->{marked} && $self->{next} < $to) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $self->{"next"} and not $self->{"marked"} and $self->{"next"} < $to
defined $self->{"next"} and not $self->{"marked"}
MC/DC66%2/3
defined $self->{"next"} and not $self->{"marked"} and $self->{"next"} < $to
defined $self->{"next"}
not $self->{"marked"}
$self->{"next"} < $to
Truth table75%3/4
A and not(B) and C
A= defined $self->{"next"}B= not $self->{"marked"}C= $self->{"next"} < $to
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 147 | ▶ | push @events, [ $self->{next} < $from ? $from : $self->{next}, { type => 'arp_step', channel => $self->{channel} } ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 147 | $self->{marked} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 242 | return sort { $a->[0] <=> $b->[0] } @events; # sort is stable: offs before a step of their sample | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # The step marked, played at $at: its notes on, [sample, event] (their note | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # offs kept for events). With no key held, the steps stop. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 147 | ▶ | sub step ($self, $at) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
step: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 147 | $self->{marked} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 147 | ▶ | return if !defined $self->{next}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 147 | ▶ | if (!@{ $self->{held} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | $self->{next} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 146 | my $length = $self->{srate} * 60 / $self->{set}{tempo} / $RATE{ $self->{set}{rate} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 146 | ▶ | my $swing = $self->{set}{swing} * ($self->{count} % 2 ? -1 : 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 146 | my $off = $at + _max(1, int($self->{set}{gate} * $length + 0.5)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 146 | my @ons; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 146 | for my $note ($self->_notes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 150 | my ($key, $velocity) = @$note; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 150 | push @ons, [ $at, { type => 'note_on', channel => $self->{channel}, key => $key, velocity => $velocity, arp => 1 } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 150 | push @{ $self->{offs} }, [ $off, $key ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 146 | $self->{next} += $length * (1 + $swing); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 146 | $self->{count}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 146 | return @ons; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # What it plays in [$from, $to) on its own, not in a synthesizer: the note | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # events, [sample, event], in time order. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 22 | ▶ | sub play ($self, $from, $to) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
play: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 22 | my @played; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 22 | ▶ | while (my @events = $self->events($from, $to)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 163 | ▶ | push @played, map { $_->[1]{type} eq 'arp_step' ? $self->step($_->[0]) : $_ } @events; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 22 | return sort { $a->[0] <=> $b->[0] } @played; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 146 | ▶ | sub _max ($a, $b) { return $a > $b ? $a : $b } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_max: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 149 | ▶ | sub _off ($self, $key) { return { type => 'note_off', channel => $self->{channel}, key => $key, arp => 1 } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_off: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # The note offs due: at a step, those at it or before (so that a note | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # ends before the same key begins again); at the end, those before it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 242 | ▶ | sub _due_offs ($self, $at, $before_only = 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_due_offs: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 242 | my (@due, @later); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 242 | for my $off (@{ $self->{offs} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 174 | ▶ | my $due = $before_only ? $off->[0] < $at : $off->[0] <= $at; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 174 | ▶ | if ($due) { push @due, [ $off->[0], $self->_off($off->[1]) ] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 25 | else { push @later, $off } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 242 | $self->{offs} = \@later; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 242 | return @due; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # The step's notes: [key, velocity], one but in chord mode. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 146 | ▶ | sub _notes ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_notes: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 146 | ▶ | my $pattern = $self->{pattern} //= $self->_pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"pattern"} //= $self->_pattern
MC/DC0%0/2
$self->{"pattern"} //= $self->_pattern
$self->{"pattern"}
$self->_pattern
Truth table66%2/3
A //= B
A= $self->{"pattern"}B= $self->_pattern
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 146 | my $mode = $self->{set}{mode}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 146 | ▶ | return @{ $pattern->[0] } if $mode eq 'chord'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 144 | ▶ | my $place = $mode eq 'random' ? int($self->_random * @$pattern) : $self->{step} % @$pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 144 | $self->{step}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 144 | return $pattern->[$place]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # The pattern of the keys held: the notes in the order they are played (a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # step each; in chord mode one step of them all). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 22 | ▶ | sub _pattern ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pattern: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 22 | my $set = $self->{set}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 22 | ▶ | my @keys = $set->{mode} eq 'played' ? @{ $self->{held} } : sort { $a->[0] <=> $b->[0] } @{ $self->{held} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | my @notes = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 23 | my $up = 12 * $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 23 | map { [ $_->[0] + $up, $_->[1] ] } grep { $_->[0] + $up <= 127 } @keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 22 | } 0 .. $set->{octaves} - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 22 | ▶ | return [ \@notes ] if $set->{mode} eq 'chord'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 21 | my $mode = $set->{mode}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 21 | my $last = $#notes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 21 | ▶ | return [@notes] if $mode eq 'up' || $mode eq 'played' || $mode eq 'random' || $last < 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$mode eq "up" or $mode eq "played" or $mode eq "random" or $last < 1
$mode eq "up" or $mode eq "played" or $mode eq "random"
$mode eq "up" or $mode eq "played"
MC/DC75%3/4
$mode eq "up" or $mode eq "played" or $mode eq "random" or $last < 1
$mode eq "up"
$mode eq "played"
$mode eq "random"
$last < 1
Truth table80%4/5
A or B or C or D
A= $mode eq "up"B= $mode eq "played"C= $mode eq "random"D= $last < 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 8 | ▶ | return [ reverse @notes ] if $mode eq 'down'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 7 | ▶ | return [ @notes, reverse @notes[ 1 .. $last - 1 ] ] if $mode eq 'updown'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 6 | ▶ | return [ reverse(@notes), @notes[ 1 .. $last - 1 ] ] if $mode eq 'downup'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 5 | ▶ | return [ _converge(@notes) ] if $mode eq 'converge'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | ▶ | return [ reverse _converge(@notes) ] if $mode eq 'diverge'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 3 | my @pedal_up = map { ($notes[0], $notes[$_]) } 1 .. $last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 3 | my @pedal_down = map { ($notes[-1], $notes[ $last - $_ ]) } 1 .. $last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 3 | ▶ | return \@pedal_up if $mode eq 'pedal_up'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | ▶ | return \@pedal_down if $mode eq 'pedal_down'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | return [ @pedal_up, @pedal_down[ 1 .. $#pedal_down ] ]; # pedal_updown | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # From the outer notes to the middle: lowest, highest, second lowest, ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | ▶ | sub _converge (@notes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_converge: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2 | ▶ | while (@notes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | push @out, shift @notes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 4 | ▶ | push @out, pop @notes if @notes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | return @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 40 | ▶ | sub _random ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_random: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 40 | $self->{seed} = ($self->{seed} * 1103515245 + 12345) % 2147483648; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 40 | return $self->{seed} / 2147483648; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||