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); }
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); } }
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); }
private void tempoTrackBar_Scroll(object sender, EventArgs e) { duration = Rhythm.GetDuration(tempoTrackBar.Value, notesCount); }