Beispiel #1
0
void initialization(void) { 
   eventBuffer.setPollPeriod(10);  // look in the algorithm buffer every 10 ms.
   tparam.setSize(PARAMSIZE);      // 256 simultaneous algorithms at once.
   tparam.allowGrowth(0);
}
Beispiel #2
0
void HumdrumFileBasic::privateSpineAnalysis(void) {
   
   int init = 0;
   int spineid = 0;

   SigCollection<char*> spineinfo;
   SigCollection<int> exinterps;

   exinterps.setSize(100);
   exinterps.setAllocSize(100);
   exinterps.setSize(1);
   exinterps[0] = 0;
   exinterps.allowGrowth();

   spineinfo.setSize(1000);
   spineinfo.setAllocSize(1000);
   spineinfo.setSize(0);
   spineinfo.allowGrowth();

   int currentwidth = 0;

   int prediction = 0;
   int length;
   int tlen = 0;
   int i, n;
   int type;
   char* tptr = NULL;
   char buffer[1024] = {0};
   char* bp;

   for (i=0; i<trackexinterp.getSize(); i++) {
      if (trackexinterp[i] != NULL) {
         delete [] trackexinterp[i];
         trackexinterp[i] = NULL;
      }
   }
   trackexinterp.setSize(100);
   trackexinterp.setGrowth(1000);
   trackexinterp.setSize(0);
   trackexinterp.allowGrowth(1);


   int linecount = getNumLines();
   for (n=0; n<linecount; n++) {
      ((*this)[n]).setLineNum(n+1);
      type = ((*this)[n]).getType(); 
      if (type == E_humrec_data || type == E_humrec_data_measure || 
            type == E_humrec_data_comment) {
         if (init == 0) {
            cout << (*this);
            cout << "Error on line " << n+1 
                 << "of data: no starting interpretation" << endl;
            exit(1);
         } 
         ((*this)[n]).copySpineInfo(spineinfo, n+1);
         currentwidth = (*this)[n].getFieldCount();
         (*this)[n].setSpineWidth(currentwidth);
      } else if (type == E_humrec_interpretation) {
         currentwidth = (*this)[n].getFieldCount();
         if (!init) {
            init = 1;
            if (!((*this)[n]).hasExclusiveQ()) {
               cout << "Error on line " << n+1 << " of file: "
                    << "No starting exclusive interpretation" << endl;
               cout << "The file contains: " << endl;
               cout << (*this) << endl;
               exit(1);
            }
            if (spineinfo.getSize() != 0) {
               cout << "Error on line " << n+1 << endl;
               exit(1);
            }
            for (i=0; i<getSpineCount(n); i++) {
               if (strncmp("**", getRecord(n)[i], 2) != 0) {
                  cout << "Error on line " << n+1 << ": nonexclusive" << endl;
               }
               tlen = strlen(getRecord(n)[i]);
               tptr = new char[tlen + 1];
               strcpy(tptr, getRecord(n)[i]); 
               trackexinterp.append(tptr);
               spineid++;
               sprintf(buffer, "%d", spineid);
               length = strlen(buffer);
               bp = new char[length + 1];
               strcpy(bp, buffer);
               spineinfo.append(bp);
               int value;
               value = Convert::exint.getValue(getRecord(n)[i]);
               if (spineid != exinterps.getSize()) {
                  cout << "Error in exclusive interpretation allocation.";
                  cout << "Line: " << n+1 << endl;
                  exit(1);
               }
               if (value == E_unknown) {
                  value = Convert::exint.add(getRecord(n)[i]);
                  exinterps.append(value);
               } else {
                  exinterps.append(value);
               }
            }
            ((*this)[n]).copySpineInfo(spineinfo, n+1);
            (*this)[n].setSpineWidth(currentwidth);
         } else if (((*this)[n]).hasExclusiveQ() || ((*this)[n]).hasPathQ()) {
            prediction = predictNewSpineCount(((*this)[n]));
            (*this)[n].setSpineWidth(currentwidth);
            currentwidth = prediction;
            int w;
            int ii;
            w = n+1;
            while (w < linecount && getSpineCount(w) == 0) {
               w++;
            }
            if ((w < linecount) && (prediction != getSpineCount(w))) {
               cerr << "Error on line " << w+1 << ": "
                    << "spine count does not match:"
                    << " prediction = " << prediction
                    << " actual = " << getSpineCount(w)
                    << endl;
               cerr << "Data up to error: " << endl;
               for (ii=0; ii<w+1; ii++) {
                  cout << (*this)[ii] << endl;
               }
               exit(1);
            } else if ((w >= linecount) && prediction != 0) {
               cerr << "Error in termination of humdrum data" << endl;
            }
            ((*this)[n]).copySpineInfo(spineinfo, n+1);
            makeNewSpineInfo(spineinfo, ((*this)[n]), prediction, spineid, 
                 exinterps);

            if (prediction == 0) {
               init = 0;
            }
         } else {
            // plain tandem interpretation
            if (init == 0) {
               cerr << "Error on first line of data: no starting interpretation"
                    << endl;
               exit(1);
            }
            ((*this)[n]).copySpineInfo(spineinfo, n+1);
            (*this)[n].setSpineWidth(currentwidth);
         }
      } else {
        // do nothing: global comment, bibliography information, or null line
        (*this)[n].setSpineWidth(currentwidth);
      }
   }

   // delete the contents of spineinfo
   for (i=0; i<spineinfo.getSize(); i++) {
      if (spineinfo[i] != NULL) {
         delete [] spineinfo[i];   
         spineinfo[i] = NULL;
      }
   }

   spineinfo.setSize(0);

   // provide Exclusive Interpretations ownerships to the record spines
   
   int spineindex;
   linecount = getNumLines();
   int m;
   const char* ptr;
   for (n=0; n<linecount; n++) {
      type = ((*this)[n]).getType(); 
      if ((type & E_humrec_data) == E_humrec_data) {
         for (m=0; m<getSpineCount(n); m++) {
            ptr = ((*this)[n]).getSpineInfo(m);
            while (ptr[0] != '\0' && !isdigit(ptr[0])) {
               ptr++;
            }
            sscanf(ptr, "%d", &spineindex);
            ((*this)[n]).setExInterp(m, exinterps[spineindex]);
         }
      }
   }

   maxtracks = spineid;
   trackexinterp.allowGrowth(0);
}