示例#1
0
 public Note[] Column(int i)
 {
     Note[] column = new Note[12];
     for (int j = 0; i < 12; i++)
     {
         column[j] = notes[j][i];
     }
     return column;
 }
示例#2
0
 private void InitializeMatrix(Note[] firstRow)
 {
     for (int i = 1; i < 12; ++i)
     {
         int primeRowNumber = 12 - noteToOrdinal[notes[0][i]];
         notes[i][0] = ordinalToNote[primeRowNumber];
         for (int j = 1; j < 12; ++j)
         {
             int nextOrdinal = primeRowNumber + noteToOrdinal[notes[0][j]];
             nextOrdinal = nextOrdinal >= 12 ? nextOrdinal - 12 : nextOrdinal;
             notes[i][j] = ordinalToNote[nextOrdinal];
         }
     }
     Console.WriteLine(ToString());
 }
示例#3
0
        private void InitializeVariables(Note[] firstRow)
        {
            notes = new Note[12][];

            notes[0] = firstRow
                .Select(x => Normalize(x, firstRow[0], firstRow[0] * 2))
                .ToArray();
            for (int i = 1; i < 12; i++)
            {
                notes[i] = new Note[12];
            }

            noteToOrdinal = notes[0]
                .OrderBy(x => (int)x)
                .Select((note, ordinal) => new { note, ordinal })
                .ToDictionary(obj => obj.note, obj => obj.ordinal);
            ordinalToNote = noteToOrdinal
                .ToDictionary(x => x.Value, x => x.Key);
        }
示例#4
0
 private Note Normalize(Note x, int lowend, int highend)
 {
     while (lowend > (int)x)
     {
         x = new Note(2 * (int)x);
     }
     while (highend <= (int)x)
     {
         x = new Note((int)x / 2);
     }
     return x;
 }
示例#5
0
 public Matrix(Note[] firstRow)
 {
     Validate(firstRow);
     InitializeVariables(firstRow);
     InitializeMatrix(firstRow);
 }
示例#6
0
        private void Validate(Note[] firstRow)
        {
            if (firstRow.Length != 12)
            {
                throw new ArgumentException("firstRow must have 12 tones");
            }

            if (firstRow.Select(x => (int)x).Distinct().Count() != firstRow.Length)
            {
                throw new ArgumentException("row must not have repeated values");
            }
        }