package vermilion;

/**
 * A parameter meant to represent a musical note. This stores a value between
 * A-0+00 (13.75 Hz) and G#B+99 (56287 Hz) represented as an integer from 0 to
 * 14399 cents. Special values are reserved for note-off actions.
 */
public class ParameterNote extends ParameterBase
{
    public int value;

    public static final int NOTE_OFF = 99999;

    /**
     * The constructor creates a parameter.
     * @param name A name for this parameter.
     * @param isTrack Indicates whether the parameter is global.
     * @param initVal A single precision floating point initial value.
     */
    public ParameterNote(String name, boolean isTrack)
    {
        this(name, isTrack, NOTE_OFF);
    }

    private ParameterNote(String name, boolean isTrack, int initVal)
    {
        super(name, PARAMETER_TYPE_NOTE, isTrack);
        value = initVal;
    }

    /**
     * The serialisation type for this object is 'NOTE'.
     */
    @Override
    public String getType() { return "NOTE"; }

    /**
     * The current serialisation version for this object is 1.
     */
    @Override
    public int getVersion() { return 1; }

    /**
     * Saves the value of this parameter.
     */
    @Override
    public String saveImpl()
    {
        return String.valueOf(value);
    }

    /**
     * Loads a saved parameter.
     */
    @Override
    public UsefulFileObject loadImpl(String str, int version)
    {
        if (version == 1)
        {
            return new ParameterNote(null, false, Integer.parseInt(str));
        }

        return null;
    }


    @Override
    public void copyValue(ParameterBase source)
    {
        value = ((ParameterNote) source).value;
    }
}
