.TH KEYVEL 1 "MIDI"
.SH NAME
keyvel \- scale MIDI key velocities
.SH SYNOPSIS
.B keyvel
[\fB\-c\fPcompression]
[\fB\-e\fPexpansion]
[\fB\-g\fPgain]
[\fB\-hist\fP]
[\fB\-r\fPrange]
[\fB\-b\fPbottom]
[\fB\-t\fPtop]
[\fBfiles\fP]
.SH DESCRIPTION
.I Keyvel
processes the attack velocities associated with MIDI "key on" events.
There are five kinds of processing possible \- compression, expansion,
gain, randomization, and limiting.
Gain simply scales the result linearly (e.g the first graph below).
Compression makes a flattened, symmetrical transfer function (e.g. the second
graph below).
Expansion makes a symmetric, smooth, S-curve transfer function (e.g. the third
graph below).
.Cs
127 |       /\-\-\-:       127 |       :      127 |          ___:
    |      /    :           |       :          |         /   :
out |     /     :       out |       /      out |       /     :
    |    /      :           |     / :          |      /      :
 64 |   /       :        64 |   /   :       64 |      |      :
    |  /        :           | /     :          |      /      :
    | /  g=1.4  :           /  c=1. :          |     / e=1.  :
    |/          :           |       :          |___/         :
  0 +\-\-\-\-\-+\-\-\-\-\-+         0 +\-\-\-+\-\-\-+        0 +\-\-\-\-\-\-+\-\-\-\-\-\-+
    0    64    127          0  64  127         0     64     127
         in                    in                    in
.Ce

Randomization adds a normally distributed offset symmetrically around zero
(see the first graph below).  Note that a \fIrange\fP of 7 gives the seven
values \-3, \-2, \-1, 0, +1, +2, and +3.
If multiple randomizations are specified the result becomes more gaussian
(see second graph below).
Limiting assures no values lie outside the prescribed range
(see third graph below).
.Cs
 32% |     r=7     :    32% | r=3 r=3 r=3 :     127 |             :
     |             :        |             :         |  t=112    \-\-:
prob |             :   prob |      +      :     out |          /  :
     |             :        |    +   +    :         |        /    :
 16% |+ + + + + + +:    16% |             :      64 |      /      :
     |             :        |  +       +  :         |    /        :
  8% |             :     8% |             :         |\-\-\-\-   b=32  :
     |             :        |+           +:         |             :
  0% +\-\-\-\-\-\-+\-\-\-\-\-\-+     0% +\-\-\-\-\-\-+\-\-\-\-\-\-+       0 +\-\-\-\-\-\-+\-\-\-\-\-\-+
     \-3     0    +3         \-3     0    +3          0     64     127
          change                change                    in
.Ce

Negative compression makes a symmetric, three-segment expansion.
Negative expansion, makes a symmetric, smooth, S-curve compression.
.PP
The \fIcompression\fP, \fIexpansion\fP, and \fIgain\fP arguments are
floating point numbers.  The default values are 0., 0., and 1.
respectively (giving no alteration of the key velocities).
The \fIrandomization\fP arguments are integers in the range 0 to 256.
The \fIbottom\fP and \fItop\fP limit arguments are integers in the
range 0 to 127.  The default values are 1 and 127.
Note that a bottom limit of 0 may turn some key-on events into
key-off events.
.PP
The \fB\-hist\fP argument suppresses MIDI output and instead prints
a histogram of key velocities.  This is also the default if no processing is
specified.
.SH EXAMPLES
.Cs
keyvel bach
56: 19
60: 36
64: 155
73: 57
82: 28
91: 15
.Ce
Apparently there are 310 key-on events in ``bach'', with half of them
at a key velocity of 64.
.Cs
keyvel \-g0.8 bach > boop
.Ce
makes a copy of "bach" with a quieter touch than the original.
On the other hand,
.Cs
keyvel \-c1 bach > beep
.Ce
copies "bach" with a more even dynamic (centered around 64 in MIDI units).
To exaggerate the expression use something like:
.Cs
keyvel \-e1 bach > blap
.Ce
Note that this is not the inverse of "keyvel \-c1", its true inverse is
"keyvel \-c\-1".
Often pieces generated by simple algorithms have such even, regular dynamics
that they sound mechanical.  A small amount of random variation can be
added with keyvel as in:
.Cs
keyvel \-r11 <piece.robot >piece.droid
.Ce
which will give equal chances (9% each) of altering each velocity by 0, 1, 2, 3,
4, or 5 units up or down.  To make the chances of large changes smaller, but
not nonexistent,
.Cs
keyvel \-r3 \-r3 \-r3 \-r3 \-r3 <piece.robot >piece.droid
.Ce
will make the chance of a +5 change 1/3^5 (0.41%), while the chance of
no change at all will be 51/3^5 (21%).
For brute force limiting there are several possibilities:
.Cs
keyvel \-t90 bach > burp
.Ce
This command clips the loud notes making no note be louder than 90.
.Cs
keyvel \-c99 bach > blorp
keyvel \-b64 \-t64 bach > blorp
keyvel \-g99 bach | keyvel \-g0.5 > blorp
.Ce
All three of these will compress the dynamics out of the piece entirely
(best done only to live bass players and drummers).
.SH SEE ALSO
play(1), record(1), stretch(1), transpose(1), tshift(1), merge(1)
.SH AUTHOR
Peter Langston, Bell Communications Research
(bellcore!psl)
