package com.cooleshow.metronome.constants;

import android.text.TextUtils;

import com.contrarywind.interfaces.IPickerViewData;

/**
 * Author by pq, Date on 2022/9/16.
 */
public enum MetronomeType implements IPickerViewData {
    METRONOME_12_TYPE(0, "1/2", "2"),
    METRONOME_22_TYPE(1, "2/2", "2"),
    METRONOME_14_TYPE(2, "1/4", "4"),
    METRONOME_24_TYPE(3, "2/4", "4"),
    METRONOME_34_TYPE(4, "3/4", "4"),
    METRONOME_44_TYPE(5, "4/4", "4"),
    METRONOME_38_TYPE(6, "3/8", "8"),
    METRONOME_68_TYPE(7, "6/8", "8"),
    METRONOME_816_TYPE(8, "8/16", "16");

    private int value;
    private String name;
    private String noteValue;


    private MetronomeType(int value, String name, String noteValue) {
        this.value = value;
        this.name = name;
        this.noteValue = noteValue;
    }

    public int getValue() {
        return this.value;
    }

    public String getName() {
        return this.name;
    }

    public String getNoteValue() {
        return noteValue;
    }

    public static MetronomeType setValue(int code) {
        MetronomeType[] var1 = values();
        int var2 = var1.length;

        for (int var3 = 0; var3 < var2; ++var3) {
            MetronomeType c = var1[var3];
            if (code == c.getValue()) {
                return c;
            }
        }

        return METRONOME_14_TYPE;
    }

    public static float getNoteSpeedValue(MetronomeType metronomeType) {
        if (TextUtils.equals(metronomeType.getNoteValue(), "4")) {
            return 1.0f;
        }
        if (TextUtils.equals(metronomeType.getNoteValue(), "2")) {
            return 2.0f;
        }

        if (TextUtils.equals(metronomeType.getNoteValue(), "8")) {
            return 0.5f;
        }

        if (TextUtils.equals(metronomeType.getNoteValue(), "16")) {
            return 0.25f;
        }
        return 1.0f;
    }

    @Override
    public String getPickerViewText() {
        return this.name;
    }
}
