/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import hanson.HansonStatics.DIRECTION;
import hanson.HansonStatics.NOTE_INTERVAL;
import hanson.HansonStatics.OCTAVE_INERVAL;
import java.util.ArrayList;

/**
 *
 * @author smuRf
 */
public class IHanson{
    private ArrayList<Double> intervals;
    
    public IHanson()
    {
        intervals = new ArrayList();
    }
    
    public void addInterval(double interval)
    {
        intervals.add(interval);
    }
    
    public ArrayList getIntervals()
    {
        return intervals;
    }
    
    public double getInterval(int index)
    {
        if(index >= intervals.size())
            return -3;
        else
            return intervals.get(index);
    }
    
    public ArrayList getNxNIntervals(int intervalCount)
    {
        ArrayList<Double[]> nxnIntervals = new ArrayList();
        
        for(int i = 0; i < intervals.size()-intervalCount; i++)
        {
            Double interval[] = new Double[intervalCount];
            
            for(int j = 0; j < intervalCount; j++)
            {
                interval[j] = intervals.get(i+j);
            }
            
            nxnIntervals.add(interval);
        }
        
        return nxnIntervals;
    }
    
    @Override
    public String toString()
    {
        String strHanson = "";
        
        for(double interval:intervals)
        {
            if(interval == -1)
                strHanson += "loo\n";
            else
            {               
                NOTE_INTERVAL i = NOTE_INTERVAL.values()[(int)interval/1000];
                OCTAVE_INERVAL o = OCTAVE_INERVAL.values()[(int)((interval-(i.ordinal()*1000))/100)];
                int k = (int)((interval-i.ordinal()*1000 - o.ordinal()*100)/10);
                System.out.println(interval +" " +i.ordinal() +" " +o.ordinal() +" " +k);
                DIRECTION d = DIRECTION.values()[(int)((interval-i.ordinal()*1000 - o.ordinal()*100)/10)];
                switch(i)
                {
                    case d:
                        strHanson += "d";
                        break;
                    case s:
                        strHanson += "s";
                        break;
                    case n:
                        strHanson += "n";
                        break;
                    case m:
                        strHanson += "m";
                        break;
                    case p:
                        strHanson += "p";
                        break;
                    case t:
                        strHanson += "t";
                        break;
                }
                switch(o)
                {
                    case a:
                        strHanson += "a";
                        break;
                    case e:
                        strHanson += "e";
                        break;
                    case i:
                        strHanson += "i";
                        break;
                    case o:
                        strHanson += "o";
                        break;
                    case u:
                        strHanson += "u";
                        break;
                }
                switch(d)
                {
                    case r:
                        strHanson += "r\n";
                        break;
                    case l:
                        strHanson += "l\n";
                        break;
                }
            }
        }
        
        return strHanson;
    }
}
