//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Thu Nov 16 15:58:02 PST 2000
// Last Modified: Thu Nov 16 15:58:08 PST 2000
// Filename: ...sig/examples/all/midimel.cpp
// Web Address: http://sig.sapp.org/examples/museinfo/midi/midimel.cpp
// Syntax: C++; museinfo
//
// Description: generate MIDI note numbers for short melodic sequences
// stored in the first spine of a Humdrum file in **kern format.
//
//
#include "humdrum.h"
#include <string.h>
// function declarations
void checkOptions(Options& opts, int argc, char* argv[]);
void example(void);
void processRecords(HumdrumFile& infile);
void usage(const char* command);
// global variables
Options options; // database for command-line arguments
///////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[]) {
HumdrumFile infile;
// process the command-line options
checkOptions(options, argc, argv);
// figure out the number of input files to process
int numinputs = options.getArgCount();
for (int 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));
}
// analyze the input file according to command-line options
if (numinputs > 0) {
cout << options.getArg(i+1)<< ": ";
}
processRecords(infile);
cout << "\n";
}
return 0;
}
///////////////////////////////////////////////////////////////////////////
//////////////////////////////
//
// checkOptions -- validate and process command-line options.
//
void checkOptions(Options& opts, int argc, char* argv[]) {
opts.define("author=b"); // author of program
opts.define("version=b"); // compilation info
opts.define("example=b"); // example usages
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, Nov 2000" << endl;
exit(0);
} else if (opts.getBoolean("version")) {
cout << argv[0] << ", version: 17 April 2000" << 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);
}
}
//////////////////////////////
//
// example -- example usage of the quality program
//
void example(void) {
cout <<
" \n"
<< endl;
}
//////////////////////////////
//
// processRecords --
//
void processRecords(HumdrumFile& infile) {
int i;
int midinum;
for (i=0; i<infile.getNumLines(); i++) {
if (infile[i].getType() != E_humrec_data) {
continue;
}
if (strcmp(infile[i][0], ".") == 0) {
continue;
}
if (strchr(infile[i][0], 'r') != NULL) {
cout << "r ";
} else {
midinum = Convert::kernToMidiNoteNumber(infile[i][0]);
cout << midinum << " ";
}
}
}
//////////////////////////////
//
// usage -- gives the usage statement for the meter program
//
void usage(const char* command) {
cout <<
" \n"
<< endl;
}
// md5sum: 63465a058d3c4388bbb3399e5ee63955 midimel.cpp [20050403]