home *** CD-ROM | disk | FTP | other *** search
- #include <time.h>
- #include <stdio.h>
- #include <conio.h>
- #include <dos.h>
- #include <sys\timeb.h>
- #include <stdlib.h>
-
- void do_time(void);
- int get_delay(void);
-
- void do_time()
- {
- unsigned int Delay,i;
- float bpm,d;
- char ch;
- int Quit;
-
- ch = ' ';
- Delay = 500;
- Quit = 0;
-
- while (!Quit)
- {
- d = Delay;
- d /= 1000;
- bpm = 60/d;
- i = (int)bpm;
-
- clrscr();
- printf("BPM : %d\n\n",i);
- printf("Press : + to increase\n");
- printf(" - to decrease\n");
- printf(" T to time\n");
- printf(" Q to quit\n");
- printf(" P to start on beat\n");
-
- while(!kbhit())
- {
- sound(500);
- delay(10);
- nosound();
- delay(Delay-10);
- }
-
- ch = getch();
- switch(ch)
- {
- case 'p' :
- case 'P' : clrscr();
- printf("Press any key to start on the beat...");
- getch();
- break;
-
- case 'q' :
- case 'Q' : Quit = 1;
- break;
-
- case 't' :
- case 'T' : Delay = get_delay();
- break;
-
- case '+' : d = Delay;
- d /= 1000;
- bpm = 60/d;
- bpm += 1;
- d = 60/bpm;
- d *= 1000;
- Delay = d;
- break;
-
- case '-' : d = Delay;
- d /= 1000;
- bpm = 60/d;
- bpm -= 1;
- d = 60/bpm;
- d *= 1000;
- Delay = d;
- break;
- }
- }
- }
-
-
- int get_delay()
- {
- char ch;
-
- struct timeb times[100],t;
- float difference;
- int i,j;
- double complete1,complete2;
-
- clrscr();
- printf("Tap the beat with any key... and then\n");
- printf("Press Q when finished.\n");
-
- i = 0;
- ch = ' ';
- while (ch != 'Q')
- {
- ch = getch();
-
- sound(500);
- delay(10);
- nosound();
-
- if ((ch != 'Q') && (ch != 'q'))
- {
- ftime(&t);
- times[i] = t;
- i++;
- }
- }
-
- j = 0;
- difference = 0;
-
- while (j < i-1)
- {
- complete1 = (double)times[j].millitm;
- complete1 /= 1000;
- complete1 += times[j].time;
-
- complete2 = (double)times[j+1].millitm;
- complete2 /= 1000;
- complete2 += times[j+1].time;
-
- difference += complete2 - complete1;
- j++;
- }
-
- difference /= (i-1);
- difference *= 1000;
- i = (int) difference;
- return i;
- }
-
-
- int main()
- {
- char *tzstr = "TZ=PST8PDT";
- int delay;
-
- putenv(tzstr);
- tzset();
-
- do_time();
-
- return 0;
-
- }
-