package tonality;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by olivier on 16/05/16.
 */
public class Scale {
    private int _tonic;
    private String _type; // Minor or Major ?
    private List<Integer> _notes;

    // ---------- Constructors ----------
    public Scale(int tonic, String s, int octaveNumber) {
        _tonic = tonic;
        _type = s;
        setScale(octaveNumber);
    }

    // ---------- Getters ----------
    public int getDegree(int degree) {
        if (_notes != null)
            return _notes.get(degree);
        return 0;
    }

    private ArrayList<Integer> getScale(int tonic, String s, int octaveNumber){
        // We have to check what we ask don't exceed G9 = 127 (highest pitch)
        if (tonic + (octaveNumber * 12) <= 127) {
            ArrayList<Integer> notes = new ArrayList<Integer>();
            for (int i = 0; i < octaveNumber; i++) {
                int[] temp = null;
                switch (s) {
                    case "major":
                        temp = new int[] {tonic, tonic + 2, tonic + 4, tonic + 5, tonic + 7, tonic + 9, tonic + 11};
                    case "minorn": // natural Minor Scale without alterations
                        temp = new int[] {tonic, tonic + 2, tonic + 3, tonic + 5, tonic + 7, tonic + 8, tonic + 10};
                    case "minorh": // Harmonic Minor Scale
                        temp = new int[] {tonic, tonic + 2, tonic + 3, tonic + 5, tonic + 7, tonic + 8, tonic + 11};
                    case "minorm": // Melodic Minor Scale
                        temp = new int[] {tonic, tonic + 2, tonic + 3, tonic + 5, tonic + 7, tonic + 9, tonic + 11};
                    default: break;
                }
                for (int j = 0; j < temp.length; j++)
                    notes.add(temp[j]);
                tonic += 12;
            }
            notes.add(tonic);
            return notes;
        }
        return null;
    }

    // ---------- Setters ----------
    public void setScale (int octaveNumber) {
        _notes = getScale(_tonic, _type, octaveNumber);
    }
    
}

@@ -419,176 +419,8 @@
  %7D%0A%0A
-    // ---------- Getters ----------%0A    public int getDegree(int degree) %7B%0A        if (_notes != null)%0A            return _notes.get(degree);%0A        return 0;%0A    %7D%0A%0A
     
@@ -427,21 +427,16 @@
 private 
-Array
 List%3CInt
@@ -441,19 +441,22 @@
 nteger%3E 
-get
+create
 Scale(in
@@ -491,16 +491,17 @@
 eNumber)
+ 
 %7B%0A      
@@ -1782,24 +1782,260 @@
 ull;%0A    %7D%0A%0A
+    // ---------- Getters ----------%0A    public int getDegree(int degree) %7B%0A        if (_notes != null)%0A            return _notes.get(degree);%0A        return 0;%0A    %7D%0A%0A    private List%3CInteger%3E getScale()%7B%0A        return _notes;%0A    %7D%0A%0A
     // -----
@@ -2122,19 +2122,22 @@
 notes = 
-get
+create
 Scale(_t
@@ -2170,15 +2170,11 @@
 ;%0A    %7D%0A
-    
 %0A%7D%0A

update Scale class