Ctrl+drop time signature now creates a 'local' time signature

This commit is contained in:
Werner Schweer 2012-06-28 09:28:13 +02:00
parent 9767fb29df
commit e3d76d3aaa
7 changed files with 41 additions and 52 deletions

View file

@ -482,7 +482,7 @@ void Score::rewriteMeasures(Measure* fm, const Fraction& ns)
// to gui command (drop timesig on measure or timesig)
//---------------------------------------------------------
void Score::cmdAddTimeSig(Measure* fm, int staffIdx, TimeSig* ts)
void Score::cmdAddTimeSig(Measure* fm, int staffIdx, TimeSig* ts, bool local)
{
Fraction ns = ts->sig();
int tick = fm->tick();
@ -513,21 +513,19 @@ void Score::cmdAddTimeSig(Measure* fm, int staffIdx, TimeSig* ts)
return;
}
}
#if 0
else {
//
// check for local timesig (only staff value changes)
// or redundant time signature
//
if (lsig == ts->sig()) {
ts->setParent(seg);
ts->setTrack(track);
undoAddElement(ts);
//TODO timesigStretchChanged(ts, fm, staffIdx);
return;
}
if (local) {
printf("insert local timesig\n");
ts->setParent(seg);
ts->setTrack(track);
ts->setActualSig(ts->sig());
ts->setSig(lsig);
undoAddElement(ts);
timesigStretchChanged(ts, fm, staffIdx);
return;
}
#endif
Measure* nfm = fm;
if (ots && ots->sig() == ts->sig() && ots->stretch() == ts->stretch()) {
//
@ -572,7 +570,7 @@ void Score::cmdAddTimeSig(Measure* fm, int staffIdx, TimeSig* ts)
}
else {
undo(new ChangeTimesig(nsig, false,
ts->sig(), nsig->stretch(), ts->subtype(),
ts->actualSig(), ts->sig(), ts->subtype(),
QString(), QString()));
nsig->setDropTarget(0); // DEBUG
}

View file

@ -1513,7 +1513,8 @@ qDebug("drop staffList");
}
case TIMESIG:
score()->cmdAddTimeSig(this, staffIdx, static_cast<TimeSig*>(e));
score()->cmdAddTimeSig(this, staffIdx, static_cast<TimeSig*>(e),
data.modifiers & Qt::ControlModifier);
return 0;
case LAYOUT_BREAK:

View file

@ -523,7 +523,7 @@ class Score {
void update();
void cmdRemoveTimeSig(TimeSig*);
void cmdAddTimeSig(Measure*, int staffIdx, TimeSig*);
void cmdAddTimeSig(Measure*, int staffIdx, TimeSig*, bool local);
void setUpdateAll(bool v = true) { _updateAll = v; }
void setLayoutAll(bool val);

View file

@ -30,8 +30,8 @@ TimeSig::TimeSig(Score* s)
setFlags(ELEMENT_SELECTABLE | ELEMENT_ON_STAFF);
_showCourtesySig = true;
customText = false;
_stretch.set(1, 1);
setSubtype(TSIG_NORMAL);
_actualSig = _nominal;
}
TimeSig::TimeSig(Score* s, TimeSigType st)
@ -40,8 +40,8 @@ TimeSig::TimeSig(Score* s, TimeSigType st)
setFlags(ELEMENT_SELECTABLE | ELEMENT_ON_STAFF);
_showCourtesySig = true;
customText = false;
_stretch.set(1, 1);
setSubtype(st);
_actualSig = _nominal;
}
TimeSig::TimeSig(Score* s, int z, int n)
@ -50,8 +50,8 @@ TimeSig::TimeSig(Score* s, int z, int n)
setFlags(ELEMENT_SELECTABLE | ELEMENT_ON_STAFF);
_showCourtesySig = true;
customText = false;
_stretch.set(1, 1);
setSig(Fraction(z, n));
_actualSig = _nominal;
setSubtype(TSIG_NORMAL);
}
@ -61,8 +61,8 @@ TimeSig::TimeSig(Score* s, const Fraction& f)
setFlags(ELEMENT_SELECTABLE | ELEMENT_ON_STAFF);
_showCourtesySig = true;
customText = false;
_stretch.set(1, 1);
setSig(f);
_actualSig = _nominal;
setSubtype(TSIG_NORMAL);
}
@ -78,10 +78,12 @@ void TimeSig::setSubtype(TimeSigType st)
case TSIG_FOUR_FOUR:
setSig(Fraction(4, 4));
customText = false;
_actualSig = _nominal;
break;
case TSIG_ALLA_BREVE:
setSig(Fraction(2, 2));
customText = false;
_actualSig = _nominal;
break;
default:
qDebug("illegal TimeSig subtype 0x%x\n", st);
@ -110,7 +112,7 @@ Element* TimeSig::drop(const DropData& data)
// change timesig applies to all staves, can't simply set subtype
// for this one only
// ownership of e is transferred to cmdAddTimeSig
score()->cmdAddTimeSig(measure(), staffIdx(), static_cast<TimeSig*>(e));
score()->cmdAddTimeSig(measure(), staffIdx(), static_cast<TimeSig*>(e), false);
return 0;
}
delete e;
@ -128,18 +130,6 @@ void TimeSig::setText(const QString& a, const QString& b)
customText = !(a.isEmpty() && b.isEmpty());
}
//---------------------------------------------------------
// setActualSig
//---------------------------------------------------------
void TimeSig::setActualSig(const Fraction& actual)
{
_stretch = (_nominal / actual).reduced();
qDebug("setActual %d/%d stretch %d/%d\n",
actual.numerator(), actual.denominator(),
_stretch.numerator(), _stretch.denominator());
}
//---------------------------------------------------------
// write TimeSig
//---------------------------------------------------------
@ -153,9 +143,9 @@ void TimeSig::write(Xml& xml) const
xml.tag("sigN", _nominal.numerator());
xml.tag("sigD", _nominal.denominator());
if (_stretch != Fraction(1,1)) {
xml.tag("stretchN", _stretch.numerator());
xml.tag("stretchD", _stretch.denominator());
if (stretch() != Fraction(1,1)) {
xml.tag("stretchN", stretch().numerator());
xml.tag("stretchD", stretch().denominator());
}
if (customText) {
xml.tag("textN", sz);
@ -175,7 +165,7 @@ void TimeSig::read(const QDomElement& de)
bool old = false;
customText = false;
_stretch.set(1, 1);
Fraction _stretch(1, 1);
for (QDomElement e = de.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
const QString& tag(e.tagName());
@ -244,6 +234,7 @@ void TimeSig::read(const QDomElement& de)
else
setSubtype(TSIG_NORMAL);
}
_actualSig = _nominal / _stretch;
}
//---------------------------------------------------------
@ -372,6 +363,6 @@ void TimeSig::setFrom(const TimeSig* ts)
sz = ts->sz;
sn = ts->sn;
_nominal = ts->_nominal;
_stretch = ts->_stretch;
_actualSig = ts->_actualSig;
customText = ts->customText;
}

View file

@ -39,7 +39,7 @@ class TimeSig : public Element {
QString sz, sn; // calculated from actualSig() if !customText
QPointF pz, pn;
Fraction _nominal;
Fraction _stretch; // _nominal / aktualSig()
Fraction _actualSig;
bool customText; // if false, sz and sn are calculated from actualSig()
public:
@ -64,10 +64,9 @@ class TimeSig : public Element {
void setSig(const Fraction& f) { _nominal = f; }
void setSig(int a, int b) { _nominal.set(a,b); }
Fraction stretch() const { return _stretch; }
void setStretch(const Fraction& f) { _stretch = f; }
Fraction actualSig() const { return _nominal / _stretch; }
void setActualSig(const Fraction& f);
Fraction actualSig() const { return _actualSig; }
void setActualSig(const Fraction& s) { _actualSig = s; }
Fraction stretch() const { return _nominal / _actualSig; }
bool acceptDrop(MuseScoreView*, const QPointF&, Element*) const;
Element* drop(const DropData&);

View file

@ -2691,7 +2691,7 @@ ChangeTimesig::ChangeTimesig(TimeSig * _timesig, bool sc, const Fraction& f1,
timesig = _timesig;
showCourtesy = sc;
actual = f1;
stretch = f2;
nominal = f2;
sz = s1;
sn = s2;
subtype = st;
@ -2706,19 +2706,19 @@ void ChangeTimesig::flip()
timesig->score()->addRefresh(timesig->abbox());
bool sc = timesig->showCourtesySig();
Fraction f1 = timesig->sig();
Fraction f2 = timesig->stretch();
Fraction f2 = timesig->actualSig();
QString s1 = timesig->zText();
QString s2 = timesig->nText();
TimeSigType st = timesig->subtype();
// setSubType() must come first, as it also calls setSig() with its own parameters
timesig->setSubtype(subtype);
timesig->setShowCourtesySig(showCourtesy);
timesig->setSig(actual);
timesig->setStretch(stretch);
timesig->setSig(nominal);
timesig->setActualSig(actual);
timesig->setText(sz, sn);
showCourtesy = sc;
actual = f1;
stretch = f2;
nominal = f2;
sz = s1;
sn = s2;
subtype = st;

View file

@ -1033,7 +1033,7 @@ class ChangeTimesig : public UndoCommand {
TimeSig* timesig;
bool showCourtesy;
Fraction actual;
Fraction stretch;
Fraction nominal;
QString sz;
QString sn;
TimeSigType subtype;
@ -1041,7 +1041,7 @@ class ChangeTimesig : public UndoCommand {
void flip();
public:
ChangeTimesig(TimeSig * _timesig, bool sc, const Fraction&,
ChangeTimesig(TimeSig* _timesig, bool sc, const Fraction&,
const Fraction&, TimeSigType subtype, const QString&, const QString&);
virtual void undo() { flip(); }
virtual void redo() { flip(); }