// // Programmer: Craig Stuart Sapp // Creation Date: Fri Apr 8 10:04:27 PDT 2016 // Last Modified: Fri Apr 8 10:04:30 PDT 2016 // Filename: ...museinfo/examples/all/arcplot.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/arcplot.cpp // Syntax: C++; museinfo // // Description: Generate arcplot. // // #include "humdrum.h" #include #include #include #include #include #include using namespace std; #define REST 0 #define RESTINT -1000000 #define MARKNOTES 1 class NoteNode { public: int b40; // base-40 pitch number or 0 if a rest int b7; // base-7 pitch number or 0 if a rest int b12; // base-7 pitch number or 0 if a rest int line; // line number in original score of note int spine; // spine number in original score of note RationalNumber duration; // duration void clear(void); NoteNode(void) { clear(); } NoteNode(const NoteNode& anode); NoteNode& operator=(NoteNode& anode); ~NoteNode(void); int isRest(void) { return b40 == REST ? 1 : 0; } }; NoteNode::NoteNode(const NoteNode& anode) { b40 = anode.b40; b12 = anode.b12; b7 = anode.b7; line = anode.line; spine = anode.spine; duration = anode.duration; } NoteNode& NoteNode::operator=(NoteNode& anode) { if (this == &anode) { return *this; } b40 = anode.b40; b12 = anode.b12; b7 = anode.b7; line = anode.line; spine = anode.spine; duration = anode.duration; return *this; } NoteNode::~NoteNode(void) { clear(); } void NoteNode::clear(void) { line = spine = b40 = b12 = b7 = -1; } /////////////////////////////////////////////////////////////////////////// // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void processSection (ostream& out, HumdrumFile& infile, int windex); void fillNoteArray (vector >& notes, HumdrumFile& infile); void printNotes (vector >& notes); void compareSequence (ostream& out, vector >& notes, int targeti, int targetj); int isEqual (int interval, vector& diff); // global variables Options options; // database for command-line arguments int ngram = 4; // number of tokens in sequence to examine; /////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { checkOptions(options, argc, argv); HumdrumStream streamer(options); HumdrumFile infile; stringstream contents; int counter = 0; while (streamer.read(infile)) { counter++; processSection(contents, infile, counter); } // print header cout << contents.str(); // print footer } /////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // processSection -- // void processSection(ostream& out, HumdrumFile& infile, int windex) { vector > notes; fillNoteArray(notes, infile); // printNotes(notes); int i, j; for (i=0; i<(int)notes.size(); i++) { for (j=0; j<(int)notes[i].size(); i++) { if (j < (int)notes[i].size() - ngram) { compareSequence(out, notes, i, j); } else { break; } } } } ////////////////////////////// // // compareSequences -- // void compareSequence(ostream& out, vector >& notes, int targeti, int targetj) { int i, j, n; vector target; target.resize(ngram); for (n=0; n (int)notes[targeti].size()) { return; } target[n] = notes[targeti][targetj+n].b7; } vector diff; diff.resize(ngram); int interval = 0; // check the current voice for matches for (j = targetj+1; j<(int)notes[targeti].size() - ngram; j++) { for (n=0; n& diff) { interval = 0; int nonzero = 0; for (int i=0; i<(int)diff.size(); i++) { if (diff[i] != 0) { if (nonzero == 0) { nonzero = diff[i]; } else { if (nonzero != diff[i]) { return 0; } } } } interval = nonzero; return 1; } ////////////////////////////// // // printNotes -- // void printNotes(vector >& notes) { for (int i=0; i<(int)notes.size(); i++) { for (int j=0; j<(int)notes[i].size(); j++) { cout << notes[i][j].b40 << " "; } cout << "\n" << endl; } } ////////////////////////////// // // fillNoteArray -- // void fillNoteArray(vector >& notes, HumdrumFile& infile) { vector ktracks; int i, j, k; infile.getKernTracks(ktracks); notes.resize(ktracks.size()); for (i=0; i<(int)notes.size(); i++) { notes[i].reserve(infile.getNumLines()); } NoteNode note; string token; int b40, b12, b7; PerlRegularExpression pre; RationalNumber duration = 0; for (k=0; k<(int)ktracks.size(); k++) { for (i=0; i