/// <summary> /// gchgc /// </summary> /// <param name="chord">аккорд</param> /// <param name="tact">такт</param> /// <returns></returns> public static int[] GetNotes(Chords chord, int tact) { Random notesCount = new Random(), positions = new Random();//position - позиция устойчивой ноты MyRandom stables = new MyRandom(new int[] { 1, 3, 5 }, new int[] { 33, 33, 34 }); switch (chord) { case Chords.Am: stables = new MyRandom(new int[] { 1, 3, 5 }, new int[] { 33, 33, 34 }); break; case Chords.Dm: stables = new MyRandom(new int[] { 1, 3, 5 }, new int[] { 33, 33, 34 }); break; case Chords.E: stables = new MyRandom(new int[] { 1, 3, 5 }, new int[] { 33, 33, 34 }); break; case Chords.F: stables = new MyRandom(new int[] { 3 }, new int[] { 100 }); break; } int length = 6;// notesCount.Next(4, 10);//количество нот во фразе int[] phrase = new int[length]; for (int i = 0; i < phrase.Length; i++) { phrase[i] = 0; } int stable = stables.Next(); int position = 1; switch (tact)//2 и 3 такт одинаковы, поэтому в параметры передаем всегда 2 { case 1: phrase[0] = 1; position = positions.Next(1, length); phrase[position] = stable; break; case 2: position = positions.Next(0, length); phrase[position] = stable; break; case 4: phrase[length - 1] = 1; position = length - 1; stable = 1; break; } phrase = Transitions(chord, phrase, stable, position); return(phrase); }
/// <summary> /// gchgc /// </summary> /// <param name="chord">аккорд</param> /// <param name="tact">такт</param> /// <returns></returns> public static int[] GetNotes(Chords chord, int tact) { Random notesCount = new Random(), positions = new Random();//position - позиция устойчивой ноты MyRandom stables = new MyRandom(new int[] { 1, 3, 5 }, new int[] { 33, 33, 34 }); switch (chord) { case Chords.Am: stables = new MyRandom(new int[] { 1, 3, 5 }, new int[] { 33, 33, 34 }); break; case Chords.Dm: stables = new MyRandom(new int[] { 1, 3, 5 }, new int[] { 33, 33, 34 }); break; case Chords.E: stables = new MyRandom(new int[] { 1, 3, 5 }, new int[] { 33, 33, 34 }); break; case Chords.F: stables = new MyRandom(new int[] { 3 }, new int[] { 100 }); break; } int length = 6;// notesCount.Next(4, 10);//количество нот во фразе int[] phrase = new int[length]; for (int i = 0; i < phrase.Length; i++) { phrase[i] = 0; } int stable = stables.Next(); int position = 1; switch (tact)//2 и 3 такт одинаковы, поэтому в параметры передаем всегда 2 { case 1: phrase[0] = 1; position = positions.Next(1, length); phrase[position] = stable; break; case 2: position = positions.Next(0, length); phrase[position] = stable; break; case 4: phrase[length - 1] = 1; position = length - 1; stable = 1; break; } phrase = Transitions(chord, phrase, stable, position); return phrase; }
public static int[] GetNotes(MyScale scale, int countOfNotes, int[] rhythm) { int[] notes = new int[countOfNotes]; notes[0] = 1; int[] scaleIntervals = scale.scaleIntervals; /* Создадим массив сдвигов и массив вероятностей выбора этого сдвига */ int[] shiftValues = new int[scaleIntervals.Length + 1]; int[] shiftProbab = MyRandom.GetProbabilities(shiftValues, scale.scaleName); MyRandom shifts = new MyRandom(shiftValues, shiftProbab); Random random = new Random(); /* Сдвиг - на сколько ступеней гаммы сдвигаемся. Случайная величина */ int shift; /* Куда сдвигаем: 0 - вниз, 1 - наверх. Случайная величина */ int upOrDown; /* Показывает, на какой ступени гаммы мы сейчас находимся(номер элемента массива) */ int position = 0; int[] shiftsOut = new int[notes.Length - 1];//////////////////////////////////////Отладка int[] notesOut = new int[notes.Length];///////////////////////////////////////////Отладка for (int i = 1; i < notes.Length; i++) { upOrDown = random.Next(0, 2); shift = shifts.Next(); /* Повтор ноты */ if (shift == 0) { notes[i] = notes[i - 1]; continue; } int sum = 0, k = position; shiftsOut[i - 1] = shift;///////////////////////Отладка notesOut[0] = 1;////////////////////////////////Отладка /////////////////////////////////////////////////////////// //int countOfSequence = CountOfSequence(rhythm, i); //int[] sequence = GetSequence(ref position, scaleIntervals, countOfSequence, notes[i - 1], upOrDown); //if (countOfSequence > 3) //&& random.Next(0, 2) == 1) //{ // int seq = 0, nt = i - 1; // for (int j = 0; j < countOfSequence; j++) // { // notes[nt] = sequence[seq]; // nt++; // seq++; // } // i = i + countOfSequence - 2; // continue; //} if (upOrDown == 1) { for (int j = 0; j < shift; j++) { sum = sum + scaleIntervals[k % scaleIntervals.Length]; k++; } position = (position + shift) % scaleIntervals.Length; } else { for (int j = 0; j < shift; j++) { if (k - 1 < 0) k = k + scaleIntervals.Length; sum = sum - scaleIntervals[(k - 1) % scaleIntervals.Length]; k--; } position = (position + scaleIntervals.Length - shift) % scaleIntervals.Length; } notesOut[i] = position;///////////////////////////////////////Отладка /* Случайное повышение или понижение на октаву (для разнообразия). Вероятность 0.1 */ if (random.Next(0, 10) == 1) { if (upOrDown == 1) { sum += 12; } else { sum -= 12; } } notes[i] = notes[i - 1] + sum; } //notes[notes.Length - 1] = 1; return notes; }
public static int[] GetNotes(MyScale scale, int countOfNotes, int[] rhythm) { int[] notes = new int[countOfNotes]; notes[0] = 1; int[] scaleIntervals = scale.scaleIntervals; /* Создадим массив сдвигов и массив вероятностей выбора этого сдвига */ int[] shiftValues = new int[scaleIntervals.Length + 1]; int[] shiftProbab = MyRandom.GetProbabilities(shiftValues, scale.scaleName); MyRandom shifts = new MyRandom(shiftValues, shiftProbab); Random random = new Random(); /* Сдвиг - на сколько ступеней гаммы сдвигаемся. Случайная величина */ int shift; /* Куда сдвигаем: 0 - вниз, 1 - наверх. Случайная величина */ int upOrDown; /* Показывает, на какой ступени гаммы мы сейчас находимся(номер элемента массива) */ int position = 0; int[] shiftsOut = new int[notes.Length - 1]; //////////////////////////////////////Отладка int[] notesOut = new int[notes.Length]; ///////////////////////////////////////////Отладка for (int i = 1; i < notes.Length; i++) { upOrDown = random.Next(0, 2); shift = shifts.Next(); /* Повтор ноты */ if (shift == 0) { notes[i] = notes[i - 1]; continue; } int sum = 0, k = position; shiftsOut[i - 1] = shift; ///////////////////////Отладка notesOut[0] = 1; ////////////////////////////////Отладка /////////////////////////////////////////////////////////// //int countOfSequence = CountOfSequence(rhythm, i); //int[] sequence = GetSequence(ref position, scaleIntervals, countOfSequence, notes[i - 1], upOrDown); //if (countOfSequence > 3) //&& random.Next(0, 2) == 1) //{ // int seq = 0, nt = i - 1; // for (int j = 0; j < countOfSequence; j++) // { // notes[nt] = sequence[seq]; // nt++; // seq++; // } // i = i + countOfSequence - 2; // continue; //} if (upOrDown == 1) { for (int j = 0; j < shift; j++) { sum = sum + scaleIntervals[k % scaleIntervals.Length]; k++; } position = (position + shift) % scaleIntervals.Length; } else { for (int j = 0; j < shift; j++) { if (k - 1 < 0) { k = k + scaleIntervals.Length; } sum = sum - scaleIntervals[(k - 1) % scaleIntervals.Length]; k--; } position = (position + scaleIntervals.Length - shift) % scaleIntervals.Length; } notesOut[i] = position;///////////////////////////////////////Отладка /* Случайное повышение или понижение на октаву (для разнообразия). Вероятность 0.1 */ if (random.Next(0, 10) == 1) { if (upOrDown == 1) { sum += 12; } else { sum -= 12; } } notes[i] = notes[i - 1] + sum; } //notes[notes.Length - 1] = 1; return(notes); }