2012-08-09 12:12:43 +02:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
|
|
|
// Copyright (C) 2012 Werner Schweer
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2
|
|
|
|
// as published by the Free Software Foundation and appearing in
|
|
|
|
// the file LICENCE.GPL
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#include "score.h"
|
2013-10-21 15:55:56 +02:00
|
|
|
#include "mscore.h"
|
|
|
|
|
|
|
|
#include "accidental.h"
|
|
|
|
#include "articulation.h"
|
|
|
|
#include "barline.h"
|
|
|
|
#include "beam.h"
|
|
|
|
#include "box.h"
|
|
|
|
#include "breath.h"
|
|
|
|
#include "chord.h"
|
|
|
|
#include "chordlist.h"
|
2012-08-09 12:12:43 +02:00
|
|
|
#include "clef.h"
|
2013-10-21 15:55:56 +02:00
|
|
|
#include "drumset.h"
|
|
|
|
#include "dynamic.h"
|
|
|
|
#include "figuredbass.h"
|
|
|
|
#include "hairpin.h"
|
|
|
|
#include "harmony.h"
|
|
|
|
#include "key.h"
|
|
|
|
#include "keysig.h"
|
|
|
|
#include "layoutbreak.h"
|
|
|
|
#include "lyrics.h"
|
|
|
|
#include "measure.h"
|
2012-08-09 12:12:43 +02:00
|
|
|
#include "navigate.h"
|
|
|
|
#include "note.h"
|
2013-10-21 15:55:56 +02:00
|
|
|
#include "noteevent.h"
|
|
|
|
#include "ottava.h"
|
|
|
|
#include "page.h"
|
|
|
|
#include "part.h"
|
|
|
|
#include "pedal.h"
|
|
|
|
#include "pitchspelling.h"
|
|
|
|
#include "repeat.h"
|
2012-08-09 12:12:43 +02:00
|
|
|
#include "rest.h"
|
2013-10-21 15:55:56 +02:00
|
|
|
#include "segment.h"
|
|
|
|
#include "sequencer.h"
|
2012-08-09 12:12:43 +02:00
|
|
|
#include "sig.h"
|
2013-10-21 15:55:56 +02:00
|
|
|
#include "slur.h"
|
2012-08-09 12:12:43 +02:00
|
|
|
#include "staff.h"
|
2013-10-21 15:55:56 +02:00
|
|
|
#include "stafftype.h"
|
|
|
|
#include "stafftext.h"
|
2012-08-09 12:12:43 +02:00
|
|
|
#include "style.h"
|
|
|
|
#include "system.h"
|
2013-12-05 21:37:28 +01:00
|
|
|
//#include "stringdata.h"
|
2012-08-09 12:12:43 +02:00
|
|
|
#include "tempo.h"
|
|
|
|
#include "tempotext.h"
|
2013-10-21 15:55:56 +02:00
|
|
|
#include "text.h"
|
|
|
|
#include "textline.h"
|
|
|
|
#include "tie.h"
|
|
|
|
#include "timesig.h"
|
|
|
|
#include "trill.h"
|
|
|
|
#include "tuplet.h"
|
|
|
|
#include "undo.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "volta.h"
|
|
|
|
#include "xml.h"
|
2012-08-09 12:12:43 +02:00
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
namespace Ms {
|
|
|
|
|
2012-08-09 12:12:43 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// pasteStaff
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2013-01-11 18:10:18 +01:00
|
|
|
void Score::pasteStaff(XmlReader& e, ChordRest* dst)
|
2012-08-09 12:12:43 +02:00
|
|
|
{
|
2013-10-14 11:56:54 +02:00
|
|
|
clearSpannerIds();
|
2013-06-19 16:25:29 +02:00
|
|
|
QList<Chord*> graceNotes;
|
2012-08-09 12:12:43 +02:00
|
|
|
int dstStaffStart = dst->staffIdx();
|
|
|
|
int dstTick = dst->tick();
|
2013-06-20 19:01:44 +02:00
|
|
|
bool done = false;
|
2013-01-11 18:10:18 +01:00
|
|
|
while (e.readNextStartElement()) {
|
2013-06-20 19:01:44 +02:00
|
|
|
if (done)
|
|
|
|
break;
|
2013-01-11 18:10:18 +01:00
|
|
|
if (e.name() != "StaffList") {
|
|
|
|
e.unknown();
|
2013-01-17 12:56:14 +01:00
|
|
|
break;
|
2012-08-09 12:12:43 +02:00
|
|
|
}
|
2013-08-05 15:27:52 +02:00
|
|
|
QString version = e.attribute("version", "NONE");
|
|
|
|
if(version != MSC_VERSION)
|
|
|
|
break;
|
2013-01-11 18:10:18 +01:00
|
|
|
int tickStart = e.intAttribute("tick", 0);
|
|
|
|
int tickLen = e.intAttribute("len", 0);
|
|
|
|
int srcStaffStart = e.intAttribute("staff", 0);
|
|
|
|
int staves = e.intAttribute("staves", 0);
|
2013-01-21 20:21:41 +01:00
|
|
|
e.setTick(tickStart);
|
2012-08-09 12:12:43 +02:00
|
|
|
|
|
|
|
bool pasted = false;
|
2013-01-11 18:10:18 +01:00
|
|
|
while (e.readNextStartElement()) {
|
2013-06-20 20:13:46 +02:00
|
|
|
if (done)
|
|
|
|
break;
|
2013-01-11 18:10:18 +01:00
|
|
|
if (e.name() != "Staff") {
|
|
|
|
e.unknown();
|
2013-01-17 12:56:14 +01:00
|
|
|
break;
|
2012-08-09 12:12:43 +02:00
|
|
|
}
|
2013-01-11 18:10:18 +01:00
|
|
|
int srcStaffIdx = e.attribute("id", "0").toInt();
|
2012-08-09 12:12:43 +02:00
|
|
|
int dstStaffIdx = srcStaffIdx - srcStaffStart + dstStaffStart;
|
2013-06-20 19:01:44 +02:00
|
|
|
if (dstStaffIdx >= nstaves()) {
|
|
|
|
done = true; // break main loop, nothing more to paste
|
2012-08-09 12:12:43 +02:00
|
|
|
break;
|
2013-06-20 19:01:44 +02:00
|
|
|
}
|
2013-07-20 16:14:39 +02:00
|
|
|
|
2013-01-21 20:21:41 +01:00
|
|
|
e.tuplets().clear();
|
2013-07-20 16:14:39 +02:00
|
|
|
bool makeGap = true;
|
2013-01-11 18:10:18 +01:00
|
|
|
while (e.readNextStartElement()) {
|
2012-08-09 12:12:43 +02:00
|
|
|
pasted = true;
|
2013-01-11 18:10:18 +01:00
|
|
|
const QStringRef& tag(e.name());
|
2013-01-07 12:36:06 +01:00
|
|
|
|
2013-06-20 20:13:46 +02:00
|
|
|
if (tag == "tick") {
|
|
|
|
int tick = e.readInt();
|
|
|
|
e.setTick(tick);
|
2013-07-20 16:14:39 +02:00
|
|
|
int shift = tick - tickStart;
|
|
|
|
if (makeGap && !makeGap1(dstTick + shift, dstStaffIdx, Fraction::fromTicks(tickLen - shift))) {
|
|
|
|
qDebug("cannot make gap in staff %d at tick %d", dstStaffIdx, dstTick + shift);
|
|
|
|
done = true; // break main loop, cannot make gap
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
makeGap = false; // create gap only once per staff
|
2013-06-20 20:13:46 +02:00
|
|
|
}
|
2012-08-09 12:12:43 +02:00
|
|
|
else if (tag == "Tuplet") {
|
|
|
|
Tuplet* tuplet = new Tuplet(this);
|
2013-01-21 20:21:41 +01:00
|
|
|
tuplet->setTrack(e.track());
|
2013-01-11 18:10:18 +01:00
|
|
|
tuplet->read(e);
|
2013-01-21 20:21:41 +01:00
|
|
|
int tick = e.tick() - tickStart + dstTick;
|
2012-08-09 12:12:43 +02:00
|
|
|
Measure* measure = tick2measure(tick);
|
|
|
|
tuplet->setParent(measure);
|
|
|
|
tuplet->setTick(tick);
|
2013-01-21 20:21:41 +01:00
|
|
|
e.addTuplet(tuplet);
|
2012-08-09 12:12:43 +02:00
|
|
|
}
|
|
|
|
else if (tag == "Chord" || tag == "Rest" || tag == "RepeatMeasure") {
|
2013-01-18 10:55:52 +01:00
|
|
|
ChordRest* cr = static_cast<ChordRest*>(Element::name2Element(tag, this));
|
2013-01-21 20:21:41 +01:00
|
|
|
cr->setTrack(e.track());
|
2013-01-11 18:10:18 +01:00
|
|
|
cr->read(e);
|
2012-08-09 12:12:43 +02:00
|
|
|
cr->setSelected(false);
|
|
|
|
int voice = cr->voice();
|
|
|
|
int track = dstStaffIdx * VOICES + voice;
|
|
|
|
cr->setTrack(track);
|
2013-01-21 20:21:41 +01:00
|
|
|
int tick = e.tick() - tickStart + dstTick;
|
2013-06-19 16:25:29 +02:00
|
|
|
if (cr->isGrace())
|
|
|
|
graceNotes.push_back(static_cast<Chord*>(cr));
|
|
|
|
else {
|
|
|
|
e.setTick(e.tick() + cr->actualTicks());
|
|
|
|
if (cr->type() == Element::CHORD) {
|
|
|
|
Chord* chord = static_cast<Chord*>(cr);
|
|
|
|
for (int i = 0; i < graceNotes.size(); ++i) {
|
|
|
|
Chord* gc = graceNotes[i];
|
|
|
|
gc->setGraceIndex(i);
|
|
|
|
chord->add(gc);
|
|
|
|
}
|
|
|
|
graceNotes.clear();
|
|
|
|
}
|
|
|
|
pasteChordRest(cr, tick);
|
|
|
|
}
|
2012-08-09 12:12:43 +02:00
|
|
|
}
|
|
|
|
else if (tag == "HairPin"
|
|
|
|
|| tag == "Pedal"
|
|
|
|
|| tag == "Ottava"
|
|
|
|
|| tag == "Trill"
|
|
|
|
|| tag == "TextLine"
|
2013-06-10 11:03:34 +02:00
|
|
|
|| tag == "Slur"
|
2012-08-09 12:12:43 +02:00
|
|
|
|| tag == "Volta") {
|
2013-01-18 10:55:52 +01:00
|
|
|
Spanner* sp = static_cast<Spanner*>(Element::name2Element(tag, this));
|
2013-06-20 17:23:24 +02:00
|
|
|
sp->setAnchor(Spanner::ANCHOR_SEGMENT);
|
2013-10-14 11:56:54 +02:00
|
|
|
sp->read(e);
|
2013-07-29 18:06:11 +02:00
|
|
|
sp->setTrack(dstStaffIdx * VOICES);
|
2013-10-11 10:45:53 +02:00
|
|
|
sp->setTrack2(dstStaffIdx * VOICES);
|
2013-06-10 11:03:34 +02:00
|
|
|
sp->setTick(e.tick() - tickStart + dstTick);
|
2013-06-20 17:23:24 +02:00
|
|
|
addSpanner(sp);
|
2012-08-09 12:12:43 +02:00
|
|
|
}
|
|
|
|
else if (tag == "endSpanner") {
|
2013-01-11 18:10:18 +01:00
|
|
|
int id = e.intAttribute("id");
|
2013-06-20 17:23:24 +02:00
|
|
|
Spanner* spanner = findSpanner(id);
|
2013-01-17 12:56:14 +01:00
|
|
|
if (spanner) {
|
2013-06-20 17:23:24 +02:00
|
|
|
// e.spanner().removeOne(spanner);
|
2013-06-10 11:03:34 +02:00
|
|
|
spanner->setTick2(e.tick() - tickStart + dstTick);
|
2013-06-20 18:48:28 +02:00
|
|
|
removeSpanner(spanner);
|
2013-01-17 12:56:14 +01:00
|
|
|
undoAddElement(spanner);
|
|
|
|
if (spanner->type() == Element::OTTAVA) {
|
|
|
|
Ottava* o = static_cast<Ottava*>(spanner);
|
2013-07-16 09:03:47 +02:00
|
|
|
o->staff()->updateOttava(o);
|
2012-08-09 12:12:43 +02:00
|
|
|
}
|
2013-01-17 12:56:14 +01:00
|
|
|
else if (spanner->type() == Element::HAIRPIN) {
|
|
|
|
Hairpin* hp = static_cast<Hairpin*>(spanner);
|
2012-08-09 12:12:43 +02:00
|
|
|
updateHairpin(hp);
|
|
|
|
}
|
|
|
|
}
|
2013-01-17 12:56:14 +01:00
|
|
|
e.readNext();
|
2012-08-09 12:12:43 +02:00
|
|
|
}
|
2013-10-21 15:55:56 +02:00
|
|
|
/* unused: Lyrics are now part of <Chord>
|
|
|
|
* and parenting lyrics to segment is wrong anyway!
|
2012-08-09 12:12:43 +02:00
|
|
|
else if (tag == "Lyrics") {
|
|
|
|
Lyrics* lyrics = new Lyrics(this);
|
2013-01-21 20:21:41 +01:00
|
|
|
lyrics->setTrack(e.track());
|
2013-01-11 18:10:18 +01:00
|
|
|
lyrics->read(e);
|
2012-08-09 12:12:43 +02:00
|
|
|
lyrics->setTrack(dstStaffIdx * VOICES);
|
2013-01-21 20:21:41 +01:00
|
|
|
int tick = e.tick() - tickStart + dstTick;
|
2012-08-09 12:12:43 +02:00
|
|
|
Segment* segment = tick2segment(tick);
|
|
|
|
if (segment) {
|
|
|
|
lyrics->setParent(segment);
|
|
|
|
undoAddElement(lyrics);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delete lyrics;
|
|
|
|
qDebug("no segment found for lyrics");
|
|
|
|
}
|
|
|
|
}
|
2013-10-21 15:55:56 +02:00
|
|
|
*/
|
2012-08-09 12:12:43 +02:00
|
|
|
else if (tag == "Harmony") {
|
|
|
|
Harmony* harmony = new Harmony(this);
|
2013-01-21 20:21:41 +01:00
|
|
|
harmony->setTrack(e.track());
|
2013-01-11 18:10:18 +01:00
|
|
|
harmony->read(e);
|
2012-08-09 12:12:43 +02:00
|
|
|
harmony->setTrack(dstStaffIdx * VOICES);
|
2013-06-18 19:11:27 +02:00
|
|
|
// transpose
|
2012-08-09 12:12:43 +02:00
|
|
|
Part* partDest = staff(dstStaffIdx)->part();
|
2013-06-18 19:11:27 +02:00
|
|
|
Interval interval = partDest->instr()->transpose();
|
|
|
|
if (!styleB(ST_concertPitch) && !interval.isZero()) {
|
|
|
|
interval.flip();
|
2012-08-09 12:12:43 +02:00
|
|
|
int rootTpc = transposeTpc(harmony->rootTpc(), interval, false);
|
|
|
|
int baseTpc = transposeTpc(harmony->baseTpc(), interval, false);
|
|
|
|
undoTransposeHarmony(harmony, rootTpc, baseTpc);
|
|
|
|
}
|
|
|
|
|
2013-01-21 20:21:41 +01:00
|
|
|
int tick = e.tick() - tickStart + dstTick;
|
2012-08-09 12:12:43 +02:00
|
|
|
Measure* m = tick2measure(tick);
|
|
|
|
Segment* seg = m->undoGetSegment(Segment::SegChordRest, tick);
|
|
|
|
harmony->setParent(seg);
|
|
|
|
undoAddElement(harmony);
|
|
|
|
}
|
|
|
|
else if (tag == "Dynamic"
|
|
|
|
|| tag == "Symbol"
|
|
|
|
|| tag == "FretDiagram"
|
|
|
|
|| tag == "Marker"
|
|
|
|
|| tag == "Jump"
|
|
|
|
|| tag == "Image"
|
|
|
|
|| tag == "Text"
|
|
|
|
|| tag == "StaffText"
|
|
|
|
|| tag == "TempoText"
|
2013-02-28 23:29:04 +01:00
|
|
|
|| tag == "FiguredBass"
|
2012-08-09 12:12:43 +02:00
|
|
|
) {
|
2013-01-18 10:55:52 +01:00
|
|
|
Element* el = Element::name2Element(tag, this);
|
2013-02-28 23:29:04 +01:00
|
|
|
el->setTrack(dstStaffIdx * VOICES); // a valid track might be necessary for el->read() to work
|
2012-08-09 12:12:43 +02:00
|
|
|
|
2013-01-21 20:21:41 +01:00
|
|
|
int tick = e.tick() - tickStart + dstTick;
|
2012-08-09 12:12:43 +02:00
|
|
|
Measure* m = tick2measure(tick);
|
|
|
|
Segment* seg = m->undoGetSegment(Segment::SegChordRest, tick);
|
2013-01-11 18:10:18 +01:00
|
|
|
el->setParent(seg);
|
|
|
|
el->read(e);
|
2012-08-09 12:12:43 +02:00
|
|
|
|
2013-02-28 23:29:04 +01:00
|
|
|
// be sure to paste the element in the destination track;
|
|
|
|
// setting track needs to be repeated, as it might have been overwritten by el->read()
|
|
|
|
el->setTrack(dstStaffIdx * VOICES);
|
2013-01-11 18:10:18 +01:00
|
|
|
undoAddElement(el);
|
2012-08-09 12:12:43 +02:00
|
|
|
}
|
|
|
|
else if (tag == "Clef") {
|
|
|
|
Clef* clef = new Clef(this);
|
2013-01-11 18:10:18 +01:00
|
|
|
clef->read(e);
|
2012-08-09 12:12:43 +02:00
|
|
|
clef->setTrack(dstStaffIdx * VOICES);
|
2013-01-21 20:21:41 +01:00
|
|
|
int tick = e.tick() - tickStart + dstTick;
|
2012-08-09 12:12:43 +02:00
|
|
|
Measure* m = tick2measure(tick);
|
|
|
|
if (m->tick() && m->tick() == tick)
|
|
|
|
m = m->prevMeasure();
|
|
|
|
Segment* segment = m->undoGetSegment(Segment::SegClef, tick);
|
|
|
|
clef->setParent(segment);
|
|
|
|
undoAddElement(clef);
|
|
|
|
}
|
|
|
|
else if (tag == "Breath") {
|
|
|
|
Breath* breath = new Breath(this);
|
2013-01-11 18:10:18 +01:00
|
|
|
breath->read(e);
|
2012-08-09 12:12:43 +02:00
|
|
|
breath->setTrack(dstStaffIdx * VOICES);
|
2013-01-21 20:21:41 +01:00
|
|
|
int tick = e.tick() - tickStart + dstTick;
|
2012-08-09 12:12:43 +02:00
|
|
|
Measure* m = tick2measure(tick);
|
|
|
|
Segment* segment = m->undoGetSegment(Segment::SegBreath, tick);
|
|
|
|
breath->setParent(segment);
|
|
|
|
undoAddElement(breath);
|
|
|
|
}
|
2013-01-22 11:38:09 +01:00
|
|
|
else if (tag == "Beam") {
|
|
|
|
Beam* beam = new Beam(this);
|
|
|
|
beam->setTrack(e.track());
|
|
|
|
beam->read(e);
|
|
|
|
beam->setParent(0);
|
|
|
|
e.addBeam(beam);
|
|
|
|
}
|
2012-08-09 12:12:43 +02:00
|
|
|
else if (tag == "BarLine") {
|
2013-01-17 12:56:14 +01:00
|
|
|
e.skipCurrentElement(); // ignore bar line
|
2012-08-09 12:12:43 +02:00
|
|
|
}
|
2013-01-22 11:42:52 +01:00
|
|
|
else {
|
|
|
|
qDebug("PasteStaff: element %s not handled", tag.toUtf8().data());
|
|
|
|
e.skipCurrentElement(); // ignore
|
|
|
|
}
|
2012-08-09 12:12:43 +02:00
|
|
|
}
|
2013-01-07 12:36:06 +01:00
|
|
|
|
2013-01-21 20:21:41 +01:00
|
|
|
foreach (Tuplet* tuplet, e.tuplets()) {
|
2012-08-09 12:12:43 +02:00
|
|
|
if (tuplet->elements().isEmpty()) {
|
|
|
|
// this should not happen and is a sign of input file corruption
|
|
|
|
qDebug("Measure:pasteStaff(): empty tuplet");
|
|
|
|
delete tuplet;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Measure* measure = tick2measure(tuplet->tick());
|
|
|
|
tuplet->setParent(measure);
|
|
|
|
tuplet->sortElements();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pasted) { //select only if we pasted something
|
|
|
|
Segment* s1 = tick2segment(dstTick);
|
|
|
|
Segment* s2 = tick2segment(dstTick + tickLen);
|
|
|
|
int endStaff = dstStaffStart + staves;
|
|
|
|
if (endStaff > nstaves())
|
|
|
|
endStaff = nstaves();
|
|
|
|
_selection.setRange(s1, s2, dstStaffStart, endStaff);
|
|
|
|
_selection.updateSelectedElements();
|
|
|
|
foreach(MuseScoreView* v, viewer)
|
|
|
|
v->adjustCanvasPosition(s1, false);
|
|
|
|
if (selection().state() != SEL_RANGE)
|
|
|
|
_selection.setState(SEL_RANGE);
|
|
|
|
}
|
|
|
|
}
|
2013-06-10 11:03:34 +02:00
|
|
|
foreach (Score* s, scoreList()) // for all parts
|
|
|
|
s->connectTies();
|
2013-07-24 10:20:15 +02:00
|
|
|
|
|
|
|
// when pasting between different staff types (pitched->tablature)
|
|
|
|
// fret/line has to be calculated:
|
|
|
|
updateNotes();
|
2012-08-09 12:12:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// pasteChordRest
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Score::pasteChordRest(ChordRest* cr, int tick)
|
|
|
|
{
|
|
|
|
// qDebug("pasteChordRest %s at %d", cr->name(), tick);
|
2012-09-13 18:01:34 +02:00
|
|
|
if (cr->type() == Element::CHORD) {
|
2012-08-09 12:12:43 +02:00
|
|
|
// set note track
|
|
|
|
// check if staffMove moves a note to a
|
|
|
|
// nonexistant staff
|
|
|
|
//
|
|
|
|
int track = cr->track();
|
|
|
|
Chord* c = static_cast<Chord*>(cr);
|
|
|
|
Part* part = cr->staff()->part();
|
|
|
|
int nn = (track / VOICES) + c->staffMove();
|
|
|
|
if (nn < 0 || nn >= nstaves())
|
|
|
|
c->setStaffMove(0);
|
|
|
|
if (!styleB(ST_concertPitch) && part->instr()->transpose().chromatic) {
|
|
|
|
Interval interval = part->instr()->transpose();
|
|
|
|
if (!interval.isZero()) {
|
|
|
|
interval.flip();
|
|
|
|
foreach(Note* n, c->notes()) {
|
|
|
|
int npitch;
|
|
|
|
int ntpc;
|
|
|
|
transposeInterval(n->pitch(), n->tpc(), &npitch, &ntpc, interval, true);
|
|
|
|
n->setPitch(npitch, ntpc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Measure* measure = tick2measure(tick);
|
2013-06-19 16:25:29 +02:00
|
|
|
if (!measure)
|
2012-08-09 12:12:43 +02:00
|
|
|
return;
|
|
|
|
|
2013-06-19 16:25:29 +02:00
|
|
|
int measureEnd = measure->endTick();
|
|
|
|
bool isGrace = (cr->type() == Element::CHORD) && (((Chord*)cr)->noteType() != NOTE_NORMAL);
|
2012-08-09 12:12:43 +02:00
|
|
|
if (!isGrace && (tick + cr->actualTicks() > measureEnd)) {
|
2012-09-13 18:01:34 +02:00
|
|
|
if (cr->type() == Element::CHORD) {
|
2012-08-09 12:12:43 +02:00
|
|
|
// split Chord
|
|
|
|
Chord* c = static_cast<Chord*>(cr);
|
|
|
|
int rest = c->actualTicks();
|
|
|
|
int len = measureEnd - tick;
|
|
|
|
rest -= len;
|
|
|
|
TDuration d;
|
|
|
|
d.setVal(len);
|
|
|
|
c->setDurationType(d);
|
|
|
|
c->setDuration(d.fraction());
|
|
|
|
undoAddCR(c, measure, tick);
|
|
|
|
while (rest) {
|
|
|
|
tick += c->actualTicks();
|
|
|
|
measure = tick2measure(tick);
|
|
|
|
if (measure->tick() != tick) { // last measure
|
|
|
|
qDebug("==last measure %d != %d", measure->tick(), tick);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Chord* c2 = static_cast<Chord*>(c->clone());
|
|
|
|
len = measure->ticks() > rest ? rest : measure->ticks();
|
|
|
|
TDuration d;
|
|
|
|
d.setVal(len);
|
|
|
|
c2->setDurationType(d);
|
|
|
|
rest -= len;
|
|
|
|
undoAddCR(c2, measure, tick);
|
|
|
|
|
|
|
|
QList<Note*> nl1 = c->notes();
|
|
|
|
QList<Note*> nl2 = c2->notes();
|
|
|
|
|
|
|
|
for (int i = 0; i < nl1.size(); ++i) {
|
|
|
|
Tie* tie = new Tie(this);
|
|
|
|
tie->setStartNote(nl1[i]);
|
|
|
|
tie->setEndNote(nl2[i]);
|
|
|
|
tie->setTrack(c->track());
|
|
|
|
Tie* tie2 = nl1[i]->tieFor();
|
|
|
|
if (tie2) {
|
|
|
|
nl2[i]->setTieFor(nl1[i]->tieFor());
|
|
|
|
tie2->setStartNote(nl2[i]);
|
|
|
|
}
|
|
|
|
nl1[i]->setTieFor(tie);
|
|
|
|
nl2[i]->setTieBack(tie);
|
|
|
|
}
|
|
|
|
c = c2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// split Rest
|
|
|
|
Rest* r = static_cast<Rest*>(cr);
|
|
|
|
Fraction rest = r->duration();
|
|
|
|
|
|
|
|
while (!rest.isZero()) {
|
|
|
|
Rest* r2 = static_cast<Rest*>(r->clone());
|
|
|
|
measure = tick2measure(tick);
|
|
|
|
Fraction mlen = Fraction::fromTicks(measure->tick() + measure->ticks() - tick);
|
|
|
|
Fraction len = rest > mlen ? mlen : rest;
|
|
|
|
r2->setDuration(len);
|
|
|
|
r2->setDurationType(TDuration(len));
|
|
|
|
undoAddCR(r2, measure, tick);
|
|
|
|
rest -= len;
|
|
|
|
tick += r2->actualTicks();
|
|
|
|
}
|
|
|
|
delete r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
undoAddCR(cr, measure, tick);
|
|
|
|
}
|
|
|
|
}
|
2013-01-23 14:14:09 +01:00
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
|
2013-10-21 15:55:56 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// pasteSymbols
|
|
|
|
//
|
|
|
|
// pastes a list of symbols into cr and following ChordRest's
|
|
|
|
//
|
|
|
|
// (Note: info about delta ticks is currently ignored)
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Score::pasteSymbols(XmlReader& e, ChordRest* dst)
|
|
|
|
{
|
|
|
|
Segment* currSegm = dst->segment();
|
2013-11-11 11:14:37 +01:00
|
|
|
int destTick = 0; // the tick and track to place the pasted element at
|
2013-10-21 15:55:56 +02:00
|
|
|
int destTrack = 0;
|
|
|
|
bool done = false;
|
2014-02-15 15:21:39 +01:00
|
|
|
int segDelta = 0;
|
2013-10-21 15:55:56 +02:00
|
|
|
Segment* startSegm= currSegm;
|
2013-11-11 11:14:37 +01:00
|
|
|
int startTick = dst->tick(); // the initial tick and track where to start pasting
|
2013-10-21 15:55:56 +02:00
|
|
|
int startTrack = dst->track();
|
|
|
|
int maxTrack = ntracks();
|
|
|
|
|
|
|
|
while (e.readNextStartElement()) {
|
|
|
|
if (done)
|
|
|
|
break;
|
|
|
|
if (e.name() != "SymbolList") {
|
|
|
|
e.unknown();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
QString version = e.attribute("version", "NONE");
|
|
|
|
if(version != MSC_VERSION)
|
|
|
|
break;
|
|
|
|
|
|
|
|
while (e.readNextStartElement()) {
|
|
|
|
if (done)
|
|
|
|
break;
|
|
|
|
const QStringRef& tag(e.name());
|
|
|
|
|
|
|
|
if (tag == "trackOffset") {
|
|
|
|
destTrack = startTrack + e.readInt();
|
|
|
|
currSegm = startSegm;
|
|
|
|
}
|
2013-11-11 11:14:37 +01:00
|
|
|
else if (tag == "tickOffset")
|
|
|
|
destTick = startTick + e.readInt();
|
|
|
|
else if (tag == "segDelta")
|
|
|
|
segDelta = e.readInt();
|
2013-10-21 15:55:56 +02:00
|
|
|
else {
|
2013-11-11 11:14:37 +01:00
|
|
|
|
|
|
|
if (tag == "Harmony") {
|
|
|
|
//
|
|
|
|
// Harmony elements (= chord symbols) are positioned respecting
|
|
|
|
// the original tickOffset: advance to destTick (or near)
|
|
|
|
//
|
|
|
|
Segment* harmSegm;
|
2013-12-26 23:29:50 +01:00
|
|
|
for (harmSegm = startSegm; harmSegm && (harmSegm->tick() < destTick);
|
|
|
|
harmSegm = harmSegm->nextCR())
|
2013-11-11 11:14:37 +01:00
|
|
|
;
|
|
|
|
// if destTick overshot, no dest. segment: create one
|
2013-12-26 23:29:50 +01:00
|
|
|
if (!harmSegm || harmSegm->tick() > destTick) {
|
2013-11-11 11:14:37 +01:00
|
|
|
Measure* meas = tick2measure(destTick);
|
|
|
|
harmSegm = meas->getSegment(Segment::SegChordRest, destTick);
|
2013-10-21 15:55:56 +02:00
|
|
|
}
|
|
|
|
Harmony* el = new Harmony(this);
|
|
|
|
el->setTrack(trackZeroVoice(destTrack));
|
|
|
|
el->read(e);
|
|
|
|
el->setTrack(trackZeroVoice(destTrack));
|
|
|
|
// transpose
|
|
|
|
Part* partDest = staff(track2staff(destTrack))->part();
|
|
|
|
Interval interval = partDest->instr()->transpose();
|
|
|
|
if (!styleB(ST_concertPitch) && !interval.isZero()) {
|
|
|
|
interval.flip();
|
|
|
|
int rootTpc = transposeTpc(el->rootTpc(), interval, false);
|
|
|
|
int baseTpc = transposeTpc(el->baseTpc(), interval, false);
|
|
|
|
undoTransposeHarmony(el, rootTpc, baseTpc);
|
|
|
|
}
|
2013-11-11 11:14:37 +01:00
|
|
|
el->setParent(harmSegm);
|
2013-10-21 15:55:56 +02:00
|
|
|
undoAddElement(el);
|
|
|
|
}
|
2013-11-11 11:14:37 +01:00
|
|
|
else {
|
|
|
|
//
|
|
|
|
// All other elements are positioned respecting the distance in chords
|
|
|
|
//
|
|
|
|
for ( ; currSegm && segDelta > 0; segDelta--)
|
2013-10-21 15:55:56 +02:00
|
|
|
currSegm = currSegm->nextCR(destTrack);
|
2013-11-11 11:14:37 +01:00
|
|
|
// check the intended dest. track and segment exist
|
|
|
|
if (destTrack >= maxTrack || currSegm == nullptr) {
|
|
|
|
qDebug("PasteSymbols: no track or segment for %s", tag.toUtf8().data());
|
|
|
|
e.skipCurrentElement(); // ignore
|
2013-10-21 15:55:56 +02:00
|
|
|
continue;
|
|
|
|
}
|
2013-11-11 11:14:37 +01:00
|
|
|
// check there is a segment element in the required track
|
|
|
|
if (currSegm->element(destTrack) == nullptr) {
|
|
|
|
qDebug("PasteSymbols: no track element for %s", tag.toUtf8().data());
|
2013-10-21 15:55:56 +02:00
|
|
|
e.skipCurrentElement();
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-11 11:14:37 +01:00
|
|
|
ChordRest* cr = static_cast<ChordRest*>(currSegm->element(destTrack));
|
|
|
|
|
|
|
|
if (tag == "Articulation") {
|
|
|
|
Articulation* el = new Articulation(this);
|
|
|
|
el->read(e);
|
|
|
|
el->setTrack(destTrack);
|
|
|
|
el->setParent(cr);
|
|
|
|
undoAddElement(el);
|
|
|
|
}
|
|
|
|
else if (tag == "FiguredBass") {
|
|
|
|
// FiguredBass always belongs to first staff voice
|
|
|
|
destTrack = trackZeroVoice(destTrack);
|
|
|
|
int ticks;
|
|
|
|
FiguredBass* el = new FiguredBass(this);
|
|
|
|
el->setTrack(destTrack);
|
|
|
|
el->read(e);
|
|
|
|
el->setTrack(destTrack);
|
|
|
|
// if f.b. is off-note, we have to locate a place before currSegm
|
|
|
|
// where an on-note f.b. element could (potentially) be
|
|
|
|
// (while having an off-note f.b. without an on-note one before it
|
|
|
|
// is un-idiomatic, possible mismatch in rhythmic patterns between
|
|
|
|
// copy source and paste destination does not allow to be too picky)
|
|
|
|
if (!el->onNote()) {
|
|
|
|
FiguredBass* onNoteFB = nullptr;
|
|
|
|
Segment* prevSegm = currSegm;
|
|
|
|
bool done = false;
|
|
|
|
while (prevSegm) {
|
|
|
|
if (done)
|
|
|
|
break;
|
|
|
|
prevSegm = prevSegm->prev1(Segment::SegChordRest);
|
|
|
|
// if there is a ChordRest in the dest. track
|
|
|
|
// this segment is a (potential) f.b. location
|
|
|
|
if (prevSegm->element(destTrack) != nullptr) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
// in any case, look for a f.b. in annotations:
|
|
|
|
// if there is a f.b. element in the right track,
|
|
|
|
// this is an (actual) f.b. location
|
|
|
|
foreach (Element* a, prevSegm->annotations()) {
|
|
|
|
if (a->type() == Element::FIGURED_BASS && a->track() == destTrack) {
|
|
|
|
onNoteFB = static_cast<FiguredBass*>(a);
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!prevSegm) {
|
|
|
|
qDebug("PasteSymbols: can't place off-note FiguredBass");
|
|
|
|
delete el;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// by default, split on-note duration in half: half on-note and half off-note
|
|
|
|
int totTicks = currSegm->tick() - prevSegm->tick();
|
|
|
|
int destTick = prevSegm->tick() + totTicks / 2;
|
|
|
|
ticks = totTicks / 2;
|
|
|
|
if (onNoteFB)
|
|
|
|
onNoteFB->setTicks(totTicks / 2);
|
|
|
|
// look for a segment at this tick; if none, create one
|
|
|
|
Segment * nextSegm = prevSegm;
|
|
|
|
while (nextSegm && nextSegm->tick() < destTick)
|
|
|
|
nextSegm = nextSegm->next1(Segment::SegChordRest);
|
|
|
|
if (!nextSegm || nextSegm->tick() > destTick) { // no ChordRest segm at this tick
|
|
|
|
nextSegm = new Segment(prevSegm->measure(), Segment::SegChordRest, destTick);
|
|
|
|
if (!nextSegm) {
|
|
|
|
qDebug("PasteSymbols: can't find or create destination segment for FiguredBass");
|
|
|
|
delete el;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
undoAddElement(nextSegm);
|
|
|
|
}
|
|
|
|
currSegm = nextSegm;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
// by default, assign to FiguredBass element the duration of the chord it refers to
|
|
|
|
ticks = static_cast<ChordRest*>(currSegm->element(destTrack))->durationTicks();
|
|
|
|
// in both cases, look for an existing f.b. element in segment and remove it, if found
|
|
|
|
FiguredBass* oldFB = nullptr;
|
|
|
|
foreach (Element* a, currSegm->annotations()) {
|
|
|
|
if (a->type() == Element::FIGURED_BASS && a->track() == destTrack) {
|
|
|
|
oldFB = static_cast<FiguredBass*>(a);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (oldFB)
|
|
|
|
undoRemoveElement(oldFB);
|
|
|
|
el->setParent(currSegm);
|
|
|
|
el->setTicks(ticks);
|
|
|
|
undoAddElement(el);
|
|
|
|
}
|
|
|
|
else if (tag == "Lyrics") {
|
|
|
|
// with lyrics, skip rests
|
|
|
|
while (cr->type() != Element::CHORD && currSegm) {
|
|
|
|
currSegm = currSegm->nextCR(destTrack);
|
|
|
|
if (currSegm)
|
|
|
|
cr = static_cast<ChordRest*>(currSegm->element(destTrack));
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (currSegm == nullptr) {
|
|
|
|
qDebug("PasteSymbols: no segment for Lyrics");
|
|
|
|
e.skipCurrentElement();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (cr->type() != Element::CHORD) {
|
|
|
|
qDebug("PasteSymbols: can't paste Lyrics to rest");
|
|
|
|
e.skipCurrentElement();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Lyrics* el = new Lyrics(this);
|
|
|
|
el->setTrack(destTrack);
|
|
|
|
el->read(e);
|
|
|
|
el->setTrack(destTrack);
|
|
|
|
el->setParent(cr);
|
|
|
|
undoAddElement(el);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
qDebug("PasteSymbols: element %s not handled", tag.toUtf8().data());
|
|
|
|
e.skipCurrentElement(); // ignore
|
|
|
|
}
|
|
|
|
} // if !Harmony
|
|
|
|
} // if element
|
|
|
|
} // outer while readNextstartElement()
|
|
|
|
} // inner while readNextstartElement()
|
|
|
|
} // pasteSymbolList()
|
2013-10-21 15:55:56 +02:00
|
|
|
|
|
|
|
}
|