// Path: src/tools/containers/CircularArrayList.java
// public class CircularArrayList<E> extends ArrayList<E> {
// 
//     /**
//      * Overriding of the get method
//      * @param index Index for the access
//      * @return Corresponding value
//      */
//     public E get(int index) {
//         while (index < 0)
//             index += size();
//         index %= size();
//         return super.get(index);
//     }
// }


import tools.containers.CircularArrayList;
import jm.constants.Pitches;
import java.util.Arrays;
import static jm.constants.Pitches.*;
    public Tonality(int tonic, Mode mode, int alteration, int keySignature, int keyQuality) {
        tonic_ = tonic;
        mode_ = mode;
        alteration_ = alteration;
        keySignature_ = keySignature;
        keyQuality_ = keyQuality;
    }

    /**
     * Tonality constructor that processes tonality from key signature and quality
     * @param keySignature Key Signature of the Score
     * @param keyQuality Key Quality of the Score
     */
    public Tonality(int keySignature, int keyQuality)
    {
        keySignature_ = keySignature;
        keyQuality_ = keyQuality;
        alteration_ = 0;
        if (keySignature == 0) {
            if (keyQuality == 0) {
                tonic_ = C0;
                mode_ = Mode.MAJOR;
            }
            else {
                tonic_ = A0;
                mode_ = Mode.MINOR;
            }
            return;
        }
        mode_ = (keyQuality == 0) ? Tonality.Mode.MAJOR : Tonality.Mode.MINOR;
// Path: src/tools/containers/CircularArrayList.java
// public class CircularArrayList<E> extends ArrayList<E> {
// 
//     /**
//      * Overriding of the get method
//      * @param index Index for the access
//      * @return Corresponding value
//      */
//     public E get(int index) {
//         while (index < 0)
//             index += size();
//         index %= size();
//         return super.get(index);
//     }
// }


// Path: src/analysis/harmonic/Tonality.java
import tools.containers.CircularArrayList;
import jm.constants.Pitches;
import java.util.Arrays;
import static jm.constants.Pitches.*;

    public Tonality(int tonic, Mode mode, int alteration, int keySignature, int keyQuality) {
        tonic_ = tonic;
        mode_ = mode;
        alteration_ = alteration;
        keySignature_ = keySignature;
        keyQuality_ = keyQuality;
    }

    /**
     * Tonality constructor that processes tonality from key signature and quality
     * @param keySignature Key Signature of the Score
     * @param keyQuality Key Quality of the Score
     */
    public Tonality(int keySignature, int keyQuality)
    {
        keySignature_ = keySignature;
        keyQuality_ = keyQuality;
        alteration_ = 0;
        if (keySignature == 0) {
            if (keyQuality == 0) {
                tonic_ = C0;
                mode_ = Mode.MAJOR;
            }
            else {
                tonic_ = A0;
                mode_ = Mode.MINOR;
            }
            return;
        }
        mode_ = (keyQuality == 0) ? Tonality.Mode.MAJOR : Tonality.Mode.MINOR;
        CircularArrayList<Integer> order = new CircularArrayList<>(); // Sharp or flat order