Turning off While loop in realtime
Hello all,
I'm going to ask a question that involves MIDI, but it actually doesn't have to be MIDI. My questions is on how to turn off the while loop via hardware input. (i.e. keyboard)
I'm trying to write code that begins looping once it receives a MIDI note on message, and turns off when it receives a MIDI note off message. Here's part of the code:
while(1)
{
if(Pm_Poll(stream))
{
length = Pm_Read(stream, event, sizeof(long));
for(i = 0; i < length; i++)
{
status = Pm_MessageStatus(event[i].message);
data1 = Pm_MessageData1(event[i].message);
data2 = Pm_MessageData2(event[i].message);
printf("Status: %d, Data1: %d, Data2: %d\n", status, data1, data2);
}
int time, temp, loop = 0;
while(status==144){
//if(status==144)
//{
time = Pt_Time(NULL);
while(Pt_Time(NULL) - time < 100);
temp = loop;
loop = temp+1;
printf("\n%d\n", loop);
//}
if(status != 144) break;
}
if(status==128 && data1==67) break;
}
What it does now is it just keeps adding 1 to int loop every 100ms once it receives a MIDI note on, which is status 144. (in the second while loop)
The problem is that once the while loop is initiated, it doesn't update the status. In other words, once status == 144 it begins the loop, and it no longer takes in information which would break the while loop.
If someone can tell me how I can turn off the while loop after it's been initiated I would greatly appreciate it. Thanks in advance.