Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -371,6 +371,9 @@ protected slots:
static const std::vector<float> m_zoomLevels;
static const std::vector<float> m_zoomYLevels;

//! Returns the width of the resize area in pixels. When zoomed in, this is a constant pixel value, but when zoomed far out, it is a fraction of the note width, to make it easier to move short notes.
Comment thread
regulus79 marked this conversation as resolved.
Outdated
int resizeGripWidth(tick_t noteLength) const;

MidiClip* m_midiClip;
NoteVector m_ghostNotes;

Expand Down
18 changes: 12 additions & 6 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ const int PR_TOP_MARGIN = 18;
const int PR_RIGHT_MARGIN = SCROLLBAR_SIZE;


// width of area used for resizing (the grip at the end of a note)
const int RESIZE_AREA_WIDTH = 9;
//! Width of area used for resizing (the grip at the end of a note)
const int RESIZE_GRIP_WIDTH = 9;
//! The maximum fraction of the note width that the resize grip is allowed to take up
const float RESIZE_GRIP_MAX_WIDTH_FRACTION = 0.25;
Comment thread
regulus79 marked this conversation as resolved.
Outdated

// width of line for setting volume/panning of note
const int NOTE_EDIT_LINE_WIDTH = 3;
Expand Down Expand Up @@ -1922,8 +1924,8 @@ void PianoRoll::mousePressEvent(QMouseEvent * me )
}

// clicked at the "tail" of the note?
if( pos_ticks * m_ppb / TimePos::ticksPerBar() >
m_currentNote->endPos() * m_ppb / TimePos::ticksPerBar() - RESIZE_AREA_WIDTH
if(x + m_currentPosition * m_ppb / TimePos::ticksPerBar() >
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I changed this from comparing the mouse position in ticks to comparing the mouse position in pixels, since at high zoom levels, ticks get very wide, and they don't provide enough resolution.

Comment thread
regulus79 marked this conversation as resolved.
Outdated
m_currentNote->endPos() * m_ppb / TimePos::ticksPerBar() - resizeGripWidth(m_currentNote->length())
&& m_currentNote->length() > 0 )
{
m_midiClip->addJournalCheckPoint();
Expand Down Expand Up @@ -2719,8 +2721,7 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me )
int noteRightX = ( note->pos() + note->length() -
m_currentPosition) * m_ppb/TimePos::ticksPerBar();
// cursor at the "tail" of the note?
bool atTail = note->length() > 0 && x > noteRightX -
RESIZE_AREA_WIDTH;
bool atTail = note->length() > 0 && x > noteRightX - resizeGripWidth(note->length());
Qt::CursorShape cursorShape = atTail ? Qt::SizeHorCursor :
Qt::SizeAllCursor;
setCursor( cursorShape );
Expand Down Expand Up @@ -3290,6 +3291,11 @@ void PianoRoll::dragNotes(int x, int y, bool alt, bool shift, bool ctrl)
}


int PianoRoll::resizeGripWidth(tick_t noteLength) const
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given how this is used, you could probably change the parameter to const Note& note and then call note.length() inside this function. That would make call sites a little nicer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 49c6026

{
const int noteWidth = noteLength * m_ppb / TimePos::ticksPerBar();
return std::min(RESIZE_GRIP_WIDTH, static_cast<int>(std::round(RESIZE_GRIP_MAX_WIDTH_FRACTION * noteWidth)));
}


void PianoRoll::paintEvent(QPaintEvent * pe )
Expand Down
Loading