Skip to content

Commit

Permalink
Better minimum length when resizing notes (LMMS#5512)
Browse files Browse the repository at this point in the history
* Limit note length to quantization value

Draging a note to it's minimum value of 1 will add this new length to
the note if you later choose to stretch it which will not be clearly
visible in the Piano Roll unless you zoom in a bit. Limit the note
length to the quantization value and use <Alt> key to override and set
a smaller value.

* Update src/gui/editors/PianoRoll.cpp

Co-authored-by: Spekular <Spekular@users.noreply.github.com>

* Remember min note length if shorter than quantization()

* Find note length modulo quantization, pick smallest from selected notes

* Comment on and improve m_minResizeLen calculation

Co-authored-by: Oskar Wallgren <oskar.wallgren13@gmail.com>
  • Loading branch information
Spekular and zonkmachine authored Jul 9, 2020
1 parent 82ba7aa commit 56e20fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,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
24 changes: 19 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 @@ -1727,9 +1728,21 @@ void PianoRoll::mousePressEvent(QMouseEvent * me )
// then resize the note
m_action = ActionResizeNote;

//Calculate the minimum length we should allow when resizing
//each note, and let all notes use the smallest one found
m_minResizeLen = quantization();
for (Note *note : selectedNotes)
{
if (note->oldLength() <= 0) { note->setOldLength(4); }
//Notes from the BB editor can have a negative length, so
//change their length to the displayed one before resizing
if (note->oldLength() <= 0) { note->setOldLength(4); }
//Let the note be sized down by quantized increments, stopping
//when the next step down would result in a negative length
int thisMin = note->oldLength() % quantization();
//The initial value for m_minResizeLen is the minimum length of
//a note divisible by the current Q. Therefore we ignore notes
//where thisMin == 0 when checking for a new minimum
if (thisMin > 0 && thisMin < m_minResizeLen) { m_minResizeLen = thisMin; }
}

// set resize-cursor
Expand Down Expand Up @@ -2664,7 +2677,7 @@ void PianoRoll::dragNotes( int x, int y, bool alt, bool shift, bool ctrl )
// If shift is pressed we resize and rearrange only the selected notes
// If shift + ctrl then we also rearrange all posterior notes (sticky)
// If shift is pressed but only one note is selected, apply sticky

auto selectedNotes = getSelectedNotes();

if (shift)
Expand Down Expand Up @@ -2750,11 +2763,12 @@ 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();

for (Note *note : selectedNotes)
{
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

0 comments on commit 56e20fb

Please sign in to comment.