Skip to content

Commit

Permalink
fix #24823
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Mar 21, 2014
1 parent ff6ba80 commit b623415
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
4 changes: 2 additions & 2 deletions libmscore/groups.cpp
Expand Up @@ -231,9 +231,9 @@ void Groups::addStop(int pos, TDuration::DurationType d, BeamMode bm)

void Groups::dump(const char* m) const
{
printf("%s\n", m);
qDebug("%s", m);
for (const GroupNode& n : *this) {
printf(" group tick %d action 0x%02x\n", n.pos * 60, n.action);
qDebug(" group tick %d action 0x%02x", n.pos * 60, n.action);
}
}

Expand Down
30 changes: 21 additions & 9 deletions libmscore/score.cpp
Expand Up @@ -1959,6 +1959,15 @@ Q_INVOKABLE void Score::setMetaTag(const QString& tag, const QString& val)
_metaTags.insert(tag, val);
}

//---------------------------------------------------------
// staffTypes
//---------------------------------------------------------

const QList<StaffType**>& Score::staffTypes() const
{
return rootScore()->_staffTypes;
}

//---------------------------------------------------------
// addStaffType
// ownership of st move to score except if the buildin
Expand All @@ -1972,22 +1981,23 @@ void Score::addStaffType(StaffType* st)

void Score::addStaffType(int idx, StaffType* st)
{
Score* s = rootScore();
// if the modified staff type is NOT replacing an existing type
if (idx < 0 || idx >= _staffTypes.size()) {
if (idx < 0 || idx >= s->_staffTypes.size()) {
// store new pointer to pointer to type data
StaffType** stp = new StaffType*;
*stp = st;
_staffTypes.append(stp);
s->_staffTypes.append(stp);
}
// if the modified staff type IS replacing an existing type
else {
StaffType* oldStaffType = *(_staffTypes[idx]);
// update the type of each score staff which uses the old type
for(int staffIdx = 0; staffIdx < staves().size(); staffIdx++)
if(staff(staffIdx)->staffType() == oldStaffType)
for (int staffIdx = 0; staffIdx < staves().size(); staffIdx++)
if (staff(staffIdx)->staffType() == oldStaffType)
staff(staffIdx)->setStaffType(st);
// store the updated staff type
*(_staffTypes[idx]) = st;
*(s->_staffTypes[idx]) = st;
// delete old staff type if not built-in
if (!oldStaffType->builtin())
delete oldStaffType;
Expand All @@ -2000,8 +2010,9 @@ void Score::addStaffType(int idx, StaffType* st)

int Score::staffTypeIdx(StaffType* st) const
{
const Score* s = rootScore();
for (int i = 0; i < _staffTypes.size(); ++i) {
if ((*_staffTypes[i]) == st)
if ((*s->_staffTypes[i]) == st)
return i;
}
return -1;
Expand All @@ -2011,11 +2022,12 @@ int Score::staffTypeIdx(StaffType* st) const
// staffType
//---------------------------------------------------------

StaffType* Score::staffType(int idx)
StaffType* Score::staffType(int idx) const
{
if (idx < 0 || idx >= _staffTypes.size())
const Score* s = rootScore();
if (idx < 0 || idx >= s->_staffTypes.size())
return 0;
return *(_staffTypes[idx]);
return *(s->_staffTypes[idx]);
}

//---------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions libmscore/score.h
Expand Up @@ -847,9 +847,9 @@ class Score : public QObject {
SynthesizerState& synthesizerState() { return _synthesizerState; }
void setSynthesizerState(const SynthesizerState& s);

const QList<StaffType**>& staffTypes() const { return _staffTypes; }
const QList<StaffType**>& staffTypes() const;
void replaceStaffTypes(const QList<StaffType*>&);
StaffType* staffType(int idx);
StaffType* staffType(int idx) const;
int staffTypeIdx(StaffType*) const;
void addStaffType(StaffType*);
void addStaffType(int idx, StaffType*);
Expand Down
2 changes: 2 additions & 0 deletions libmscore/staff.cpp
Expand Up @@ -425,6 +425,8 @@ void Staff::read(XmlReader& e)
_barLineFrom = (lines() == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : 0);
_barLineTo = (lines() == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (lines() - 1) * 2);
}
else
qDebug("Staff::read: unknown staff type");
}
else if (tag == "small")
setSmall(e.readInt());
Expand Down
10 changes: 6 additions & 4 deletions mscore/editstaff.cpp
Expand Up @@ -83,13 +83,13 @@ EditStaff::EditStaff(Staff* s, QWidget* parent)
void EditStaff::fillStaffTypeCombo()
{
Score* score = staff->score();
int curIdx = 0;
int n = score->staffTypes().size();
int curIdx = -1;
// can this instrument accept tabs or drum set?
bool canUseTabs = instrument.stringData() && instrument.stringData()->strings() > 0;
bool canUsePerc = instrument.useDrumset();
staffType->clear();
for (int idx = 0; idx < n; ++idx) {

for (int idx = 0; idx < score->staffTypes().size(); ++idx) {
StaffType* st = score->staffType(idx);
if ( (canUseTabs && st->group() == TAB_STAFF_GROUP)
|| ( canUsePerc && st->group() == PERCUSSION_STAFF_GROUP)
Expand All @@ -99,7 +99,9 @@ void EditStaff::fillStaffTypeCombo()
curIdx = staffType->count() - 1;
}
}
staffType->setCurrentIndex(curIdx);
if (curIdx == -1)
qDebug("EditStaff::fillStaffTypeCombo: staff type not found");
staffType->setCurrentIndex(curIdx == -1 ? 0 : curIdx);
}

//---------------------------------------------------------
Expand Down

0 comments on commit b623415

Please sign in to comment.