Skip to content

Commit

Permalink
fix for note edit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Jul 19, 2018
1 parent cad046a commit 076b56f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 53 deletions.
106 changes: 56 additions & 50 deletions libmscore/note.cpp
Expand Up @@ -1542,52 +1542,6 @@ QRectF Note::drag(EditData& ed)
return QRectF();
}

//---------------------------------------------------------
// endDrag
//---------------------------------------------------------

void Note::endDrag(EditData& ed)
{
Staff* staff = score()->staff(chord()->vStaffIdx());
int tick = chord()->tick();

NoteEditData* ned = static_cast<NoteEditData*>(ed.getData(this));
if (staff->isTabStaff(tick)) {
#if 0 // TODO
// on TABLATURE staves, dragging a note keeps same pitch on a different string (if possible)
// determine new string of dragged note (if tablature is upside down, invert _lineOffset)
// and fret for the same pitch on the new string
const StringData* strData = staff->part()->instrument()->stringData();
int nString = _string + (staff->staffType(tick)->upsideDown() ? -_lineOffset : _lineOffset);
int nFret = strData->fret(_pitch, nString, staff, tick);
if (nFret < 0) // no fret?
return; // no party!
// move the note together with all notes tied to it
for (Note* nn : tiedNotes()) {
bool refret = false;
if (nn->fret() != nFret) {
nn->undoChangeProperty(Pid::FRET, nFret);
refret = true;
}
if (nn->string() != nString) {
nn->undoChangeProperty(Pid::STRING, nString);
refret = true;
}
if (refret)
strData->fretChords(nn->chord());
}
#endif
}
else {
for (Note* nn : tiedNotes()) {
for (PropertyData pd : ned->propertyData) {
score()->undoPropertyChanged(nn, pd.id, pd.data);
}
}
}
score()->select(this, SelectType::SINGLE, 0);
}

//---------------------------------------------------------
// acceptDrop
//---------------------------------------------------------
Expand Down Expand Up @@ -2391,17 +2345,69 @@ int Note::customizeVelocity(int velo) const
}

//---------------------------------------------------------
// endEdit
// endDrag
//---------------------------------------------------------

void Note::endEdit(EditData&)
void Note::endDrag(EditData& ed)
{
Staff* staff = score()->staff(chord()->vStaffIdx());
int tick = chord()->tick();

NoteEditData* ned = static_cast<NoteEditData*>(ed.getData(this));
if (staff->isTabStaff(tick)) {
#if 0 // TODO
// on TABLATURE staves, dragging a note keeps same pitch on a different string (if possible)
// determine new string of dragged note (if tablature is upside down, invert _lineOffset)
// and fret for the same pitch on the new string
const StringData* strData = staff->part()->instrument()->stringData();
int nString = _string + (staff->staffType(tick)->upsideDown() ? -_lineOffset : _lineOffset);
int nFret = strData->fret(_pitch, nString, staff, tick);
if (nFret < 0) // no fret?
return; // no party!
// move the note together with all notes tied to it
for (Note* nn : tiedNotes()) {
bool refret = false;
if (nn->fret() != nFret) {
nn->undoChangeProperty(Pid::FRET, nFret);
refret = true;
}
if (nn->string() != nString) {
nn->undoChangeProperty(Pid::STRING, nString);
refret = true;
}
if (refret)
strData->fretChords(nn->chord());
}
#endif
}
else {
for (Note* nn : tiedNotes()) {
for (PropertyData pd : ned->propertyData) {
score()->undoPropertyChanged(nn, pd.id, pd.data);
}
}
}
score()->select(this, SelectType::SINGLE, 0);
}

//---------------------------------------------------------
// editDrag
//---------------------------------------------------------

void Note::editDrag(EditData& ed)
{
Chord* ch = chord();
if (ch->notes().size() == 1) {
ch->undoChangeProperty(Pid::USER_OFF, ch->userOff() + userOff());
// if the chord contains only this note, then move the whole chord
// including stem, flag etc.
ch->undoChangeProperty(Pid::USER_OFF, ch->userOff() + userOff() + ed.delta);
setUserOff(QPointF());
triggerLayout();
}
else {
setUserOff(userOff() + ed.delta);
undoChangeProperty(Pid::AUTOPLACE, false);
}
triggerLayout();
}

//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion libmscore/note.h
Expand Up @@ -262,7 +262,7 @@ class Note final : public Element {
virtual void startDrag(EditData&) override;
virtual QRectF drag(EditData&) override;
virtual void endDrag(EditData&) override;
void endEdit(EditData&);
virtual void editDrag(EditData&) override;
void addSpanner(Spanner*);
void removeSpanner(Spanner*);
int concertPitchIdx() const;
Expand Down
6 changes: 6 additions & 0 deletions libmscore/scorefile.cpp
Expand Up @@ -839,14 +839,20 @@ Score::FileError MasterScore::loadMsc(QString name, bool ignoreVersionError)

Score::FileError MasterScore::loadMsc(QString name, QIODevice* io, bool ignoreVersionError)
{
extern bool __loadScore;
bool ols = __loadScore;
__loadScore = true;
fileInfo()->setFile(name);

Score::FileError rv;
if (name.endsWith(".mscz"))
return loadCompressedMsc(io, ignoreVersionError);
else {
XmlReader r(io);
return read1(r, ignoreVersionError);
}
__loadScore = ols;
return rv;
}

//---------------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions libmscore/undo.cpp
Expand Up @@ -250,7 +250,9 @@ void UndoStack::push(UndoCommand* cmd, EditData* ed)
void UndoStack::push1(UndoCommand* cmd)
{
if (!curCmd) {
qWarning("no active command, UndoStack %p", this);
extern bool __loadScore;
if (!__loadScore)
qWarning("no active command, UndoStack %p", this);
return;
}
curCmd->appendChild(cmd);
Expand Down Expand Up @@ -286,7 +288,9 @@ void UndoStack::remove(int idx)
void UndoStack::pop()
{
if (!curCmd) {
qWarning("no active command");
extern bool __loadScore;
if (!__loadScore)
qWarning("no active command");
return;
}
UndoCommand* cmd = curCmd->removeChild();
Expand Down

0 comments on commit 076b56f

Please sign in to comment.