Skip to content

Commit

Permalink
fix #271198: Add a more flexible way to choose noteheads in drumset f…
Browse files Browse the repository at this point in the history
…or percussion instrument

Added "Custom" item to noteheads combobox, removed "invalid" item, set selection at the first tree element when opening the drumset editor, added interaction between custom noteheads group and notehead group combobox, fixed tab order.
Fixed drawing custom noteheads in preview window: Set cachedSymbol from current quarter note combobox value and added slot to update preview on chaning quarter value.
Fixed shadow note drawing: Apply specific notehead from drumset data.
  • Loading branch information
anatoly-os committed May 5, 2018
1 parent b46e136 commit 0214736
Show file tree
Hide file tree
Showing 10 changed files with 510 additions and 279 deletions.
15 changes: 11 additions & 4 deletions libmscore/drumset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void Drumset::save(XmlWriter& xml) const
xml.tag("head", NoteHead::group2name(noteHead(i)));
if (noteHead(i) == NoteHead::Group::HEAD_CUSTOM) {
xml.stag("noteheads");
for (int j = 0; j < int(NoteHead::Type::HEAD_TYPES) - 1; j++) {
for (int j = 0; j < int(NoteHead::Type::HEAD_TYPES); j++) {
xml.tag(NoteHead::type2name(NoteHead::Type(j)), Sym::id2name((noteHeads(i, NoteHead::Type(j)))));
}
xml.etag();
Expand Down Expand Up @@ -68,14 +68,21 @@ void Drumset::save(XmlWriter& xml) const

bool Drumset::readProperties(XmlReader& e, int pitch)
{
if (pitch < 0 || pitch > DRUM_INSTRUMENTS - 1)
return false;

const QStringRef& tag(e.name());
if (tag == "head")
_drum[pitch].notehead = NoteHead::name2group(e.readElementText());
else if (tag == "noteheads") {
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
_drum[pitch].noteheads[int(NoteHead::name2type(tag.toString()))] = Sym::name2id(e.readElementText());
}
const QStringRef& nhTag(e.name());
int noteType = int(NoteHead::name2type(nhTag.toString()));
if (noteType > int(NoteHead::Type::HEAD_TYPES) - 1 || noteType < 0)
return false;

_drum[pitch].noteheads[noteType] = Sym::name2id(e.readElementText());
}
}
else if (tag == "line")
_drum[pitch].line = e.readInt();
Expand Down
2 changes: 1 addition & 1 deletion libmscore/drumset.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Drumset {
DrumInstrument _drum[DRUM_INSTRUMENTS];

public:
bool isValid(int pitch) const { return _drum[pitch].notehead != NoteHead::Group::HEAD_INVALID; }
bool isValid(int pitch) const { return !_drum[pitch].name.isEmpty(); }
NoteHead::Group noteHead(int pitch) const { return _drum[pitch].notehead; }
SymId noteHeads(int pitch, NoteHead::Type t) const { return _drum[pitch].noteheads[int(t)]; }
int line(int pitch) const { return _drum[pitch].line; }
Expand Down
1 change: 1 addition & 0 deletions libmscore/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace Ms {
// notehead groups
//---------------------------------------------------------

//int(NoteHead::Group::HEAD_GROUPS) - 1: "-1" is needed to prevent building CUSTOM_GROUP noteheads set, since it is built by users and keep a specific set of existing noteheads
static const SymId noteHeads[2][int(NoteHead::Group::HEAD_GROUPS) - 1][int(NoteHead::Type::HEAD_TYPES)] = {
{ // down stem
{ SymId::noteheadWhole, SymId::noteheadHalf, SymId::noteheadBlack, SymId::noteheadDoubleWhole },
Expand Down
1 change: 1 addition & 0 deletions libmscore/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class Note final : public Element {

void layout();
void layout2();
//setter is used only in drumset tools to setup the notehead preview in the drumset editor and the palette
void setCachedNoteheadSym(SymId i) { _cachedNoteheadSym = i; };
void scanElements(void* data, void (*func)(void*, Element*), bool all=true);
void setTrack(int val);
Expand Down
16 changes: 12 additions & 4 deletions mscore/drumtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ DrumTools::DrumTools(QWidget* parent)
w->setLayout(layout);

QVBoxLayout* layout1 = new QVBoxLayout;
layout1->setSpacing(6);
pitchName = new QLabel;
pitchName->setAlignment(Qt::AlignCenter);
layout1->addWidget(pitchName);
editButton = new QToolButton;
layout1->addWidget(editButton);
layout1->addStretch();
Expand All @@ -77,6 +81,7 @@ DrumTools::DrumTools(QWidget* parent)
void boxClicked(int);
connect(drumPalette, SIGNAL(boxClicked(int)), SLOT(drumNoteSelected(int)));
retranslate();
drumPalette->setContextMenuPolicy(Qt::PreventContextMenu);
}

//---------------------------------------------------------
Expand Down Expand Up @@ -121,6 +126,9 @@ void DrumTools::updateDrumset(const Drumset* ds)
chord->setStemDirection(dir);
chord->setUp(up);
chord->setTrack(voice);
Stem* stem = new Stem(gscore);
stem->setLen((up ? -3.0 : 3.0) * _spatium);
chord->add(stem);
Note* note = new Note(gscore);
note->setMark(true);
note->setParent(chord);
Expand All @@ -135,12 +143,9 @@ void DrumTools::updateDrumset(const Drumset* ds)
noteheadSym = drumset->noteHeads(pitch, NoteHead::Type::HEAD_QUARTER);
else
noteheadSym = note->noteHead(true, noteHead, NoteHead::Type::HEAD_QUARTER);

note->setCachedNoteheadSym(noteheadSym); // we use the cached notehead so we don't recompute it at each layout
chord->add(note);
Stem* stem = new Stem(gscore);
stem->setLen((up ? -3.0 : 3.0) * _spatium);
chord->add(stem);
stem->setPos(chord->stemPos());
int sc = drumset->shortcut(pitch);
QString shortcut;
if (sc)
Expand Down Expand Up @@ -203,6 +208,9 @@ void DrumTools::drumNoteSelected(int val)
getAction("voice-2")->setChecked(element->voice() == 1);
getAction("voice-3")->setChecked(element->voice() == 2);
getAction("voice-4")->setChecked(element->voice() == 3);

auto pitchCell = drumPalette->cellAt(drumPalette->getCurrentIdx());
pitchName->setText(pitchCell->name);
}
}

Expand Down
1 change: 1 addition & 0 deletions mscore/drumtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class DrumTools : public QDockWidget {
Staff* staff;
Palette* drumPalette;
QToolButton* editButton;
QLabel* pitchName;
const Drumset* drumset;

private slots:
Expand Down
Loading

0 comments on commit 0214736

Please sign in to comment.