//________________________________________________________________________ void notevisitor::print (ostream& out) const { if (isGrace()) out << "grace "; if (isCue()) out << "cue "; int type = getType(); if (type == kUndefinedType) out << "type undefined"; else if (type == kUnpitched) { out << "unpitched note - duration " << getDuration() << " "; } else if (type == kRest) { out << "rest - duration " << getDuration() << " "; } else if (type == kPitched) { out << "note " << getStep(); int alter = int(getAlter()); float diff = getAlter() - alter; if (diff >= 0.5) alter++; else if (diff <= -0.5) alter--; while (alter < 0) { out << 'b'; alter++; } while (alter > 0) { out << '#'; alter--; } out << getOctave() << " (" << getMidiPitch() << ")"; out << " - duration " << getDuration() << " "; } else out << "unknown type " << type << " "; if (inChord()) out << "in chord "; if (getTie() & StartStop::start) out << "- tie start "; if (getTie() & StartStop::stop) out << "- tie stop "; string instr = getInstrument(); if (!instr.empty()) out << "instrument " << instr << " "; if (getDynamics() >= 0) out << "dynamics " << getDynamics(); }
Pyramid::Pyramid(const Image &inputImage, const double inputSigma, const int octaveCount, const double levelCount) { Image levelImage = inputImage; double levelSigma = inputSigma; Image internalImage = levelImage.gaussFilter(sqrt(inputSigma * inputSigma - 0.5 * 0.5)); int octavsCount = log2f(std::min(inputImage.getHeight(),inputImage.getWidth())/50); for(int octaveNumber = 0; octaveNumber < octavsCount; octaveNumber++) { PyramidOctave octave(octaveNumber); levelSigma = inputSigma; if(octaveNumber > 0) { internalImage.copy(getOctave(octaveNumber-1).getLevel(levelCount-3).getImage()); internalImage.changeSize(qRound((double)internalImage.getWidth() / 2.0), qRound((double)internalImage.getHeight() / 2.0)); } for(int levelNumber = 0; levelNumber < levelCount + 2; levelNumber++) { if(levelNumber == 0 ) { PyramidLevel level(internalImage,levelSigma,levelNumber); octave.addLevel(level); } else { double tempSigma; levelSigma = inputSigma * pow(pow(2.0, 1.0 / (levelCount-1)), levelNumber); internalImage.copy(octave.getLevel(levelNumber-1).getImage()); tempSigma = sqrt(levelSigma * levelSigma - octave.getLevel(levelNumber-1).getSigma() * octave.getLevel(levelNumber-1).getSigma()); //printf("temp sigma %lf\n", tempSigma); PyramidLevel level(internalImage.gaussFilter(tempSigma),levelSigma,levelNumber); octave.addLevel(level); } } addOctave(octave); } }
//________________________________________________________________________ float notevisitor::getMidiPitch() const { if (fType == kPitched) { int step = step2i(getStep()); if (step >= 0) { short step2pitch [] = { 0, 2, 4, 5, 7, 9, 11 }; float pitch = (getOctave() * 12.f) + step2pitch[step]; return pitch + getAlter(); } } return -1; }
void PaeInput::parsePlainAndEasy(std::istream &infile) { // buffers char c_clef[1024] = {0}; char c_key[1024] = {0}; char c_keysig[1024] = {0}; char c_timesig[1024] = {0}; char c_alttimesig[1024] = {0}; char incipit[10001] = {0}; int in_beam = 0; std::string s_key; MeasureObject current_measure; NoteObject current_note; Clef *staffDefClef = NULL; std::vector<MeasureObject> staff; // read values while (!infile.eof()) { infile.getline(data_line, 10000); if (infile.eof()) { LogDebug("Truncated file or ending tag missing"); //exit(1); } getAtRecordKeyValue(data_key, data_value, data_line); if (strcmp(data_key,"end")==0) { break; } else if (strcmp(data_key,"clef")==0) { strcpy( c_clef, data_value ); } else if (strcmp(data_key,"key")==0) { strcpy( c_key, data_value ); } else if (strcmp(data_key,"keysig")==0) { strcpy( c_keysig, data_value ); } else if (strcmp(data_key,"timesig")==0) { strcpy( c_timesig, data_value ); } else if (strcmp(data_key,"alttimesig")==0) { strcpy( c_alttimesig, data_value ); } else if (strcmp(data_key,"data")==0) { strcpy( incipit, data_value ); } } if (strlen(c_clef)) { Clef *c = new Clef; getClefInfo(c_clef, c ); // do we need to put a default clef? if (!staffDefClef) staffDefClef = c; else current_measure.clef = c; } if (strlen(c_keysig)) { KeySig *k = new KeySig(); getKeyInfo( c_keysig, k); current_measure.key = k; } if (strlen(c_timesig)) { MeterSig *meter = new MeterSig; getTimeInfo( c_timesig, meter); // What about previous values? Potential memory leak? LP current_measure.meter = meter; } // read the incipit string size_t length = strlen(incipit); int i = 0; while(i < length) { // eat the input... if (incipit[i] == ' ') { // just skip i++; } // octaves if ((incipit[i] == '\'') || (incipit[i] == ',')) { i += getOctave( incipit, ¤t_note.octave, i ); } // rhythmic values else if (isdigit(incipit[i]) != 0) { i += getDurations( incipit, ¤t_measure, i ); } //accidentals (1 = n; 2 = x; 3 = xx; 4 = b; 5 = bb) else if (incipit[i] == 'n' || incipit[i] == 'x' || incipit[i] == 'b') { i += getAccidental( incipit, ¤t_note.accidental, i ); } // // beaming starts else if (incipit[i] == '{') { //current_note.beam = 1; current_note.beam = BEAM_INITIAL; in_beam++; } // beaming ends else if (incipit[i] == '}' && in_beam > 0) { current_measure.notes[current_measure.notes.size() - 1].beam = BEAM_TERMINAL; current_note.beam = 0; in_beam--; } // slurs are read when adding the note else if (incipit[i] == '+') { } // beginning tuplets & fermatas else if (incipit[i] == '(') { i += getTupletFermata( incipit, ¤t_note, i ); } // end of tuplets else if ((incipit[i] == ';') || (incipit[i] == ')')) { i += getTupletFermataEnd( incipit, ¤t_note, i ); } // trills are read when adding the note else if (incipit[i] == 't') { } //grace notes else if ((incipit[i] == 'g') || (incipit[i] == 'q')) { i += getGraceNote( incipit, ¤t_note, i ); } // end of appogiatura else if (incipit[i] == 'r') { current_note.appoggiatura = 0; // should not have to be done, but just in case } //note and rest // getNote also creates a new note object else if (((incipit[i]-'A'>=0) && (incipit[i]-'A'<7)) || (incipit[i]=='-')) { i += getNote( incipit, ¤t_note, ¤t_measure, i ); } // whole rest else if (incipit[i] == '=') { i += getWholeRest( incipit, ¤t_measure.wholerest, i ); } // abbreviation else if (incipit[i] == '!') { i += getAbbreviation( incipit, ¤t_measure, i ); } // measure repetition else if ((incipit[i] == 'i') && staff.size() > 0) { MeasureObject last_measure = staff[staff.size() - 1]; current_measure.notes = last_measure.notes; current_measure.wholerest = last_measure.wholerest; // if old measure does not end with a tie // force the first note of the newly copied measure to be without tie // this is to prevent copying tie closes which are invalid if (last_measure.notes.size() > 0 && last_measure.notes[last_measure.notes.capacity() - 1].tie == 0) current_measure.notes[0].tie = 0; } //barLine else if ((incipit[i] == ':') || (incipit[i] == '/')) { i += getBarline(incipit, ¤t_measure.barLine, i); current_measure.abbreviation_offset = 0; // just in case... staff.push_back( current_measure ); current_measure.reset(); } //clef change else if ((incipit[i] == '%') && (i+1 < length)) { Clef *c = new Clef; i += getClefInfo(incipit, c, i + 1); // if (!staffDefClef) { staffDefClef = c; } // If there are no notes yet in the measure // attach this clef change to the measure else if (current_measure.notes.size() == 0) { // If a clef was already assigned, remove it if (current_measure.clef) delete current_measure.clef; current_measure.clef = c; } else { // as above if (current_note.clef) delete current_note.clef; current_note.clef = c; } } //time signature change else if ((incipit[i] == '@') && (i+1 < length)) { MeterSig *meter = new MeterSig; i += getTimeInfo( incipit, meter, i + 1); if (current_measure.notes.size() == 0) { if (current_measure.meter) { delete current_measure.meter; } // When will this be deleted? Potential memory leak? LP current_measure.meter = meter; } else { if (current_note.meter) { delete current_note.meter; } current_note.meter = meter; } } //key signature change else if ((incipit[i] == '$') && (i+1 < length)) { KeySig *k = new KeySig; i += getKeyInfo( incipit, k, i + 1); if (current_measure.notes.size() == 0) { if (current_measure.key) delete current_measure.key; current_measure.key = k; } else { if (current_note.key) delete current_note.key; current_note.key = k; } } i++; } // we need to add the last measure if it has no barLine at the end if (current_measure.notes.size() != 0) { //current_measure.barLine = "=-"; staff.push_back( current_measure ); current_measure.notes.clear(); } m_doc->Reset( Raw ); Page *page = new Page(); System *system = new System(); int measure_count = 1; std::vector<MeasureObject>::iterator it; for ( it = staff.begin() ; it < staff.end(); it++ ) { m_staff = new Staff( 1 ); m_measure = new Measure( true, measure_count ); m_layer = new Layer( ); m_layer->SetN( 1 ); m_staff->AddLayer(m_layer); m_measure->AddStaff( m_staff ); system->AddMeasure( m_measure ); MeasureObject obj = *it; convertMeasure( &obj ); measure_count++; } // add miniaml scoreDef StaffGrp *staffGrp = new StaffGrp(); StaffDef *staffDef = new StaffDef(); staffDef->SetN( 1 ); staffDef->SetLines(5); if (staffDefClef) { staffDef->SetClefShape(staffDefClef->GetShape()); staffDef->SetClefLine(staffDefClef->GetLine()); staffDef->SetClefDis(staffDefClef->GetDis()); staffDef->SetClefDisPlace(staffDefClef->GetDisPlace()); delete staffDefClef; } staffGrp->AddStaffDef( staffDef ); m_doc->m_scoreDef.AddStaffGrp( staffGrp ); page->AddSystem( system ); m_doc->AddPage( page ); }