// // Programmer: Craig Stuart Sapp // Creation Date: Mon Jun 10 21:08:22 PDT 2002 // Last Modified: Mon Jun 10 21:08:27 PDT 2002 // Last Modified: Wed Jan 1 22:45:16 PST 2003 (not finished?) // Filename: ...sig/examples/all/koto2midi.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/koto2midi.cpp // Syntax: C++; museinfo // // Description: Convert **koto representation to a MIDI performance. // #include "humdrum.h" #include "MidiFile.h" #include #include #include #include /* class StringEvent { public: StringEvent(void) { state = ornament = time = 0; } int pitch; // MIDI note number of natural string int state; // 0 = note off, 1 = note on int ornament; // enumerated ornaments here int time; // time of event in MIDI ticks }; typedef Array StringEventArray; // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void convertKoto (HumdrumFile& infile); void convertKotoToMidi (HumdrumFile& infile, MidiFile& midifile, int instrument); void processKotoData (HumdrumRecord& line); void processInterpretation (HumdrumRecord& line); void storeTuning (const char* tunestring); void printRhythm (const char* string); void printPitch (const char* string); // command line options: Options options; // database for command-line arguments int debugQ = 0; // for debugging options --debug int appendQ = 0; // for use with the -a option int instrument = 107; // 107 = General MIDI Koto Array tuning; // for koto tuning /////////////////////////////////////////////////////////////////////////// */ int main(int argc, char* argv[]) { /* HumdrumFile infile; // input Humdrum Format file MidiFile midifile; // output MIDI file tuning.setSize(13); tuning.allowGrowth(0); // process the command-line options checkOptions(options, argc, argv); // figure out the number of input files to process int numinputs = options.getArgCount(); infile.clear(); if (numinputs < 1) { infile.read(cin); } else { infile.read(options.getArg(1)); } convertKotoToMidi(infile, midifile); cout << midifile; */ return 0; } /////////////////////////////////////////////////////////////////////////// /* ////////////////////////////// // // convertKotoToMidi -- // void convertKotoToMidi(HumdrumFile& infile, MidiFile& midifile, int instrument) { midifile.clear(); midifile.addTrack(13); // 13 tracks for strings + track 0 for tempo midifile.absolute; int i; Array data; data.setSize(2); data.setSize(2); data[1] = instrument; for (i=0; i<13; i++) { data[0] = 0xc0 + i; track = i; midifile.addEvent(i, 0, data); } Array stringEvents; stringEvents.setSize(13); getStringEvents(stringEvents, infile); for (i=0; i<13; i++) { storeStringTrack(midifile, i, stringEvents[i]); } midifile.sort(); } ////////////////////////////// // // storeStringTrack -- // void storeStringTrack(MidiFile& midifile, int track, Array& events) { Array noteondata; Array noteoffdata; noteondata.setSize(3); noteoffdata.setSize(3); if (track >= 9) { // avoiding channel 10 noteondata[0] = 0x90 + track + 1; noteoffdata[0] = 0x80 + track + 1; } else { noteondata[0] = 0x90 + track; noteoffdata[0] = 0x90 + track; } noteondata[2] = 64; noteoffdata[2] = 64; int i; for (i=0; i& stringEvents, MidiFile& infile) { int i; for (i=0; i info(13); for (i=0; i<13; i++) { info[i] = -1; } for (i=6; i 0) { tuning[i] = info[i]; } } } ////////////////////////////// // // processKotoData -- // void processKotoData(HumdrumRecord& line, Array& stringEvents) { static char buffer[1024] = {0}; if (strncmp(line[0], "-", 1) == 0) { return; } if (strcmp(line[0], ".", 1) == 0) { return; } int tokencount = line.getTokenCount(0); int i; for (i=0; i& stringEvents) { } ////////////////////////////// // // printRhythm -- // double getDuration(const char* string) { int pluscount = 0; int dotcount = 0; int pipecount = 0; int i; int length = strlen(string); double output = 1.0; // print a rhythm only if there is a string number int stringQ = 0; for (i=0; i 0) { // cout << 4 / pow(2, pluscount); } else if (pipecount > 0) { // cout << 4 * pow(2, pipecount); } else { // cout << "RERROR"; } for (i=0; i 3) { cout << "PERROR"; } // cout << ">" << sharpcount << "," << sharpcount2 << "<"; Convert::base40ToKern(buffer, pvalue); cout << buffer; } return; } } } cout << "x"; } ////////////////////////////// // // checkOptions -- validate and process command-line options. // void checkOptions(Options& opts, int argc, char* argv[]) { opts.define("a|append=b", "append analysis"); 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 2001" << endl; exit(0); } else if (opts.getBoolean("version")) { cout << argv[0] << ", version: Dec 2001" << 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); } appendQ = opts.getBoolean("append"); debugQ = opts.getBoolean("debug"); } ////////////////////////////// // // example -- example usage of the koto2midi program // void example(void) { cout << " \n" << endl; } ////////////////////////////// // // usage -- gives the usage statement for the koto2midi program // void usage(const char* command) { cout << " \n" << endl; } */ // md5sum: 29ef80a3264eaf45d0230ba8e9be4ff6 koto2midi.cpp [20050403]