1/* scales.pl
    2Author: Gimenez, Christian.
    3
    4Copyright (C) 2025 Gimenez, Christian
    5
    6This program is free software: you can redistribute it and/or modify
    7it under the terms of the GNU General Public License as published by
    8the Free Software Foundation, either version 3 of the License, or
    9at your option) any later version.
   10
   11This program is distributed in the hope that it will be useful,
   12but WITHOUT ANY WARRANTY; without even the implied warranty of
   13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14GNU General Public License for more details.
   15
   16You should have received a copy of the GNU General Public License
   17along with this program.  If not, see <http://www.gnu.org/licenses/>.
   18
   192025-10-12
   20*/
   21
   22:- module(scales, [
   23              scale_type/1,
   24              scale/3,
   25              arpeggio_type/1,
   26              arpeggio/3,
   27              tonic/2, supertonic/2, mediant/2,
   28              subdominant/2, dominant/2,
   29              submediant/2, leading/2, leading_tone/2
   30          ]).

scales: Scales calculation.

Calculate notes for different scale tipes and any scale-refered concepts.

author
- Christian Gimenez
license
- GPLv3 */
   40:- use_module(library(music/notes)).
 scale_type(?Type:atom)
Supported and implemented scale types.
   45scale_type(major).
   46scale_type(minor).
   47% scale_type(blues).
   48
   49% ! scale(+Type, +Start, -Notes) is det.
   50% 
   51% @param Type The type of scale. See scale_type/1.
   52scale(major, C, [C, D, E, F, G, A, B, C]) :-
   53    tone(C, D),
   54    tone(D, E),
   55    semitone(E, F),
   56    tone(F, G),
   57    tone(G, A),
   58    tone(A, B),
   59    semitone(B, C).
   60scale(minor, A, [A, B, C, D, E, F, G, A]) :-
   61    tone(A, B),
   62    semitone(B, C),
   63    tone(C, D),
   64    tone(D, E),
   65    semitone(E, F),
   66    tone(F, G),
   67    tone(G, A).
   68
   69tonic([Note|_], Note).
   70supertonic([_, Note|_], Note).
   71mediant([_, _, Note|_], Note).
   72subdominant([_, _, _, Note|_], Note).
   73dominant([_, _, _, _, Note|_], Note).
   74submediant([_, _, _, _, _, Note|_], Note).
   75leading_tone([_, _, _, _, _, _, Note|_], Note).
   76leading(List, Note) :-
   77    leading_tone(List, Note).
 arpeggio_type(-Type:atom)
Arpeggios types for this library implementation.
   82arpeggio_type(major).
   83arpeggio_type(minor).
 arpeggio(+Type:atom, +ScaleNote:atom, -NoteList:list)
Calculate the arpeggio notes of the given scale.
   88arpeggio(Type, C, [C, E, G]) :-
   89    arpeggio_type(Type), !,
   90    third(Type, C, E),
   91    fifth(C, G).
scale_notes(Type, C, Amount, List) :-