Beispiel #1
0
        /// <summary>
        /// サウンドオン
        /// </summary>
        public virtual void KeyOn()
        {
            IsSoundingStarted = true;
            IsKeyOff          = false;
            IsSoundOff        = false;

            if (ParentModule.ModulationDepthes[NoteOnEvent.Channel] > 64 ||
                ParentModule.Modulations[NoteOnEvent.Channel] > 0)
            {
                ModulationEnabled = true;
            }

            int ln = ParentManager.GetLastNoteNumber(NoteOnEvent.Channel);

            if (ParentModule.Portamentos[NoteOnEvent.Channel] >= 64 || ln > 0x80)
            {
                if (ln >= 0)
                {
                    ln &= 0x7f;
                    PortamentoDeltaNoteNumber = ln - NoteOnEvent.NoteNumber;
                    portStartNoteDeltSign     = Math.Sign(PortamentoDeltaNoteNumber);

                    PortamentoEnabled = true;
                }
            }

            var adsrs = Timbre.SDS.ADSR;

            ActiveADSR = adsrs.Enable;
            if (ActiveADSR)
            {
                AdsrEngine = new AdsrEngine();
                AdsrEngine.SetAttackRate(Math.Pow(10d * (127d - adsrs.AR) / 127d, 2));
                AdsrEngine.SetDecayRate(Math.Pow(100d * (adsrs.DR / 127d), 2));
                AdsrEngine.SetReleaseRate(Math.Pow(60d * (adsrs.RR / 127d), 2));
                AdsrEngine.SetSustainLevel((127d - adsrs.SL) / 127d);
                AdsrEngine.Gate(true);
            }

            var efs = Timbre.SDS.FxS;

            if (efs != null)
            {
                ActiveFx = efs.Enable;
            }

            SoundKeyOn?.Invoke(this, new SoundUpdatedEventArgs(NoteOnEvent.NoteNumber, NoteOnEvent.Velocity, lastPitch));

            if (DrumTimbre != null)
            {
                HighPrecisionTimer.SetPeriodicCallback
                    (new Func <object, double>(processGateTime), DrumTimbre.GateTime, this, true);
            }
        }
Beispiel #2
0
        /// <summary>
        ///キーオフ
        /// </summary>
        public virtual void KeyOff()
        {
            if (IsKeyOff)
            {
                return;
            }

            IsKeyOff = true;
            AdsrEngine?.Gate(false);

            TrySoundOff();

            SoundKeyOff?.Invoke(this, new SoundUpdatedEventArgs(NoteOnEvent.NoteNumber, NoteOnEvent.Velocity, lastPitch));
        }
Beispiel #3
0
        /// <summary>
        /// サウンドオフ
        /// </summary>
        public virtual void SoundOff()
        {
            if (!IsKeyOff)
            {
                IsKeyOff = true;
                AdsrEngine?.Gate(false);

                SoundKeyOff?.Invoke(this, new SoundUpdatedEventArgs(NoteOnEvent.NoteNumber, NoteOnEvent.Velocity, lastPitch));
            }

            IsSoundOff = true;

            SoundOffTime = soundOffTimeCounter++;

            SoundSoundOff?.Invoke(this, EventArgs.Empty);
        }
Beispiel #4
0
        private double processAdsr(object state)
        {
            if (!IsDisposed && ActiveADSR && AdsrEngine != null)
            {
                AdsrEngine.Process();

                OnProcessAdsr();

                if (AdsrEngine.AdsrState != AdsrState.SoundOff)
                {
                    return(1);
                }

                ActiveADSR = false;
                TrySoundOff();
            }
            return(-1);
        }