//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Mon Apr 9 14:01:16 PDT 2001
// Last Modified: Mon May 23 12:13:43 PDT 2005
// Filename: ...sig/examples/all/keyscape3.cpp
// Web Address: http://sig.sapp.org/examples/museinfo/humdrum/keyscape3.cpp
// Syntax: C++; museinfo
//
// Description: Generates keyscape pictures of musical input.
// Output format is PPM. Use convert file.ppm file.gif
// to conver to GIF images.
//
#include "humdrum.h"
// vertical scaling of pictures (linear = triangular; log = curved top)
#define SCALE_UNKNOWN (0)
#define SCALE_LOG (1)
#define SCALE_LINEAR (2)
// function declarations
void checkOptions(Options &opts, int argc, char* argv[]);
void example(void);
void usage(const char* command);
// command-line options:
Options options; // database for command-line arguments
typedef struct {
int imageWidth, imageHeight;
int vscale;
int debug;
} GlobalValues;
GlobalValues g;
///////////////////////////////////////////////////////////////////////
//
// Default colorings. Indexes into array are in base-40 notation
// with C-natural being the first element in the array.
//
int red[40] = {
0, 9, 18, 0, 63, 63, 63, 73, 82, 0, 218, 237, 255, 255, 255,
255, 255, 255, 218, 182, 0, 45, 54, 63, 63, 63, 0, 109, 118,
127, 145, 164, 0, 255, 255, 255, 255, 255, 73, 36
};
int green[40] = {
255, 246, 237, 0, 123, 109, 95, 86, 77, 0, 9, 4, 0, 18, 36, 218,
237, 255, 255, 255, 0, 209, 200, 191, 177, 164, 0, 50, 41, 31,
27, 22, 0, 91, 109, 127, 145, 164, 255, 255
};
int blue[40] = {
0, 36, 73, 0, 255, 255, 255, 255, 255, 0, 73, 36, 0, 0, 0, 0,
0, 0, 0, 0, 0, 182, 218, 255, 255, 255, 0, 255, 255, 255, 219,
182, 0, 0, 0, 0, 0, 0, 0, 0
};
//
//
///////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[]) {
g.imageWidth = 1000; // set with -d option
g.imageHeight = 500; // set with -d option
g.vscale = SCALE_LOG; // set with -l option
g.debug = 0; // set with --debug option
HumdrumFile infile; // input Humdrum Format file
// process the command-line options
checkOptions(options, argc, argv);
// figure out the number of input files to process
int numinputs = options.getArgCount();
Array<Array<int> > matrix;
int i;
for (i=0; i<numinputs || i==0; i++) {
infile.clear();
// if no command-line arguments read data file from standard input
if (numinputs < 1) {
infile.read(cin);
} else {
infile.read(options.getArg(i+1));
}
infile.analyzeRhythm("4");
int duration = infile.getTotalDuration();
if (debugQ) {
cout << "Duration of input file is " << duration
<< " quarter notes" << endl;
}
switch (g.style) {
case STYLE_CORRELATION:
generatePictureCorellation(infile, matrix);
break;
case STYLE_COMPACNESS:
generatePictureCompactness(infile, matrix);
break;
}
printPPM(matrix);
if (i == 1) {
// only allow one input file to be processed
break;
}
}
return 0;
}
//////////////////////////////
//
// checkOptions -- validate and process command-line options.
//
void checkOptions(Options& opts, int argc, char* argv[]) {
opts.define("d|dimension=s:10x10","pixel width and height of picture");
opts.define("k|ks=b", "generate Krumhansl-Schmuckler key picture");
opts.define("q|quarter=b", "Calculate KS algorithm without durations");
opts.define("l|linear=b", "linear plot instead of logarithmic");
opts.define("debug=b", "trace input parsing");
opts.define("author=b", "author of the program");
opts.define("version=b", "compilation information");
opts.define("example=b", "example usage");
opts.define("h|help=b", "short description");
opts.process(argc, argv);
// handle basic options:
if (opts.getBoolean("author")) {
cout << "Written by Craig Stuart Sapp, "
<< "craig@ccrma.stanford.edu, Dec 2000" << endl;
exit(0);
} else if (opts.getBoolean("version")) {
cout << argv[0] << ", version: 22 May 2005" << endl;
cout << "compiled: " << __DATE__ << endl;
cout << MUSEINFO_VERSION << endl;
exit(0);
} else if (opts.getBoolean("help")) {
usage(opts.getCommand());
exit(0);
} else if (opts.getBoolean("example")) {
example();
exit(0);
}
g.debug = opts.getBoolean("debug");
sscanf(opts.getString("dimension"), "%dx%d", &g.imageWidth, &g.imageHeight);
styleQ =
if (opts.getBoolean("linear")) {
g.vscale = SCALE_LINEAR;
} else {
g.vscale = SCALE_LOG;
}
}
//////////////////////////////
//
// example -- example usage of the maxent program
//
void example(void) {
cout <<
" \n"
<< endl;
}
//////////////////////////////
//
// usage -- gives the usage statement for the quality program
//
void usage(const char* command) {
cout <<
" \n"
<< endl;
}