Beispiel #1
0
 public float ToCents()
 {
     if (!rational.IsDefault())
     {
         return((float)rational.ToCents());
     }
     return(cents);
 }
Beispiel #2
0
 public EqualDivision(int stepCount, Rational basis)
 {
     _stepCount = stepCount;
     _stepCents = basis.ToCents() / stepCount;
     if (_stepCents == 12 && basis.Equals(Rational.Two))
     {
         _noteNames = "C C# D D# E F F# G G# A A# B B#".Split(' ');
     }
 }
Beispiel #3
0
        public float CalculateMeasuredCents(Rational r)
        {
            if (_matrix == null)
            {
                return((float)r.ToCents());
            }

            float[] coords = _matrix.FindFloatCoordinates(r);
            if (coords == null)
            {
                //throw new Exception("Can't solve temperament");
                return((float)r.ToCents());
            }

            float cents = 0;

            for (int j = 0; j < coords.Length; ++j)
            {
                cents += coords[j] * _measuredCents[j];
            }
            return(cents);
        }
Beispiel #4
0
        public void SetTemperament(Tempered[] tempered, Subgroup subgroup)
        {
            // skip invalid tempered intervals
            Tempered[] ts = Validate(tempered, subgroup);

            if (ts == null || ts.Length == 0)
            {
                // unset temperament
                _matrix        = null;
                _pureCents     = null;
                _deltaCents    = null;
                _measuredCents = null;
                return;
            }

            // Fill cents arrays and temperament matrix.
            // We add the subgroup items to be able to solve each narrow prime of the basis.
            Rational[] subgroupItems = subgroup.GetItems();
            int        matrixSize    = ts.Length + subgroupItems.Length;

            Rational[] rs = new Rational[matrixSize];
            _pureCents     = new float[matrixSize];
            _deltaCents    = new float[matrixSize];
            _measuredCents = new float[matrixSize];
            for (int i = 0; i < ts.Length; ++i)   // tempered intervals
            {
                Rational r = ts[i].rational;
                rs[i] = r;
                float cents = (float)r.ToCents();
                _pureCents [i] = cents;
                _deltaCents[i] = ts[i].cents - cents;
            }
            for (int i = 0; i < subgroupItems.Length; ++i)   // subgroup intervals
            {
                int      j = ts.Length + i;
                Rational r = subgroupItems[i];
                rs[j] = r;
                float cents = (float)r.ToCents();
                _pureCents [j] = cents;
                _deltaCents[j] = 0f;
            }
            _matrix = new Matrix(rs, makeDiagonal: true);

            //
            UpdateMeasuredCents();
        }
Beispiel #5
0
 public string FormatRational(Rational r)
 {
     return(FormatCents(r.ToCents()));
 }