From 9c4ac9e97c4909b8f74b248d8f569aabf0914b74 Mon Sep 17 00:00:00 2001 From: "Maurizio M. Gavioli" Date: Sun, 21 Dec 2014 09:34:24 +0100 Subject: [PATCH] Intermediate fix: MXML I/O and Selection Filter tests - MXML I/O code has been adapted to the new glissando code. - Ref. scores for Selection filter tests have been updated. Guitar Pro: import code needs to be adapted to the new glissando code and I have no idea how to do that. --- mscore/exportxml.cpp | 92 ++++++++++--------- mscore/importxml.cpp | 64 +++++++++++-- mscore/musicxml.h | 36 ++++---- .../selectionfilter12-base-ref.xml | 28 ++++-- .../selectionfilter/selectionfilter12-ref.xml | 2 + 5 files changed, 146 insertions(+), 76 deletions(-) diff --git a/mscore/exportxml.cpp b/mscore/exportxml.cpp index 62ccf99854..5662d58d81 100644 --- a/mscore/exportxml.cpp +++ b/mscore/exportxml.cpp @@ -243,14 +243,14 @@ public: //--------------------------------------------------------- class GlissandoHandler { - const Chord* glissChrd[MAX_NUMBER_LEVEL]; - const Chord* slideChrd[MAX_NUMBER_LEVEL]; - int findChord(const Chord* c, int st) const; + const Note* glissNote[MAX_NUMBER_LEVEL]; + const Note* slideNote[MAX_NUMBER_LEVEL]; + int findNote(const Note* note, int type) const; public: GlissandoHandler(); - void doGlissandoStart(Chord* chord, Notations& notations, Xml& xml); - void doGlissandoStop(Chord* chord, Notations& notations, Xml& xml); + void doGlissandoStart(Glissando* gliss, Notations& notations, Xml& xml); + void doGlissandoStop(Glissando* gliss, Notations& notations, Xml& xml); }; //--------------------------------------------------------- @@ -637,25 +637,25 @@ static void glissando(const Glissando* gli, int number, bool start, Notations& n GlissandoHandler::GlissandoHandler() { for (int i = 0; i < MAX_NUMBER_LEVEL; ++i) { - glissChrd[i] = 0; - slideChrd[i] = 0; + glissNote[i] = 0; + slideNote[i] = 0; } } //--------------------------------------------------------- -// findChord -- get index of chord in chord table for subtype st +// findNote -- get index of Note in note table for subtype type // return -1 if not found //--------------------------------------------------------- -int GlissandoHandler::findChord(const Chord* c, int st) const +int GlissandoHandler::findNote(const Note* note, int type) const { - if (st != 0 && st != 1) { - qDebug("GlissandoHandler::findChord: unknown glissando subtype %d", st); + if (type != 0 && type != 1) { + qDebug("GlissandoHandler::findNote: unknown glissando subtype %d", type); return -1; } for (int i = 0; i < MAX_NUMBER_LEVEL; ++i) { - if (st == 0 && slideChrd[i] == c) return i; - if (st == 1 && glissChrd[i] == c) return i; + if (type == 0 && slideNote[i] == note) return i; + if (type == 1 && glissNote[i] == note) return i; } return -1; } @@ -664,56 +664,58 @@ int GlissandoHandler::findChord(const Chord* c, int st) const // doGlissandoStart //--------------------------------------------------------- -void GlissandoHandler::doGlissandoStart(Chord* chord, Notations& notations, Xml& xml) +void GlissandoHandler::doGlissandoStart(Glissando* gliss, Notations& notations, Xml& xml) { -/* Glissando::Type st = chord->glissando()->glissandoType(); - if (st != Glissando::Type::STRAIGHT && st != Glissando::Type::WAVY) { - qDebug("doGlissandoStart: unknown glissando subtype %hhd", st); + Glissando::Type type = gliss->glissandoType(); + if (type != Glissando::Type::STRAIGHT && type != Glissando::Type::WAVY) { + qDebug("doGlissandoStart: unknown glissando subtype %hhd", type); return; } + Note* note = static_cast(gliss->startElement()); // check if on chord list - int i = findChord(chord, int(st)); + int i = findNote(note, int(type)); if (i >= 0) { // print error and remove from list - qDebug("doGlissandoStart: chord %p already on list", chord); - if (st == Glissando::Type::STRAIGHT) slideChrd[i] = 0; - if (st == Glissando::Type::WAVY) glissChrd[i] = 0; + qDebug("doGlissandoStart: note for glissando/slide %p already on list", gliss); + if (type == Glissando::Type::STRAIGHT) slideNote[i] = 0; + if (type == Glissando::Type::WAVY) glissNote[i] = 0; } // find free slot to store it - i = findChord(0, int(st)); + i = findNote(0, int(type)); if (i >= 0) { - if (st == Glissando::Type::STRAIGHT) slideChrd[i] = chord; - if (st == Glissando::Type::WAVY) glissChrd[i] = chord; - glissando(chord->glissando(), i + 1, true, notations, xml); + if (type == Glissando::Type::STRAIGHT) slideNote[i] = note; + if (type == Glissando::Type::WAVY) glissNote[i] = note; + glissando(gliss, i + 1, true, notations, xml); } else - qDebug("doGlissandoStart: no free slot"); */ + qDebug("doGlissandoStart: no free slot"); } //--------------------------------------------------------- // doGlissandoStop //--------------------------------------------------------- -void GlissandoHandler::doGlissandoStop(Chord* chord, Notations& notations, Xml& xml) +void GlissandoHandler::doGlissandoStop(Glissando* gliss, Notations& notations, Xml& xml) { -/* Glissando::Type st = chord->glissando()->glissandoType(); - if (st != Glissando::Type::STRAIGHT && st != Glissando::Type::WAVY) { - qDebug("doGlissandoStart: unknown glissando subtype %hhd", st); + Glissando::Type type = gliss->glissandoType(); + if (type != Glissando::Type::STRAIGHT && type != Glissando::Type::WAVY) { + qDebug("doGlissandoStart: unknown glissando subtype %hhd", type); return; } + Note* note = static_cast(gliss->startElement()); for (int i = 0; i < MAX_NUMBER_LEVEL; ++i) { - if (st == Glissando::Type::STRAIGHT && slideChrd[i] == chord) { - slideChrd[i] = 0; - glissando(chord->glissando(), i + 1, false, notations, xml); + if (type == Glissando::Type::STRAIGHT && slideNote[i] == note) { + slideNote[i] = 0; + glissando(gliss, i + 1, false, notations, xml); return; } - if (st == Glissando::Type::WAVY && glissChrd[i] == chord) { - glissChrd[i] = 0; - glissando(chord->glissando(), i + 1, false, notations, xml); + if (type == Glissando::Type::WAVY && glissNote[i] == note) { + glissNote[i] = 0; + glissando(gliss, i + 1, false, notations, xml); return; } } - qDebug("doGlissandoStop: glissando chord %p not found", chord); */ + qDebug("doGlissandoStop: glissando note %p not found", note); } //--------------------------------------------------------- @@ -2131,7 +2133,7 @@ static void arpeggiate(Arpeggio* arp, bool front, bool back, Xml& xml, Notations } // find the next chord in the same track - +/* NO LONGER NEEDED static Chord* nextChord(Chord* ch) { Segment* s = ch->segment(); @@ -2152,7 +2154,7 @@ static Chord* nextChord(Chord* ch) } return c; } - +*/ //--------------------------------------------------------- // determineTupletNormalTicks //--------------------------------------------------------- @@ -2569,8 +2571,16 @@ void ExportMusicXml::chord(Chord* chord, int staff, const QList* ll, bo if (chord->arpeggio()) { arpeggiate(chord->arpeggio(), note == nl.front(), note == nl.back(), xml, notations); } - // write glissando (only for last note) -/* Chord* ch = nextChord(chord); + for (Spanner* spanner : note->spannerFor()) + if (spanner->type() == Element::Type::GLISSANDO) { + gh.doGlissandoStart(static_cast(spanner), notations, xml); + } + for (Spanner* spanner : note->spannerBack()) + if (spanner->type() == Element::Type::GLISSANDO) { + gh.doGlissandoStop(static_cast(spanner), notations, xml); + } +/* // write glissando (only for last note) + Chord* ch = nextChord(chord); if ((note == nl.back()) && ch && ch->glissando()) { gh.doGlissandoStart(ch, notations, xml); } diff --git a/mscore/importxml.cpp b/mscore/importxml.cpp index 1aa6a553f3..c44b1066a4 100644 --- a/mscore/importxml.cpp +++ b/mscore/importxml.cpp @@ -783,13 +783,15 @@ void MusicXml::initPartState() hairpins[i] = 0; for (int i = 0; i < MAX_NUMBER_LEVEL; ++i) trills[i] = 0; + for (int i = 0; i < MAX_NUMBER_LEVEL; ++i) + glissandi[i][0] = glissandi[i][1] = 0; pedal = 0; pedalContinue = 0; harmony = 0; tremStart = 0; figBass = 0; - glissandoText = ""; - glissandoColor = ""; +// glissandoText = ""; +// glissandoColor = ""; } //--------------------------------------------------------- @@ -4731,7 +4733,7 @@ void MusicXml::xmlNotations(Note* note, ChordRest* cr, int trk, int tick, int ti QString wavyLineType; int wavyLineNo = 0; QString arpeggioType; - QString glissandoType; +// QString glissandoType; int breath = -1; int tremolo = 0; QString tremoloType; @@ -4970,6 +4972,52 @@ void MusicXml::xmlNotations(Note* note, ChordRest* cr, int trk, int tick, int ti } else if (ee.tagName() == "non-arpeggiate") arpeggioType = "non-arpeggiate"; + + if (ee.tagName() == "glissando" || ee.tagName() == "slide") { + int n = ee.attribute(QString("number"), "1").toInt() - 1; + QString spannerType = ee.attribute(QString("type")); + int tag = ee.tagName() == "slide" ? 0 : 1; +// QString lineType = ee.attribute(QString("line-type"), "solid"); + Glissando*& gliss = glissandi[n][tag]; + if (spannerType == "start") { + if (gliss) { + qDebug("overlapping glissando/slide %d not supported", n+1); + delete gliss; + gliss = 0; + } + else { + gliss = new Glissando(score); + gliss->setAnchor(Spanner::Anchor::NOTE); + gliss->setStartElement(note); + gliss->setTick(tick); + gliss->setTrack(track); + gliss->setParent(note); + gliss->setText(ee.text()); + QColor color(ee.attribute("color")); + if (color.isValid()) + gliss->setColor(color); + gliss->setGlissandoType(tag == 0 ? Glissando::Type::STRAIGHT : Glissando::Type::WAVY); + spanners[gliss] = QPair(tick, -1); + // qDebug("glissando/slide=%p inserted at first tick %d", gliss, tick); + } + } + else if (spannerType == "stop") { + if (!gliss) { + qDebug("glissando/slide %d stop without start", n+1); + } + else { + spanners[gliss].second = tick + ticks; + gliss->setEndElement(note); + gliss->setTick2(tick); + gliss->setTrack2(track); + // qDebug("glissando/slide=%p second tick %d", gliss, tick); + gliss = 0; + } + } + else + qDebug("unknown glissando/slide type %s", qPrintable(spannerType)); + } +/* // glissando and slide are added to the "stop" chord only // but text and color are read at start else if (ee.tagName() == "glissando") { @@ -4987,7 +5035,7 @@ void MusicXml::xmlNotations(Note* note, ChordRest* cr, int trk, int tick, int ti else if (ee.attribute("type") == "stop") glissandoType = "slide"; } else - domError(ee); + domError(ee); */ } // no support for arpeggio on rest if (!arpeggioType.isEmpty() && cr->type() == Element::Type::CHORD) { @@ -5013,7 +5061,7 @@ void MusicXml::xmlNotations(Note* note, ChordRest* cr, int trk, int tick, int ti else cr->add(a); } - +/* if (!glissandoType.isEmpty()) { Glissando* g = new Glissando(score); if (glissandoType == "slide") @@ -5040,14 +5088,14 @@ void MusicXml::xmlNotations(Note* note, ChordRest* cr, int trk, int tick, int ti glissandoColor = ""; } } -/* if ((static_cast(cr))->glissando()) { + if ((static_cast(cr))->glissando()) { // there can be only one delete g; g = 0; } else - cr->add(g); */ - } + cr->add(g); + } */ if (!wavyLineType.isEmpty()) { int n = wavyLineNo - 1; diff --git a/mscore/musicxml.h b/mscore/musicxml.h index 5f7d6b9b4a..fc1af26312 100644 --- a/mscore/musicxml.h +++ b/mscore/musicxml.h @@ -34,27 +34,28 @@ namespace Ms { +class Beam; +class Chord; +class ChordRest; +class FiguredBass; +class Glissando; +class Hairpin; +class Harmony; class Instrument; +class Lyrics; class Measure; -class Tuplet; -class Tie; -class Slur; -class Part; -class Score; class Note; class Ottava; -class Trill; +class Part; class Pedal; -class Volta; -class TextLine; -class Chord; -class Harmony; -class Hairpin; +class Score; +class Slur; class Spanner; -class Lyrics; -class ChordRest; -class Beam; -class FiguredBass; +class TextLine; +class Tie; +class Trill; +class Tuplet; +class Volta; enum class StaffTypes : char; //--------------------------------------------------------- @@ -182,6 +183,7 @@ class MusicXml { Ottava* ottavas[MAX_NUMBER_LEVEL]; ///< Current ottavas Hairpin* hairpins[MAX_NUMBER_LEVEL]; ///< Current hairpins Trill* trills[MAX_NUMBER_LEVEL]; ///< Current trills + Glissando* glissandi[MAX_NUMBER_LEVEL][2]; ///< Current slides ([0]) / glissandi ([1]) Tie* tie; Volta* lastVolta; @@ -211,8 +213,8 @@ class MusicXml { FiguredBass* figBass; ///< Current figured bass element (to attach to next note) QVector figBassList; ///< List of figured bass elements under a single note Beam::Mode beamMode; ///< Current beam mode - QString glissandoText; ///< Glissando text at glissando start - QString glissandoColor; ///< Glissando color at glissando start +// QString glissandoText; ///< Glissando text at glissando start +// QString glissandoColor; ///< Glissando color at glissando start int pageWidth; ///< Page width read from defaults int pageHeight; ///< Page height read from defaults diff --git a/mtest/libmscore/selectionfilter/selectionfilter12-base-ref.xml b/mtest/libmscore/selectionfilter/selectionfilter12-base-ref.xml index 1c47814f3b..0b8e5dcacb 100644 --- a/mtest/libmscore/selectionfilter/selectionfilter12-base-ref.xml +++ b/mtest/libmscore/selectionfilter/selectionfilter12-base-ref.xml @@ -10,6 +10,14 @@ 0 72 14 + + gliss. + 0 + 0 + 1 + 0.15 + 3 + @@ -19,12 +27,8 @@ 0 60 14 + - - gliss. - 0 - 0 - 0 @@ -33,6 +37,14 @@ 0 67 15 + + gliss. + 1 + 0 + 1 + 0.15 + 3 + @@ -42,12 +54,8 @@ 0 79 15 + - - gliss. - 1 - 0 - diff --git a/mtest/libmscore/selectionfilter/selectionfilter12-ref.xml b/mtest/libmscore/selectionfilter/selectionfilter12-ref.xml index 565a647190..6f4f287a39 100644 --- a/mtest/libmscore/selectionfilter/selectionfilter12-ref.xml +++ b/mtest/libmscore/selectionfilter/selectionfilter12-ref.xml @@ -19,6 +19,7 @@ 0 60 14 + @@ -37,6 +38,7 @@ 0 79 15 +