Пример #1
0
bool KoDocumentInfoAuthor::saveOasis( KoXmlWriter &xmlWriter )
{
    if ( !m_fullName.isEmpty() )
    {
     xmlWriter.startElement( "dc:creator");
     xmlWriter.addTextNode( m_fullName );
     xmlWriter.endElement();
    }
    if ( !m_initial.isEmpty() )
    {
     xmlWriter.startElement( "meta:user-defined");
     xmlWriter.addAttribute( "meta:name", "initial" );
     xmlWriter.addTextNode( m_initial );
     xmlWriter.endElement();
    }
    if ( !m_title.isEmpty() )
    {
     xmlWriter.startElement( "meta:user-defined");
     xmlWriter.addAttribute( "meta:name", "author-title" );
     xmlWriter.addTextNode( m_title );
     xmlWriter.endElement();
    }
    if ( !m_company.isEmpty() )
    {
     xmlWriter.startElement( "meta:user-defined");
     xmlWriter.addAttribute( "meta:name", "company" );
     xmlWriter.addTextNode( m_company );
     xmlWriter.endElement();
    }
    if ( !m_email.isEmpty() )
    {
     xmlWriter.startElement( "meta:user-defined");
     xmlWriter.addAttribute( "meta:name", "email" );
     xmlWriter.addTextNode( m_email );
     xmlWriter.endElement();
    }
    if ( !m_telephoneHome.isEmpty() )
    {
     xmlWriter.startElement( "meta:user-defined");
     xmlWriter.addAttribute( "meta:name", "telephone" );
     xmlWriter.addTextNode( m_telephoneHome );
     xmlWriter.endElement();
    }
    if ( !m_telephoneWork.isEmpty() )
    {
     xmlWriter.startElement( "meta:user-defined");
     xmlWriter.addAttribute( "meta:name", "telephone-work" );
     xmlWriter.addTextNode( m_telephoneWork );
     xmlWriter.endElement();
    }
    if ( !m_fax.isEmpty() )
    {
     xmlWriter.startElement( "meta:user-defined");
     xmlWriter.addAttribute( "meta:name", "fax" );
     xmlWriter.addTextNode( m_fax );
     xmlWriter.endElement();
    }
    if ( !m_country.isEmpty() )
    {
     xmlWriter.startElement( "meta:user-defined");
     xmlWriter.addAttribute( "meta:name", "country" );
     xmlWriter.addTextNode( m_country );
     xmlWriter.endElement();
    }
    if ( !m_postalCode.isEmpty() )
    {
     xmlWriter.startElement( "meta:user-defined");
     xmlWriter.addAttribute( "meta:name", "postal-code" );
     xmlWriter.addTextNode( m_postalCode );
     xmlWriter.endElement();
    }
    if ( !m_city.isEmpty() )
    {
     xmlWriter.startElement( "meta:user-defined");
     xmlWriter.addAttribute( "meta:name", "city" );
     xmlWriter.addTextNode( m_city );
     xmlWriter.endElement();
    }
    if ( !m_street.isEmpty() )
    {
     xmlWriter.startElement( "meta:user-defined");
     xmlWriter.addAttribute( "meta:name", "street" );
     xmlWriter.addTextNode( m_street );
     xmlWriter.endElement();
    }
    if ( !m_position.isEmpty() )
    {
     xmlWriter.startElement( "meta:user-defined");
     xmlWriter.addAttribute( "meta:name", "position" );
     xmlWriter.addTextNode( m_position );
     xmlWriter.endElement();
    }
    return true;
}
Пример #2
0
static void writeChord(KoXmlWriter& w, Chord* chord, Voice* voice, Part* part, int bar)
{
    if (!chord->noteCount()) {
        w.startElement("music:note");

        w.startElement("music:rest");
        w.endElement();  // music:rest

        w.startElement("music:duration");
        w.addTextNode(QString::number(chord->length()));
        w.endElement(); // music:duration
        
        w.startElement("music:voice");
        w.addTextNode(QString::number(part->indexOfVoice(voice) + 1));
        w.endElement(); // music:voice
        
        w.startElement("music:type");
        w.addTextNode(durationToString(chord->duration()));
        w.endElement(); // music:type
        
        for (int i = 0; i < chord->dots(); i++) {
            w.startElement("music:dot");
            w.endElement(); // music:dot
        }
        
        if (part->staffCount() > 1) {
            // only write staff info when more than one staff exists
            Staff* s = chord->staff();
            w.startElement("music:staff");
            w.addTextNode(QString::number(part->indexOfStaff(s) + 1));
            w.endElement();  //music:staff
        }
        w.endElement(); // music:note
    } else for (int n = 0; n < chord->noteCount(); n++) {
        Staff* staff = chord->note(n)->staff();
        w.startElement("music:note");
        
        if (n > 0) {
            w.startElement("music:chord");
            w.endElement(); // music:chord
        }

        w.startElement("music:pitch");
        w.startElement("music:step");
        int pitch = chord->note(n)->pitch();
        char note = 'A' + ((((pitch + 2) % 7) + 7) % 7);
        w.addTextNode(QString(note));
        w.endElement(); // music:step

        if (chord->note(n)->accidentals()) {
            w.startElement("music:alter");
            w.addTextNode(QString::number(chord->note(n)->accidentals()));
            w.endElement(); // music:alter
        }
        
        w.startElement("music:octave");
        w.addTextNode(QString::number((pitch + 4*7) / 7)); // first add, than divide to get proper rounding
        w.endElement(); // music:octave
        w.endElement(); // music:pitch
        w.startElement("music:duration");
        w.addTextNode(QString::number(chord->length()));
        w.endElement(); // music:duration
        
        w.startElement("music:voice");
        w.addTextNode(QString::number(part->indexOfVoice(voice) + 1));
        w.endElement(); // music:voice
        
        w.startElement("music:type");
        w.addTextNode(durationToString(chord->duration()));
        w.endElement(); // music:type
        
        for (int i = 0; i < chord->dots(); i++) {
            w.startElement("music:dot");
            w.endElement(); // music:dot
        }
        
        int activeAccidentals = 0;
        KeySignature* ks = staff->lastKeySignatureChange(bar);
        if (ks) activeAccidentals = ks->accidentals(chord->note(n)->pitch());
        VoiceBar* vb = chord->voiceBar();
        // next check the bar for the last previous note in the same voice with the same pitch
        for (int e = 0; e < vb->elementCount(); e++) {
            Chord* c = dynamic_cast<Chord*>(vb->element(e));
            if (!c) continue;
            if (c == chord) break;
            for (int nid = 0; nid < c->noteCount(); nid++) {
                Note* note = c->note(nid);
                if (note->staff() != staff) continue;
                if (note->pitch() == chord->note(n)->pitch()) {
                    activeAccidentals = note->accidentals();
                }
            }
        }
        
        if (chord->note(n)->accidentals() != activeAccidentals) {
            w.startElement("music:accidental");
            switch (chord->note(n)->accidentals()) {
                case -2: w.addTextNode("flat-flat"); break;
                case -1: w.addTextNode("flat"); break;
                case  0: w.addTextNode("natural"); break;
                case  1: w.addTextNode("sharp"); break;
                case  2: w.addTextNode("double-sharp"); break;
            }
            w.endElement(); // music:accidental
        }
        
        if (part->staffCount() > 1) {
            // only write staff info when more than one staff exists
            Staff* s = chord->note(n)->staff();
            w.startElement("music:staff");
            w.addTextNode(QString::number(part->indexOfStaff(s) + 1));
            w.endElement();  //music:staff
        }
        w.endElement(); // music:note
    }
}
Пример #3
0
static void writePart(KoXmlWriter& w, int id, Part* part)
{
    w.startElement("music:part");
    w.addAttribute("id", QString("P%1").arg(id));

    for (int i = 0; i < part->sheet()->barCount(); i++) {
        Bar* bar = part->sheet()->bar(i);
        
        w.startElement("music:measure");
        w.addAttribute("number", i+1);

        bool inAttributes = false;
        if (i == 0) {
            w.startElement("music:attributes");
            w.startElement("music:divisions");
            w.addTextNode(QString::number(QuarterLength));
            w.endElement(); // music:divisions
            inAttributes = true;
        }

        for (int st = 0; st < part->staffCount(); st++) {
            Staff* staff = part->staff(st);
            for (int e = 0; e < bar->staffElementCount(staff); e++) {
                StaffElement* se = bar->staffElement(staff, e);
                
                KeySignature* ks = dynamic_cast<KeySignature*>(se);
                if (ks) {
                    if (!inAttributes) {
                        w.startElement("music:attributes");
                        inAttributes = true;
                    }
                    writeKeySignature(w, ks, part);
                }
            }
        }
        for (int st = 0; st < part->staffCount(); st++) {
            Staff* staff = part->staff(st);
            for (int e = 0; e < bar->staffElementCount(staff); e++) {
                StaffElement* se = bar->staffElement(staff, e);
                
                TimeSignature* ts = dynamic_cast<TimeSignature*>(se);
                if (ts) {
                    if (!inAttributes) {
                        w.startElement("music:attributes");
                        inAttributes = true;
                    }
                    writeTimeSignature(w, ts, part);
                }
            }
        }

        if (i == 0 && part->staffCount() != 1) {
            w.startElement("music:staves");
            w.addTextNode(QString::number(part->staffCount()));
            w.endElement(); // music:staves
        }            
            
        for (int st = 0; st < part->staffCount(); st++) {
            Staff* staff = part->staff(st);
            for (int e = 0; e < bar->staffElementCount(staff); e++) {
                StaffElement* se = bar->staffElement(staff, e);
                
                Clef* c = dynamic_cast<Clef*>(se);
                if (c) {
                    if (!inAttributes) {
                        w.startElement("music:attributes");
                        inAttributes = true;
                    }
                    writeClef(w, c, part);
                }
            }
        }

        if (inAttributes) {
            w.endElement(); // music:attributes
        }

        int curTime = 0;
        for (int voice = 0; voice < part->voiceCount(); voice++) {
            if (curTime != 0) {
                w.startElement("music:backup");
                w.startElement("music:duration");
                w.addTextNode(QString::number(curTime));
                w.endElement(); // music:duration
                w.endElement(); // music:backup
            }

            Voice* v = part->voice(voice);
            VoiceBar* vb = part->sheet()->bar(i)->voice(v);
            for (int e = 0; e < vb->elementCount(); e++) {
                VoiceElement* ve = vb->element(e);
                curTime += ve->length();

                Chord* c =  dynamic_cast<Chord*>(ve);
                if(c) writeChord(w, c, v, part, i);
            }
        }
        w.endElement(); // music:measure
    }

    w.endElement(); // music:part
}