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

import java.util.ArrayList;
import jm.music.data.Note;
import jm.music.data.Part;
import jm.music.data.Phrase;
import jm.music.data.Score;

/**
 *
 * @author smuRf
 */
public class IScore implements BasicDataElement{
    private String name;
    private double tempo;
    private int numerator;
    private int denominator;
    private int ppqn;
    private ArrayList<IPart> parts;
        
    public IScore(String _name, double _tempo, int _numerator, int _denominator)
    {
        name = _name;
        tempo = _tempo;
        numerator = _numerator;
        denominator = _denominator;
        parts = new ArrayList<>();
    }
    
    public IScore(String _name, double _tempo)
    {
        name = _name;
        tempo = _tempo;
        numerator = 4;
        denominator = 4;
        parts = new ArrayList<>();
    }
    
    public void setPPQN(int ppqn)
    {
        this.ppqn = ppqn;
    }
    
    public int getPPQN()
    {
        return ppqn;
    }
    
    public int getNumerator()
    {
        return numerator;
    }
    
    public int getDenominator()
    {
        return denominator;
    }
  
    public String getName()
    {
        return name;
    }
    
    public void setName(String name) {
       this.name = name;
    }
    
    public double getTempo()
    {
        return tempo;
    }
    
    public void addIPart(IPart part)
    {
        part.updateName(parts.size());
        part.setParent(this);
        parts.add(part);
    }
    
    public IPart getIPart(int i)
    {
        return parts.get(i);
    }
    
    public ArrayList<IPart> getIParts()
    {
        return parts;
    }

    public Score getScore() {
        Score score = new Score(name, tempo);
        score.setPPQN(ppqn);
        return score;
    }

    @Override
    public Score getMusicStructure() {
        Score score = getScore();
        score.setPPQN(ppqn);
        
        for(IPart iPart:getIParts())
        {
            Part part = iPart.getPart();

            for(IPhrase iPhrase:iPart.getOriginalIPhrases())
            {
                Phrase phrase = iPhrase.getPhrase();

                for(INote iNote: iPhrase.getINotes())
                {
                    Note note = iNote.getNote();
                    phrase.add(note);
                }
                part.add(phrase);
            }
            score.add(part);
        }
        return score;
    }
}
