Majoring in Scales
In western music, the twelve notes used in musical notation are arranged in the following order: C/B# C#/Db D D#/Eb E/Fb F/E# F#/Gb G G#/Ab A A#/Bb B/Cb
Note that a slash in the above list indicates alternate notations for the same note.
Any two notes that are adjacent to each other in the above list are known as a semitone. Any two notes that have one note separating them in the list above are known as a tone. A major scale is made up of 8 notes. It starts on one of the above notes and moves in the progression tone-tone-semitone- tone-tone-tone-semitone. For example, the major scale starting on Db is made up of the following notes:
Db Eb F Gb Ab Bb C Db
The following rules also apply to major scales:
- The scale will contain each letter from A to G once and only once, with the exception of the first letter of the scale (which will be repeated as the last note of the scale).
- The scale may not contain a combination of both flat (b) notes and sharp (#) notes.
For the purposes of this problem, we are only concerned with the following major scales: C, Db, D,
Eb, E, F, Gb, G, Ab, A, Bb, and B.
An interval is a distance between two notes on a scale. It can be either ascending or descending. The names of the intervals are derived by the distance between the two notes. Two notes adjacent to each other in a major scale are known as a major second. Two notes in a major scale with three notes separating them are known as a major fifth. An octave is a special interval which spans from one occurrence of a note to the next occurrence of it in the major scale.
Input
Your program is to read an input file that contains major scale intervals to calculate, and is to output the results to an output file. The data in the input file will consist of pairs of lines. The first line of each pair will contain the major scale to be used, and the second line of each pair will contain one or more intervals to be calculated. Each interval to be calculated will be separated by a semicolon. The interval to calculate will be specified with a starting note, a direction (UP or DOWN), and the interval itself (SECOND, THIRD, FOURTH, FIFTH, SIXTH, SEVENTH, or OCTAVE). When specifying notes, the lowercase letter ‘b’ will be used to represent a flat, and the symbol ‘#’ will be used to represent a sharp. No spaces will immediately precede or follow a semicolon, but one space will separate the note from the direction as well as the direction from the interval.
Output
The output file should be formatted as shown below, with a blank line after every test case. Each pair of lines in the input file will produce a line stating the key, followed by the results of the calculated intervals, one interval per line. If the starting note of the interval is not a part of the major scale being used, the program should output ‘invalid note for this key’.
The following example shows more clearly the format of the input and output files:
2/2 Sample Input
C
F UP SECOND;G DOWN THIRD
E
F# DOWN FOURTH;Bb DOWN SEVENTH;B UP OCTAVE
Sample Output
Key of C
F: UP SECOND > G
G: DOWN THIRD > E
Key of E
F#: DOWN FOURTH > C#
Bb: invalid note for this key
B: UP OCTAVE > B