# Rhythm extensions for **recip/**kern

(Redirected from Rational rhythms)

## Contents

Rhythm values in **kern and **recip representations are encoded as integers and augmentation dots. For example, "4" represents a quarter note, "16" represents a sixteenth note, and "1" represents a whole note. The integer part of the rhythm value represents the number of notes in that rhythm which can be contained in a whole note. Since four quarter notes can fit into a whole note, the representation for quarter notes is "4".

One way of conceptualizing the rhythmic values is as durations. For example, a quarter note is 1/4th of a whole note. Therefore, durations are the reciprocal of Humdrum rhythm values. Note, however, that Humdrum-derived durations must have a "1" in the numerator, since the rhythm representations are integers. In Humdrum **recip and **kern representations, only the augmentation dots can alter the denominator of the rhythm, or the numerator of the duration: "4." is a dotted quarter note which has a duration that is equal to the duration of a quarter note plus the duration of half of a quarter note: 1/4 + 1/2 * 1/4 = 3/8. Thus, if the augmentation dot did not exist in the Humdrum representations, the rhythm would have to be encoded as 8/3 (the inverse of the duration, since a whole note can contain 2 and 2/3 dotted quarter notes). However, since the rhythm "8/3" contains a denominator, it cannot be represented in **recip or **kern data.

The vast majority of music from 1600-1900 in western music can be encoded without the need for denominator's other than 1 in Humdrum rhythms, but there are certain basic cases such as triplet whole notes, tuplets occurring on dotted rhythms, and notes larger than a whole note that cause representational problems for certain repertories.

## Notes larger than a whole note

A basic escape mechanism which is built into standard Humdrum Toolkit programs is the use of the "0" rhythm to indicate the breve or double-whole note rhythm.

Subsequently, the code "00" was added to represent the (imperfect) long, which has the duration of four whole notes, or two breves. And the code "000" was included to represent the (imperfect) maxima, which has the duration of 8 whole notes, or two longs. These to codes allow for backwards compatibility with regular expressions, since the rhythmic codes contain only a sequence of digits. However, they are not understood by all Humdrum Toolkit programs, and therefore must be used with caution.

## Rational rhythm extension

A further non-backwards compatible extension allows for the encoding of a denominator as well as a numerator in rhythmic codes. In this extension, the numerator and denominator of the rhythm are separated by the "%" character. For example triplet whole notes posses 2/3rds of the duration of whole notes, and therefore a whole note can contain one and a half triplet wholenotes. Thus the rhythmic representation of a triplet whole note is 3/2. When encoded in **recip or **kern data, this is expressed as "3%2". Here is an example of three triplet wholenotes being played against two regular wholenotes:

```  **kern   **kern
3%2c     1c
3%2c     .
.        1c
3%2c     .
*-       *-
```

Breves (double-whole notes) can be represented as "1%2" in the rational extension for rhythm. However, since the code "0" is already used to represent breves, this code should be preferred in order to minimize backwards compatibility issues.

Likewise, long and maxima notes should be represented by "00" and "000" preferably, in order to minimize backwards incompatibility with regular expression searches such as "[0-9]+" or "\d+" in PERL regular expressions. However this is of minor concern, since a new regular expressions can be used:

```   [0-9]+%?[0-9]*            (extended regular expressions)
\d+%?\d*                  (PERL regular expressions)
```

## Backwards compatibility

To warn that the rational rhythm extension is being used, an RDF reference record may be given in the file:

```  !!!RDF**kern: %=rational rhythm
```

or for **recip spines:

```  !!!RDF**recip: %=rational rhythm
```

The "%" character is a user-designated code in **kern data. However, it should no longer be used as such, although it can still be used without collision with the rational rhythm extension since it is not otherwise possible to place digits both before and after a user-signified "%" character.

Rhythm values with a "1" in the denominator should not be encoded as a reciprocal extension. For example, a quarter note rhythm could be expressed as "4%1", but should not. Also using "%" without a digit on both sides of the character should not be done, for example trying to abbreviate "4%1" as "4%", since this use is reserved for a (deprecated) user signifier.

The Humdrum Extras program called rscale can be used to scale rhythms using the rational extension so that they become understood by programs which do not understand the extension. Data encoded with the rational rhythm extension should have a reference record which suggests a rhythmic scaling factor which will convert the data so that the rhythms are backwards-compatible with the basic rhythmic representation:

```   !!!rscale-alt: 1/4
```

This reference record means that in order to get backwards compatible rhythms in the data, apply a 1/4 duration scaling to the notes. This particular scaling would map whole notes to quarter notes, maximas to whole notes, etc.

 ```**kern **name 000e maxima 00f long 0g breve 1a whole 2b half 4cc quarter *- *- !!!rscale-alt: 1/4 ```

Using the -a option (or --alternate) will cause the 1/4 duration scaling to be applied to rhythm values:

```# rscale -a input.krn
```
 ```**kern **name 0e maxima 1f long 2g breve 4a whole 8b half 16c quarter *- *- !!!rscale-alt: 1/4 !!!rscale: 1/4 ```

And to return to the original rational rhythm extension values, use the -o (or --original) option:

```# rscale -a input.krn | rscale -o
```
```**kern  **name
000c    maxima
00d     long
0e      breve
1f      whole
2g      half
4a      quarter
*-      *-
!!!rscale-alt: 1/4
```

Note that applying "rscale -a" to any file which does not contain an "rscale-alt" reference record will echo the original contents of the file. This feature can be used to guarantee backwards-compatible rhythms in a data stream, provided that files with the rational rhythm extension are encoded with the correct "!!!rscale-alt:" rhythmic scaling.

Here is an example for encoding triple whole notes:

```**kern  **kern
3%2c    1c
3%2c    .
.       1c
3%2c    .
*-      *-
!!!rscale-alt: 1/6
```

Then applying the alternate rhythmic scaling of 1/6 will convert whole notes into triplet quarter notes, and triplet whole notes into 1/9th of whole notes (or the nested-tuplet of triplet-quarter notes within triplet half-notes):

```# rscale -a input.krn
```
```**kern  **kern
9c      6c
9c      .
.       6c
9c      .
*-      *-
!!!rscale-alt: 1/6
!!!rscale: 1/6
```