Hi guys - new to the board ( and C in general)...so go easy
I'm currently working on the following code for a musical test and, basically, I'd like to add an option for the user to restart the test from within the program ( rather than running the .exe again).
I'll print something like "Do you want to run the test again? Y/N?"
Do I use another if/else statement ( like, ..if user_input == 'Y' then ...re-run the for loop - or however you code it - else if user_input =='N' then...quit=TRUE?
I know it's a simple question, but I can't seem to suss it.
Thanks in advance for any help!
insertCode:include "midi_lib.h" #include <stdio.h> #include <conio.h> #define TRUE 1 #define FALSE 0 int main(void) { int pitch_array[5] = {60,62,64,65,67}; //Range of notes ( C D E F G ) stored in an array// int count = 0; //Variable called count - counts through notes in the array// int quit = FALSE; //Variable called quit - starts and ends loop// int timbre = 1; //Variable called timbre - midi channel allocation// int pause_val = 1000; //Variable called pause_val - determines note length// char user_input; //Variable called char - keyboard input from user// //Changes timbres from initial value 1// program_change(1, 19); /* rock organ on channel 1 */ program_change(2, 1); /* piano on channel 2 */ program_change(3, 32); /* guitar harmonics on channel 3 */ program_change(4, 105);/* sitar on channel 4 */ printf (" =================PSYCHOACOUSTIC TEST================="); printf ("\n"); printf ("\n"); printf ("\nThe aim of this test is to determine the point at which a sequence of ascending"); printf ("\n"); printf ("\ntones consisting of different timbres, will appear to:"); printf ("\n"); printf ("\n"); printf ("\n1.descend in pitch, and"); printf ("\n"); printf ("\n2.sound alike to the listener."); printf ("\n"); printf ("\n"); printf ("\n"); printf ("\nWhen you begin the test, you will initially hear the sequence play slowly and"); printf ("\n"); printf ("\nbe aware of an incrementally ascending pitch scale consisting of easily"); printf ("\n"); printf ("\nidentifiable and contrasting timbres. It will then gradually begin to increase"); printf ("\n"); printf ("\nin speed and,at some point,you should be able to hear the sequence appear to"); printf ("\n"); printf ("\ndescend in pitch.(Initially, you may hear one prominent timbre descending -"); printf ("\n"); printf ("\ntry not to focus on this and wait until you begin to sense an overall effect)."); printf ("\n"); printf ("\nYou should also start to hear the different timbres begin to sound alike."); printf ("\n"); printf ("\nIf you hear the descending pitches, but not the similarity of timbres, I would"); printf ("\n"); printf ("\nlike you to take the test again in order to establish when this particular"); printf ("\n"); printf ("\neffect occurs. As a general guide, it will probably happen later than the"); printf ("\n"); printf ("\ndescending effect (i.e, when the sequence is faster)"); printf ("\n"); printf ("\nDuring the test, if you need to increase the speed of the sequence, press the"); printf ("\n"); printf ("\nPLUS key until you hear a difference ( you will also see a numerical counter on"); printf ("\n"); printf ("\nyour screen as it plays) Should you need to decrease the speed of the sequence"); printf ("\n"); printf ("\npress the MINUS key. When you hear the sequence appear to descend"); printf ("\n"); printf ("\npress the Q key.This will stop the test and record the time at which"); printf ("\n"); printf ("\nyou perceived the change to occur."); printf ("\n"); printf ("\n"); printf ("\nAre you are ready to begin the test?"); printf ("\n"); printf ("\n"); printf ("\nPress any key to start"); getch(); //gets any character from the keyboard// while (quit == FALSE ) { for(count=0; count < 5; count++) //loop counts from 0 to <5 in increments of one// { printf(" \n %d", pause_val); //continously prints the note length in milliseconds to the user// midi_note(pitch_array[count], timbre, 64); //turns MIDI notes on and sets velocity// pause(pause_val); // duration specified by variable pause_val// midi_note(pitch_array[count], timbre, 0); //turns notes off// timbre++; //midi channel selections increase in increments of one// pause_val=pause_val-(pause_val/50);} //sets the speed at which sequence increases// if (timbre == 5) timbre = 1; //when midi channel selection reaches 5, revert to 1// if ( qwerty_input() ) { //enables user input from keyboard// user_input=input_char(); if (user_input == '+') {pause_val=pause_val-(pause_val/10); printf("+");} //allows user to increase speed of sequence// if (user_input == '-') {pause_val=pause_val+(pause_val/10); printf("-");} //allows user to decrease speed of sequence// if (user_input == 'q') { //allows user to stop test// printf("You perceived the sequence appear to change at this point = %d \n", pause_val); getch(); //gets character from the keyboard// midi_note(pitch_array[count], timbre, 0); // turns MIDI notes off// quit = TRUE;//ends loop// break; } } } return 0; }



LinkBack URL
About LinkBacks



