From 53a9b25fb1649a1ac0972a1f60b51280769ef799 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 13 Dec 2008 10:29:04 +0000 Subject: [PATCH] note edit area has adjustable height git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1911 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 2 +- TODO | 1 - include/piano_roll.h | 4 ++- src/gui/piano_roll.cpp | 81 ++++++++++++++++++++++++++++++++---------- 4 files changed, 66 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 95965fd61..34fc67b55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,7 +13,7 @@ 3 notes, rather than just the first one - if you click towards the end of the key in the piano roll, it plays the note louder than if you play it towards the base - + - note edit area has adjustable height 2008-12-11 Tobias Doerffel diff --git a/TODO b/TODO index ab6f9ee8c..fc3d64b61 100644 --- a/TODO +++ b/TODO @@ -52,7 +52,6 @@ - add FLAC as export-format? Andrew Kelley's todo: -- piano roll: make the note volume section have adjustable height - add note panning ability to piano roll - paint piano roll notes with a darker color based on how high volume the note is - paint note volume blue if selected diff --git a/include/piano_roll.h b/include/piano_roll.h index 45c628ffb..8353787e0 100644 --- a/include/piano_roll.h +++ b/include/piano_roll.h @@ -149,7 +149,8 @@ private: ActionSelectNotes, ActionMoveSelection, ActionChangeNoteVolume, - ActionChangeNotePanning + ActionChangeNotePanning, + ActionResizeNoteEditArea, } ; enum pianoRollKeyTypes @@ -254,6 +255,7 @@ private: int m_moveStartX; int m_moveStartY; + int m_oldNotesEditHeight; int m_notesEditHeight; int m_ppt; int m_totalKeysToScroll; diff --git a/src/gui/piano_roll.cpp b/src/gui/piano_roll.cpp index cf78efe0b..764e3f5ff 100644 --- a/src/gui/piano_roll.cpp +++ b/src/gui/piano_roll.cpp @@ -92,6 +92,8 @@ const int KEY_LINE_HEIGHT = 12; const int OCTAVE_HEIGHT = KEY_LINE_HEIGHT * KeysPerOctave; // = 12 * 12; const int NOTE_EDIT_RESIZE_BAR = 6; +const int NOTE_EDIT_MIN_HEIGHT = 50; +const int KEY_AREA_MIN_HEIGHT = 100; const int PR_BOTTOM_MARGIN = SCROLLBAR_SIZE; const int PR_TOP_MARGIN = 48; const int PR_RIGHT_MARGIN = SCROLLBAR_SIZE; @@ -144,6 +146,7 @@ pianoRoll::pianoRoll( void ) : m_action( ActionNone ), m_lastMouseX( 0 ), m_lastMouseY( 0 ), + m_oldNotesEditHeight( 100 ), m_notesEditHeight( 100 ), m_ppt( DEFAULT_PR_PPT ), m_lenOfNewNotes( midiTime( 0, DefaultTicksPerTact/4 ) ), @@ -1124,6 +1127,21 @@ void pianoRoll::mousePressEvent( QMouseEvent * _me ) return; } + // keep track of the point where the user clicked down + if( _me->button() == Qt::LeftButton ) + { + m_moveStartX = _me->x(); + m_moveStartY = _me->y(); + } + + if( _me->y() > keyAreaBottom() && _me->y() < noteEditTop() ) + { + // resizing the note edit area + m_action = ActionResizeNoteEditArea; + m_oldNotesEditHeight = m_notesEditHeight; + return; + } + if( _me->y() > PR_TOP_MARGIN ) { volume vol = DefaultVolume; @@ -1259,10 +1277,7 @@ void pianoRoll::mousePressEvent( QMouseEvent * _me ) m_currentNote = *it; - - // keep track of the point where the user clicked down - m_moveStartX = _me->x(); - m_moveStartY = _me->y(); + // remember which key and tick we started with m_mouseDownKey = m_startKey; m_mouseDownTick = m_currentPosition; @@ -1611,11 +1626,35 @@ void pianoRoll::mouseMoveEvent( QMouseEvent * _me ) return; } + if( m_action == ActionNone && _me->buttons() == 0 ) + { + if( _me->y() > keyAreaBottom() && _me->y() < noteEditTop() ) + { + QApplication::setOverrideCursor( QCursor( Qt::SizeVerCursor ) ); + return; + } + else + { + QApplication::setOverrideCursor( QCursor( Qt::ArrowCursor ) ); + } + } + else if( m_action == ActionResizeNoteEditArea ) + { + // change m_notesEditHeight and then repaint + m_notesEditHeight = tLimit( + m_oldNotesEditHeight - ( _me->y() - m_moveStartY ), + NOTE_EDIT_MIN_HEIGHT, + height() - PR_TOP_MARGIN - NOTE_EDIT_RESIZE_BAR - + PR_BOTTOM_MARGIN - KEY_AREA_MIN_HEIGHT ); + repaint(); + return; + } + if( _me->y() > PR_TOP_MARGIN || m_action != ActionNone ) { bool edit_note = ( _me->y() > noteEditTop() ) && m_action != ActionSelectNotes; - + int key_num = getKey( _me->y() ); int x = _me->x(); @@ -1680,11 +1719,11 @@ void pianoRoll::mouseMoveEvent( QMouseEvent * _me ) const noteVector & notes = m_pattern->notes(); // determine what volume to set note to - volume vol = tLimit( 2 * ( -_me->y() + - height() - - PR_BOTTOM_MARGIN ), - MinVolume, - MaxVolume ); + volume vol = tLimit( + ( ( (float)noteEditBottom() ) - ( (float)_me->y() ) ) / + ( (float)( noteEditBottom() - noteEditTop() ) ) * + ( MaxVolume - MinVolume ), + MinVolume, MaxVolume ); // loop through vector bool use_selection = isSelection(); @@ -2419,16 +2458,17 @@ void pianoRoll::paintEvent( QPaintEvent * _pe ) qMin(255, 60 + ( *it )->getVolume() ) ); p.setPen( QPen( color, NE_LINE_WIDTH ) ); - p.drawLine( x + WHITE_KEY_WIDTH, - height() - PR_BOTTOM_MARGIN - - ( *it )->getVolume() / 2, - x + WHITE_KEY_WIDTH, - height() - PR_BOTTOM_MARGIN ); + + int volumeHandleTop = noteEditBottom() - + ( (float)( ( *it )->getVolume() - MinVolume ) ) / + ( (float)( MaxVolume - MinVolume ) ) * + ( (float)( noteEditBottom() - noteEditTop() ) ); + p.drawLine( noteEditLeft() + x, volumeHandleTop, + noteEditLeft() + x, noteEditBottom() ); - volumeHandles << QPoint( x + WHITE_KEY_WIDTH + 1, - height() - PR_BOTTOM_MARGIN - - ( *it )->getVolume() / 2+1 ); + volumeHandles << QPoint( x + noteEditLeft() + 1, + volumeHandleTop+1 ); if( ( *it )->hasDetuningInfo() ) { @@ -2489,7 +2529,10 @@ void pianoRoll::paintEvent( QPaintEvent * _pe ) } // bar to resize note edit area - p.fillRect( 0, keyAreaBottom(), noteEditRight()-noteEditLeft(), NOTE_EDIT_RESIZE_BAR, QColor( 255, 255, 255 ) ); + p.setClipRect( 0, 0, width(), height() ); + p.fillRect( QRect( 0, keyAreaBottom(), + width()-PR_RIGHT_MARGIN, NOTE_EDIT_RESIZE_BAR ), + QColor( 64, 64, 64 ) ); const QPixmap * cursor = NULL; // draw current edit-mode-icon below the cursor