2012-05-26 14:26:10 +02:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
|
|
|
// Copyright (C) 2002-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"
|
|
|
|
#include "measure.h"
|
|
|
|
#include "segment.h"
|
|
|
|
#include "chordrest.h"
|
|
|
|
#include "range.h"
|
2016-11-28 17:25:26 +01:00
|
|
|
#include "tuplet.h"
|
2017-03-14 17:00:38 +01:00
|
|
|
#include "spanner.h"
|
2018-07-14 17:04:07 +02:00
|
|
|
#include "undo.h"
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
namespace Ms {
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// cmdSplitMeasure
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void Score::cmdSplitMeasure(ChordRest* cr)
|
2016-08-06 10:33:32 +02:00
|
|
|
{
|
|
|
|
startCmd();
|
2016-10-25 17:30:55 +02:00
|
|
|
splitMeasure(cr->segment());
|
2016-08-06 10:33:32 +02:00
|
|
|
endCmd();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// splitMeasure
|
2016-11-28 17:25:26 +01:00
|
|
|
// return true on success
|
2016-08-06 10:33:32 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2016-10-25 17:30:55 +02:00
|
|
|
void Score::splitMeasure(Segment* segment)
|
2012-05-26 14:26:10 +02:00
|
|
|
{
|
2016-11-28 17:25:26 +01:00
|
|
|
if (segment->rtick() == 0) {
|
|
|
|
MScore::setError(CANNOT_SPLIT_MEASURE_FIRST_BEAT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (segment->splitsTuplet()) {
|
|
|
|
MScore::setError(CANNOT_SPLIT_MEASURE_TUPLET);
|
|
|
|
return;
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
Measure* measure = segment->measure();
|
|
|
|
|
|
|
|
ScoreRange range;
|
2014-05-14 19:19:29 +02:00
|
|
|
range.read(measure->first(), measure->last());
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2017-03-14 17:00:38 +01:00
|
|
|
int stick = measure->tick();
|
|
|
|
int etick = measure->endTick();
|
|
|
|
|
2018-07-14 17:04:07 +02:00
|
|
|
std::list<std::tuple<Spanner*, int, int>> sl;
|
2017-03-14 17:00:38 +01:00
|
|
|
for (auto i : spanner()) {
|
|
|
|
Spanner* s = i.second;
|
2018-07-14 17:04:07 +02:00
|
|
|
Element* start = s->startElement();
|
|
|
|
Element* end = s->endElement();
|
2017-03-14 17:00:38 +01:00
|
|
|
if (s->tick() >= stick && s->tick() < etick)
|
2018-07-14 17:04:07 +02:00
|
|
|
start = nullptr;
|
2017-03-14 17:00:38 +01:00
|
|
|
if (s->tick2() >= stick && s->tick2() < etick)
|
2018-07-14 17:04:07 +02:00
|
|
|
end = nullptr;
|
|
|
|
if (start != s->startElement() || end != s->endElement())
|
|
|
|
undo(new ChangeStartEndSpanner(s, start, end));
|
|
|
|
if (s->tick() < stick && s->tick2() > stick)
|
|
|
|
sl.push_back(make_tuple(s, s->tick(), s->ticks()));
|
2017-03-14 17:00:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MeasureBase* nm = measure->next();
|
2016-04-11 15:28:32 +02:00
|
|
|
undoRemoveMeasures(measure, measure);
|
2016-10-25 17:30:55 +02:00
|
|
|
undoInsertTime(measure->tick(), -measure->ticks());
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
// create empty measures:
|
2017-03-14 17:00:38 +01:00
|
|
|
insertMeasure(ElementType::MEASURE, nm, true);
|
|
|
|
Measure* m2 = toMeasure(nm ? nm->prev() : lastMeasure());
|
|
|
|
insertMeasure(ElementType::MEASURE, m2, true);
|
|
|
|
Measure* m1 = toMeasure(m2->prev());
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
int tick = segment->tick();
|
|
|
|
m1->setTick(measure->tick());
|
|
|
|
m2->setTick(tick);
|
|
|
|
int ticks1 = segment->tick() - measure->tick();
|
|
|
|
int ticks2 = measure->ticks() - ticks1;
|
|
|
|
m1->setTimesig(measure->timesig());
|
|
|
|
m2->setTimesig(measure->timesig());
|
2017-03-24 17:31:25 +01:00
|
|
|
m1->adjustToLen(Fraction::fromTicks(ticks1), false);
|
|
|
|
m2->adjustToLen(Fraction::fromTicks(ticks2), false);
|
2014-05-14 19:19:29 +02:00
|
|
|
range.write(this, m1->tick());
|
2018-07-14 17:04:07 +02:00
|
|
|
|
|
|
|
for (auto i : sl) {
|
|
|
|
Spanner* s = std::get<0>(i);
|
|
|
|
int tick = std::get<1>(i);
|
|
|
|
int ticks = std::get<2>(i);
|
|
|
|
if (s->tick() != tick)
|
|
|
|
s->undoChangeProperty(Pid::SPANNER_TICK, tick);
|
|
|
|
if (s->ticks() != ticks)
|
|
|
|
s->undoChangeProperty(Pid::SPANNER_TICKS, ticks);
|
|
|
|
}
|
2012-05-26 14:26:10 +02:00
|
|
|
}
|
2013-05-13 18:49:17 +02:00
|
|
|
}
|
|
|
|
|