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

import jm.music.data.Note;
import jm.music.data.Part;
import jm.music.data.Phrase;
import jm.music.data.Score;

/**
 *
 * @author smuRf
 */
public class INote implements BasicDataElement{
    private String noteValue;
    private int octave;
    private double duration;
    private double realDuration;
    private int pitch;
    private int postPitchDiff;
    private int prePitchDiff;
    private double rhythmValue;
    private int dynamic;
    private IPhrase parent;
    
    public INote(INote iNote)
    {
        noteValue = iNote.getNoteValue();
        octave = iNote.getOctave();
        duration = iNote.getDuration();
        realDuration = iNote.getRealDuration();
        pitch = iNote.getPitch();
        postPitchDiff = iNote.getPostPitchDiff();
        prePitchDiff = iNote.getPrePitchDiff();
        rhythmValue = iNote.getRhythmValue();
        dynamic = iNote.getDynamic();
    }
    
    public INote(String _noteValue, double _duration, double _realDuration, double _rhythmValue, int _dynamic)
    {
        noteValue = _noteValue;
        octave = 0;
        duration = _duration;
        realDuration = _realDuration;
        pitch = Integer.MIN_VALUE; //Anmerkung: war auf 0, sollte aber minus Unendlich sein fuer REST (geaendert von Tom)
        rhythmValue = _rhythmValue;
        dynamic = _dynamic;
    }
    
    public INote(String _noteValue, double _duration, double _realDuration, int _pitch, double _rhythmValue, int _dynamic)
    {
        noteValue = _noteValue;
        octave = 0;
        duration = _duration;
        realDuration = _realDuration;
        pitch = _pitch;
        rhythmValue = _rhythmValue;
        dynamic = _dynamic;
    }
    
    public INote(String _noteValue, int _octave, double _duration, double _realDuration, int _pitch, double _rhythmValue, int _dynamic)
    {
        noteValue = _noteValue;
        octave = _octave;
        duration = _duration;
        realDuration = _realDuration;
        pitch = _pitch;
        rhythmValue = _rhythmValue;
        dynamic = _dynamic;
    }
    
    public int getOctave()
    {
        return octave;
    }
    
    public int getDynamic()
    {
        return dynamic;
    }
    
    public double getDuration()
    {
        return duration;
    }
    
    public void setDuration(double duration)
    {
        this.duration = duration;
    }
    
    public void setParent(IPhrase iPhrase)
    {
        parent = iPhrase;
    }
    
    public void setPostPitchDiff(int _pitchDiff)
    {
        postPitchDiff = _pitchDiff;
    }
    
    public int getPostPitchDiff()
    {
        return postPitchDiff;
    }
    
    public void setPrePitchDiff(int _pitchDiff)
    {
        prePitchDiff = _pitchDiff;
    }
    
    public int getPrePitchDiff()
    {
        return prePitchDiff;
    }
    
    public void setPitch(int pitch)
    {
        this.pitch = pitch;
        octave = (pitch / 12) - 1;
        noteValue = getNote().getNote();
    }
    
    public int getPitch()
    {
        return pitch;
    }
    
    public double getRhythmValue()
    {
        return rhythmValue;
    }
    
    public void setRhythmValue(double rhythmValue)
    {
        this.rhythmValue = rhythmValue;
    }
    
    public double getRealDuration()
    {
        return realDuration;
    }
    
    public void setRealDuration(int realDuration)
    {
        this.realDuration = realDuration;
    }
    
    public String getNoteValue()
    {
        return noteValue;
    }
    
    public String getName()
    {
        if(noteValue.equals("REST"))
            return noteValue;
        
        return noteValue+""+octave;
    }
    
    public String getINote()
    {
        return noteValue;
    }
    
    public int getIOctave()
    {
        return octave;
    }
    
    public double  getIDuration()
    {
        return duration;
    }
    
    public int getIPitch()
    {
        return pitch;
    }
    
    public Note getOriginalNote()
    {
        return new Note(pitch, rhythmValue, dynamic);
    }
    
    public Note getNote()
    {
        return new Note(pitch, realDuration, dynamic);
    }

    @Override
    public Score getMusicStructure() {
        Score score = parent.getParent().getParent().getScore();
        Part part = parent.getParent().getPart();
        Phrase phrase = parent.getPhrase();
        Note note = getNote();
        
        phrase.setStartTime(phrase.getStartTime() - parent.getParent().getShortestPhraseStartTime());

        phrase.add(note);
        part.add(phrase);
        score.add(part);

        return score;
    }
}
