In the previous tutorial on keys and modes we worked with scales and different modes to enrich the harmonies. Now we will add dynamics.
Table of Contents
• • • •
Already in some of the first tutorials you encountered the velocity attribute
of entities which controls how strong a note is played. It is not only a matter of
loudness, also the timbre changes across different velocities. Lower
velocities sound softer, more calm and uniform. While velocity is an audio
engineering term, traditional musicians rather use dynamics.
If you want to preserve the timbre associated with a particular velocity while changing its volume,
it is very hard to achieve with a real instrument. However, on a computer you
can simply amplify the respective channel. This can be achieved by
changing the gain. It acts as a pure post-processing effect multiplying
the volume by the selected gain factor. The default value of gain = 1
means there is no change.
function Main()
{
@span = 12;
@Split(24).Then(idx => @gain = 2 * idx.Relative); //just amplification of the recorded sound
}function Main()
{
@span = 12;
@Split(24).Then(idx => @velocity = idx.Relative); //changes how the real instrument is played
}Since velocity has a far more natural effect, we will not use gain further in this tutorial.
Here comes a more musical example for the dynamics. It plays a simple waltz with accents on the first beat.
function Main()
{
@span = 12;
@instrument = "cello";
@Split(8).Then(measure => {
@Split(3).Then(beat => {
if (beat.IsFirst)
@degree -= measure.Index % 2 == 0 ? 4 : 6;
else
{
@velocity *= 0.6; //reduce velocity at the 2nd and 3rd beat
@span *= 0.5;
}
});
});
}For computer scientists it is common to represent everything with numbers.
If you feel more comfortable with musical markings, there is a set
of predefined constants following standard musical notation: ppppp, pppp, ppp, pp, p,
mp, mf, f, ff, fff, ffff. They reside in the Dynamics enum.
Note that velocities below ppp and above fff are rarely used.
var dynamics = [Dynamics.ppppp, Dynamics.pppp, Dynamics.ppp, Dynamics.pp, Dynamics.p, Dynamics.mp, Dynamics.mf, Dynamics.f, Dynamics.ff, Dynamics.fff, Dynamics.ffff];
function Main()
{
@span = dynamics.Length * 3;
@instrument = "cello";
@Split(dynamics.Length).Then(idx => @velocity = dynamics[idx.Index]);
@span *= 0.9;
}The default velocity corresponds to Dynamics.mf.
D♭ also offers smooth transitions between different velocities. Some instruments
are built so that they support velocity changes during the playback of a single
note, e.g. violins, oboes or trombones. Others like all the percussion,
piano or acoustic guitar do not.
Let us demonstrate the dynamic transitions with a french horn. The following example will keep the first note silent while the second will be very loud. There is no gradual change within the single notes yet.
function Main()
{
@span = 4;
@instrument = "french horn";
@Split(2).Then(idx => @velocity = idx.Index);
}Crescendo (gradually louder) and decrescendo (gradually more silent) transitions
can be activated for entities to produce a gradual change in dynamics.
The corresponding attribute is called transitions.
It works in a different way than other attributes. First of all, it
only applies to entities from a single track (see the very last example in this tutorial).
A dynamic transition covers all upcoming entities in the
track until terminated. Transitions are terminated implicitly when:
velocity changes, or
the dynamics flag is removed from transitions or
the track ends.
Let us activate a dynamic transition for the previous example.
The transitions attribute is a set of flags for different
transitions (see following tutorials). Enabling dynamics transition
means adding it to the set. The safest way is to use the += operator
which also preserves any other active transitions.
function Main()
{
@span = 4;
@instrument = "french horn";
@Split(2).Then(idx => {
@velocity = idx.Index;
@transitions += Transition.Velocity;
});
}The first note is now gradually louder until it reaches the full strength at the second note.
If you wish to keep getting louder at the second note as well, you will need a little hack, since
dynamic transitions stop at the beginning of the note that defines a new velocity. So
let us shift the @velocity = 1 to a third note that will be just a rest, yet it
will convey the dynamics information needed.
function Main()
{
@span = 4;
@instrument = "french horn";
@Split(2).Then(idx => {
@velocity = 0.1; //a dynamic transition only works while velocity is constant
@transitions += Transition.Velocity;
if (idx.IsLast) //append a fictive rest after the last note
@Append().Then(() => {
@velocity = 1;
@Rest();
});
});
}Notice that @velocity = 0.1 for both notes, since the transition
is evaluated once the velocity changes. If we would assign a different
velocity to the second note, the transition would cover only the first
note and the second one would be constant. The result would sound like
the previous example.
D♭ transitions have a simple correction mechanism. If you happen to assign the velocity
just for the first note of a transition and keep the rest untouched, for the purposes
of the transition it is recognized as if the velocity would be equal to the first note.
Same holds for the transitions flags. The recognition of the unassigned state
in connection with a linear propagation of the last assigned value in time only works
with respect to transitions.
function Main()
{
@span = 4;
@instrument = "french horn";
@Split(2).Then(idx => {
if (idx.IsFirst) //assign dynamics just for the first note
{
@velocity = 0.1;
@transitions += Transition.Velocity;
}
if (idx.IsLast) //append a fictive rest after the last tone
@Append().Then(() => {
@velocity = 1;
@Rest();
});
});
}A dynamics transition may be stopped by removing the flag from the set of
active transitions. Just as with adding, it is recommended to use
the -= operator to preserve other active transitions.
The following example contains two crescendos separated by a constant part.
The velocity values are set only for the first and for the very last note.
Therefore, removing the dynamics flag only pauses the transition. It
reached half the intensity at the second note, keeps it constant and then
picks up at the third note to reach the maximum intensity at the end.
function Main()
{
@span = 12;
@instrument = "french horn";
@Split(3).Then(idx => {
switch(idx.Index)
{
case 0: @transitions += Transition.Velocity; @velocity = Dynamics.ppp; break;
case 1: @transitions -= Transition.Velocity; break;
case 2: @transitions += Transition.Velocity; @Append().Then(() => { @velocity = Dynamics.fff; @Rest(); }); break;
}
});
}Dynamic transitions are evaluated independently within each instrument track. If
you wish to have two sections of the same instrument playing different
dynamic transitions, make sure to separate them in individual tracks.
function Main()
{
@span = 12;
@instrument = "french horn";
//this shows how overlaying two tracks in parallel
//should NOT be done
//but the appropriate commands @Slice and @Clone will be first
//introduced in the orchestration tutorial
@Split(2).Then(idx => {
if (idx.IsLast) {
@time -= @span; //shift the second part back
@track = 1; //now french horn has two parallel tracks
@octave += 1;
}
});
if (@track == 0)
@Split(2).Then(idx => {
@velocity = Dynamics.pp;
@degree -= idx % 2;
//crescendo
@transitions += Transition.Velocity;
if (idx.IsLast)
@Append().Then(() => {
@velocity = Dynamics.ff;
@Rest();
});
});
else
{
@Split(4).Then(idx => {
@velocity = Dynamics.ff;
@degree += idx.Index;
//decrescendo
@transitions += Transition.Velocity;
if (idx.IsLast)
@Append().Then(() => {
@velocity = Dynamics.pp;
@Rest();
});
});
}
}The first part of this tutorial was concerned with dynamics transitions. Now we will look at pitch transitions which are associated with different articulations. The most common is called legato. It is denoted by slurs over the respective notes. The corresponding D♭ flag is called Transition.Legato.
The following example plays a repeating ascending melody motive. Legato is on by default. Switching it off for the first note of the progression separates it the last note of the previous progression. Try removing the the legato switch and hear the difference.
function Main()
{
@span = 4;
@instrument = "viola";
@Split(2);
@Split(3).Then(i => {
@degree = i;
if (i == 0) //break legato on the first note of the motive
@transitions -= Transition.Legato;
});
}While dynamics flags have effect on the whole sequence that follows, a legato flag only affects the entity it is applied to. So to switch off legato for a whole sequence, it must be deactivated for all of them.
function Main()
{
@span = 4;
@instrument = "viola";
@Split(2).Then(i => @index = i);
@Split(3).Then(i => @degree = i);
if (@index > 0) //do legato only in the first repetition
@transitions -= Transition.Legato;
}Legato is on by default. So in the previous example it needed to be explicitly switched off for the second part. Legato is automatically interrupted:
at a rest or when there is a time gap between notes
at a repeating note
at a non-sustained articulation.
Legato always relates to the previous note, so the flag has no effect for the very first note in a phrase or after an interruption. The previous example can be altered to feature an interruption, resulting in two separated legato sequences. For example, making a note slightly shorter already triggers an interruption of the legato.
function Main()
{
@span = 4;
@instrument = "viola";
@Split(2);
@Split(3).Then(i => {
@degree = i;
if (i.IsLast) @span *= 0.99; //interruption
});
}The second type of interruption can be demonstrated by changing the melody
so that a repeated note occurs. For example, by a modulo setting the last
degree back to 0.
function Main()
{
@span = 4;
@instrument = "viola";
@Split(2);
@Split(4).Then(i => @degree = i % 3); //added a 4th note
}Repeating notes actually need a tie instead of a slur.
The interruption triggered at a repeating note can be overridden
by manually setting the Legato flag Without too much effort,
adding it to the whole phrase will do the job.
function Main()
{
@span = 4;
@instrument = "viola";
@Split(2);
@Split(4).Then(i => @degree = i % 3); //added a 4th note
@transitions += Transition.Legato;
}Important: Coded music sometimes requires long sustained notes to be broken into a sequence of shorter notes tied together. Therefore, please keep in mind that in order to blend them into a single long sustained note Transition.Legato has to be added.
function Main()
{
@span = 6;
@instrument = "viola";
@Split(8);
//@transitions += Transition.Legato; //enable to achive a long sustained note
}The D♭ sampler supports legato only for instruments that are capable of dynamic transitions on sustained notes, so there is no legato for a piano, but bowed strings, woodwinds and brass support it. Legato is also limited to articulations that produce sustained notes, so it is deactivated for staccato or pizzicato and similar.
function Main()
{
@span = 6;
@instrument = "viola";
@Split(8).Then(i => {
@degree = i;
if (i == 4) {
@articulation = Articulations.Pizzicato;
@color = "orange";
}
});
@transitions += Transition.Legato;
}The next tutorial will introduce the exciting world of musical instruments.
D♭ Tutorials — Basic
D♭ Tutorials — Intermediate
D♭ Reference
D♭ Examples
Links