Example #1
0
bool DarmsInput::ImportString(std::string data_str) {
    int len, res;
    int pos = 0;
    const char *data = data_str.c_str();
    len = data_str.length();

    m_doc->Reset( Raw );
    System *system = new System();
    Page *page = new Page();
    m_staff = new Staff( 1 );
    m_measure = new Measure( true, 1 );
    m_layer = new Layer( 1 );

    m_current_tie = NULL;
    m_staff->AddLayer(m_layer);
    m_measure->AddStaff( m_staff );
    system->AddMeasure( m_measure );

    // do this the C style, char by char
    while (pos < len) {
        char c = data[pos];

        if (c == '!') {
            LogDebug("DarmsInput: Global spec. at %i", pos);
            res = do_globalSpec(pos, data);
            if (res) pos = res;
            // if notehead type was specified in the !Nx option preserve it
            m_staff->notAnc = m_antique_notation;
        } else if (isdigit(c) || c == '-' ) { // check for '-' too as note positions can be negative
            //is number followed by '!' ? it is a clef
            if (data[pos + 1] == '!') {
                res = do_Clef(pos, data);
                if (res) pos = res;
            } else { // we assume it is a note
                res = do_Note(pos, data, false);
                if (res) pos = res;
            }
        } else if (c == 'R') {
            res = do_Note(pos, data, true);
            if (res) pos = res;
        } else {
            //if (!isspace(c))
            //LogMessage("Other %c", c);
        }

        pos++;
    }

    // add miniaml scoreDef
    StaffGrp *staffGrp = new StaffGrp();
    StaffDef *staffDef = new StaffDef();
    staffDef->SetStaffNo( 1 );
    staffGrp->AddStaffDef( staffDef );
    m_doc->m_scoreDef.AddStaffGrp( staffGrp );

    page->AddSystem( system );
    m_doc->AddPage( page );

    return true;
}
Example #2
0
int StaffGrp::OptimizeScoreDefEnd(FunctorParams *)
{
    // OptimizeScoreDefParams *params = dynamic_cast<OptimizeScoreDefParams *>(functorParams);
    // assert(params);

    this->SetDrawingVisibility(OPTIMIZATION_HIDDEN);

    for (auto &child : m_children) {
        if (child->Is(STAFFDEF)) {
            StaffDef *staffDef = dynamic_cast<StaffDef *>(child);
            assert(staffDef);
            if (staffDef->GetDrawingVisibility() != OPTIMIZATION_HIDDEN) {
                this->SetDrawingVisibility(OPTIMIZATION_SHOW);
                break;
            }
        }
        else if (child->Is(STAFFGRP)) {
            StaffGrp *staffGrp = dynamic_cast<StaffGrp *>(child);
            assert(staffGrp);
            if (staffGrp->GetDrawingVisibility() != OPTIMIZATION_HIDDEN) {
                this->SetDrawingVisibility(OPTIMIZATION_SHOW);
                break;
            }
        }
    }

    if ((this->GetSymbol() == staffGroupingSym_SYMBOL_brace) && (this->GetDrawingVisibility() != OPTIMIZATION_HIDDEN)) {
        for (auto &child : m_children) {
            if (child->Is(STAFFDEF)) {
                StaffDef *staffDef = dynamic_cast<StaffDef *>(child);
                assert(staffDef);
                staffDef->SetDrawingVisibility(OPTIMIZATION_SHOW);
            }
        }
    }

    return FUNCTOR_CONTINUE;
}
void CScribeToNeoScribeXML::SegmentScribe2MEIXML(const CScribeReaderVisitable& scribe_data)
{
    std::unordered_set<std::string> rep_no_record;
    
    for (std::vector<scribe_part>::const_iterator part = scribe_data.GetScribeParts().begin(); part != scribe_data.GetScribeParts().end(); part++)
    {
        int i = 0;
        
        //save record of first part
        scribe_part first_part = *part;
        
        //create an instance of XML doc representation, etc.
        delete doc;
        doc = new MeiDocument();
        
        Mei *mei = new Mei;
        doc->setRootElement(mei);
        /*
            MEI
                - <meiHead>
                    - FileDescription
                    - EncodingDescription
                    - Work Description
                    - Revision Description
         
         */
        //create MEIhead to contain file, encoding, work and revision description
        MeiHead* mei_head = new MeiHead;
        mei->addChild(mei_head);
        
        AltId* altId = new AltId;
        mei_head->addChild(altId);
        if (scribe_data.GetType()==scribe_type::trecento)
        {
            altId->addAttribute("type", "repnum");
            altId->setValue(part->rep_num);
        } else if (scribe_data.GetType()==scribe_type::trecento)
        {
            altId->addAttribute("type", "cao");
            altId->setValue(std::to_string(part->cao_num));

        }
        //Create and link fileDesc
        FileDesc* fileDesc = Scribe2MEIFileDesc();
        mei_head->addChild(fileDesc);
        
        //Create and link encodingDesc
        EncodingDesc* encodingDesc = Scribe2MEIEncoderDesc();
        mei_head->addChild(encodingDesc);
        
        //Create and link workDesc
        WorkDesc* workDesc = Scribe2MEIWorkDesc();
        mei_head->addChild(workDesc);
        //</meiHead> - not really at this stage - other elements completed in main routine
        
        //music - contains all music data
        Music* music = new Music;
        mei->addChild(music);
        Mdiv* mdiv = new Mdiv; //for chant source this needs to be specified repeatedly, with n and type attributes
        music->addChild(mdiv);
        Score* score = new Score;
        mdiv->addChild(score);
        
        //start adding score definitions - child of score
        ScoreDef* scoredef = new ScoreDef;
        score->addChild(scoredef);
        StaffGrp* staffgrp = new StaffGrp;
        scoredef->addChild(staffgrp);
        staffgrp->setId("all");
        
        //skip along and collect parts - all have the same REPNUM
        
        std::string xml_file_name("");
        
        if (scribe_data.GetType()==scribe_type::trecento)
        {
            do
            {
                ++i;
                
                if (i==1)
                {
                    Scribe2MEIXMLFileData(fileDesc, *part);
                    Scribe2MEIXMLWorkData(workDesc, *part);
                }
                //add section - child of score
                Section* section = new Section;
                score->addChild(section);
                
                //handle staff and link to section
                Staff* staff = Scribe2MEIXMLStaff(scribe_data, *part, staffgrp, i);
                section->addChild(staff); //or TiXmlElement* layer;?
                
                part++;
                
            } while ( part->rep_num==first_part.rep_num && part != scribe_data.GetScribeParts().end());
            
            part--; // step back to last part in piece
            
            xml_file_name = first_part.rep_num;
            
            //find duplicates - doesn't find triplicates
            if (rep_no_record.find(part->rep_num) == rep_no_record.end())
            {
                rep_no_record.insert(part->rep_num);
            }
            else
            {
                xml_file_name += " copy";
            }
            
        }
        else if (scribe_data.GetType()==scribe_type::chant)
        {
            
            Scribe2MEIXMLFileData(fileDesc, *part);
            Scribe2MEIXMLWorkData(workDesc, *part);
            
                //add section - child of score
            Section* section = new Section;
            score->addChild(section);
                
                //handle staff and link to section
            Staff* staff = Scribe2MEIXMLStaff(scribe_data, *part, staffgrp, i);
            section->addChild(staff);
            
            xml_file_name = part->abbrev_ms + ZeroPadNumber(part->partID,4)+ " (" + std::to_string(first_part.cao_num) + ")";
            
        }
        
        //need to check if there already exists a file with the same name
        
        xml_file_name +=  ".xml";
        
        SaveMEIXML(xml_file_name);
    
    }
    
}
MeiDocument* CScribeToNeoScribeXML::Scribe2MEIXML(const CScribeReaderVisitable& scribe_data)
{
    
    Mei* mei = new Mei;
    doc->setRootElement(mei);

    //create MEIhead to contain file, encoding, work and revision description
    MeiHead* mei_head = new MeiHead; //"meiHead"
    mei->addChild(mei_head);
    
    //Create and link fileDesc
    FileDesc* fileDesc = Scribe2MEIFileDesc();
    mei_head->addChild(fileDesc);
    
    //Create and link encodingDesc
    EncodingDesc* encodingDesc = Scribe2MEIEncoderDesc();
    mei_head->addChild(encodingDesc);
    
    //Create and link workDesc
    WorkDesc* workDesc = Scribe2MEIWorkDesc();
    mei_head->addChild(workDesc);
    //</meiHead> - not really at this stage - other elements completed in main routine
    
    //music - contains all music data
    Music* music = new Music;
    mei->addChild(music);
    Mdiv* mdiv = new Mdiv; //for chant source this needs to be specified repeatedly, with n and type attributes
    music->addChild(mdiv);
    Score* score = new Score;
    mdiv->addChild(score);
    
    //start adding score definitions - child of score
    ScoreDef* scoredef = new ScoreDef;
    score->addChild(scoredef);
    StaffGrp* staffgrp = new StaffGrp;
    scoredef->addChild(staffgrp);
    staffgrp->setId("all");
    
    int i=0;
    
    for (std::vector<scribe_part>::const_iterator partit = scribe_data.GetScribeParts().begin(); partit!=scribe_data.GetScribeParts().end(); partit++)
    {
        ++i;
        if (i==1)
        {
            Scribe2MEIXMLFileData(fileDesc, *partit);
            Scribe2MEIXMLWorkData(workDesc, *partit);
        }
        
        //add section - child of score
        Section* section = new Section();
        score->addChild(section);
        
        //handle staff and link to section
        Staff* staff = Scribe2MEIXMLStaff(scribe_data, *partit, staffgrp, i);
        section->addChild(staff);
        
    }
    
    return doc;
}
Example #5
0
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, &current_note.octave, i );
        }
        
        // rhythmic values
        else if (isdigit(incipit[i]) != 0) {
            i += getDurations( incipit, &current_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, &current_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, &current_note, i );
		}
        
        // end of tuplets
		else if ((incipit[i] == ';') || (incipit[i] == ')')) {
            i += getTupletFermataEnd( incipit, &current_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, &current_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, &current_note, &current_measure, i );
        }
        
  		// whole rest
		else if (incipit[i] == '=') {
            i += getWholeRest( incipit, &current_measure.wholerest, i );		
		} 
        
		// abbreviation
        else if (incipit[i] == '!') {
            i += getAbbreviation( incipit, &current_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, &current_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 );
}