// // Programmer: Craig Stuart Sapp // Creation Date: Tue Jun 12 23:17:41 PDT 2001 // Last Modified: Fri Jun 12 22:58:34 PDT 2009 (renamed SigCollection class) // Filename: ...sig/examples/all/kern2skini.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/kern2skini.cpp // Syntax: C++; museinfo // // Description: Generates a list of pitches in a Humdrum file // according to the STK SKINI format. // #include "humdrum.h" #include #include #include #include #ifndef OLDCPP #include #include #else #include #include #endif typedef long TEMP64BITFIX; class SKINI { public: int message; double time; TEMP64BITFIX chan; double note; double vel; double id; }; #define UNKNOWN -1 #define MEASURE 0 #define NOTEON 1 #define NOTEOFF 2 #define COMMENT 3 #define TEMPO 4 #define KEYSIG 5 #define INFO 6 #define INSTRUMENT 7 // function declarations: void checkOptions (Options& opts, int argc, char** argv); void example (void); void preparePitch (char* buffer2, const char* buffer1); void generateSkini (HumdrumFile& hfile, SigCollection& skini); void printSkini (SigCollection& skini); void usage (const char* command); ostream& operator<< (ostream& out, SKINI skini); int skinicompare (const void* a, const void* b); // User interface variables: Options options; int barlinesQ = 1; // used with the -B option int midinoteQ = 0; // used with the -m option int classQ = 0; // used with the -c option double tdefault = 60.0; // used with the -t option int idcounter = 0; // used to sort output data ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { // process the command-line options checkOptions(options, argc, argv); SigCollection skini; skini.setGrowth(100000); skini.setSize(100000); skini.setSize(0); skini.allowGrowth(1); HumdrumFile hfile(options.getArg(1).data()); hfile.analyzeRhythm(); generateSkini(hfile, skini); printSkini(skini); return 0; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // printSkini -- sort SKINI messages and output // void printSkini(SigCollection& skini) { int i; qsort(skini.getBase(), skini.getSize(), sizeof(SKINI), skinicompare); // convert to delta times: for (i=skini.getSize()-1; i>0; i--) { skini[i].time = skini[i].time - skini[i-1].time; if (skini[i].time < 0.00001) { skini[i].time = 0.0; } } skini[0].time = 0.0; for (i=0; i& skini) { Array tempo; hfile.analyzeTempoMarkings(tempo, tdefault); double currentmillisecond = 0.0; double lastduration = 0.0; double endmillisecond; SKINI tempskini; int i, j, k; char buffer1[1024] = {0}; char buffer2[1024] = {0}; double duration; for (i=0; i 4) { continue; } if (hfile[i][j][length-1] == ':') { cout << "// key "; cout << (char)toupper(hfile[i][j][1]); if (hfile[i][j][2] == '-') { cout << "-flat"; } if (hfile[i][j][2] == '#') { cout << "-sharp"; } if (std::islower(hfile[i][j][1])) { cout << " Minor"; } else { cout << " Major"; } cout << endl; break; } } } */ // look for tempo markings if (hfile[i].getType() == E_humrec_interpretation) { for (j=0; j 0) { out << "number " << skini.chan; } out << "\t=" << skini.vel; return out; } if (skini.message == COMMENT) { out << "// " << (char*)(skini.chan); return out; } if (skini.message == INFO) { out << "///" << (char*)(skini.chan); return out; } if (skini.message == TEMPO) { out << "// Tempo " << skini.vel << " MM per quarter note"; return out; } if (skini.message == INSTRUMENT) { out << "// Instrument <" << (char*)skini.chan << "> for channel " << skini.note; return out; } if (skini.message == KEYSIG) { out << "// Keysig " << labs(skini.chan); if (skini.chan == 0) { out << " accidentals"; } else if (skini.chan < 0) { out << " flat"; } else { out << " sharp"; } if (labs(skini.chan) > 1) { out << "s"; } return out; } switch (skini.message) { case NOTEON: out << "NoteOn \t"; break; case NOTEOFF: out << "NoteOff \t"; break; default: out << "UNKNOWN \t"; } // send time value: out.setf(ios::left, ios::adjustfield); out << setw(10) << skini.time << " "; // send channel: out << skini.chan << "\t"; // send note number: out << " " << skini.note << "\t"; // send attack/release velocity: out << " " << skini.vel; // out << "\t[" << skini.id << "]"; return out; } /////////////////////////////// // // skinicompare -- for sorting the times of SKINI messages // int skinicompare(const void* a, const void* b) { SKINI& aa = *((SKINI*)a); SKINI& bb = *((SKINI*)b); if (fabs(aa.time - bb.time) < 0.0001) { // break ties by the id number if (aa.id < bb.id) { return -1; } else if (aa.id > bb.id) { return 1; } else { return 0; } } else if (aa.time < bb.time) { return -1; } else if (aa.time > bb.time) { return 1; } return 1; } // md5sum: 05edc8766e9f11dc0efd60b79b362492 kern2skini.cpp [20151120]