AlphaTab.Audio.Generator.MidiFileGenerator.GenerateBend C# (CSharp) Метод

GenerateBend() приватный Метод

private GenerateBend ( Note note, int noteStart, int noteDuration, int noteKey, DynamicValue dynamicValue ) : void
note AlphaTab.Model.Note
noteStart int
noteDuration int
noteKey int
dynamicValue DynamicValue
Результат void
        private void GenerateBend(Note note, int noteStart, int noteDuration, int noteKey, DynamicValue dynamicValue)
        {
            var track = note.Beat.Voice.Bar.Staff.Track;
            var ticksPerPosition = ((double)noteDuration) / BendPoint.MaxPosition;
            for (int i = 0; i < note.BendPoints.Count - 1; i++)
            {
                var currentPoint = note.BendPoints[i];
                var nextPoint = note.BendPoints[i + 1];

                // calculate the midi pitchbend values start and end values
                var currentBendValue = DefaultBend + (currentPoint.Value * DefaultBendSemitone);
                var nextBendValue = DefaultBend + (nextPoint.Value * DefaultBendSemitone);

                // how many midi ticks do we have to spend between this point and the next one?
                var ticksBetweenPoints = ticksPerPosition * (nextPoint.Offset - currentPoint.Offset);

                // we will generate one pitchbend message for each value
                // for this we need to calculate how many ticks to offset per value

                var ticksPerValue = ticksBetweenPoints / Math.Abs(nextBendValue - currentBendValue);
                var tick = noteStart + (ticksPerPosition * currentPoint.Offset);
                // bend up
                if (currentBendValue < nextBendValue)
                {
                    while (currentBendValue <= nextBendValue)
                    {
                        _handler.AddBend(track.Index, (int)tick, (byte)track.PlaybackInfo.PrimaryChannel, (byte)Math.Round(currentBendValue));
                        currentBendValue++;
                        tick += ticksPerValue;
                    }
                }
                // bend down
                else if (currentBendValue > nextBendValue)
                {
                    while (currentBendValue >= nextBendValue)
                    {
                        _handler.AddBend(track.Index, (int)tick, (byte)track.PlaybackInfo.PrimaryChannel, (byte)Math.Round(currentBendValue));
                        currentBendValue--;
                        tick += ticksPerValue;
                    }
                }
            }
        }