MuseScore/libmscore/iname.cpp
J. Edward Sanchez f363220a1b Fix #297426: The playback cursor is not repositioned when selecting items other than notes, rests or measures
Improved the functionality of the playhead (a.k.a. the playback cursor) so that whenever the user selects an element, the playhead is automatically repositioned to the element's time position. Previously, this worked only for noteheads and rests, but it now works for note stems, beams, augmentation dots, accidentals, ties, slurs, articulations, time signatures, key signatures, clefs, tempo changes, dynamics, lines, barlines, breaks, spacers, measure numbers, text, and so on.

Special cases handled:

* Barlines. The playhead is moved to the start of the measure to the right of the barline, unless it's the last barline in either the entire score or the system, in which case the playhead is moved to the start of the measure to the left of the barline.

* Brackets always have a time position of zero, so the playhead is moved to the start of the first measure in the system that the bracket belongs to.

* Instrument names always have a time position of zero, so the playhead is moved to the start of the first measure in the system that the instrument name belongs to.
2020-04-14 05:15:05 -07:00

156 lines
4.6 KiB
C++

//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2011 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 "iname.h"
#include "measure.h"
#include "staff.h"
#include "system.h"
#include "part.h"
#include "undo.h"
namespace Ms {
//---------------------------------------------------------
// longInstrumentStyle
//---------------------------------------------------------
static const ElementStyle longInstrumentStyle {
};
//---------------------------------------------------------
// shortInstrumentStyle
//---------------------------------------------------------
static const ElementStyle shortInstrumentStyle {
};
//---------------------------------------------------------
// InstrumentName
//---------------------------------------------------------
InstrumentName::InstrumentName(Score* s)
: TextBase(s, Tid::INSTRUMENT_LONG, ElementFlag::NOTHING)
{
setFlag(ElementFlag::MOVABLE, false);
setInstrumentNameType(InstrumentNameType::LONG);
}
//---------------------------------------------------------
// instrumentNameTypeName
//---------------------------------------------------------
QString InstrumentName::instrumentNameTypeName() const
{
return instrumentNameType() == InstrumentNameType::SHORT ? "short" : "long";
}
//---------------------------------------------------------
// setInstrumentNameType
//---------------------------------------------------------
void InstrumentName::setInstrumentNameType(const QString& s)
{
if (s == "short")
setInstrumentNameType(InstrumentNameType::SHORT);
else if (s == "long")
setInstrumentNameType(InstrumentNameType::LONG);
else
qDebug("InstrumentName::setSubtype: unknown <%s>", qPrintable(s));
}
//---------------------------------------------------------
// setInstrumentNameType
//---------------------------------------------------------
void InstrumentName::setInstrumentNameType(InstrumentNameType st)
{
_instrumentNameType = st;
if (st == InstrumentNameType::SHORT) {
setTid(Tid::INSTRUMENT_SHORT);
initElementStyle(&shortInstrumentStyle);
}
else {
setTid(Tid::INSTRUMENT_LONG);
initElementStyle(&longInstrumentStyle);
}
}
//---------------------------------------------------------
// playTick
//---------------------------------------------------------
Fraction InstrumentName::playTick() const
{
// Instrument names always have a tick value of zero, so play from the start of the first measure in the system that the instrument name belongs to.
const auto sys = system();
if (sys) {
const auto firstMeasure = sys->firstMeasure();
if (firstMeasure)
return firstMeasure->tick();
}
return tick();
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
QVariant InstrumentName::getProperty(Pid id) const
{
switch (id) {
case Pid::INAME_LAYOUT_POSITION:
return _layoutPos;
default:
return TextBase::getProperty(id);
}
}
//---------------------------------------------------------
// setProperty
//---------------------------------------------------------
bool InstrumentName::setProperty(Pid id, const QVariant& v)
{
bool rv = true;
switch (id) {
case Pid::INAME_LAYOUT_POSITION:
_layoutPos = v.toInt();
break;
case Pid::VISIBLE:
case Pid::COLOR:
// not supported
break;
default:
rv = TextBase::setProperty(id, v);
break;
}
return rv;
}
//---------------------------------------------------------
// propertyDefault
//---------------------------------------------------------
QVariant InstrumentName::propertyDefault(Pid id) const
{
switch (id) {
case Pid::INAME_LAYOUT_POSITION:
return 0;
default:
return TextBase::propertyDefault(id);
}
}
}