Example #1
0
        /// <summary>
        /// 버퍼에 저장되어 있던 음표를 안전하게 재생하고 버퍼를 비웁니다.
        /// </summary>
        private static void FlushSyncPlayBuffer()
        {
            /*
             * List<KeyValuePair<Note, int>> tempSyncPlayBuffer = syncPlayBuffer;
             * syncPlayBuffer = new List<KeyValuePair<Note, int>>();
             * try
             * {
             *  foreach (KeyValuePair<Note, int> p in tempSyncPlayBuffer)
             *  {
             *      Score.PlayANote(outDevice, p.Key, (int)Math.Round(p.Value * (SFXTheme.CurrentSFXTheme.Volume / 100D)));
             *  }
             *
             *  List<int> tempPlayPitchEventBuffer = playPitchEventBuffer;
             *  playPitchEventBuffer = new List<int>();
             *  foreach (int pitch in tempPlayPitchEventBuffer)
             *  {
             *      OnPlayNotes?.Invoke(pitch);
             *  }
             * }
             * catch (InvalidOperationException)
             * {
             *
             * }
             */
            void FlushPlay(object[] args)
            {
                List <Note> tempSyncPlayBuffer = syncPlayBuffer;

                syncPlayBuffer = new List <Note>();
                for (int i = tempSyncPlayBuffer.Count - 1; i >= 0; i--)
                {
                    Note n = tempSyncPlayBuffer[i];
                    //Score.PlayANote(outDevice, p.Key, (int)Math.Round(p.Value * (SFXTheme.CurrentSFXTheme.Volume / 100D)));
                    Score.PlayANote(syn, n, SFXTheme.CurrentSFXTheme.Volume / 100f);
                }

                List <int> tempPlayPitchEventBuffer = playPitchEventBuffer;

                playPitchEventBuffer = new List <int>();
                for (int i = tempPlayPitchEventBuffer.Count - 1; i >= 0; i--)
                {
                    OnPlayNotes?.Invoke(tempPlayPitchEventBuffer[i]);
                }
            }

            Util.TaskQueue.Add("play", FlushPlay);
        }
Example #2
0
        /// <summary>
        /// 음표 하나를 버퍼에 저장했다가 다음 박자에 맞춰 재생합니다.
        /// </summary>
        /// <param name="pitch"></param>
        /// <param name="rhythm"></param>
        /// <param name="staff"></param>
        /// <param name="velocity"></param>
        public static void PlayANoteSync(int pitch, int velocity, int rhythm, int staff)
        {
            if (!HasStart)
            {
                return;
            }

            void PlaySync(object[] args)
            {
                int pitch_    = (int)args[0];
                int velocity_ = (int)args[1];
                int rhythm_   = (int)args[2];
                int staff_    = (int)args[3];

                Note note = new Note(pitch_, velocity_, rhythm_, Measure, Position, staff_);

                if (NoteResolution == 0)
                {
                    //Score.PlayANote(outDevice, note, (int)Math.Round(velocity * (SFXTheme.CurrentSFXTheme.Volume / 100D)));
                    Score.PlayANote(syn, note, SFXTheme.CurrentSFXTheme.Volume / 100f);

                    List <int> tempPlayPitchEventBuffer = playPitchEventBuffer;
                    playPitchEventBuffer = new List <int>();
                    foreach (int p in tempPlayPitchEventBuffer)
                    {
                        OnPlayNotes?.Invoke(p);
                    }
                }
                else
                {
                    syncPlayBuffer.Add(note);
                }
            }

            Util.TaskQueue.Add("play", PlaySync, pitch, velocity, rhythm, staff);
        }