# npm

## ji-rcn

9.1.2 • Public • Published

# Just Intonation - Rational Comma Notation

JI-RCN, ji-rcn module. Find module on npm and code repo with examples on GitHub.

Just Intonation (JI) tunes musical instruments to have whole number frequency ratios between notes. This is the natural system of tuning for many important musical instruments, including the human voice, stringed instruments, and wind instruments. For such instruments, JI tuning sounds better, more natural, more 'in tune' than tempered tuning. A common example of tempered tuning is 12TET (12 tone equal temperament) which splits the octave into 12 equal semitones; this is the default modern tuning, used for many instruments such as pianos, but noticeably out of tune from pure JI intervals.

JI can also be called Rational Intonation (RI) since its interval ratios are rational numbers of the form a/b, or equivalently simple ratios of the form a:b. In JI chords with three or more notes make complex ratios of the form a:b:c, a:b:c:d, etc.

• Examples of intervals include: an octave (1:2), a perfect fifth (2:3), a perfect fourth (3:4), a major third (4:5)
• Examples of chords include: a major triad (4:5:6), a minor triad (10:12:15), an extended seventh chord (4:6:7:10)

The tempered tuning 12TET has only 12 notes in the octave. However, Just Intonation has an unlimited number of notes available in the octave. This gives more musical variety, but it poses a greater notational challenge. The whole of 12TET can be notated with less than 100 notations of the form C4, Bb7, E0, etc. However, how is it possible to notate the whole of JI, where there are a potentially infinite number of different notes and chords?

Rational Comma Notation (RCN) was designed to solve this problem. It was developed by David Ryan between 2015 and 2017, and is documented in this paper.

For RCN it is necessary to specify an algorithm which maps any prime p to its prime comma n/m. For example, primes 5 and 7 are usually given commas 80/81 and 63/64 respectively. The primes used in the comma for p are usually 2, 3 and p only (since limiting commas to these three prime components reduces computational complexity). Even with that constraint, algorithms tend to vary for higher primes. Three algorithms which have been developed are: DR, SAG, and KG2; these are each described in the paper above.

The purpose of the ji-rcn npm package is to help convert between:

• A musical interval with a frequency ratio expressed as a rational number
• Start and end points of the interval expressed as:
• Notations from an RCN scheme
• Frequencies in Hz

## Get started with JI-RCN

• npm i ji-rcn to install
• npm test to run all tests
• npm run examples to run examples, which can be found in the GitHub examples directory

## Contents of index

Note that the JInterval class is built upon the Peo class, which stands for 'Prime Exponent Object'. Peo allows exact representations of positive fractions with potentially large numerators and denominators. This is achieved by splitting both numerator and denominator into prime components, and keeping track of exponents of each prime separately using a JSON object. An example is the fraction 45/28 which can be represented as {2:-2, 3:2, 5:1, 7:-1}. The Peo class wraps this object, and provides it with a suitable set of methods, including multiplication. Use require('peo') to access the Peo class.

## Constructors for JInterval

Two types of constructors are available: shorthand constructors taking parameters in separate arguments, and the general constructor which takes all parameters inside one argument which is an object:

### Shorthand constructors

A JInterval instance stores its interval frequency ratio internally as a Peo, for exact representations of positive integers and fractions. All the different ratio formats available in the constructor will get converted into a suitable Peo.

The shorthand constructors above can have an extra argument to specify an algorithm, which may be given as a string acronym, a function, or an object combining these (as described above), e.g. new JInterval(peo, algAcronym), new JInterval(num, denom, algFn) etc.

### Extra options inside constructor object

Example of using an extra option: var jint = new JInterval({ratio: 7/3, alg: 'SAG'}).

For display above, you need a sub-object with any or all of these options set:

Option Format Default Description
hide5 boolean false Syntonic comma 80/81 displayed as ' if false or  if true. Inverse syntonic comma 81/80 displayed as . if false or [1/5] if true.
lev12 positive integer undefined Pythagorean comma 531441/524288 = 3^12/2^19 (23.46 cents) displayed as p, its inverse as d, if this option is set with a positive integer. The integer is the minimum 3-exponent which gets p or d in its notation. Default (undefined) is to not use p or d notation.
lev53 positive integer undefined Mercator comma 3^53/2^84 (3.615 cents) displayed as m, its inverse as w
lev665 positive integer undefined Small comma 3^665/2^1054 (0.07558 cents) displayed as s, its inverse as r
lev190537 positive integer undefined Tiny comma 3^190537/2^301994 (0.0001117 cents) displayed as t, its inverse as y
comMax positive integer 1000 Max number in comma that displays as-is, without factorisation. For example,  is displayed as [7 11 13] if comMax is set lower than 1001. To fully factorise every comma, set comMax to 1.
reps positive integer 4 Max times a character is repeated, without using bracket notation. For example, #### and (#5) are default notations for 4 and 5 sharps respectively.

Another example of using general constructor, including display options:

## JInterval API - Static or Class methods

Some examples of using getComma are given below. Format is either getComma(p) or getComma(p, alg), which both return a Peo. The argument alg can be any of the valid formats, including a recognised text acronym, a function, or an object.

## JInterval API - Instance Methods

### Interval Frequency Ratio

(Also known as interval width, size, relative size, relative position)

### Absolute Position

Every JInterval has a relative size, which a rational number describing the interval's frequency ratio; this is stored as a Peo. Each JInterval may also store a cache of its absolute position, including start and end frequencies in Hz, and start and end notations in RCN. Each JInterval uses either the default tuning {pitchNotation: 'C4', freqHz: 256} or a custom tuning, to convert between frequency and notation. The tuning allows calculating frequency from notation, and notation from frequency.

The set of functions below generate frequency and notation for absolute position. Since parsing notation is slow, and generating notation may be slow, for efficiency the last generated values are cached. When calling the functions below, they return the cached value if it is still available. Any change to the JInterval which might change the absolute position should thus wipe the cache.

Parsing notation is slow. In the situation where you have many instances of JInterval with 1) the same setup options (in particular, tuning), and 2) the same start notation; there is a more efficient method to recalculate the absolute position:

Here are the relevant API calls:

For this internal format, C4 is represented by 1/1, so with jint.setStartPeo(new Peo(1/1)) you are working in the key of C. However the other API calls allow you to work in any key signature, e.g. with jint.getEndNotation('G4') you are working in the key of G. Afterwards you can use var peoG = jint.getStartPeo() and then jint2.setStartPeo(peoG) to continue working in the key of G.

### Maths

Create a new JInterval using mathematical operations on existing intervals. Can be used to quickly generate new JIntervals with same setup as jint:

### Algorithm

An algorithm can be specified on a JInterval during construction, or later on. In ji-rcn, the default algorithm has text acronym DR, and has an associated (internal) comma function getCommaDR. The format for specifying an algorithm as an object is {txt: txt, fn: getCommaFn}, and this format can be obtained from a JInterval using getSetupAlgObject. If txt is one of DR, SAG, KG2 then the function can be omitted since three functions are already internally available for these comma algorithms.

### Tuning

A tuning can be specified on a JInterval during construction, or later on. Default tuning is {pitchNotation: 'C4', freqHz: 256}.

## Examples

There are many more examples in the examples directory on GitHub, you can run them using npm run examples.

## Epilogue

These higher prime commas and notations are being made available to enable writing beautiful JI music that goes way outside the 12 notes of the standard scale. A piece of music written at the prime limit of 2499949 is available here (which used the DR comma given above), and the rest of the author's music is available here.

Hope you will enjoy the infinite possibilities of justly intoned music!

### Install

npm i ji-rcn

### Repository

github.com/davidryan59/ji-rcn

2

9.1.2