compose.m
/*------------------------------------------------------------------------------- This file is the application that composes couterpoint. It opens either opens the .cpt files passed into it and passes them on to the MKComposer object, which composes another voice, or, if no files are passed in, it creates a .cpt file and passes it to MKComposer to compose a cantus firmus. The code contained in this file is under copyright and is strictly private. Written by Michael Krzyzaniak krzyzani@uga.edu -------------------------------------------------------------------------------*/ #include "MKCptComposer.h" BOOL getIsAboveByPrompting(); unsigned int getSlicesPerMeasureByPrompting(); void saveByPrompting(MKCptFile* cptFile); int main(int argc, char* argv[]) { MKCptComposer* composer = [[MKCptComposer alloc] init]; BOOL isAbove; unsigned int numSlices; if(argc<2) { MKCptFile* cptFile = [[MKCptFile alloc] init]; [cptFile addSlices: 10]; numSlices = getSlicesPerMeasureByPrompting(); [composer composeVoiceForCptFile: cptFile withSlicesPerMeasure: numSlices forTopVoice: isAbove]; saveByPrompting(cptFile); [cptFile free]; } while(--argc) { argv++; MKCptFile* cptFile = [MKCptFile cptFileFromFile: *argv]; if(cptFile == nil){printf("could not open %s\n", *argv); continue;} printf("%s OK\n", *argv); numSlices = getSlicesPerMeasureByPrompting(); isAbove = getIsAboveByPrompting(); [composer composeVoiceForCptFile: cptFile withSlicesPerMeasure: numSlices forTopVoice: isAbove]; saveByPrompting(cptFile); [cptFile free]; } [composer free]; return 0; } BOOL getIsAboveByPrompting() { BOOL isAbove; char answer[6]; printf("compose a voice above or below? "); top: scanf("%s", answer); switch(answer[0]) { case 'a': isAbove = YES; break; case 'b': isAbove = NO; break; default: printf("please answer \"above\" or \"below\" "); goto top; } return isAbove; } unsigned int getSlicesPerMeasureByPrompting() { unsigned int numSlices; printf("how many slices would you like per measure?\n"); scanf("%u", &numSlices); return numSlices; } void saveByPrompting(MKCptFile* cptFile) { char filename[51]; printf("save as (must end in .cpt): "); scanf("%s", filename); [cptFile saveWithFilename: filename]; }
:/ root#