예제 #1
0
 private static void PlayNoteAsRequired(string note, int a4Reference, PlayableSequence playableSequence)
 {
     if (note != null)
     {
         var musicNote = MusicNote.Create(note, a4Reference);
         if (musicNote?.IsValid ?? false)
         {
             ShowNote(musicNote);
             var musicNotes = musicNote.MajorScale.ToArray();
             WriteMessage($"Playing Major Scale: {string.Join(',', musicNotes)}");
             playableSequence.LoadSequenceFromString(musicNote.MajorScale);
             playableSequence.Prepare();
             playableSequence.Play();
             Thread.Sleep(1000);
             musicNotes = musicNote.MinorScale.ToArray();
             WriteMessage($"Playing Minor Scale: {string.Join(',', musicNotes)}");
             playableSequence.LoadSequenceFromString(musicNote.MinorScale);
             playableSequence.Prepare();
             playableSequence.Play();
             Thread.Sleep(1000);
             WriteMessage($"Playing Relative Minor Scale {musicNote.RelativeMinor}m: {string.Join(',', musicNote.RelativeMinorScale)}");
             playableSequence.LoadSequenceFromString(musicNote.RelativeMinorScale);
             playableSequence.Prepare();
             playableSequence.Play();
         }
         else
         {
             WriteMessage($"{note} is NOT a valid note!", ConsoleColor.Red);
         }
     }
 }
예제 #2
0
        private IEnumerable <FrequencyDuration> GetNoteFrequencyAndDuration(IEnumerable <string> notes, int a4Ref, IPlayer player, InstrumentType instrument)
        {
            var noteDuration = 0;

            foreach (var noteString in notes)
            {
                string currentNote    = null;
                var    noteInstrument = instrument;
                var    notesParts     = noteString.Split('-');
                if (notesParts.Length > 0)
                {
                    currentNote = notesParts[0];
                }
                if (notesParts.Length > 1)
                {
                    noteDuration = (int)(float.Parse(notesParts[1]));
                }
                if (notesParts.Length > 2)
                {
                    noteInstrument = (InstrumentType)Enum.Parse(typeof(InstrumentType), notesParts[2]);
                }
                if (currentNote.Contains("W", StringComparison.InvariantCultureIgnoreCase))
                {
                    yield return(new FrequencyDuration("W", 0, 0F, noteDuration));
                }
                else
                {
                    var musicNote = MusicNote.Create(currentNote, a4Ref, player, noteDuration, noteInstrument);
                    yield return(new FrequencyDuration(musicNote.Key, musicNote.DesiredOctave, musicNote.CurrentFrequency, noteDuration));
                }
            }
        }