Beispiel #1
0
        /// <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;
        }
Beispiel #2
0
        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;
        }
Beispiel #3
0
        public static int[] Transitions(Chords chord, int[] phrase, int stable, int position)
        {
            var random = new Random();
            int[] notes;
            switch (chord)
            {
                case Chords.Am:
                    for (int i = position + 1; i < phrase.Length; i++)
                    {
                        if (random.Next(0, 2) == 1)//идем либо вверх либо вниз по гамме
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = (phrase[i - 1] + random.Next(1, 8)) % 7;
                                if (phrase[i] == 0)
                                    phrase[i] = 7;
                            }
                        }
                        else
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = (Math.Abs(phrase[i - 1] - random.Next(1, 8))) % 7;
                                if (phrase[i] == 0)
                                    phrase[i] = 7;
                            }
                        }
                    }
                    for (int i = position - 1; i >= 0; i--)
                    {
                        if (random.Next(0, 2) == 1)//идем либо вверх либо вниз по гамме
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = (phrase[i + 1] + random.Next(1, 8)) % 7;
                                if (phrase[i] == 0)
                                    phrase[i] = 7;
                            }
                        }
                        else
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = (Math.Abs(phrase[i + 1] - random.Next(1, 8))) % 7;
                                if (phrase[i] == 0)
                                    phrase[i] = 7;
                            }
                        }
                    }
                    break;

                case Chords.Dm:
                    for (int i = position + 1; i < phrase.Length; i++)
                    {
                        if (random.Next(0, 2) == 1)//идем либо вверх либо вниз по гамме
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = (phrase[i - 1] + random.Next(1, 8)) % 7;
                                if (phrase[i] == 0)
                                    phrase[i] = 7;
                                if (phrase[i] == 2)
                                    phrase[i] = random.Next(3, 5);
                            }
                        }
                        else
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = (Math.Abs(phrase[i - 1] - random.Next(1, 8))) % 7;
                                if (phrase[i] == 0)
                                    phrase[i] = 7;
                                if (phrase[i] == 2)
                                    phrase[i] = new MyRandom(new int[] { 1, 7 }, new int[] { 50, 50 }).Next();
                            }
                        }
                    }
                    for (int i = position - 1; i >= 0; i--)
                    {
                        if (random.Next(0, 2) == 1)//идем либо вверх либо вниз по гамме
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = (phrase[i + 1] + random.Next(1, 8)) % 7;
                                if (phrase[i] == 0)
                                    phrase[i] = 7;
                                if (phrase[i] == 2)
                                    phrase[i] = random.Next(3, 5);
                            }
                        }
                        else
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = (Math.Abs(phrase[i + 1] - random.Next(1, 8))) % 7;
                                if (phrase[i] == 0)
                                    phrase[i] = 7;
                                if (phrase[i] == 2)
                                    phrase[i] = new MyRandom(new int[] { 1, 7 }, new int[] { 50, 50 }).Next();
                            }
                        }
                    }
                    break;

                case Chords.E:
                    for (int i = position - 1; i >= 0; i--)
                    {
                        if (random.Next(0, 2) == 1)//идем либо вверх либо вниз по гамме
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = (phrase[i + 1] + random.Next(1, 8)) % 7;
                                if (phrase[i] == 0)
                                    phrase[i] = 7;
                                if (phrase[i] == 6)
                                    phrase[i] = new MyRandom(new int[] { 1, 7 }, new int[] { 50, 50 }).Next();
                            }
                        }
                        else
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = (Math.Abs(phrase[i + 1] - random.Next(1, 8))) % 7;
                                if (phrase[i] == 0)
                                    phrase[i] = 7;
                                if (phrase[i] == 6)
                                    phrase[i] = random.Next(4, 6);
                            }
                        }
                    }
                    break;

                case Chords.F:
                    notes = new int[3] { 3, 6, 7 };
                    if (position - 1 >= 0)
                        phrase[position - 1] = 4;
                    for (int i = position + 1; i < phrase.Length; i++)
                    {
                        if (random.Next(0, 2) == 1)//идем либо вверх либо вниз по гамме
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = notes[random.Next(0, 3)];////////////////////////////////////////////
                            }
                        }
                        else
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = notes[random.Next(0, 3)];/////////////////////////////////////////////
                            }
                        }
                    }
                    for (int i = position - 1; i >= 0; i--)
                    {

                        if (random.Next(0, 2) == 1)//идем либо вверх либо вниз по гамме
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = notes[random.Next(0, 3)];/////////////////////////////////////////////
                            }
                        }
                        else
                        {
                            if (phrase[i] == 0)
                            {
                                phrase[i] = notes[random.Next(0, 3)];/////////////////////////////////////////////
                            }
                        }
                    }
                    break;
            }
            return phrase;
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        public static int[] Transitions(Chords chord, int[] phrase, int stable, int position)
        {
            var random = new Random();

            int[] notes;
            switch (chord)
            {
            case Chords.Am:
                for (int i = position + 1; i < phrase.Length; i++)
                {
                    if (random.Next(0, 2) == 1)    //идем либо вверх либо вниз по гамме
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = (phrase[i - 1] + random.Next(1, 8)) % 7;
                            if (phrase[i] == 0)
                            {
                                phrase[i] = 7;
                            }
                        }
                    }
                    else
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = (Math.Abs(phrase[i - 1] - random.Next(1, 8))) % 7;
                            if (phrase[i] == 0)
                            {
                                phrase[i] = 7;
                            }
                        }
                    }
                }
                for (int i = position - 1; i >= 0; i--)
                {
                    if (random.Next(0, 2) == 1)    //идем либо вверх либо вниз по гамме
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = (phrase[i + 1] + random.Next(1, 8)) % 7;
                            if (phrase[i] == 0)
                            {
                                phrase[i] = 7;
                            }
                        }
                    }
                    else
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = (Math.Abs(phrase[i + 1] - random.Next(1, 8))) % 7;
                            if (phrase[i] == 0)
                            {
                                phrase[i] = 7;
                            }
                        }
                    }
                }
                break;

            case Chords.Dm:
                for (int i = position + 1; i < phrase.Length; i++)
                {
                    if (random.Next(0, 2) == 1)    //идем либо вверх либо вниз по гамме
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = (phrase[i - 1] + random.Next(1, 8)) % 7;
                            if (phrase[i] == 0)
                            {
                                phrase[i] = 7;
                            }
                            if (phrase[i] == 2)
                            {
                                phrase[i] = random.Next(3, 5);
                            }
                        }
                    }
                    else
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = (Math.Abs(phrase[i - 1] - random.Next(1, 8))) % 7;
                            if (phrase[i] == 0)
                            {
                                phrase[i] = 7;
                            }
                            if (phrase[i] == 2)
                            {
                                phrase[i] = new MyRandom(new int[] { 1, 7 }, new int[] { 50, 50 }).Next();
                            }
                        }
                    }
                }
                for (int i = position - 1; i >= 0; i--)
                {
                    if (random.Next(0, 2) == 1)    //идем либо вверх либо вниз по гамме
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = (phrase[i + 1] + random.Next(1, 8)) % 7;
                            if (phrase[i] == 0)
                            {
                                phrase[i] = 7;
                            }
                            if (phrase[i] == 2)
                            {
                                phrase[i] = random.Next(3, 5);
                            }
                        }
                    }
                    else
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = (Math.Abs(phrase[i + 1] - random.Next(1, 8))) % 7;
                            if (phrase[i] == 0)
                            {
                                phrase[i] = 7;
                            }
                            if (phrase[i] == 2)
                            {
                                phrase[i] = new MyRandom(new int[] { 1, 7 }, new int[] { 50, 50 }).Next();
                            }
                        }
                    }
                }
                break;

            case Chords.E:
                for (int i = position - 1; i >= 0; i--)
                {
                    if (random.Next(0, 2) == 1)    //идем либо вверх либо вниз по гамме
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = (phrase[i + 1] + random.Next(1, 8)) % 7;
                            if (phrase[i] == 0)
                            {
                                phrase[i] = 7;
                            }
                            if (phrase[i] == 6)
                            {
                                phrase[i] = new MyRandom(new int[] { 1, 7 }, new int[] { 50, 50 }).Next();
                            }
                        }
                    }
                    else
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = (Math.Abs(phrase[i + 1] - random.Next(1, 8))) % 7;
                            if (phrase[i] == 0)
                            {
                                phrase[i] = 7;
                            }
                            if (phrase[i] == 6)
                            {
                                phrase[i] = random.Next(4, 6);
                            }
                        }
                    }
                }
                break;

            case Chords.F:
                notes = new int[3] {
                    3, 6, 7
                };
                if (position - 1 >= 0)
                {
                    phrase[position - 1] = 4;
                }
                for (int i = position + 1; i < phrase.Length; i++)
                {
                    if (random.Next(0, 2) == 1)    //идем либо вверх либо вниз по гамме
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = notes[random.Next(0, 3)];    ////////////////////////////////////////////
                        }
                    }
                    else
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = notes[random.Next(0, 3)];    /////////////////////////////////////////////
                        }
                    }
                }
                for (int i = position - 1; i >= 0; i--)
                {
                    if (random.Next(0, 2) == 1)    //идем либо вверх либо вниз по гамме
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = notes[random.Next(0, 3)];    /////////////////////////////////////////////
                        }
                    }
                    else
                    {
                        if (phrase[i] == 0)
                        {
                            phrase[i] = notes[random.Next(0, 3)];    /////////////////////////////////////////////
                        }
                    }
                }
                break;
            }
            return(phrase);
        }