private void SongNoteDuration_Error(object sender, Exception e)
 {
     PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent()
     {
         EventType = PlayableEventType.Error, EventDetails = $"{e}"
     });
 }
 private void NotePlayer_PlayerEvent(object sender, PlayerEngineEvent e)
 {
     if (e.EventType == PlayerEventType.PlayNotes)
     {
         PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent()
         {
             EventType = PlayableEventType.PlayingNote, EventDetails = e.Message
         });
     }
 }
 /// <summary>
 /// Loads a sequence of octave weighted, timed and instrument specific notes from a string into <see cref="NoteSequence"/>
 /// </summary>
 /// <param name="sequence"></param>
 public void LoadSequenceFromString(IEnumerable <string> sequence)
 {
     Song.SetNoteSequence(sequence.ToArray());
     PrepareSequence();
     PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent()
     {
         EventType    = PlayableEventType.SequenceLoaded,
         EventDetails = $"{NoteSequence.Count()} Notes loaded."
     });
 }
 private void SongNoteDuration_PlayingNote(object sender, EventArgs e)
 {
     if (sender is MusicNote musicNote)
     {
         var message = $"Playing note {musicNote.Key}{musicNote.DesiredOctave} at {musicNote.Frequencies[musicNote.DesiredOctave]} Hz for {musicNote.Duration}ms as {musicNote.Instrument}.";
         PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent()
         {
             EventType = PlayableEventType.PlayingNote, EventDetails = message
         });
     }
 }
        /// <summary>
        /// Plays the sequence of notes in <see cref="NoteSequence"/>
        /// </summary>
        public void Play()
        {
            if ((CompositeNotes?.Count() ?? 0) == 0)
            {
                PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent()
                {
                    EventType = PlayableEventType.Error, EventDetails = "There are no notes to play"
                });
                return;
            }

            var repeat  = Repeat ?? 1;
            var message = $"Playing sequence of {CompositeNotes?.Count() ?? 0} notes {repeat} time(s).";

            PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent()
            {
                EventType = PlayableEventType.StartSequence, EventDetails = message
            });
            for (var counter = repeat; counter > 0; counter--)
            {
                foreach (var songNoteDuration in CompositeNotes)
                {
                    try
                    {
                        NotePlayer.Play(songNoteDuration.Notes, InstrumentType);
                    }
                    catch (Exception ex)
                    {
                        PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent()
                        {
                            EventType = PlayableEventType.Error, EventDetails = $"{ex}"
                        });
                    }
                }
            }
            PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent()
            {
                EventType = PlayableEventType.StopSequence, EventDetails = $"Finished playing {CompositeNotes.Count()} notes."
            });
        }