Exemple #1
0
        private void scaleComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            int[]     scaleIntervals = minorScale;
            ScaleName scaleName      = ScaleName.Minor;

            switch (scaleComboBox.SelectedIndex)
            {
            case 0:    //Выбран натуральный минор
                scaleIntervals = minorScale;
                scaleName      = ScaleName.Minor;
                break;

            case 1:    //Выбран натуральный мажор
                scaleIntervals = majorScale;
                scaleName      = ScaleName.Major;
                break;

            case 2:
                scaleIntervals = flamencoScale;
                scaleName      = ScaleName.Flamenco;
                break;

            case 3:
                scaleIntervals = bluesScale;
                scaleName      = ScaleName.Blues;
                break;

            case 4:
                scaleIntervals = flamenco2Scale;
                scaleName      = ScaleName.Flamenco2;
                break;
            }

            selectedScale = new MyScale(scaleName, scaleIntervals);
        }
Exemple #2
0
        public static List <Melody> GetAllMelodys()
        {
            List <Melody> list = new List <Melody>();
            StreamReader  sr   = new StreamReader("Melodys.txt", Encoding.Default);
            String        line = "";

            while ((line = sr.ReadLine()) != null)
            {
                if (line == "")
                {
                    continue;
                }
                char[]   separators = { ';' };
                string[] tokens     = line.Split(separators, StringSplitOptions.RemoveEmptyEntries);

                string name       = tokens[0];
                string scale      = tokens[1];
                string notesLine  = tokens[2];
                string rhythmLine = tokens[3];

                ScaleName scaleName = MyScale.GetScaleName(scale);


                char[]   separators2  = { ' ' };
                string[] stringNotes  = notesLine.Split(separators2, StringSplitOptions.RemoveEmptyEntries);
                string[] stringRhythm = rhythmLine.Split(separators2, StringSplitOptions.RemoveEmptyEntries);

                int[] notes  = new int[stringNotes.Length];
                int[] rhythm = new int[stringRhythm.Length];

                for (int i = 0; i < rhythm.Length; i++)
                {
                    rhythm[i] = int.Parse(stringRhythm[i]);
                }
                for (int i = 0; i < notes.Length; i++)
                {
                    notes[i] = int.Parse(stringNotes[i]);
                }

                Melody melody = new Melody(name, notes, rhythm, scaleName);
                list.Add(melody);
            }

            sr.Close();
            return(list);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            savedMelodysList = new List <Melody>();
            savedMelodysList = Parser.GetAllMelodys();
            for (int i = 0; i < savedMelodysList.Count; i++)
            {
                savedMelodysComboBox.Items.Add(savedMelodysList[i].Name + "(" + savedMelodysList[i].ScaleName.ToString() + ")");
            }
            if (savedMelodysComboBox.Items.Count != 0)
            {
                savedMelodysComboBox.SelectedIndex = 0;
            }
            nameLabel.Text         = "Сгенерируйте мелодию!";
            notesTextBox.Text      = "";
            rhythmTextBox.Text     = "";
            notesCountTextBox.Text = "16";

            //Melody.Number = melodyList.Count + 1;

            generatedMelodysList = new List <Melody>();

            gridButtons = new int[6, 16];

            /* Гаммы можно менять, но их длина должна оставаться прежней.
             * В противном случае, нужно произвести изменения в файле MyRandom.cs
             */
            minorScale = new int[7] {
                2, 1, 2, 2, 1, 2, 2
            };
            majorScale = new int[7] {
                2, 2, 1, 2, 2, 2, 1
            };
            flamencoScale = new int[7] {
                1, 3, 1, 2, 1, 3, 1
            };
            bluesScale     = new int[] { 3, 2, 1, 1, 3, 2 };
            flamenco2Scale = new int[7] {
                1, 3, 1, 2, 1, 2, 2
            };

            int[]     scaleIntervals = minorScale;
            ScaleName scaleName      = ScaleName.Minor;

            selectedScale = new MyScale(scaleName, scaleIntervals);

            tonica = Note.A3;

            scaleComboBox.SelectedIndex = 0;

            buttons       = new Button[6, 16];
            player        = new MediaPlayer();
            player.Volume = 0.3;
            outputDevice  = ExampleUtil.ChooseOutputDeviceFromConsole();
            outputDevice.Open();
            outputDevice.SendProgramChange(Channel.Channel1, Instrument.AcousticGuitarSteel);

            grifNotes = new Note[6, 16];

            //Заполняем 6 струну
            for (int i = 0; i < grifNotes.GetLength(1); i++)
            {
                grifNotes[5, i] = (Note)(40 + i);
            }
            //Заполняем 5 струну
            for (int i = 0; i < grifNotes.GetLength(1); i++)
            {
                grifNotes[4, i] = (Note)(45 + i);
            }
            //Заполняем 4 струну
            for (int i = 0; i < grifNotes.GetLength(1); i++)
            {
                grifNotes[3, i] = (Note)(50 + i);
            }
            //Заполняем 3 струну
            for (int i = 0; i < grifNotes.GetLength(1); i++)
            {
                grifNotes[2, i] = (Note)(55 + i);
            }
            //Заполняем 2 струну
            for (int i = 0; i < grifNotes.GetLength(1); i++)
            {
                grifNotes[1, i] = (Note)(59 + i);
            }
            //Заполняем 1 струну
            for (int i = 0; i < grifNotes.GetLength(1); i++)
            {
                grifNotes[0, i] = (Note)(64 + i);
            }

            int tabindex = 4;

            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    buttons[i, j]          = (Button)this.Controls["s" + (i + 1).ToString() + j.ToString()];
                    buttons[i, j].TabIndex = tabindex;
                    tabindex++;
                }
            }

            //Создание надписей над аппликатурой
            labels = new Label[6, 16]; this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    labels[i, j]           = new Label();
                    labels[i, j].AutoSize  = true;
                    labels[i, j].Font      = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
                    labels[i, j].ForeColor = System.Drawing.Color.Black;
                    Point p = new Point();
                    p.X = buttons[i, j].Location.X;// +buttons[i, j].Width / 2;
                    p.Y = buttons[i, j].Location.Y;
                    labels[i, j].Location = p;
                    labels[i, j].Name     = "label" + i.ToString() + j.ToString();
                    labels[i, j].Size     = new System.Drawing.Size(15, 13);
                    //labels[i, j].TabIndex = 113;
                    labels[i, j].Text      = "T";
                    labels[i, j].Visible   = false;
                    labels[i, j].BackColor = System.Drawing.Color.Transparent;
                    this.Controls.Add(labels[i, j]);
                    labels[i, j].BringToFront();
                }
            }

            for (int j = 0; j < 6; j++)
            {
                for (int k = 0; k < 16; k++)
                {
                    buttons[j, k].Click += grif_Click;
                }
            }
        }
Exemple #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;
        }
Exemple #5
0
        private void scaleComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            int[] scaleIntervals = minorScale;
            ScaleName scaleName = ScaleName.Minor;
            
            switch (scaleComboBox.SelectedIndex)
            {
                case 0://Выбран натуральный минор
                    scaleIntervals = minorScale;
                    scaleName = ScaleName.Minor;
                    break;
                case 1://Выбран натуральный мажор
                    scaleIntervals = majorScale;
                    scaleName = ScaleName.Major;
                    break;
                case 2:
                    scaleIntervals = flamencoScale;
                    scaleName = ScaleName.Flamenco;
                    break;
                case 3:
                    scaleIntervals = bluesScale;
                    scaleName = ScaleName.Blues;
                    break;
                case 4:
                    scaleIntervals = flamenco2Scale;
                    scaleName = ScaleName.Flamenco2;
                    break;
            }

            selectedScale = new MyScale(scaleName, scaleIntervals);
        }
Exemple #6
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);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            savedMelodysList = new List<Melody>();
            savedMelodysList = Parser.GetAllMelodys();
            for (int i = 0; i < savedMelodysList.Count; i++)
            {
                savedMelodysComboBox.Items.Add(savedMelodysList[i].Name + "(" + savedMelodysList[i].ScaleName.ToString() + ")");
            }
            if(savedMelodysComboBox.Items.Count != 0)
                savedMelodysComboBox.SelectedIndex = 0;
            nameLabel.Text = "Сгенерируйте мелодию!";
            notesTextBox.Text = "";
            rhythmTextBox.Text = "";
            notesCountTextBox.Text = "16";

            //Melody.Number = melodyList.Count + 1;

            generatedMelodysList = new List<Melody>();

            gridButtons = new int[6, 16];

            /* Гаммы можно менять, но их длина должна оставаться прежней.
             * В противном случае, нужно произвести изменения в файле MyRandom.cs
             */
            minorScale = new int[7] { 2, 1, 2, 2, 1, 2, 2 };
            majorScale = new int[7] { 2, 2, 1, 2, 2, 2, 1 };
            flamencoScale = new int[7] { 1, 3, 1, 2, 1, 3, 1 };
            bluesScale = new int[] { 3, 2, 1, 1, 3, 2 };
            flamenco2Scale = new int[7] { 1, 3, 1, 2, 1, 2, 2 };

            int[] scaleIntervals = minorScale;
            ScaleName scaleName = ScaleName.Minor;
            selectedScale = new MyScale(scaleName, scaleIntervals);

            tonica = Note.A3;

            scaleComboBox.SelectedIndex = 0;

            buttons = new Button[6, 16];
            player = new MediaPlayer();
            player.Volume = 0.3;
            outputDevice = ExampleUtil.ChooseOutputDeviceFromConsole();
            outputDevice.Open();
            outputDevice.SendProgramChange(Channel.Channel1, Instrument.AcousticGuitarSteel);

            grifNotes = new Note[6, 16];

            //Заполняем 6 струну
            for (int i = 0; i < grifNotes.GetLength(1); i++)
            {
                grifNotes[5, i] = (Note)(40 + i);
            }
            //Заполняем 5 струну
            for (int i = 0; i < grifNotes.GetLength(1); i++)
            {
                grifNotes[4, i] = (Note)(45 + i);
            }
            //Заполняем 4 струну
            for (int i = 0; i < grifNotes.GetLength(1); i++)
            {
                grifNotes[3, i] = (Note)(50 + i);
            }
            //Заполняем 3 струну
            for (int i = 0; i < grifNotes.GetLength(1); i++)
            {
                grifNotes[2, i] = (Note)(55 + i);
            }
            //Заполняем 2 струну
            for (int i = 0; i < grifNotes.GetLength(1); i++)
            {
                grifNotes[1, i] = (Note)(59 + i);
            }
            //Заполняем 1 струну
            for (int i = 0; i < grifNotes.GetLength(1); i++)
            {
                grifNotes[0, i] = (Note)(64 + i);
            }

            int tabindex = 4;
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    buttons[i, j] = (Button)this.Controls["s" + (i + 1).ToString() + j.ToString()];
                    buttons[i, j].TabIndex = tabindex;
                    tabindex++;
                }
            }

            //Создание надписей над аппликатурой
            labels = new Label[6, 16]; this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    labels[i, j] = new Label();
                    labels[i, j].AutoSize = true;
                    labels[i, j].Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
                    labels[i, j].ForeColor = System.Drawing.Color.Black;
                    Point p = new Point();
                    p.X = buttons[i, j].Location.X;// +buttons[i, j].Width / 2;
                    p.Y = buttons[i, j].Location.Y;
                    labels[i, j].Location = p;
                    labels[i, j].Name = "label" + i.ToString() + j.ToString();
                    labels[i, j].Size = new System.Drawing.Size(15, 13);
                    //labels[i, j].TabIndex = 113;
                    labels[i, j].Text = "T";
                    labels[i, j].Visible = false;
                    labels[i, j].BackColor = System.Drawing.Color.Transparent;
                    this.Controls.Add(labels[i, j]);
                    labels[i, j].BringToFront();
                }
            }

            for (int j = 0; j < 6; j++)
            {
                for (int k = 0; k < 16; k++)
                {
                    buttons[j, k].Click += grif_Click;
                }
            }
        }