Esempio n. 1
0
        private static void PlayableSequence_PlayableSequenceEvent(object sender, PlayableSequenceEvent e)
        {
            var textColor = ConsoleColor.White;

            switch (e.EventType)
            {
            case PlayableEventType.StartSequence:
            case PlayableEventType.CreateNote:
                textColor = ConsoleColor.Blue;
                break;

            case PlayableEventType.SettingSequence:
            case PlayableEventType.StopSequence:
                textColor = ConsoleColor.Yellow;
                break;

            case PlayableEventType.PlayingNote:
                textColor = ConsoleColor.Green;
                break;

            case PlayableEventType.Error:
                textColor = ConsoleColor.Red;
                break;

            case PlayableEventType.SequenceLoaded:
                textColor = ConsoleColor.White;
                break;
            }
            WriteMessage($"Event: {e.EventType} -> {e.EventDetails}", textColor);
        }
Esempio n. 2
0
 private void SongNoteDuration_Error(object sender, Exception e)
 {
     PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent()
     {
         EventType = PlayableEventType.Error, EventDetails = $"{e}"
     });
 }
Esempio n. 3
0
 private void NotePlayer_PlayerEvent(object sender, PlayerEngineEvent e)
 {
     if (e.EventType == PlayerEventType.PlayNotes)
     {
         PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent()
         {
             EventType = PlayableEventType.PlayingNote, EventDetails = e.Message
         });
     }
 }
Esempio n. 4
0
 /// <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."
     });
 }
Esempio n. 5
0
 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
         });
     }
 }
Esempio n. 6
0
        /// <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."
            });
        }