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); }
public void RefreshListAndCombobox(List<Melody> list, Melody melody, ComboBox cmb, int[] notes, int[] rhythm) { int i = list.IndexOf(melody); cmb.Items.RemoveAt(i); cmb.Items.Insert(i, nameTextBox.Text + "(" + melody.ScaleName.ToString() + ")"); int j = list.IndexOf(melody); list.RemoveAt(i); melody = new Melody(nameTextBox.Text, notes, rhythm, melody.ScaleName); list.Insert(j, melody); /* Здесь срабатывает событие и меняется значение notesCountTextBox */ cmb.SelectedIndex = i; nameLabel.Text = melody.Name + "(" + melody.ScaleName.ToString() + ")"; }
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 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); }
public void SetLabelsNameNotesAndRhythm(Melody melody) { nameLabel.Text = melody.Name + "(" + melody.ScaleName.ToString() + ")"; notesTextBox.Text = Parser.GetString(melody.Notes); rhythmTextBox.Text = Parser.GetString(melody.Rhythm); notesCountTextBox.Text = melody.Notes.Length.ToString(); }
public static void PlayMelodyWithRhythm(SoundDevices sd, Melody melody, Note tonica, double duration, Note[,] grifNotes, Button[,] buttons, CancellationToken ct) { sd.output.SilenceAllNotes(); int[] notes = melody.Notes; int[] rhythm = melody.Rhythm; PlayMelodyWithRhythm(sd, notes, rhythm, tonica, duration, grifNotes, buttons, ct); }
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; }
public static void SaveMelodyToFile(Melody melody) { string line = melody.Name + ";" + melody.ScaleName.ToString() + ";" + GetString(melody.Notes) + ";" + GetString(melody.Rhythm) + ";"; using (StreamWriter sw = new StreamWriter("Melodys.txt", true, Encoding.GetEncoding(1251))) { sw.WriteLine(line); } }