/// <summary> /// Tries to read the Note, next tries to change frequency of it and /// every single note in base. /// </summary> public void ReadNoteChange(string note, float frequency) { if (MusicalNote.IsValidName(note) && MusicalNote.IsValidFrequency(frequency)) { rm.ChangeNoteArray(note, frequency); } }
public void PlaySound(MusicalNote note, float gain, float time, SignalGeneratorType signalType) { PlaySound( new MusicalNote[] { note }, gain, time, signalType ); }
public async void PlaySound() { try { Chord chord; chord = SelectedChord; if (ChordsPlayed.Count == 0) { return; } foreach (var i in SelectedChord.MusicalNotes) { if (!MusicalNote.IsValidName(i.Name)) { chord = ChordsPlayed[ChordsPlayed.Count - 1]; break; } } List <MusicalNote> chordWithFrequencies = new List <MusicalNote>(); foreach (var n in chord.MusicalNotes) { chordWithFrequencies.Add(RuntimeSettings.MusicalNotes.Find(x => x.Name == n.Name)); } if (AllAtOnce) { nAudioCommunication. PlaySound( chordWithFrequencies.ToArray(), RuntimeSettings.Volume, RuntimeSettings.Duration, SignalGeneratorType.Sin //todo przenieść to ); } else { foreach (var note in chordWithFrequencies) { nAudioCommunication. PlaySound( note, RuntimeSettings.Volume, RuntimeSettings.Duration / chord.MusicalNotes.Length, SignalGeneratorType.Sin //todo przenieść to ); await Task.Delay((int)RuntimeSettings.Duration / chord.MusicalNotes.Length * 1000); } } } catch (Exception e) { } }
/// <summary> /// Reads the Chord content /// </summary> public Chord ReadChord(string input) { input = input.Replace(" ", ""); var s = input.Split('^'); List <Note> notes = new List <Note>(); foreach (var item in s) { int t = 0; List <string> parts = new List <string>(); parts.Add(""); for (int i = 0; i < item.Length; i++) { if (item[i] == '-' || item[i] == '+') { parts.Add(""); t++; } parts[t] += item[i]; } string note = ""; int modifier = 0; foreach (var part in parts) { try { if (MusicalNote.IsValidName(part)) { note = part; } else { if (int.TryParse(part, out int result)) { modifier += result; } else { throw new ArgumentException(); } } } catch (ArgumentException e) { throw e; } } var u = rm.RuntimeSettings.MusicalNotes.Find(x => x.Name == note); // Note tried to create MusicalNote because he has given frequency, // Issues with serialization TODO if (u != null && !(u.Frequency == 0)) { var z = rm.RuntimeSettings.MusicalNotes.Find(y => y.Rank == u.Rank + modifier); Note o = new Note(); o.Name = z.Name; notes.Add(o); } } return(new Chord(notes.ToArray())); }