Velocity, Playing Durations, and Time Shifts

This chapter explains directions for musical expression that can be specified for each note. Additionally, context attributes, which are the underlying mechanism for these directions, are described.

Velocity

Velocity is a terminology of MIDI that represents the speed of a key press, meaning the dynamics of the sound (it can also be used for instruments other than keyboard instruments). The velocity value ranges from 1 to 127. In Pytakt, the default velocity value is 80.

To specify velocity, write v= followed by the velocity value. This sets the velocity for subsequent notes.

cde v=90 fg v=80 ab
Notes Velocity
c, d, e 80
f, g 90
a, b 80

When velocity is specified within a block enclosed by curly braces or square brackets, that specification is only valid within that block. Upon exiting the block, the value reverts to the original value when entering the block. Therefore, the above example is equivalent to the following:

cde {v=90 fg} ab

Here is another example. The velocity of each note is shown in the table below.

[v=100 c {d v=90 e v=85 f}/3 g] a
Notes Velocity
c, d, g 100
e 90
f 85
a 80

You can use expressions containing arithmetic operations to specify the values, and you can use v within the expression to represent the current velocity value. For example, you can write v=v+10 to increase the velocity value by 10 from the current value. Furthermore, in cases like v=v10 (where • is +, -, *, or /), it can be abbreviated as v=10. Therefore, the first example can also be written as follows:

cde {v+=10 fg} ab

Additionally, when changing velocity for only one note or chord, you can specify it immediately after the note (or chord) using parentheses, such as c(v=90) or [ceg](v+=10). These are equivalent to {v=90 c} and [v+=10 ceg], respectively, but they make it clearer that the specification applies only to a single note or chord. Furthermore, symbols ` (backquote) and ? can be used instead of (v+=10) and (v-=10), respectively (see example below).

c d(v*=1.2) e`` f? [gab`]`
Note Velocity
c 80
d 96
e 100
f 70
g 90
a 90
b 100

In other words, ` (backquote) corresponds to accent, while ? corresponds to deaccent. The default value for the increase/decrease amount is 10, but it can be customized.

Playing durations

In Pytakt, the time between the start of a note (note-on) and its end (note-off) is referred to as playing duration (this is sometimes called gate time in other software). While the note duration (or note value) represents the length of the note on the score, when actually performed, the sound is often not sustained for its full length. Instead, performers frequently add expression to the piece by either making the note off earlier (corresponding to staccato), or conversely, delaying the note off to partially overlap with the next note (corresponding to legatissimo). Specifying the playing duration allows control over such articulations.

Pytakt offers two methods for specifying playing duration: specifying a percentage relative to the note duration, or specifying an absolute length.

To specify a percentage relative to the note duration, modify the setting named dr (in Pytakt, such settings are called context attributes). Changes are made in the same way as for velocity, that is, dr=value or dr=value (where • is either +, -, *, or /). The default value of dr is 100, meaning the playing duration equals the note duration. Examples of dr settings are shown below.

dr=50 c{d dr=25 e}/ f~(dr=80)
Note Note duration (ticks) Playing duration (ticks)
c 480 240
d 240 120
e 240 60
f 960 768

Additionally, the symbol ! is provided as an equivalent for (dr*=0.5), corresponding to a staccato. Therefore, the above example can also be written as

c!{d! e!!}/ f~(dr=80)

To directly specify the playing duration, use the du context attribute. Setting a positive value to du makes that value become the playing duration, regardless of the note duration. Setting a negative value to du makes the playing duration equal to the note duration plus that negative value. This effectively maintains a constant gap between notes.

When both dr and du are set, the one set later overrides the earlier. For example, dr=60 c d(du=240) sets the playing duration of the D note to 240 ticks, not 144 ticks.

Time shifts

The playing duration mentioned above was for controlling the note-off time, but sometimes you may want to shift the note-on time slightly from the time on the score during playback. In such cases, you can use the dt context attribute. Setting a value to dt adds that value to both the note-on and note-off times during playback. For example,

c(dt=30) e(dt=-60)

makes the note-on and note-off times (in ticks) as follows:

Note Without the dt setting With the dt setting
Note-on time Note-off time Note-on time Note-off time
c 0 480 30 510
d 480 960 420 900

The symbols < and > can be used for time shifts, equivalent to (dt-=30) and (dt+=30) respectively (where 30 corresponds to the length of a 64th note). Therefore, the above example can also be written as

c> e<<

Note that the absolute value of dt is limited to 1920 (the duration of a whole note).

Other context attributes

In addition to the v, dr, du, and dt described above, the o, key, and L introduced in earlier chapters are also context attributes. Context attributes share a unified specification method: their values can be modified using attribute_name=value or attribute_name=value (where • is either +, -, *, or /), and their scope of effect can be limited using braces, brackets, and parentheses ({, }, [, ], (, )).

The following are context attributes that have not been explained yet.

Attribute name Initial value Meaning
nv None Note-off velocity, representing the speed of key release with values from 0 to 127. Set it to None when not in use.
tk 1 Track number. Specify an integer 0 or greater. Assigning separate track numbers allows individual mute control and placement on different staffs in the score, for example. Outputted MIDI files (format-1) will be split into tracks based on these numbers.
ch 1 MIDI channel number. Specify an integer between 1 and 16. Assigning separate channel numbers allows individual control over parameters such as timbre, pitch bend, and volume. Channel 10 is assigned to rhythmic instruments on most synthesizers.


Last update: Jan 22 2026 12:43 JST     Copyright (C) 2026 Satoshi Nishimura Top Page