void Soundy::playABC(String abc) { //abc.toLowerCase(); // legacy Serial.write("L="+L); for (int n = 0; n < abc.length(); n++) { char note = abc.charAt(n); if (!isNote(String(note))) continue; Serial.write(note); int duration = 1; if (n < abc.length()-1) { String next = String(abc.charAt(n+1)); if (next.toInt() > 0) { duration = next.toInt(); n++; } } Serial.write(duration); if (note == ' ') { delay ( duration * L); } else { playNote(String(note), duration * L); } delay( L / 2); } }
void Parser::parseSeqNonNotes() { qDebug() << "Parser::parseSeqNonNotes() value:" << qPrintable(lex.symValue()); MeasureBeginFlags mbfl; MeasureEndFlags mefl; while (isNonNote(lex.symType())) { if (lex.symType() == CLEF) { mbfl.firstOfSystem = true; mefl.lastOfSystem = true; lex.getSym(); } else if (lex.symType() == KEY) lex.getSym(); // ignore else if (lex.symType() == TSIG) parseTSig(); else if (lex.symType() == PART) parsePart(mbfl, mefl); else if (lex.symType() == BAR) parseBar(mefl); } // First end the previous measure if (!measures.isEmpty()) { measures.last().mef = mefl; } // Then start a new measure, if necessary if (isNote(lex.symType())) { MeasureDescription md; md.mbf = mbfl; measures.append(md); } }
void CIniFile::readInfo(void) { m_lstNodeInfo.clear(); std::fstream inStream(m_strFile.c_str(), std::ios::in); if (!inStream.good()) { Q_Printf("open file %s error.", m_strFile.c_str()); inStream.close(); return; } char pBuffer[Q_ONEK]; std::string strTmp; std::string strNode; while(inStream.good()) { Q_Zero(pBuffer, sizeof(pBuffer)); inStream.getline(pBuffer, (std::streamsize)(sizeof(pBuffer) - 1)); strTmp = std::string(pBuffer); strTmp = Q_Trim(strTmp); if (strTmp.empty() || isNote(strTmp)) { continue; } //去掉注释 removeNote(strTmp); strTmp = Q_Trim(strTmp); if (strTmp.empty()) { continue; } if (isNode(strTmp)) { strNode = getNode(strTmp); continue; } if (isKey(strTmp)) { setStringValue(strNode.c_str(), getKey(strTmp).c_str(), getVal(strTmp).c_str()); } } inStream.close(); return; }
int ConfigLoader::loadInfo(const char* tool_file) { FILE* fp = fopen(tool_file, "r"); if (fp == NULL) { fprintf(stderr, "can't open file\n"); return 0; } const char* value = NULL; char buffer[CONFIG_BUFFER_SIZE]; while(fgets(buffer, 4095, fp) != NULL) { if (isNote(buffer)) { continue; } value = match(buffer, CONFIG_SERVER_1); if (value != NULL) { int len = strlen(value); _master_config_server = (char*)malloc(sizeof(char) * (len + 1)); if (_master_config_server == NULL) { fprintf(stderr, "file %s, line %d: malloc failed\n", __FILE__, __LINE__); } strcpy(_master_config_server, value); continue; } value = match(buffer, CONFIG_SERVER_2); if (value != NULL) { int len = strlen(value); _slave_config_server = (char*)malloc(sizeof(char) * (len + 1)); if (_slave_config_server == NULL) { fprintf(stderr, "file %s, line %d: malloc failed\n", __FILE__, __LINE__); } strcpy(_slave_config_server, value); continue; } value = match(buffer, GROUP_NAME); if (value != NULL) { int len = strlen(value); _group_name = (char*)malloc(sizeof(char) * (len + 1)); if (_group_name == NULL) { fprintf(stderr, "file %s, line %d: malloc failed\n", __FILE__, __LINE__); } strcpy(_group_name, value); continue; } value = match(buffer, NAMESPACE); if (value != NULL) { sscanf(value, "%d", &_namespace); continue; } value = match(buffer, KEYS_FILE); if (value != NULL) { int len = strlen(value); _keys_file = (char*)malloc(sizeof(char) * (len + 1)); if (_keys_file == NULL) { fprintf(stderr, "file %s, line %d: malloc failed\n", __FILE__, __LINE__); } strcpy(_keys_file, value); continue; } value = match(buffer, WORKER_NUM); if (value != NULL) { sscanf(value, "%d", &_worker_num); continue; } value = match(buffer, DEL_JOB_SIZE); if (value != NULL) { sscanf(value, "%d", &_del_job_size); continue; } value = match(buffer, KEY_FORMAT); if (value != NULL) { sscanf(value, "%d", &_key_format); continue; } } if (fp != NULL) { fclose(fp); } return 1; }
//--------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------- void BufferOverride::doTheProcess(float **inputs, float **outputs, long sampleFrames, bool replacing) { //-------------------------SAFETY CHECK---------------------- #if LINUX // no memory allocations during interrupt #else // there must have not been available memory or something (like WaveLab goofing up), // so try to allocate buffers now if ( (buffer1 == NULL) #ifdef BUFFEROVERRIDE_STEREO || (buffer2 == NULL) #endif ) createAudioBuffers(); #endif // if the creation failed, then abort audio processing if (buffer1 == NULL) return; #ifdef BUFFEROVERRIDE_STEREO if (buffer2 == NULL) return; #endif //-------------------------INITIALIZATIONS---------------------- // this is a handy value to have during LFO calculations & wasteful to recalculate at every sample numLFOpointsDivSR = NUM_LFO_POINTS_FLOAT / SAMPLERATE; divisorLFO->pickTheLFOwaveform(); bufferLFO->pickTheLFOwaveform(); // calculate this scaler value to minimize calculations later during processOutput() // float inputGain = 1.0f - fDryWetMix; // float outputGain = fDryWetMix; float inputGain = sqrtf(1.0f - fDryWetMix); float outputGain = sqrtf(fDryWetMix); //-----------------------TEMPO STUFF--------------------------- // figure out the current tempo if we're doing tempo sync if ( onOffTest(fBufferTempoSync) || (onOffTest(divisorLFO->fTempoSync) || onOffTest(bufferLFO->fTempoSync)) ) { // calculate the tempo at the current processing buffer if ( (fTempo > 0.0f) || (hostCanDoTempo != 1) ) // get the tempo from the user parameter { currentTempoBPS = tempoScaled(fTempo) / 60.0f; needResync = false; // we don't want it true if we're not syncing to host tempo } else // get the tempo from the host { timeInfo = getTimeInfo(kBeatSyncTimeInfoFlags); if (timeInfo) { if (kVstTempoValid & timeInfo->flags) currentTempoBPS = (float)timeInfo->tempo / 60.0f; else currentTempoBPS = tempoScaled(fTempo) / 60.0f; // currentTempoBPS = ((float)tempoAt(reportCurrentPosition())) / 600000.0f; // but zero & negative tempos are bad, so get the user tempo value instead if that happens if (currentTempoBPS <= 0.0f) currentTempoBPS = tempoScaled(fTempo) / 60.0f; // // check if audio playback has just restarted & reset buffer stuff if it has (for measure sync) if (timeInfo->flags & kVstTransportChanged) { needResync = true; currentForcedBufferSize = 1; writePos = 1; minibufferSize = 1; prevMinibufferSize = 0; smoothcount = smoothDur = 0; } } else // do the same stuff as above if the timeInfo gets a null pointer { currentTempoBPS = tempoScaled(fTempo) / 60.0f; needResync = false; // we don't want it true if we're not syncing to host tempo } } } //-----------------------AUDIO STUFF--------------------------- // here we begin the audio output loop, which has two checkpoints at the beginning for (long samplecount = 0; (samplecount < sampleFrames); samplecount++) { // check if it's the end of this minibuffer if (readPos >= minibufferSize) updateBuffer(samplecount); // store the latest input samples into the buffers buffer1[writePos] = inputs[0][samplecount]; #ifdef BUFFEROVERRIDE_STEREO buffer2[writePos] = inputs[1][samplecount]; #endif // get the current output without any smoothing float out1 = buffer1[readPos]; #ifdef BUFFEROVERRIDE_STEREO float out2 = buffer2[readPos]; #endif // and if smoothing is taking place, get the smoothed audio output if (smoothcount > 0) { // crossfade between the current input & its corresponding overlap sample // out1 *= 1.0f - (smoothStep * (float)smoothcount); // current // out1 += buffer1[readPos+prevMinibufferSize] * smoothStep*(float)smoothcount; // + previous // float smoothfract = smoothStep * (float)smoothcount; // float newgain = sqrt(1.0f - smoothfract); // float oldgain = sqrt(smoothfract); // out1 = (out1 * newgain) + (buffer1[readPos+prevMinibufferSize] * oldgain); // out1 = (out1 * sqrtFadeIn) + (buffer1[readPos+prevMinibufferSize] * sqrtFadeOut); out1 = (out1 * fadeInGain) + (buffer1[readPos+prevMinibufferSize] * fadeOutGain); #ifdef BUFFEROVERRIDE_STEREO // out2 *= 1.0f - (smoothStep * (float)smoothcount); // current // out2 += buffer2[readPos+prevMinibufferSize] * smoothStep*(float)smoothcount; // + previous // out2 = (out2 * newgain) + (buffer2[readPos+prevMinibufferSize] * oldgain); // out2 = (out2 * sqrtFadeIn) + (buffer2[readPos+prevMinibufferSize] * sqrtFadeOut); out2 = (out2 * fadeInGain) + (buffer2[readPos+prevMinibufferSize] * fadeOutGain); #endif smoothcount--; // smoothFract += smoothStep; // sqrtFadeIn = 0.5f * (sqrtFadeIn + (smoothFract / sqrtFadeIn)); // sqrtFadeOut = 0.5f * (sqrtFadeOut + ((1.0f-smoothFract) / sqrtFadeOut)); fadeInGain = (fadeOutGain * imaginaryFadePart) + (fadeInGain * realFadePart); fadeOutGain = (realFadePart * fadeOutGain) - (imaginaryFadePart * fadeInGain); } // write the output samples into the output stream if (replacing) { outputs[0][samplecount] = (out1 * outputGain) + (inputs[0][samplecount] * inputGain); #ifdef BUFFEROVERRIDE_STEREO outputs[1][samplecount] = (out2 * outputGain) + (inputs[1][samplecount] * inputGain); #endif } else { outputs[0][samplecount] += (out1 * outputGain) + (inputs[0][samplecount] * inputGain); #ifdef BUFFEROVERRIDE_STEREO outputs[1][samplecount] += (out2 * outputGain) + (inputs[1][samplecount] * inputGain); #endif } // increment the position trackers readPos++; writePos++; } //-----------------------MIDI STUFF--------------------------- // check to see if there may be a note or pitchbend message left over that hasn't been implemented if (midistuff->numBlockEvents > 0) { long eventcount; for (eventcount = 0; eventcount < midistuff->numBlockEvents; eventcount++) { if (isNote(midistuff->blockEvents[eventcount].status)) { // regardless of whether it's a note-on or note-off, we've found some note message oldNote = true; // store the note & update the notes table if it's a note-on message if (midistuff->blockEvents[eventcount].status == kMidiNoteOn) { midistuff->insertNote(midistuff->blockEvents[eventcount].byte1); lastNoteOn = midistuff->blockEvents[eventcount].byte1; // since we're not doing the fDivisor updating yet, this needs to be falsed divisorWasChangedByHand = false; } // otherwise remove the note from the notes table else midistuff->removeNote(midistuff->blockEvents[eventcount].byte1); } else if (midistuff->blockEvents[eventcount].status == ccAllNotesOff) { oldNote = true; midistuff->removeAllNotes(); } } for (eventcount = (midistuff->numBlockEvents-1); (eventcount >= 0); eventcount--) { if (midistuff->blockEvents[eventcount].status == kMidiPitchbend) { // set this pitchbend message as lastPitchbend lastPitchbend = midistuff->blockEvents[eventcount].byte2; break; // leave this for loop } } } // always reset numBlockEvents because processEvents() may not get called before the next process() midistuff->numBlockEvents = 0; }
void Parser::parse() { // read the header, handling only strings and tune tempo while (lex.symType() == COMMENT || lex.symType() == STRING || lex.symType() == TEMPO) { if (lex.symType() == STRING) parseString(); else if (lex.symType() == TEMPO) parseTempo(); else if (lex.symType() == COMMENT) lex.getSym(); } qDebug() << "Parser::parse()" << "title:" << title << "type:" << type << "composer:" << composer << "footer:" << footer ; wrt.header(title, type, composer, footer, tempo); // read the actual music if (lex.symType() != CLEF) errorHandler("clef ('&') expected"); while (lex.symType() != NONE) { if (isNonNote(lex.symType())) parseSeqNonNotes(); else if (isNote(lex.symType())) parseSeqNotes(); else if (lex.symType() == UNKNOWN) { errorHandler("unknown symbol '" + lex.symValue() + "'"); lex.getSym(); } else { ; // others not implemented yet: silently ignored lex.getSym(); } } qDebug() << "Parser::parse() finished, #measures" << measures.size() ; calculateMeasureDurations(measures); if (!tsigFound) { determineTimesig(measures, beats, beat); wrt.tsig(beats, beat); } findIrregularMeasures(measures, beats, beat); determineBeamStates(measures); setLastOfPart(measures); dumpMeasures(measures); dumpBeams(measures); for (int j = 0; j < measures.size(); ++j) { wrt.beginMeasure(measures.at(j).mbf); for (int i = 0; i < measures.at(j).notes.size(); ++i) { wrt.note(measures.at(j).notes.at(i).pitch, measures.at(j).notes.at(i).beamList, measures.at(j).notes.at(i).type, measures.at(j).notes.at(i).dots, measures.at(j).notes.at(i).tieStart, measures.at(j).notes.at(i).tieStop, measures.at(j).notes.at(i).triplet, measures.at(j).notes.at(i).grace ); } wrt.endMeasure(measures.at(j).mef); } // trailer wrt.trailer(); }