Hey guys,

Here are 3 small patches that I propose to you, based on stable-0.4
(cacc0d6).

These patches are only ergonomics enhancements: magnetic knob, piano roll
remove from selection and piano roll smarter note resizing. If you decide
to integrate these patches for a future release I will of course update the
documentation wiki.

regards,
From 898b84ceec69f2d37be8c25f244b489e44285fd1 Mon Sep 17 00:00:00 2001
From: NoiseByNorthwest <[email protected]>
Date: Sat, 21 Jan 2012 20:34:24 +0100
Subject: [PATCH 1/3] Add magnetic effect (for init value) on knobs

---
 include/AutomatableModel.h |    5 +++++
 src/gui/widgets/knob.cpp   |   28 +++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/include/AutomatableModel.h b/include/AutomatableModel.h
index b9b436f..453949b 100644
--- a/include/AutomatableModel.h
+++ b/include/AutomatableModel.h
@@ -268,6 +268,11 @@ signals:
 		return AutomatableModel::value<type>( _frameOffset );	\
 	}															\
 																\
+	inline type initValue() const								\
+	{															\
+		return AutomatableModel::initValue<type>();				\
+	}															\
+																\
 	inline type minValue() const								\
 	{															\
 		return AutomatableModel::minValue<type>();				\
diff --git a/src/gui/widgets/knob.cpp b/src/gui/widgets/knob.cpp
index 40dff8d..0df4a8b 100644
--- a/src/gui/widgets/knob.cpp
+++ b/src/gui/widgets/knob.cpp
@@ -558,7 +558,33 @@ void knob::wheelEvent( QWheelEvent * _we )
 
 void knob::setPosition( const QPoint & _p )
 {
-	model()->setValue( model()->value() - getValue( _p ) );
+	const float current = model()->value();
+	const float next = current - getValue( _p );
+
+	if( model()->initValue() == current )
+	{
+		// not critical but should be a property
+		static int magnet_dec = 0;
+		if( ++magnet_dec > 20 )
+		{
+			magnet_dec = 0;
+			model()->setValue( next );
+		}
+
+		return;
+	}
+
+	const bool current_sign = model()->initValue() - current < 0;
+	const bool next_sign = model()->initValue() - next < 0;
+
+	if( current_sign != next_sign )
+	{
+		model()->setValue( model()->initValue() );
+	}
+	else
+	{
+		model()->setValue( next );
+	}
 }
 
 
-- 
1.7.5.4


From 11d0252bde5f8d247616e195b8ae60899fae8e70 Mon Sep 17 00:00:00 2001
From: NoiseByNorthwest <[email protected]>
Date: Sat, 21 Jan 2012 22:23:42 +0100
Subject: [PATCH 2/3] Piano-roll: remove from selection feature (shift +
 left-click)

---
 src/gui/piano_roll.cpp |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/gui/piano_roll.cpp b/src/gui/piano_roll.cpp
index e81c657..030c9fe 100644
--- a/src/gui/piano_roll.cpp
+++ b/src/gui/piano_roll.cpp
@@ -1765,7 +1765,15 @@ void pianoRoll::computeSelectedNotes(bool shift)
 				pos_ticks + len_ticks > sel_pos_start &&
 				pos_ticks < sel_pos_end )
 			{
-				( *it )->setSelected( true );
+				// remove from selection when holding shift
+				if( shift && ( *it )->selected() )
+				{
+					( *it )->setSelected(false);
+				}
+				else
+				{
+					( *it )->setSelected(true);
+				}
 			}
 		}
 	}
-- 
1.7.5.4


From 8e4b09ae0f88dc28aba6b87374a840c29bfc5744 Mon Sep 17 00:00:00 2001
From: NoiseByNorthwest <[email protected]>
Date: Sun, 22 Jan 2012 13:25:58 +0100
Subject: [PATCH 3/3] Piano-roll: preserve melody when resizing a note by
 holding shift

---
 include/piano_roll.h   |    2 +-
 src/gui/piano_roll.cpp |   53 ++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/include/piano_roll.h b/include/piano_roll.h
index 426fd81..c00d649 100644
--- a/include/piano_roll.h
+++ b/include/piano_roll.h
@@ -204,7 +204,7 @@ private:
 	inline int noteEditRight() const;
 	inline int noteEditLeft() const;
 	
-	void dragNotes( int x, int y, bool alt );
+	void dragNotes( int x, int y, bool alt, bool shift );
 		
 	static const int cm_scrollAmtHoriz = 10;
 	static const int cm_scrollAmtVert = 1;
diff --git a/src/gui/piano_roll.cpp b/src/gui/piano_roll.cpp
index 030c9fe..7bb995f 100644
--- a/src/gui/piano_roll.cpp
+++ b/src/gui/piano_roll.cpp
@@ -927,8 +927,8 @@ void pianoRoll::keyPressEvent( QKeyEvent * _ke )
 						m_action == ActionResizeNote )
 				{
 					dragNotes( m_lastMouseX, m_lastMouseY,
-							_ke->modifiers() &
-							Qt::AltModifier );
+							_ke->modifiers() & Qt::AltModifier,
+							_ke->modifiers() & Qt::ShiftModifier );
 				}
 			}
 			_ke->accept();
@@ -955,8 +955,8 @@ void pianoRoll::keyPressEvent( QKeyEvent * _ke )
 						m_action == ActionResizeNote )
 				{
 					dragNotes( m_lastMouseX, m_lastMouseY,
-							_ke->modifiers() &
-							Qt::AltModifier );
+							_ke->modifiers() & Qt::AltModifier,
+							_ke->modifiers() & Qt::ShiftModifier );
 				}
 			}
 			_ke->accept();
@@ -995,8 +995,8 @@ void pianoRoll::keyPressEvent( QKeyEvent * _ke )
 						m_action == ActionResizeNote )
 				{
 					dragNotes( m_lastMouseX, m_lastMouseY,
-							_ke->modifiers() &
-							Qt::AltModifier );
+							_ke->modifiers() & Qt::AltModifier,
+							_ke->modifiers() & Qt::ShiftModifier );
 				}				
 				
 			}
@@ -1033,8 +1033,8 @@ void pianoRoll::keyPressEvent( QKeyEvent * _ke )
 						m_action == ActionResizeNote )
 				{
 					dragNotes( m_lastMouseX, m_lastMouseY,
-							_ke->modifiers() &
-							Qt::AltModifier );
+							_ke->modifiers() & Qt::AltModifier,
+							_ke->modifiers() & Qt::ShiftModifier );
 				}				
 				
 			}
@@ -1944,7 +1944,12 @@ void pianoRoll::mouseMoveEvent( QMouseEvent * _me )
 				pauseTestNotes();
 			}
 			
-			dragNotes(_me->x(), _me->y(), _me->modifiers() & Qt::AltModifier);
+			dragNotes(
+				_me->x(),
+				_me->y(),
+				_me->modifiers() & Qt::AltModifier,
+				_me->modifiers() & Qt::ShiftModifier
+			);
 			
 			if( replay_note && m_action == ActionMoveNote )
 			{
@@ -2318,7 +2323,7 @@ void pianoRoll::mouseMoveEvent( QMouseEvent * _me )
 
 
 
-void pianoRoll::dragNotes( int x, int y, bool alt )
+void pianoRoll::dragNotes( int x, int y, bool alt, bool shift )
 {
 	// dragging one or more notes around
 		
@@ -2355,7 +2360,10 @@ void pianoRoll::dragNotes( int x, int y, bool alt )
 			off_key += 0 - (m_moveBoundaryBottom + off_key);
 		}
 	}
-	
+
+	int shift_offset = 0;
+	int shift_ref_pos = -1;
+
 	// get note-vector of current pattern
 	const NoteVector & notes = m_pattern->notes();
 
@@ -2363,6 +2371,19 @@ void pianoRoll::dragNotes( int x, int y, bool alt )
 	NoteVector::ConstIterator it = notes.begin();
 	while( it != notes.end() )
 	{
+		const int pos = ( *it )->pos().getTicks();
+		// when resizing a note and holding shift: shift the following
+		// notes to preserve the melody
+		if( m_action == ActionResizeNote && shift )
+		{
+			int shifted_pos = ( *it )->oldPos().getTicks() + shift_offset;
+			if( shifted_pos && pos == shift_ref_pos )
+			{
+				shifted_pos -= off_ticks;
+			}
+			( *it )->setPos( midiTime( shifted_pos ) );
+		}
+
 		if( ( *it )->selected() )
 		{
 			
@@ -2399,6 +2420,16 @@ void pianoRoll::dragNotes( int x, int y, bool alt )
 				{
 					ticks_new = 1;
 				}
+				else if( shift )
+				{
+					// when holding shift: update the offset used to shift
+					// the following notes
+					if( pos > shift_ref_pos )
+					{
+						shift_offset += off_ticks;
+						shift_ref_pos = pos;
+					}
+				}
 				( *it )->setLength( midiTime( ticks_new ) );
 				
 				m_lenOfNewNotes = ( *it )->length();
-- 
1.7.5.4

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
LMMS-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lmms-devel

Reply via email to