Predicates that calculates semitones, tones, and intervals in notes.
Names
In order to create a more convenient way to programming with Prolog, name of
notes, intervals, and othe possible concepts are different from literature.
It may be different from Lilypond or other software too.
For instance, C3 is not used to represent C note in Prolog in third octave
because the it would be interpreted as a Prolog variable. Also, 'C3'
or c3
wolud requier extra processing to separate the octave number from the C/c.
However, the c-3
term would represent the C note at 3 octave effectively, and
the octave number is already separated from the note name.
A simmilar approach is implemented for intervals and other concepts.
Note representation
Notes are terms with the following possible representations:
Intervals
Interval calculations can be achieved by the interval/2 and interval/3
predicates, or by using sum_semitones/3 with the specific amount of semitones.
There are also aliases for second/3, third/3, etc.
Intervals are represented as: Nth-Type
. Where Nth is the number of interval,
and the Type is one of the atoms: perfect
, major
, minor
, or extra
. The
4-extra
atom is used to assign a name to the interval between the P4
(perfect 4th) and P5 (perfect 5th) which has 6 semitones of distance. This
interval name does not exists in the literature, and is used to complete the
names to a semitone distance in case the calculations results in that number.
- author
- - Christian Gimenez
- license
- - GPLv3
- note_order(-L:list) is det
- The order of the musical notes in this implementation.
- notenum(+Note:atom, -Num:integer) is det
- notenum(-Note:atom, +Num:integer) is det
- Represent the given note as number, or the number as a note.
When calculating the number, only the first number is given (is determinate).
For instance,
notenum(c, R)
will result in R = 0
, and without more results.
But notenum(c, 12)
is also true (indicating that C note is also represented
as 12).
Representing notes in numbers are easy for calculations. Adding an amount of
semitones to a given note represented as a number instead as a Prolog atom is
more efficient.
If Num is a negative number or greater than 11, it is calculated to be between
0 (c note) to 11 (b note).
- sum_semitones(+StartNote:atom, +Semitones:integer, -EndNote:atom)
- sum_semitones(+StartNote:term, +Semitones:integer, -EndNote:term)
- Calculate the ending note after adding the given semitones.
- Arguments:
-
StartNote | - can be an atom with the note, or a Note-Octave term. |
- sum_tones(+StartNote:atom, +Tones:integer, -ResultNote:atom)
- sum_tones(+StartNote:term, +Tones:integer, -ResultNote:term)
- Same as sum_semitones/3 but using tones as unit.
- Arguments:
-
StartNote | - can be an atom with the note, or a Note-Octave term. |
- tone(+StartNote:atom, -ResultNote:atom)
- tone(+StartNote:term, -ResultNote:term)
- Add a tone to StartNote.
- Arguments:
-
StartNote | - can be an atom with the note, or a Note-Octave term. |
- semitone(+StartNote:atom, -ResultNote:atom)
- semitone(+StartNote:term, -ResultNote:term)
- Add a semitone to StartNote.
- Arguments:
-
StartNote | - can be an atom with the note, or a Note-Octave term. |
- semitones(+FromNote:atom, +ToNote:atom, -Diff:integer)
- semitones(+FromNote:term, +ToNote:term, -Diff:integer)
- Calculate the semitones between FromNote and ToNote.
- Arguments:
-
FromNote | - A Note-Octave or a note name. |
ToNote | - A Note-Octave or a note name. |
Diff | - The amount of semitones between FromNote and ToNote. |
- interval(+Interval:term, -Semitones:integer) is det
- Calculate the semitones of the given interval.
In the literature, the interval between 4-perfect and 5-perfect (6 semitones)
has no name. In this implementation, the term 4-extra is assigned to this
interval.
- Arguments:
-
Interval | - a Number-Type term where Number is the nth interval, and the
type can be the perfect , minor , or major atom. |
Semitones | - the amount of semitones for that interval. |
- interval(+Interval:term, +StartNote:atom, -EndNote:atom)
- Calculate the interval notes.
- second(+Type:atom, +StartNote:atom, -EndNote:atom)
- Calculate the major/minor second interval (M2/m2) of StartNote.
- Arguments:
-
Type | - is the type of interval. Can be the atom major , or minor . |
- third(+Type:atom, +StartNote:atom, -EndNote:atom)
- Calculate the major/minor third interval (M3/m3) of StartNote.
- Arguments:
-
Type | - is the type of interval. Can be the atom major , or minor . |
- fourth(+StartNote:atom, -EndNote:atom)
- Calculate the perfect fourth interval (P4) of StartNote.
- fifth(+StartNote:atom, -EndNote:atom)
- Calculate the perfect fifth interval (P5) of StartNote.
- sixth(+Type:atom, +StartNote:atom, -EndNote:atom)
- Calculate the major/minor sixth interval (M6/m6) of StartNote.
- Arguments:
-
Type | - is the type of interval. Can be the atom major , or minor . |
- seventh(+Type:atom, +StartNote:atom, -EndNote:atom)
- Calculate the major/minor seventh interval (M7/m7) of StartNote.
- Arguments:
-
Type | - is the type of interval. Can be the atom major , or minor . |
- eighth(+StartNote:atom, -EndNote:atom)
- Calculate the perfect eighth interval (P8 or octave) of StartNote.
Same as octave/2.
- octave(+StartNote:atom, -EndNote:atom)
- Calculate the octave of StartNote.
Same as eighth/2.
- transpose(+Notes:list, +Semitones:integer, -NewNotes:list) is det
- Transpose a list notes adding the given semitones.
- transpose(+Notes:list, +FromNote:atom, +ToNote:atom, -NewNotes:list) is det
- Transpose a list notes from the FromNote scale to ToNote scale.
- Arguments:
-
Notes | - A list of notes (all notation accepted). The Notes list is
considered to be in FromNote scale or tuning. |
FromNote | - The source tuning note name. No Note-Octave notation is accepted. |
ToNote | - The destination tuning note name. No Note-Octave notation is accepted. |
NewNotes | - A list of notes with the calculated tuning. |