Neo
Neo

Reputation: 203

The program ends straight away, why?

This code is supposed to repeatedly check the state of the D9 slider on an Axiom keyboard and use its value to control the pitch of a frequency.

int main()
{
    int note;
    int modwheel;
    float frequency;


    while (modwheel != 0)

    {
        note = aserveGetControl(74);
        modwheel = aserveGetControl(01);

        frequency = 440 * pow(2, (note-69) /12.0);
        aserveOscillator(1,frequency,1.0,0);
        aserveSleep(100);
    }



    return 0;
}

Upvotes: 1

Views: 110

Answers (1)

unwind
unwind

Reputation: 399803

You never initialize modwheel, so when the while loop starts, its value is "random", i.e. it can be zero, which causes the loop to end immediately.

Use a do/while loop to ensure it has at least one iteration, or use an infinite while (true) loop with an if inside to avoid actually handling 0 as valid input.

Upvotes: 3

Related Questions