private void textBoxNewFinal_TextChanged(object sender, EventArgs e)
        {
            recalcReentranceGuard++;
            try
            {
                if (recalcReentranceGuard == 1)
                {
                    // reverse-engineer other parameters from this desired value

                    double duration;
                    Double.TryParse(textBoxDuration.Text, out duration);

                    double initial, final;
                    Double.TryParse(textBoxInitial.Text, out initial);
                    Double.TryParse(textBoxFinal.Text, out final);

                    double newEnd;
                    Double.TryParse(textBoxEndOffset.Text, out newEnd);

                    double newFinal;
                    Double.TryParse(textBoxNewFinal.Text, out newFinal);

                    bool exponential = comboBoxFunction.SelectedIndex != 0;

                    if (!exponential)
                    {
                        // linear
                        newEnd = (newFinal - initial) / (final - initial);
                    }
                    else
                    {
                        // exponential

                        double initialDecibels  = Synthesizer.ExpSegEndpointToLog(initial);
                        double finalDecibels    = Synthesizer.ExpSegEndpointToLog(final);
                        double newFinalDecibels = Synthesizer.ExpSegEndpointToLog(newFinal);

                        newEnd = (newFinalDecibels - initialDecibels) / (finalDecibels - initialDecibels);
                    }

                    textBoxEndOffset.Text = newEnd.ToString();
                }
            }
            finally
            {
                recalcReentranceGuard--;
            }

            Recalculate(false /*updateInitialFinal*/);
        }
示例#2
0
        private double F(double x) // x normalized to [0..1]
        {
            if (!exponential)
            {
                return(initial + x * (final - initial));
            }
            else
            {
                double logInitial = Synthesizer.ExpSegEndpointToLog(initial);
                double logFinal   = Synthesizer.ExpSegEndpointToLog(final);

                double y = logInitial + x * (logFinal - logInitial);

                return(Synthesizer.ExpSegEndpointToLinear(y));
            }
        }
        private void Recalculate(bool updateInitialFinal)
        {
            recalcReentranceGuard++;
            try
            {
                if (recalcReentranceGuard == 1)
                {
                    double duration;
                    Double.TryParse(textBoxDuration.Text, out duration);

                    double initial, final;
                    Double.TryParse(textBoxInitial.Text, out initial);
                    Double.TryParse(textBoxFinal.Text, out final);

                    double newStart, newEnd;
                    Double.TryParse(textBoxStartOffset.Text, out newStart);
                    Double.TryParse(textBoxEndOffset.Text, out newEnd);

                    bool exponential = comboBoxFunction.SelectedIndex != 0;

                    double newInitial, newFinal;
                    if (!exponential)
                    {
                        // linear
                        newInitial = initial + newStart * (final - initial);
                        newFinal   = initial + newEnd * (final - initial);
                    }
                    else
                    {
                        // exponential

                        double initialDecibels = Synthesizer.ExpSegEndpointToLog(initial);
                        double finalDecibels   = Synthesizer.ExpSegEndpointToLog(final);

                        newInitial = initialDecibels + newStart * (finalDecibels - initialDecibels);
                        newFinal   = initialDecibels + newEnd * (finalDecibels - initialDecibels);

                        newInitial = Synthesizer.ExpSegEndpointToLinear(newInitial);
                        newFinal   = Synthesizer.ExpSegEndpointToLinear(newFinal);
                    }

                    newInitial = Math.Round(newInitial, 8);
                    newFinal   = Math.Round(newFinal, 8);

                    if (updateInitialFinal)
                    {
                        textBoxNewInitial.Text = newInitial.ToString();
                        textBoxNewFinal.Text   = newFinal.ToString();
                    }
                    statement = String.Format(
                        "delay {0} level {1}{2};",
                        duration * (newEnd - newStart),
                        newFinal,
                        exponential ? " exponential" : String.Empty);
                    textBoxStatement.Text = String.Format(
                        "[{0}]: {1}",
                        newInitial,
                        statement);

                    segmentCalculatorGraph.Update(initial, final, duration, newStart, newEnd, exponential);

                    savedInitial     = initial;
                    savedDelay       = duration;
                    savedFinal       = final;
                    savedExponential = exponential;
                    savedNewStart    = newStart;
                    savedNewEnd      = newEnd;
                }
            }
            finally
            {
                recalcReentranceGuard--;
            }
        }