Пример #1
0
 public void Play(CollisionEvent collisionEvent)
 {
     this.ModWheel = collisionEvent.ModWheel;
     this.Play(collisionEvent.Note, collisionEvent.Velocity);
 }
Пример #2
0
 public void AddSound(int gameObjectIndex, CollisionEvent soundEvent)
 {
     this.soundDataList.Add(new CollisionSoundData(gameObjectIndex, soundEvent));
 }
Пример #3
0
        public CollisionEvent CreateCollisionEvent(float impulse, bool withBall, bool withTable)
        {
            CollisionEvent result = null;

            if (float.IsNaN(impulse) || impulse < this.configuration.MinimumImpulse)
            {
            }
            else
            {
                // Set mod wheel according to the impulse value. This will vary the attack of the sound
                // and make them less repetitive and more dynamic. The sampler patch is set up to play the full
                // sound with modWheel off, and shortened attack with increasing modwheel value. So we invert the
                // normalized range.
                //
                // Also, we want to alter the velocity so that higher impulse means a louder note.

                byte note;
                if (withTable)
                {
                    note = Note.CollisionWithTable;
                }
                else if (withBall)
                {
                    note = Note.CollisionWithBall;
                }
                else
                {
                    note = Note.CollisionWithBlock;
                }

                note = (byte)(note + this.variant[0]);

                // move this variant randomly to another position
                var otherIndex = new Random().Next(variant.Length - 1);// Int(arc4random_uniform(UInt32(variant.count - 1)))

                //variant.swapAt(0, 1 + otherIndex)
                var temp = variant[0];
                variant[0] = variant[1 + otherIndex];
                variant[1 + otherIndex] = temp;

                var normalizedImpulse = DigitExtensions.Clamp((impulse - this.configuration.MinimumImpulse) / (this.configuration.MaximumImpulse - this.configuration.MinimumImpulse),
                                                              0f,
                                                              1f);

                // Once the impulse is normalized to the range 0...1, doing a sqrt
                // on it causes lower values to be higher. This curve was chosen because
                // it sounded better aesthetically.
                normalizedImpulse = (float)Math.Sqrt(normalizedImpulse);

                var rangedImpulse = this.configuration.VelocityMinimum + (this.configuration.VelocityMaximum - this.configuration.VelocityMinimum) * normalizedImpulse;
                var velocity      = (byte)(DigitExtensions.Clamp(rangedImpulse, 0, 127));

                result = new CollisionEvent
                {
                    Note     = note,
                    Velocity = velocity,
                    ModWheel = 1f - normalizedImpulse,
                };
            }

            return(result);
        }