Exemple #1
0
    public void Fix(MusicMeter meter)
    {
        int totalUnit = Bar * meter.UnitPerBar + Beat * meter.UnitPerBeat + Unit;

        Bar  = totalUnit / meter.UnitPerBar;
        Beat = (totalUnit - Bar * meter.UnitPerBar) / meter.UnitPerBeat;
        Unit = (totalUnit - Bar * meter.UnitPerBar - Beat * meter.UnitPerBeat);
    }
Exemple #2
0
 public void Add(int bar, int beat = 0, int unit = 0, MusicMeter meter = null)
 {
     Bar += bar; Beat += beat; Unit += unit;
     if (meter != null)
     {
         Fix(meter);
     }
 }
Exemple #3
0
 public void Subtract(int bar, int beat = 0, int unit = 0, MusicMeter meter = null)
 {
     Bar -= bar; Beat -= beat; Unit -= unit;
     if (meter != null)
     {
         Fix(meter);
     }
 }
Exemple #4
0
    void DrawMeter(SerializedProperty meterProp)
    {
        SerializedProperty startBarProp    = meterProp.FindPropertyRelative("StartBar");
        SerializedProperty tempoProp       = meterProp.FindPropertyRelative("Tempo");
        SerializedProperty unitPerBarProp  = meterProp.FindPropertyRelative("UnitPerBar");
        SerializedProperty unitPerBeatProp = meterProp.FindPropertyRelative("UnitPerBeat");
        SerializedProperty numeratorProp   = meterProp.FindPropertyRelative("Numerator");
        SerializedProperty denominatorProp = meterProp.FindPropertyRelative("Denominator");

        int    startBar    = startBarProp.intValue;
        double tempo       = tempoProp.doubleValue;
        int    unitPerBar  = unitPerBarProp.intValue;
        int    unitPerBeat = unitPerBeatProp.intValue;
        int    numerator   = numeratorProp.intValue;
        int    denominator = denominatorProp.intValue;

        meterProp.isExpanded = EditorGUILayout.Foldout(meterProp.isExpanded, string.Format("Meter {0}~ ({1}/{2}, {3:F2})", startBar, numerator, denominator, tempo));
        if (meterProp.isExpanded)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(startBarProp);
            EditorGUILayout.PropertyField(tempoProp);

            if (showUnitPerBarBeat_)
            {
                EditorGUILayout.PropertyField(unitPerBeatProp);
                EditorGUILayout.PropertyField(unitPerBarProp);

                if (unitPerBar != unitPerBarProp.intValue || unitPerBeat != unitPerBeatProp.intValue)
                {
                    MusicMeter.CalcMeterByUnits(unitPerBeatProp.intValue, unitPerBarProp.intValue, out numerator, out denominator);
                    numeratorProp.intValue   = numerator;
                    denominatorProp.intValue = denominator;
                }
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Meter", GUILayout.Width(EditorGUIUtility.labelWidth - 4));
                    EditorGUIUtility.labelWidth = 1;
                    EditorGUILayout.PropertyField(numeratorProp, GUILayout.Width(55));
                    denominatorProp.intValue    = EditorGUILayout.IntPopup("/", denominatorProp.intValue, MeterDenominatorCandidatesString, MeterDenominatorCandidates);
                    EditorGUIUtility.labelWidth = 0;

                    if (numerator != numeratorProp.intValue || denominator != denominatorProp.intValue)
                    {
                        MusicMeter.CalcMeterByFraction(numeratorProp.intValue, denominatorProp.intValue, out unitPerBeat, out unitPerBar);
                        unitPerBeatProp.intValue = unitPerBeat;
                        unitPerBarProp.intValue  = unitPerBar;
                    }
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUI.indentLevel--;
        }
    }
Exemple #5
0
 public void LoopBack(int loopBar, MusicMeter meter)
 {
     if (loopBar > 0)
     {
         Bar += loopBar;
         Fix(meter);
         Bar %= loopBar;
     }
 }
Exemple #6
0
    void CalcMeter(float fBeatDuration, float fBarDuration, int iActiveDuration)
    {
        double tempo       = 60.0 / fBeatDuration;
        int    unitPerBeat = 4;
        int    unitPerBar  = Mathf.RoundToInt(unitPerBeat * (fBarDuration / fBeatDuration));

        currentMeter_   = new MusicMeter(0, unitPerBeat, unitPerBar, tempo);
        sequenceEndBar_ = Mathf.RoundToInt((iActiveDuration / 1000.0f) / fBarDuration);
        currentMeter_.Validate(0);
    }
Exemple #7
0
    void ResetParams()
    {
        isJustChanged_ = false;
        isNearChanged_ = false;
        isJustLooped_  = false;
        isNearLooped_  = false;
        near_.Set(-1, 0, 0);
        just_.Set(-1, 0, 0);
        oldNear_.Set(near_);
        oldJust_.Set(just_);
        fractionFromJust_  = 0.0f;
        isFormerHalf_      = true;
        numRepeat_         = 0;
        sequenceEndTiming_ = null;
        currentMeter_      = null;

        ResetParamsInternal();
    }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Init(property);

        var fieldRect = position;

        fieldRect.height = GetPropertyHeight(property, label);

        using (new EditorGUI.PropertyScope(fieldRect, label, property))
        {
            //int startBar = _property.StartBar.intValue;
            double tempo       = _property.Tempo.doubleValue;
            int    unitPerBar  = _property.UnitPerBar.intValue;
            int    unitPerBeat = _property.UnitPerBeat.intValue;
            int    numerator   = _property.Numerator.intValue;
            int    denominator = _property.Denominator.intValue;

            fieldRect.height = EditorGUIUtility.singleLineHeight;

            property.isExpanded = EditorGUI.Foldout(fieldRect, property.isExpanded, string.Format("{0} ({1}/{2}, {3:F2})", label.text, numerator, denominator, tempo));
            if (property.isExpanded)
            {
                EditorGUI.indentLevel++;

                //fieldRect.y += EditorGUIUtility.singleLineHeight;
                //EditorGUI.PropertyField(fieldRect, _property.StartBar);
                fieldRect.y += EditorGUIUtility.singleLineHeight;
                EditorGUI.PropertyField(fieldRect, _property.Tempo);

                fieldRect.y        += EditorGUIUtility.singleLineHeight;
                showUnitPerBarBeat_ = EditorGUI.Toggle(fieldRect, "Show Meter In UnitPerBar/Beat", showUnitPerBarBeat_);

                if (showUnitPerBarBeat_)
                {
                    fieldRect.y += EditorGUIUtility.singleLineHeight;
                    EditorGUI.PropertyField(fieldRect, _property.UnitPerBeat);
                    fieldRect.y += EditorGUIUtility.singleLineHeight;
                    EditorGUI.PropertyField(fieldRect, _property.UnitPerBar);

                    if (unitPerBar != _property.UnitPerBar.intValue || unitPerBeat != _property.UnitPerBeat.intValue)
                    {
                        MusicMeter.CalcMeterByUnits(_property.UnitPerBeat.intValue, _property.UnitPerBar.intValue, out numerator, out denominator);
                        _property.Numerator.intValue   = numerator;
                        _property.Denominator.intValue = denominator;
                    }
                }
                else
                {
                    fieldRect.y    += EditorGUIUtility.singleLineHeight;
                    fieldRect       = EditorGUI.PrefixLabel(fieldRect, GUIUtility.GetControlID(FocusType.Passive), new GUIContent("Meter"));
                    fieldRect.x    -= 16;
                    fieldRect.width = 55;
                    EditorGUI.PropertyField(fieldRect, _property.Numerator, GUIContent.none);
                    fieldRect.x    += 60;
                    fieldRect.width = 60;
                    _property.Denominator.intValue = EditorGUI.IntPopup(fieldRect, _property.Denominator.intValue, MeterDenominatorCandidatesString, MeterDenominatorCandidates);

                    if (numerator != _property.Numerator.intValue || denominator != _property.Denominator.intValue)
                    {
                        MusicMeter.CalcMeterByFraction(_property.Numerator.intValue, _property.Denominator.intValue, out unitPerBeat, out unitPerBar);
                        _property.UnitPerBeat.intValue = unitPerBeat;
                        _property.UnitPerBar.intValue  = unitPerBar;
                    }
                }

                EditorGUI.indentLevel--;
            }
        }
    }
Exemple #9
0
 public int GetTotalUnits(MusicMeter meter)
 {
     return(Bar * meter.UnitPerBar + Beat * meter.UnitPerBeat + Unit);
 }
Exemple #10
0
 public void Subtract(Timing t, MusicMeter meter = null)
 {
     Subtract(t.Bar, t.Beat, t.Unit, meter);
 }
Exemple #11
0
 public void Add(Timing t, MusicMeter meter = null)
 {
     Add(t.Bar, t.Beat, t.Unit, meter);
 }
Exemple #12
0
 public void Decrement(MusicMeter meter)
 {
     --Unit;
     Fix(meter);
 }
Exemple #13
0
 public void Increment(MusicMeter meter)
 {
     ++Unit;
     Fix(meter);
 }