예제 #1
0
        public void FillMidiEventQueue()
        {
            if (!IsPlaying || Synth.MidiEventQueue.Length != 0)
            {
                return;
            }
            if (CurrentTime >= EndTime)
            {
                CurrentTime = 0;
                _eventIndex = 0;
                IsPlaying   = false;
                Synth.NoteOffAll(true);
                Synth.ResetPrograms();
                Synth.ResetSynthControls();
                FireFinished();
                return;
            }

            var newMSize  = (int)(Synth.MicroBufferSize * _playbackRate);
            var endSample = CurrentTime + (newMSize * Synth.MicroBufferCount);

            for (int x = 0; x < Synth.MicroBufferCount; x++)
            {
                CurrentTime += newMSize;
                while (_eventIndex < _synthData.Length && _synthData[_eventIndex].Delta < CurrentTime)
                {
                    if (_synthData[_eventIndex].Event.Command != MidiEventTypeEnum.NoteOn || !_blockList[_synthData[_eventIndex].Event.Channel])
                    {
                        Synth.MidiEventQueue.AddFirst(_synthData[_eventIndex]);
                        Synth.MidiEventCounts[x]++;
                    }
                    _eventIndex++;
                }
            }
        }
예제 #2
0
        public void Seek(int milliseconds)
        {
            var targetSampleTime = (int)(Synth.SampleRate * (milliseconds / 1000.0));

            if (targetSampleTime > CurrentTime)
            {//process forward
                SilentProcess(targetSampleTime - CurrentTime);
            }
            else if (targetSampleTime < CurrentTime)
            {//we have to restart the midi to make sure we get the right state: instruments, volume, pan, etc
                CurrentTime = 0;
                _eventIndex = 0;
                Synth.NoteOffAll(true);
                Synth.ResetPrograms();
                Synth.ResetSynthControls();
                SilentProcess(targetSampleTime);
            }
        }