void checkBuffers(void) { // look at the volume buffers for old volumes: while ( (voltimes.getCount() > 0) && (voltimes[voltimes.getCount()-1] < t_time - volDuration) ) { volumes.extract(); voltimes.extract(); } // look at the duration buffers for old durations: while ( (durtimes.getCount() > 0) && (durtimes[durtimes.getCount()-1] < t_time - durDuration) ) { durations.extract(); durtimes.extract(); } // look at the key buffers for old keys: int oldkey; while ( (keytimes.getCount() > 0) && (keytimes[keytimes.getCount()-1] < t_time - keyDuration) ) { oldkey = keys.extract(); keytimes.extract(); performerPCHistory[oldkey%12]--; if (performerPCHistory[oldkey%12] < 0) { performerPCHistory[oldkey%12] = 0; } } }
void mainloopalgorithms(void) { if (comparestate && notetimer.expired()) { if (notetimer.expired() > 2) { notetimer.reset(); } else { notetimer.update(); } notestate = !notestate; if (notestate == 1 || notestate == -1) { synth.play(0, note, 64); data = 0x90; sentout.insert(data); data = note; sentout.insert(data); data = 64; sentout.insert(data); } else { synth.play(0, note, 0); data = 0x90; sentout.insert(data); data = note; sentout.insert(data); data = 0; sentout.insert(data); note += step * direction; if (note > highestnote) { note = lowestnote; } if (note < lowestnote) { note = highestnote; } } } if (midiinput.getCount() > 0) { message = midiinput.extract(); receivedin.insert(message.p0()); receivedin.insert(message.p1()); receivedin.insert(message.p2()); // check that the messages are identical if (receivedin.getCount() < 3) { cout << "Error: not enough received data" << endl; } else { checkin[0] = receivedin.extract(); checkin[1] = receivedin.extract(); checkin[2] = receivedin.extract(); } if (sentout.getCount() < 3) { cout << "Error: not enough sent data" << endl; } else { checkout[0] = sentout.extract(); checkout[1] = sentout.extract(); checkout[2] = sentout.extract(); } if ((checkout[0] != checkin[0]) || (checkout[1] != checkin[1]) || (checkout[2] != checkin[2])) { synth.rawsend(0xaa, 0x7f, 0x00); cout << "Error " << "output was = (" << hex << (int)checkout[0] << ") " << dec << (int)checkout[1] << " " << dec << (int)checkout[2] << "\tbut input is = (" << hex << (int)checkin[0] << ") " << dec << (int)checkin[1] << " " << dec << (int)checkin[2] << " " << endl; // assume that a note message was missed. if (sentout.getCount() < 3) { cout << "Error: not enough sent data during error" << endl; } else { checkout[0] = sentout.extract(); checkout[1] = sentout.extract(); checkout[2] = sentout.extract(); } stop(); cout << "Press space to restart testing, " "or press 'S' to silence synth" << endl; } } }
void processRecords(HumdrumFile& infile, HumdrumFile& outfile) { infile.analyzeRhythm(); char buffer[10000] = {0}; int style; double duration; style = styles.extract(); duration = durations.extract(); double currbeat = 0; double targetbeat = 0; int lastline = 0; double currdur; int state = 0; for (int i=0; i<infile.getNumLines(); i++) { if (options.getBoolean("debug")) { cout << "processing line " << (i+1) << " of input ..." << endl; } if (infile[i].getType() != E_humrec_data) { outfile.appendLine(infile[i]); continue; } state = 0; currbeat = infile[i].getAbsBeat(); currdur = infile[i].getDuration(); while ((currbeat+currdur > targetbeat) || (fabs(currbeat-targetbeat) < 0.001)) { if (fabs(currbeat - targetbeat) < 0.0001) { createDataLine(buffer, infile, i, duration, style); outfile.appendLine(buffer); styles.insert(style); durations.insert(duration); style = styles.extract(); duration = durations.extract(); targetbeat += duration; } else if (currbeat+currdur > targetbeat) { if (state == 1) { createDataLine(buffer, infile, lastline, duration, style); } else { createDataLine(buffer, infile, i, duration, style); } outfile.appendLine(buffer); styles.insert(style); durations.insert(duration); style = styles.extract(); duration = durations.extract(); targetbeat += duration; } else { break; } } lastline = i; } }