예제 #1
0
파일: notify.c 프로젝트: 8l/go
int
notify(void (*f)(void*, char*))
{
	static int init;

	notifyf = f;
	if(!init){
		init = 1;
		noteinit();
	}
	return 0;
}
예제 #2
0
void createJsonProll(HumdrumFile& infile) {
   infile.analyzeRhythm("4");
   Array<int> ktracks;
   infile.getTracksByExInterp(ktracks, "**kern");
   Array<int> rktracks(infile.getMaxTracks()+1);
   rktracks.allowGrowth(0);
   rktracks.setAll(-1);
   int i, j, k;
   for (i=0; i<ktracks.getSize(); i++) {
      rktracks[ktracks[i]] = i;
   }

   int ksize = ktracks.getSize();
   stringstream* staves;
   staves = new stringstream[ksize];

   char buffer[1024] = {0};
   int b40;
   RationalNumber duration;
   int track;
   int tcount;

   Array<Array<char> > partnames(ktracks.getSize());

   Array<int> partmax(ktracks.getSize());
   Array<int> partmin(ktracks.getSize());
   partmax.setAll(-10000);
   partmin.setAll(+10000);

   Array<int> noteinit(ktracks.getSize());
   noteinit.setAll(0);

   for (i=0; i<infile.getNumLines(); i++) {
      if (!infile[i].isData()) {
         continue;
      }
      for (j=0; j<infile[i].getFieldCount(); j++) {
         if (!infile[i].isExInterp(j, "**kern")) {
            continue;
         }
         if (strcmp(infile[i][j], ".") == 0) {
            continue;
         }
         tcount = infile[i].getTokenCount(j);
         track = infile[i].getPrimaryTrack(j);
         for (k=0; k<tcount; k++) {
            infile[i].getToken(buffer, j, k);
            if (strchr(buffer, 'r') != NULL) {
               continue;
            }
            if (strchr(buffer, ']') != NULL) {
               continue;
            }
            if (strchr(buffer, '_') != NULL) {
               continue;
            }
            if (strcmp(buffer, ".") == 0) {
               continue;
            }
            b40 = Convert::kernToBase40(buffer);
            duration = infile.getTiedDurationR(i, j, k);
            if (noteinit[rktracks[track]] == 0) {
               noteinit[rktracks[track]] = 1;
               pi(staves[rktracks[track]], 4);
               staves[rktracks[track]] << "{\n";
            } else {
               pi(staves[rktracks[track]], 4);
               staves[rktracks[track]] << "},\n";
               pi(staves[rktracks[track]], 4);
               staves[rktracks[track]] << "{\n";
            }
            printJsonNote(staves[rktracks[track]], b40, duration, buffer, 
                  infile, i, j, k);

            if (b40 > partmax[rktracks[track]]) {
               partmax[rktracks[track]] = b40;
            }
            if (b40 < partmin[rktracks[track]]) {
               partmin[rktracks[track]] = b40;
            }
         }
      }
   }

   printJsonHeader(infile, 0, ktracks, partmin, partmax);

   pi(cout, 2);
   cout << "[\n";

   pi(cout, 2);
   cout << "{\n";

   int pindex = 0;
   for (i=ktracks.getSize()-1; i>=0; i--) {
      pi(cout, 3);
      cout << "\"partindex\"\t:\t" << pindex++ << ",\n";

      pi(cout, 3);
      cout << "\"notedata\"\t:\t" << "\n";

      pi(cout, 4);
      cout << "[\n";
     
      cout << staves[i].str();

      pi(cout, 4);
      cout << "}\n";

      pi(cout, 4);
      cout << "]\n";
  
      if (i > 0) {
         pi(cout, 2);
         cout << "},\n";
         pi(cout, 2);
         cout << "{\n";
      } else {
         pi(cout, 2);
         cout << "}\n";
      }
   }

   pi(cout, 2);
   cout << "]\n";

   pi(cout, 0);
   cout << "}\n";

   delete [] staves;
}