Exemplo n.º 1
0
        private void generateButton_Click(object sender, EventArgs e)
        {
            int[] notes  = Notes.GetNotes(Notes.Chords.Am, 1);
            int[] rhythm = Rhythm.GetRhythm(6, 4);

            //testTextBox.Text = Parser.GetString(notes);

            player.Open(new Uri(Application.StartupPath + "\\Chords\\Am.m4a", UriKind.Absolute));
            player.Play();

            SoundDevices sd = new SoundDevices(outputDevice, Channel.Channel1);

            MelodyPlayer.PlayMelody(sd, notes, player);

            notes = Notes.GetNotes(Notes.Chords.F, 2);
            //testTextBox.Text = Parser.GetString(notes);

            MelodyPlayer.PlayMelody(sd, notes, player);

            notes = Notes.GetNotes(Notes.Chords.Dm, 2);
            //testTextBox.Text = Parser.GetString(notes);

            MelodyPlayer.PlayMelody(sd, notes, player);

            notes = Notes.GetNotes(Notes.Chords.E, 4);
            //testTextBox.Text = Parser.GetString(notes);

            MelodyPlayer.PlayMelody(sd, notes, player);
        }
Exemplo n.º 2
0
        private void newGenerateButton_Click(object sender, EventArgs e)
        {
            tabControl1.SelectedIndex = 0;
            duration = Rhythm.GetDuration(tempoTrackBar.Value, notesCount);
            Random random = new Random();
            int    divisor = random.Next(3, 5), addition = random.Next(1, 4);

            int[] rhythm = Rhythm.GetRhythm(notesCount + notesCount / divisor + addition, notesCount);
            int[] notes  = Notes.GetNotes(selectedScale, notesCount, rhythm);

            generatedMelody = new Melody(Melody.Number + "-ая мелодия", notes, rhythm, selectedScale.scaleName);
            generatedMelodysList.Add(generatedMelody);
            generatedMelodysComboBox.Items.Add(generatedMelody.Name + "(" + generatedMelody.ScaleName.ToString() + ")");
            generatedMelodysComboBox.SelectedIndex = generatedMelodysList.IndexOf(generatedMelody);
            Melody.Number++;

            rhythmTextBox.Text = Parser.GetString(rhythm);
            notesTextBox.Text  = Parser.GetString(notes);

            if (sd == null)
            {
                sd = new SoundDevices(outputDevice, Channel.Channel1);
            }

            SetLabelsNameNotesAndRhythm(generatedMelody);
            //saveMelodyButton.Enabled = true;

            SetEnable(false, SetEnableMode.All);
            cts = new CancellationTokenSource();
            stopButton.Select();
            timer.Start();
            task = Task.Run(() =>
            {
                MelodyPlayer.PlayMelodyWithRhythm(sd, generatedMelody, tonica, duration, grifNotes, buttons, cts.Token);
            }, cts.Token);
        }