예제 #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);
        }
예제 #2
0
        private void playGeneratedMelodyButton_Click(object sender, EventArgs e)
        {
            SetEnable(false, SetEnableMode.All);
            isGenerated = true;

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

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

                duration = Rhythm.GetDuration(tempoTrackBar.Value, generatedMelody.Notes.Length);
                cts      = new CancellationTokenSource();
                stopButton.Select();
                timer.Start();
                task = Task.Run(() =>
                {
                    MelodyPlayer.PlayMelodyWithRhythm(sd, generatedMelody, tonica, duration, grifNotes, buttons, cts.Token);
                }, cts.Token);
            }
        }
예제 #3
0
        private void playYourMelodyButton_Click(object sender, EventArgs e)
        {
            SetEnable(false, SetEnableMode.All);

            int[] notes  = Parser.GetMassive(notesTextBox.Text);
            int[] rhythm = Parser.GetMassive(rhythmTextBox.Text);

            if (notes.Length == 0 || rhythm.Length == 0)
            {
                MessageBox.Show("Неверный формат мелодии!");
                return;
            }

            notesCountTextBox.Text = notes.Length.ToString();
            duration = Rhythm.GetDuration(tempoTrackBar.Value, notes.Length);

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

            Melody melody = new Melody("My melody", notes, rhythm, ScaleName.Other);

            cts = new CancellationTokenSource();
            stopButton.Select();
            timer.Start();
            task = Task.Run(() =>
            {
                MelodyPlayer.PlayMelodyWithRhythm(sd, melody, tonica, duration, grifNotes, buttons, cts.Token);
            }, cts.Token);
        }
예제 #4
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);
        }