// // Programmer: Craig Stuart Sapp // Creation Date: Sun May 2 23:56:35 PDT 2004 // Last Modified: Sun May 2 23:56:37 PDT 2004 // Last Modified: Thu Jun 3 19:54:09 PDT 2004 (added polyphonic feature) // Last Modified: Fri Jun 25 00:17:43 PDT 2004 allowed for correcting two // or more ties in a row: [[ to [_] // Last Modified: Tue Sep 7 01:39:07 PDT 2004 (allowed for basic splitting // into two subspines) // Filename: ...sig/examples/all/tiefix.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/tiefix.cpp // Syntax: C++; museinfo // // Description: Fix tie errors in essen music (single voice parts only) // Will usually work with upto two subspines as well. // Currently ignores the secondary subspine. // #include "humdrum.h" #include #include #define TIENONE 0 #define TIESTART 1 #define TIECONT 2 #define TIESTOP 3 #ifndef OLDCPP #include #define SSTREAM stringstream #define CSTRING str().c_str() using namespace std; #else #ifdef VISUAL #include /* for windows 95 */ #else #include #endif #define SSTREAM strstream #define CSTRING str() #endif #include /* for qsort and bsearch functions */ /////////////////////////////////////////////////////////////////////////// // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void processFile (HumdrumFile& infile, int index); void getPitchesAndTies (HumdrumFile& infile, Array& lines, Array& pitches, Array& tiestates, int index, Array& localindex); int getTieCorrections (Array& tiecorrections, Array& pitches, Array& tiestates); void printTieCorrection (ostream& out, HumdrumRecord& line, int tiecorrection, int index); void printStringWithoutTie(ostream& out, const char* string); void printStringWithTie (ostream& out, const char* string, int correction); void printFileWithCorrections(ostream& out, HumdrumFile& infile, Array& lines, Array& tiecorrections, Array& localindex); // global variables Options options; // database for command-line arguments int testQ = 0; // used with -t option const char* filename = ""; /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile; // process the command-line options checkOptions(options, argc, argv); infile.clear(); // if no command-line arguments read data file from standard input int numinputs = options.getArgCount(); if (numinputs < 1) { infile.read(cin); } else { filename = options.getArg(1); infile.read(options.getArg(1)); } int i; for (i=0; i lines; Array pitches; Array tiestates; Array tiecorrections; Array localindex; int i; for (i=0; i& lines, Array& tiecorrections, Array& localindex) { int i; int lindex = 0; for (i=0; i= lines.getSize()) { out << infile[i] << "\n"; continue; } if (lines[lindex] == i) { if (tiecorrections[lindex]) { // print a tie correction printTieCorrection(out, infile[i], tiecorrections[lindex], localindex[lindex]); } else { out << infile[i] << "\n"; } lindex++; } else { out << infile[i] << "\n"; } } } ////////////////////////////// // // printTieCorrection -- // void printTieCorrection(ostream& out, HumdrumRecord& line, int tiecorrection, int index) { int i; for (i=0; i 0) { printStringWithTie(out, line[index], tiecorrection); } else { out << line[index]; } if (i < line.getFieldCount() - 1) { out << "\t"; } } out << "\n"; } ////////////////////////////// // // printStringWithTie -- // void printStringWithTie(ostream& out, const char* string, int correction) { int hasslurstart = 0; int hasslurstop = 0; if (strchr(string, '{') != NULL) { // these are really phrase markers hasslurstart = 1; } if (strchr(string, '}') != NULL) { // these are really phrase markers hasslurstop = 1; } int hasoldtie = 0; if (strchr(string, '[') != NULL) { hasoldtie = 1; } if (strchr(string, '_') != NULL) { hasoldtie = 2; } if (strchr(string, ']') != NULL) { hasoldtie = 3; } int i; int len = strlen(string); switch (correction) { case TIESTART: if (!hasslurstart) { out << "[" << string; return; } for (i=0; i& tiecorrections, Array& pitches, Array& tiestates) { int output = 0; tiecorrections.setSize(pitches.getSize()); tiecorrections.setAll(0); int i; for (i=0; i=2; i--) { if ((tiestates[i] == TIESTOP) && (tiestates[i-1] == TIESTART) && (tiestates[i-2] == TIESTART)) { tiecorrections[i-1] = TIECONT; tiestates[i-1] = TIECONT; output += 1; } else if ((tiestates[i] == TIECONT) && (tiestates[i-1] == TIESTART) && (tiestates[i-2] == TIESTART)) { tiecorrections[i-1] = TIECONT; tiestates[i-1] = TIECONT; output += 1; } } return output; } ////////////////////////////// // // getPitchesAndTies -- // void getPitchesAndTies(HumdrumFile& infile, Array& lines, Array& pitches, Array& tiestates, int index, Array& localindex) { int i; int j; int pitch; int tiestate; lines.setSize(infile.getNumLines()); lines.setSize(0); pitches.setSize(infile.getNumLines()); pitches.setSize(0); tiestates.setSize(infile.getNumLines()); tiestates.setSize(0); localindex.setSize(infile.getNumLines()); localindex.setSize(0); int pindex = index; // the primary index for (i=0; i