Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better minimum length when resizing notes #5512

Merged
merged 7 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ protected slots:
volume_t m_lastNoteVolume;
panning_t m_lastNotePanning;

//When resizing several notes, we want to calculate a common minimum length
MidiTime m_minResizeLen;

int m_startKey; // first key when drawing
int m_lastKey;

Expand Down
21 changes: 16 additions & 5 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ PianoRoll::PianoRoll() :
m_lenOfNewNotes( MidiTime( 0, DefaultTicksPerBar/4 ) ),
m_lastNoteVolume( DefaultVolume ),
m_lastNotePanning( DefaultPanning ),
m_minResizeLen( 0 ),
m_startKey( INITIAL_START_KEY ),
m_lastKey( 0 ),
m_editMode( ModeDraw ),
Expand Down Expand Up @@ -1010,8 +1011,8 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y,
int const distanceToBorder = 2;
int const xOffset = borderWidth + distanceToBorder;

// noteTextHeight, textSize are not suitable for determining vertical spacing,
// capHeight() can be used for this, but requires Qt 5.8.
// noteTextHeight, textSize are not suitable for determining vertical spacing,
// capHeight() can be used for this, but requires Qt 5.8.
// We use boundingRect() with QChar (the QString version returns wrong value).
QRect const boundingRect = fontMetrics.boundingRect(QChar::fromLatin1('H'));
int const yOffset = (noteHeight - boundingRect.top() - boundingRect.bottom()) / 2;
Expand Down Expand Up @@ -1772,6 +1773,15 @@ void PianoRoll::mousePressEvent(QMouseEvent * me )
// then resize the note
m_action = ActionResizeNote;

m_minResizeLen = quantization();
for (Note *note : getSelectedNotes())
{
int thisMin = note->oldLength() % quantization();
Spekular marked this conversation as resolved.
Show resolved Hide resolved
if (thisMin == 0) { thisMin = quantization(); }
if (thisMin < m_minResizeLen) { m_minResizeLen = thisMin; }
}


// set resize-cursor
setCursor( Qt::SizeHorCursor );
}
Expand Down Expand Up @@ -2806,13 +2816,14 @@ void PianoRoll::dragNotes( int x, int y, bool alt, bool shift, bool ctrl )
else
{
// shift is not pressed; stretch length of selected notes but not their position
int minLength = alt ? 1 : m_minResizeLen.getTicks();
zonkmachine marked this conversation as resolved.
Show resolved Hide resolved

for (Note *note : notes)
{
if (note->selected())
{
int newLength = note->oldLength() + off_ticks;
newLength = qMax(1, newLength);
note->setLength( MidiTime(newLength) );
int newLength = qMax(minLength, note->oldLength() + off_ticks);
note->setLength(MidiTime(newLength));

m_lenOfNewNotes = note->length();
}
Expand Down