From a4909e6d1c43d0598293cac26245134a4c8ab815 Mon Sep 17 00:00:00 2001 From: akimaze Date: Tue, 7 Apr 2020 18:53:42 +0200 Subject: [PATCH 01/10] Preparing piano roll for changing the height of the keys. --- src/gui/editors/PianoRoll.cpp | 43 ++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index d49c6f0b798..3348f58b21e 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -78,11 +78,28 @@ const int SCROLLBAR_SIZE = 12; const int PIANO_X = 0; const int WHITE_KEY_WIDTH = 64; -const int WHITE_KEY_SMALL_HEIGHT = 18; +const int BLACK_KEY_WIDTH = 41; +/*const int WHITE_KEY_SMALL_HEIGHT = 18; const int WHITE_KEY_BIG_HEIGHT = 24; const int BLACK_KEY_HEIGHT = 16; const int KEY_LINE_HEIGHT = 12; -const int OCTAVE_HEIGHT = KEY_LINE_HEIGHT * KeysPerOctave; // = 12 * 12; +const int OCTAVE_HEIGHT = KEY_LINE_HEIGHT * KeysPerOctave; // = 12 * 12;*/ + +// double size +/*const int WHITE_KEY_SMALL_HEIGHT = 27; //18*2; // key line * 1.5 +const int WHITE_KEY_BIG_HEIGHT = 36; //24*2; // key line * 2 +const int BLACK_KEY_HEIGHT = 24; //16*2; // keyline * 1.3333 +const int KEY_LINE_HEIGHT = 18; //12*2; +const int OCTAVE_HEIGHT = KEY_LINE_HEIGHT * KeysPerOctave; // = 12 * 12;*/ + +const int KEY_LINE_HEIGHT = 24; +const int DEFAULT_KEY_LINE_WIDTH = 12; +const int OCTAVE_HEIGHT = KEY_LINE_HEIGHT * KeysPerOctave; +const int WHITE_KEY_SMALL_HEIGHT = KEY_LINE_HEIGHT * 1.5; +const int WHITE_KEY_BIG_HEIGHT = KEY_LINE_HEIGHT * 2; +const int BLACK_KEY_HEIGHT = round(KEY_LINE_HEIGHT * 1.3333); + + const int NOTE_EDIT_RESIZE_BAR = 6; const int NOTE_EDIT_MIN_HEIGHT = 50; @@ -139,7 +156,7 @@ PianoRoll::PianoRollKeyTypes PianoRoll::prKeyOrder[] = } ; -const int DEFAULT_PR_PPB = KEY_LINE_HEIGHT * DefaultStepsPerBar; +const int DEFAULT_PR_PPB = DEFAULT_KEY_LINE_WIDTH * DefaultStepsPerBar; const QVector PianoRoll::m_zoomLevels = { 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f }; @@ -2884,7 +2901,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) PR_BLACK_KEY ) { // draw it! - p.drawPixmap( PIANO_X, y - WHITE_KEY_SMALL_HEIGHT, + p.drawPixmap( PIANO_X, y - WHITE_KEY_SMALL_HEIGHT, WHITE_KEY_WIDTH, WHITE_KEY_SMALL_HEIGHT, *s_whiteKeySmallPm ); // update y-pos y -= WHITE_KEY_SMALL_HEIGHT / 2; @@ -2901,11 +2918,13 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // draw a small one while checking if it is pressed or not if( hasValidPattern() && m_pattern->instrumentTrack()->pianoModel()->isKeyPressed( key ) ) { - p.drawPixmap( PIANO_X, y - WHITE_KEY_SMALL_HEIGHT, *s_whiteKeySmallPressedPm ); + p.drawPixmap(PIANO_X, y - WHITE_KEY_SMALL_HEIGHT, WHITE_KEY_WIDTH, WHITE_KEY_SMALL_HEIGHT, + *s_whiteKeySmallPressedPm); } else { - p.drawPixmap( PIANO_X, y - WHITE_KEY_SMALL_HEIGHT, *s_whiteKeySmallPm ); + p.drawPixmap(PIANO_X, y - WHITE_KEY_SMALL_HEIGHT, WHITE_KEY_WIDTH, WHITE_KEY_SMALL_HEIGHT, + *s_whiteKeySmallPm); } // update y-pos y -= WHITE_KEY_SMALL_HEIGHT; @@ -2916,11 +2935,13 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // draw a big one while checking if it is pressed or not if( hasValidPattern() && m_pattern->instrumentTrack()->pianoModel()->isKeyPressed( key ) ) { - p.drawPixmap( PIANO_X, y - WHITE_KEY_BIG_HEIGHT, *s_whiteKeyBigPressedPm ); + p.drawPixmap(PIANO_X, y - WHITE_KEY_BIG_HEIGHT, WHITE_KEY_WIDTH, WHITE_KEY_BIG_HEIGHT, + *s_whiteKeyBigPressedPm); } else { - p.drawPixmap( PIANO_X, y-WHITE_KEY_BIG_HEIGHT, *s_whiteKeyBigPm ); + p.drawPixmap(PIANO_X, y-WHITE_KEY_BIG_HEIGHT, WHITE_KEY_WIDTH, WHITE_KEY_BIG_HEIGHT, + *s_whiteKeyBigPm); } // if a big white key has been the first key, // black keys needs to be lifted up @@ -3000,7 +3021,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) PR_BLACK_KEY ) { // draw the black key! - p.drawPixmap( PIANO_X, y - BLACK_KEY_HEIGHT / 2, + p.drawPixmap( PIANO_X, y - BLACK_KEY_HEIGHT / 2, BLACK_KEY_WIDTH, BLACK_KEY_HEIGHT, *s_blackKeyPm ); // is the one after the start-note a black key?? if( prKeyOrder[( key + 1 ) % KeysPerOctave] != @@ -3021,14 +3042,14 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) p.drawPixmap( PIANO_X, y - ( first_white_key_height - WHITE_KEY_SMALL_HEIGHT ) - WHITE_KEY_SMALL_HEIGHT/2 - 1 - - BLACK_KEY_HEIGHT, *s_blackKeyPressedPm ); + BLACK_KEY_HEIGHT, BLACK_KEY_WIDTH, BLACK_KEY_HEIGHT, *s_blackKeyPressedPm ); } else { p.drawPixmap( PIANO_X, y - ( first_white_key_height - WHITE_KEY_SMALL_HEIGHT ) - WHITE_KEY_SMALL_HEIGHT/2 - 1 - - BLACK_KEY_HEIGHT, *s_blackKeyPm ); + BLACK_KEY_HEIGHT, BLACK_KEY_WIDTH, BLACK_KEY_HEIGHT, *s_blackKeyPm ); } // update y-pos y -= WHITE_KEY_BIG_HEIGHT; From 5fca16b13bb2521c940debb844a2a841cf743c70 Mon Sep 17 00:00:00 2001 From: akimaze Date: Tue, 7 Apr 2020 18:53:57 +0200 Subject: [PATCH 02/10] Implemented piano roll vertical zooming. --- include/PianoRoll.h | 12 +++ src/gui/editors/PianoRoll.cpp | 198 +++++++++++++++++++--------------- 2 files changed, 125 insertions(+), 85 deletions(-) diff --git a/include/PianoRoll.h b/include/PianoRoll.h index 27a15149e8a..cad052d311c 100644 --- a/include/PianoRoll.h +++ b/include/PianoRoll.h @@ -192,6 +192,8 @@ class PianoRoll : public QWidget // for entering values with dblclick in the vol/pan bars void enterValue( NoteVector* nv ); + void updateYScroll(); + protected slots: void play(); void record(); @@ -217,6 +219,7 @@ protected slots: void updatePositionStepRecording(const MidiTime & t ); void zoomingChanged(); + void zoomingYChanged(); void quantizeChanged(); void noteLengthChanged(); void quantizeNotes(); @@ -330,12 +333,14 @@ protected slots: static TextFloat * s_textFloat; ComboBoxModel m_zoomingModel; + ComboBoxModel m_zoomingYModel; ComboBoxModel m_quantizeModel; ComboBoxModel m_noteLenModel; ComboBoxModel m_scaleModel; ComboBoxModel m_chordModel; static const QVector m_zoomLevels; + static const QVector m_zoomYLevels; Pattern* m_pattern; NoteVector m_ghostNotes; @@ -385,6 +390,12 @@ protected slots: int m_ppb; // pixels per bar int m_totalKeysToScroll; + static int s_keyLineHeight; + int m_octaveHeight; + int m_whiteKeySmallHeight; + int m_whiteKeyBigHeight; + int m_blackKeyHeight; + // remember these values to use them // for the next note that is set MidiTime m_lenOfNewNotes; @@ -501,6 +512,7 @@ private slots: PianoRoll* m_editor; ComboBox * m_zoomingComboBox; + ComboBox * m_zoomingYComboBox; ComboBox * m_quantizeComboBox; ComboBox * m_noteLenComboBox; ComboBox * m_scaleComboBox; diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 3348f58b21e..6e3f274d20b 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -79,26 +79,9 @@ const int PIANO_X = 0; const int WHITE_KEY_WIDTH = 64; const int BLACK_KEY_WIDTH = 41; -/*const int WHITE_KEY_SMALL_HEIGHT = 18; -const int WHITE_KEY_BIG_HEIGHT = 24; -const int BLACK_KEY_HEIGHT = 16; -const int KEY_LINE_HEIGHT = 12; -const int OCTAVE_HEIGHT = KEY_LINE_HEIGHT * KeysPerOctave; // = 12 * 12;*/ - -// double size -/*const int WHITE_KEY_SMALL_HEIGHT = 27; //18*2; // key line * 1.5 -const int WHITE_KEY_BIG_HEIGHT = 36; //24*2; // key line * 2 -const int BLACK_KEY_HEIGHT = 24; //16*2; // keyline * 1.3333 -const int KEY_LINE_HEIGHT = 18; //12*2; -const int OCTAVE_HEIGHT = KEY_LINE_HEIGHT * KeysPerOctave; // = 12 * 12;*/ - -const int KEY_LINE_HEIGHT = 24; -const int DEFAULT_KEY_LINE_WIDTH = 12; -const int OCTAVE_HEIGHT = KEY_LINE_HEIGHT * KeysPerOctave; -const int WHITE_KEY_SMALL_HEIGHT = KEY_LINE_HEIGHT * 1.5; -const int WHITE_KEY_BIG_HEIGHT = KEY_LINE_HEIGHT * 2; -const int BLACK_KEY_HEIGHT = round(KEY_LINE_HEIGHT * 1.3333); +const int DEFAULT_KEY_LINE_HEIGHT = 12; +const int DEFAULT_CELL_WIDTH = 12; const int NOTE_EDIT_RESIZE_BAR = 6; @@ -138,6 +121,8 @@ QPixmap * PianoRoll::s_toolOpen = NULL; TextFloat * PianoRoll::s_textFloat = NULL; +int PianoRoll::s_keyLineHeight = DEFAULT_KEY_LINE_HEIGHT; + static QString s_noteStrings[12] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; static QString getNoteString( int key ) @@ -145,8 +130,6 @@ static QString getNoteString( int key ) return s_noteStrings[key % 12] + QString::number( static_cast( key / KeysPerOctave ) ); } - - // used for drawing of piano PianoRoll::PianoRollKeyTypes PianoRoll::prKeyOrder[] = { @@ -156,10 +139,13 @@ PianoRoll::PianoRollKeyTypes PianoRoll::prKeyOrder[] = } ; -const int DEFAULT_PR_PPB = DEFAULT_KEY_LINE_WIDTH * DefaultStepsPerBar; +const int DEFAULT_PR_PPB = DEFAULT_CELL_WIDTH * DefaultStepsPerBar; const QVector PianoRoll::m_zoomLevels = - { 0.125f, 0.25f, 0.5f, 1.0f, 2.0f, 4.0f, 8.0f }; + {0.125f, 0.25f, 0.5f, 1.0f, 1.5f, 2.0f, 4.0f, 8.0f}; + +const QVector PianoRoll::m_zoomYLevels = + {0.25f, 0.5f, 1.0f, 1.5f, 2.0f, 2.5f, 3.0f, 4.0f}; PianoRoll::PianoRoll() : @@ -167,6 +153,7 @@ PianoRoll::PianoRoll() : m_noteEditMenu( NULL ), m_semiToneMarkerMenu( NULL ), m_zoomingModel(), + m_zoomingYModel(), m_quantizeModel(), m_noteLenModel(), m_scaleModel(), @@ -188,6 +175,10 @@ PianoRoll::PianoRoll() : m_oldNotesEditHeight( 100 ), m_notesEditHeight( 100 ), m_ppb( DEFAULT_PR_PPB ), + m_octaveHeight(s_keyLineHeight * KeysPerOctave), + m_whiteKeySmallHeight(round(s_keyLineHeight * 1.5)), + m_whiteKeyBigHeight(round(s_keyLineHeight * 2)), + m_blackKeyHeight(round(s_keyLineHeight * 1.3333)), m_lenOfNewNotes( MidiTime( 0, DefaultTicksPerBar/4 ) ), m_lastNoteVolume( DefaultVolume ), m_lastNotePanning( DefaultPanning ), @@ -369,6 +360,15 @@ PianoRoll::PianoRoll() : connect( &m_zoomingModel, SIGNAL( dataChanged() ), this, SLOT( zoomingChanged() ) ); + // zoom y + for (float const & zoomLevel : m_zoomYLevels) + { + m_zoomingYModel.addItem(QString( "%1\%" ).arg(zoomLevel * 100)); + } + m_zoomingYModel.setValue(m_zoomingYModel.findText("100%")); + connect(&m_zoomingYModel, SIGNAL(dataChanged()), + this, SLOT(zoomingYChanged())); + // Set up quantization model m_quantizeModel.addItem( tr( "Note lock" ) ); for( int i = 0; i <= NUM_EVEN_LENGTHS; ++i ) @@ -968,7 +968,7 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, const int borderWidth = borders ? 1 : 0; - const int noteHeight = KEY_LINE_HEIGHT - 1 - borderWidth; + const int noteHeight = s_keyLineHeight - 1 - borderWidth; int noteWidth = width + 1 - borderWidth; // adjust note to make it a bit faded if it has a lower volume @@ -1039,7 +1039,7 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, void PianoRoll::drawDetuningInfo( QPainter & _p, const Note * _n, int _x, int _y ) const { - int middle_y = _y + KEY_LINE_HEIGHT / 2; + int middle_y = _y + s_keyLineHeight / 2; _p.setPen( noteColor() ); _p.setClipRect(WHITE_KEY_WIDTH, PR_TOP_MARGIN, width() - WHITE_KEY_WIDTH, @@ -1056,7 +1056,7 @@ void PianoRoll::drawDetuningInfo( QPainter & _p, const Note * _n, int _x, const float level = it.value(); - int pos_y = middle_y - level * KEY_LINE_HEIGHT; + int pos_y = middle_y - level * s_keyLineHeight; if( old_x != 0 && old_y != 0 ) { @@ -2613,7 +2613,7 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me ) int visible_keys = ( height() - PR_TOP_MARGIN - PR_BOTTOM_MARGIN - m_notesEditHeight ) / - KEY_LINE_HEIGHT + 2; + s_keyLineHeight + 2; const int s_key = m_startKey - 1; if( key_num <= s_key ) @@ -2870,20 +2870,20 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // calculate y_offset according to first key switch( prKeyOrder[m_startKey % KeysPerOctave] ) { - case PR_BLACK_KEY: y_offset = KEY_LINE_HEIGHT / 4; break; - case PR_WHITE_KEY_BIG: y_offset = KEY_LINE_HEIGHT / 2; break; + case PR_BLACK_KEY: y_offset = s_keyLineHeight / 4; break; + case PR_WHITE_KEY_BIG: y_offset = s_keyLineHeight / 2; break; case PR_WHITE_KEY_SMALL: if( prKeyOrder[( ( m_startKey + 1 ) % KeysPerOctave)] != PR_BLACK_KEY ) { - y_offset = KEY_LINE_HEIGHT / 2; + y_offset = s_keyLineHeight / 2; } break; } // start drawing at the bottom int key_line_y = keyAreaBottom() - 1; // used for aligning black-keys later - int first_white_key_height = WHITE_KEY_SMALL_HEIGHT; + int first_white_key_height = m_whiteKeySmallHeight; // key-counter - only needed for finding out whether the processed // key is the first one int keys_processed = 0; @@ -2892,7 +2892,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // draw all white keys... for( int y = key_line_y + 1 + y_offset; y > PR_TOP_MARGIN; - key_line_y -= KEY_LINE_HEIGHT, ++keys_processed ) + key_line_y -= s_keyLineHeight, ++keys_processed ) { // check for white key that is only half visible on the // bottom of piano-roll @@ -2901,16 +2901,16 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) PR_BLACK_KEY ) { // draw it! - p.drawPixmap( PIANO_X, y - WHITE_KEY_SMALL_HEIGHT, WHITE_KEY_WIDTH, WHITE_KEY_SMALL_HEIGHT, + p.drawPixmap( PIANO_X, y - m_whiteKeySmallHeight, WHITE_KEY_WIDTH, m_whiteKeySmallHeight, *s_whiteKeySmallPm ); // update y-pos - y -= WHITE_KEY_SMALL_HEIGHT / 2; + y -= m_whiteKeySmallHeight / 2; // move first black key down (we didn't draw whole // white key so black key needs to be lifted down) // (default for first_white_key_height = - // WHITE_KEY_SMALL_HEIGHT, so WHITE_KEY_SMALL_HEIGHT/2 + // m_whiteKeySmallHeight, so m_whiteKeySmallHeight/2 // is smaller) - first_white_key_height = WHITE_KEY_SMALL_HEIGHT / 2; + first_white_key_height = m_whiteKeySmallHeight / 2; } // check whether to draw a big or a small white key if( prKeyOrder[key % KeysPerOctave] == PR_WHITE_KEY_SMALL ) @@ -2918,16 +2918,16 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // draw a small one while checking if it is pressed or not if( hasValidPattern() && m_pattern->instrumentTrack()->pianoModel()->isKeyPressed( key ) ) { - p.drawPixmap(PIANO_X, y - WHITE_KEY_SMALL_HEIGHT, WHITE_KEY_WIDTH, WHITE_KEY_SMALL_HEIGHT, + p.drawPixmap(PIANO_X, y - m_whiteKeySmallHeight, WHITE_KEY_WIDTH, m_whiteKeySmallHeight, *s_whiteKeySmallPressedPm); } else { - p.drawPixmap(PIANO_X, y - WHITE_KEY_SMALL_HEIGHT, WHITE_KEY_WIDTH, WHITE_KEY_SMALL_HEIGHT, + p.drawPixmap(PIANO_X, y - m_whiteKeySmallHeight, WHITE_KEY_WIDTH, m_whiteKeySmallHeight, *s_whiteKeySmallPm); } // update y-pos - y -= WHITE_KEY_SMALL_HEIGHT; + y -= m_whiteKeySmallHeight; } else if( prKeyOrder[key % KeysPerOctave] == PR_WHITE_KEY_BIG ) @@ -2935,22 +2935,22 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // draw a big one while checking if it is pressed or not if( hasValidPattern() && m_pattern->instrumentTrack()->pianoModel()->isKeyPressed( key ) ) { - p.drawPixmap(PIANO_X, y - WHITE_KEY_BIG_HEIGHT, WHITE_KEY_WIDTH, WHITE_KEY_BIG_HEIGHT, + p.drawPixmap(PIANO_X, y - m_whiteKeyBigHeight, WHITE_KEY_WIDTH, m_whiteKeyBigHeight, *s_whiteKeyBigPressedPm); } else { - p.drawPixmap(PIANO_X, y-WHITE_KEY_BIG_HEIGHT, WHITE_KEY_WIDTH, WHITE_KEY_BIG_HEIGHT, + p.drawPixmap(PIANO_X, y-m_whiteKeyBigHeight, WHITE_KEY_WIDTH, m_whiteKeyBigHeight, *s_whiteKeyBigPm); } // if a big white key has been the first key, // black keys needs to be lifted up if( keys_processed == 0 ) { - first_white_key_height = WHITE_KEY_BIG_HEIGHT; + first_white_key_height = m_whiteKeyBigHeight; } // update y-pos - y -= WHITE_KEY_BIG_HEIGHT; + y -= m_whiteKeyBigHeight; } // Compute the corrections for the note names @@ -2977,7 +2977,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) if( Piano::isWhiteKey( key ) ) { // Draw note names if activated in the preferences, C notes are always drawn - if ( key % 12 == 0 || drawNoteNames ) + if ( (key % 12 == 0 || drawNoteNames) && s_keyLineHeight > 10 ) { QString noteString = getNoteString( key ); @@ -3021,14 +3021,14 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) PR_BLACK_KEY ) { // draw the black key! - p.drawPixmap( PIANO_X, y - BLACK_KEY_HEIGHT / 2, BLACK_KEY_WIDTH, BLACK_KEY_HEIGHT, + p.drawPixmap( PIANO_X, y - m_blackKeyHeight / 2, BLACK_KEY_WIDTH, m_blackKeyHeight, *s_blackKeyPm ); // is the one after the start-note a black key?? if( prKeyOrder[( key + 1 ) % KeysPerOctave] != PR_BLACK_KEY ) { // no, then move it up! - y -= KEY_LINE_HEIGHT / 2; + y -= s_keyLineHeight / 2; } } // current key black? @@ -3040,19 +3040,19 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) if( hasValidPattern() && m_pattern->instrumentTrack()->pianoModel()->isKeyPressed( key ) ) { p.drawPixmap( PIANO_X, y - ( first_white_key_height - - WHITE_KEY_SMALL_HEIGHT ) - - WHITE_KEY_SMALL_HEIGHT/2 - 1 - - BLACK_KEY_HEIGHT, BLACK_KEY_WIDTH, BLACK_KEY_HEIGHT, *s_blackKeyPressedPm ); + m_whiteKeySmallHeight ) - + m_whiteKeySmallHeight/2 - 1 - + m_blackKeyHeight, BLACK_KEY_WIDTH, m_blackKeyHeight, *s_blackKeyPressedPm ); } else { p.drawPixmap( PIANO_X, y - ( first_white_key_height - - WHITE_KEY_SMALL_HEIGHT ) - - WHITE_KEY_SMALL_HEIGHT/2 - 1 - - BLACK_KEY_HEIGHT, BLACK_KEY_WIDTH, BLACK_KEY_HEIGHT, *s_blackKeyPm ); + m_whiteKeySmallHeight ) - + m_whiteKeySmallHeight/2 - 1 - + m_blackKeyHeight, BLACK_KEY_WIDTH, m_blackKeyHeight, *s_blackKeyPm ); } // update y-pos - y -= WHITE_KEY_BIG_HEIGHT; + y -= m_whiteKeyBigHeight; // reset white-counter white_cnt = 0; } @@ -3063,7 +3063,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) ++white_cnt; if( white_cnt > 1 ) { - y -= WHITE_KEY_BIG_HEIGHT/2; + y -= m_whiteKeyBigHeight/2; } } @@ -3124,7 +3124,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // Draw horizontal lines key = m_startKey; for( int y = keyAreaBottom() - 1; y > PR_TOP_MARGIN; - y -= KEY_LINE_HEIGHT ) + y -= s_keyLineHeight ) { if( static_cast( key % KeysPerOctave ) == Key_C ) { @@ -3183,14 +3183,14 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) { const int key_num = m_markedSemiTones.at( i ); const int y = keyAreaBottom() + 5 - - KEY_LINE_HEIGHT * ( key_num - m_startKey + 1 ); + - s_keyLineHeight * ( key_num - m_startKey + 1 ); if( y > keyAreaBottom() ) { break; } - p.fillRect( WHITE_KEY_WIDTH + 1, y - KEY_LINE_HEIGHT / 2, width() - 10, KEY_LINE_HEIGHT + 1, + p.fillRect( WHITE_KEY_WIDTH + 1, y - s_keyLineHeight / 2, width() - 10, s_keyLineHeight + 1, markedSemitoneColor() ); } } @@ -3221,7 +3221,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) height() - PR_TOP_MARGIN ); const int visible_keys = ( keyAreaBottom()-keyAreaTop() ) / - KEY_LINE_HEIGHT + 2; + s_keyLineHeight + 2; QPolygonF editHandles; @@ -3260,7 +3260,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // we've done and checked all, let's draw the // note drawNoteRect( p, x + WHITE_KEY_WIDTH, - y_base - key * KEY_LINE_HEIGHT, + y_base - key * s_keyLineHeight, note_width, note, ghostNoteColor(), ghostNoteTextColor(), selectedNoteColor(), ghostNoteOpacity(), ghostNoteBorders(), drawNoteNames ); } @@ -3302,7 +3302,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // we've done and checked all, let's draw the // note drawNoteRect( p, x + WHITE_KEY_WIDTH, - y_base - key * KEY_LINE_HEIGHT, + y_base - key * s_keyLineHeight, note_width, note, noteColor(), noteTextColor(), selectedNoteColor(), noteOpacity(), noteBorders(), drawNoteNames ); } @@ -3353,7 +3353,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) { drawDetuningInfo( p, note, x + WHITE_KEY_WIDTH, - y_base - key * KEY_LINE_HEIGHT ); + y_base - key * s_keyLineHeight ); p.setClipRect(WHITE_KEY_WIDTH, PR_TOP_MARGIN, width() - WHITE_KEY_WIDTH, height() - PR_TOP_MARGIN); @@ -3389,7 +3389,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // we've done and checked all, let's draw the note drawNoteRect( p, x + WHITE_KEY_WIDTH, - y_base - key * KEY_LINE_HEIGHT, + y_base - key * s_keyLineHeight, note_width, note, m_stepRecorder.curStepNoteColor(), noteTextColor(), selectedNoteColor(), noteOpacity(), noteBorders(), drawNoteNames ); } @@ -3420,8 +3420,8 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) MidiTime::ticksPerBar(); int w = ( ( ( sel_pos_end - m_currentPosition ) * m_ppb ) / MidiTime::ticksPerBar() ) - x; - int y = (int) y_base - sel_key_start * KEY_LINE_HEIGHT; - int h = (int) y_base - sel_key_end * KEY_LINE_HEIGHT - y; + int y = (int) y_base - sel_key_start * s_keyLineHeight; + int h = (int) y_base - sel_key_end * s_keyLineHeight - y; p.setPen( selectedNoteColor() ); p.setBrush( Qt::NoBrush ); p.drawRect( x + WHITE_KEY_WIDTH, y, w, h ); @@ -3447,8 +3447,8 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) if( hasValidPattern() ) { int key_num = getKey( mapFromGlobal( QCursor::pos() ).y() ); - p.fillRect( 10, keyAreaBottom() + 3 - KEY_LINE_HEIGHT * - ( key_num - m_startKey + 1 ), width() - 10, KEY_LINE_HEIGHT - 7, currentKeyCol ); + p.fillRect( 10, keyAreaBottom() + 3 - s_keyLineHeight * + ( key_num - m_startKey + 1 ), width() - 10, s_keyLineHeight - 7, currentKeyCol ); } // bar to resize note edit area @@ -3496,23 +3496,7 @@ void PianoRoll::resizeEvent(QResizeEvent * re) SCROLLBAR_SIZE, width()-WHITE_KEY_WIDTH, SCROLLBAR_SIZE ); - m_topBottomScroll->setGeometry( width() - SCROLLBAR_SIZE, PR_TOP_MARGIN, - SCROLLBAR_SIZE, - height() - PR_TOP_MARGIN - - SCROLLBAR_SIZE ); - - int total_pixels = OCTAVE_HEIGHT * NumOctaves - ( height() - - PR_TOP_MARGIN - PR_BOTTOM_MARGIN - - m_notesEditHeight ); - m_totalKeysToScroll = total_pixels * KeysPerOctave / OCTAVE_HEIGHT; - - m_topBottomScroll->setRange( 0, m_totalKeysToScroll ); - - if( m_startKey > m_totalKeysToScroll ) - { - m_startKey = m_totalKeysToScroll; - } - m_topBottomScroll->setValue( m_totalKeysToScroll - m_startKey ); + updateYScroll(); Engine::getSong()->getPlayPos( Song::Mode_PlayPattern ).m_timeLine->setFixedWidth( width() ); @@ -3685,7 +3669,7 @@ int PianoRoll::getKey(int y ) const { int key_line_y = keyAreaBottom() - 1; // pressed key on piano - int key_num = ( key_line_y - y ) / KEY_LINE_HEIGHT; + int key_num = ( key_line_y - y ) / s_keyLineHeight; key_num += m_startKey; // some range-checking-stuff @@ -4060,6 +4044,28 @@ void PianoRoll::enterValue( NoteVector* nv ) } +void PianoRoll::updateYScroll() +{ + m_topBottomScroll->setGeometry(width() - SCROLLBAR_SIZE, PR_TOP_MARGIN, + SCROLLBAR_SIZE, + height() - PR_TOP_MARGIN - + SCROLLBAR_SIZE); + + int total_pixels = m_octaveHeight * NumOctaves - (height() - + PR_TOP_MARGIN - PR_BOTTOM_MARGIN - + m_notesEditHeight); + m_totalKeysToScroll = total_pixels * KeysPerOctave / m_octaveHeight; + + m_topBottomScroll->setRange(0, m_totalKeysToScroll); + + if(m_startKey > m_totalKeysToScroll) + { + m_startKey = m_totalKeysToScroll; + } + m_topBottomScroll->setValue(m_totalKeysToScroll - m_startKey); +} + + void PianoRoll::copyToClipboard( const NoteVector & notes ) const { DataFile dataFile( DataFile::ClipboardData ); @@ -4300,6 +4306,17 @@ void PianoRoll::zoomingChanged() } +void PianoRoll::zoomingYChanged() +{ + s_keyLineHeight = m_zoomYLevels[m_zoomingYModel.value()] * DEFAULT_KEY_LINE_HEIGHT; + m_octaveHeight = s_keyLineHeight * KeysPerOctave; + m_whiteKeySmallHeight = round(s_keyLineHeight * 1.5); + m_whiteKeyBigHeight = round(s_keyLineHeight * 2); + m_blackKeyHeight = round(s_keyLineHeight * 1.3333); + + updateYScroll(); + update(); +} void PianoRoll::quantizeChanged() @@ -4522,13 +4539,21 @@ PianoRollWindow::PianoRollWindow() : DropToolBar *zoomAndNotesToolBar = addDropToolBarToTop( tr( "Zoom and note controls" ) ); QLabel * zoom_lbl = new QLabel( m_toolBar ); - zoom_lbl->setPixmap( embed::getIconPixmap( "zoom" ) ); + zoom_lbl->setPixmap( embed::getIconPixmap( "zoom_x" ) ); m_zoomingComboBox = new ComboBox( m_toolBar ); m_zoomingComboBox->setModel( &m_editor->m_zoomingModel ); m_zoomingComboBox->setFixedSize( 64, 22 ); m_zoomingComboBox->setToolTip( tr( "Horizontal zooming") ); + QLabel * zoom_y_lbl = new QLabel(m_toolBar); + zoom_y_lbl->setPixmap(embed::getIconPixmap("zoom_y")); + + m_zoomingYComboBox = new ComboBox(m_toolBar); + m_zoomingYComboBox->setModel(&m_editor->m_zoomingYModel); + m_zoomingYComboBox->setFixedSize(64, 22); + m_zoomingYComboBox->setToolTip(tr("Vertical zooming")); + // setup quantize-stuff QLabel * quantize_lbl = new QLabel( m_toolBar ); quantize_lbl->setPixmap( embed::getIconPixmap( "quantize" ) ); @@ -4576,6 +4601,9 @@ PianoRollWindow::PianoRollWindow() : zoomAndNotesToolBar->addWidget( zoom_lbl ); zoomAndNotesToolBar->addWidget( m_zoomingComboBox ); + zoomAndNotesToolBar->addWidget(zoom_y_lbl); + zoomAndNotesToolBar->addWidget(m_zoomingYComboBox); + zoomAndNotesToolBar->addSeparator(); zoomAndNotesToolBar->addWidget( quantize_lbl ); zoomAndNotesToolBar->addWidget( m_quantizeComboBox ); From c69f02677a280ab50b12914ff9747e1741dca4a6 Mon Sep 17 00:00:00 2001 From: akimaze Date: Tue, 14 Apr 2020 16:56:02 +0200 Subject: [PATCH 03/10] Removed static from PianoRoll:drawNoteRect() and s_keyLineHeight --> m_keyLineHeight. --- include/PianoRoll.h | 4 +-- src/gui/editors/PianoRoll.cpp | 67 +++++++++++++++++------------------ 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/include/PianoRoll.h b/include/PianoRoll.h index cad052d311c..8421392c36b 100644 --- a/include/PianoRoll.h +++ b/include/PianoRoll.h @@ -180,7 +180,7 @@ class PianoRoll : public QWidget void focusOutEvent( QFocusEvent * ) override; int getKey( int y ) const; - static void drawNoteRect( QPainter & p, int x, int y, + void drawNoteRect( QPainter & p, int x, int y, int width, const Note * n, const QColor & noteCol, const QColor & noteTextColor, const QColor & selCol, const int noteOpc, const bool borderless, bool drawNoteName ); void removeSelection(); @@ -390,7 +390,7 @@ protected slots: int m_ppb; // pixels per bar int m_totalKeysToScroll; - static int s_keyLineHeight; + int m_keyLineHeight; int m_octaveHeight; int m_whiteKeySmallHeight; int m_whiteKeyBigHeight; diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 6e3f274d20b..5214b086529 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -121,8 +121,6 @@ QPixmap * PianoRoll::s_toolOpen = NULL; TextFloat * PianoRoll::s_textFloat = NULL; -int PianoRoll::s_keyLineHeight = DEFAULT_KEY_LINE_HEIGHT; - static QString s_noteStrings[12] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; static QString getNoteString( int key ) @@ -175,10 +173,11 @@ PianoRoll::PianoRoll() : m_oldNotesEditHeight( 100 ), m_notesEditHeight( 100 ), m_ppb( DEFAULT_PR_PPB ), - m_octaveHeight(s_keyLineHeight * KeysPerOctave), - m_whiteKeySmallHeight(round(s_keyLineHeight * 1.5)), - m_whiteKeyBigHeight(round(s_keyLineHeight * 2)), - m_blackKeyHeight(round(s_keyLineHeight * 1.3333)), + m_keyLineHeight(DEFAULT_KEY_LINE_HEIGHT), + m_octaveHeight(m_keyLineHeight * KeysPerOctave), + m_whiteKeySmallHeight(round(m_keyLineHeight * 1.5)), + m_whiteKeyBigHeight(round(m_keyLineHeight * 2)), + m_blackKeyHeight(round(m_keyLineHeight * 1.3333)), m_lenOfNewNotes( MidiTime( 0, DefaultTicksPerBar/4 ) ), m_lastNoteVolume( DefaultVolume ), m_lastNotePanning( DefaultPanning ), @@ -968,7 +967,7 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, const int borderWidth = borders ? 1 : 0; - const int noteHeight = s_keyLineHeight - 1 - borderWidth; + const int noteHeight = m_keyLineHeight - 1 - borderWidth; int noteWidth = width + 1 - borderWidth; // adjust note to make it a bit faded if it has a lower volume @@ -1039,7 +1038,7 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, void PianoRoll::drawDetuningInfo( QPainter & _p, const Note * _n, int _x, int _y ) const { - int middle_y = _y + s_keyLineHeight / 2; + int middle_y = _y + m_keyLineHeight / 2; _p.setPen( noteColor() ); _p.setClipRect(WHITE_KEY_WIDTH, PR_TOP_MARGIN, width() - WHITE_KEY_WIDTH, @@ -1056,7 +1055,7 @@ void PianoRoll::drawDetuningInfo( QPainter & _p, const Note * _n, int _x, const float level = it.value(); - int pos_y = middle_y - level * s_keyLineHeight; + int pos_y = middle_y - level * m_keyLineHeight; if( old_x != 0 && old_y != 0 ) { @@ -2613,7 +2612,7 @@ void PianoRoll::mouseMoveEvent( QMouseEvent * me ) int visible_keys = ( height() - PR_TOP_MARGIN - PR_BOTTOM_MARGIN - m_notesEditHeight ) / - s_keyLineHeight + 2; + m_keyLineHeight + 2; const int s_key = m_startKey - 1; if( key_num <= s_key ) @@ -2870,13 +2869,13 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // calculate y_offset according to first key switch( prKeyOrder[m_startKey % KeysPerOctave] ) { - case PR_BLACK_KEY: y_offset = s_keyLineHeight / 4; break; - case PR_WHITE_KEY_BIG: y_offset = s_keyLineHeight / 2; break; + case PR_BLACK_KEY: y_offset = m_keyLineHeight / 4; break; + case PR_WHITE_KEY_BIG: y_offset = m_keyLineHeight / 2; break; case PR_WHITE_KEY_SMALL: if( prKeyOrder[( ( m_startKey + 1 ) % KeysPerOctave)] != PR_BLACK_KEY ) { - y_offset = s_keyLineHeight / 2; + y_offset = m_keyLineHeight / 2; } break; } @@ -2892,7 +2891,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // draw all white keys... for( int y = key_line_y + 1 + y_offset; y > PR_TOP_MARGIN; - key_line_y -= s_keyLineHeight, ++keys_processed ) + key_line_y -= m_keyLineHeight, ++keys_processed ) { // check for white key that is only half visible on the // bottom of piano-roll @@ -2977,7 +2976,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) if( Piano::isWhiteKey( key ) ) { // Draw note names if activated in the preferences, C notes are always drawn - if ( (key % 12 == 0 || drawNoteNames) && s_keyLineHeight > 10 ) + if ( (key % 12 == 0 || drawNoteNames) && m_keyLineHeight > 10 ) { QString noteString = getNoteString( key ); @@ -3028,7 +3027,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) PR_BLACK_KEY ) { // no, then move it up! - y -= s_keyLineHeight / 2; + y -= m_keyLineHeight / 2; } } // current key black? @@ -3124,7 +3123,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // Draw horizontal lines key = m_startKey; for( int y = keyAreaBottom() - 1; y > PR_TOP_MARGIN; - y -= s_keyLineHeight ) + y -= m_keyLineHeight ) { if( static_cast( key % KeysPerOctave ) == Key_C ) { @@ -3183,14 +3182,14 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) { const int key_num = m_markedSemiTones.at( i ); const int y = keyAreaBottom() + 5 - - s_keyLineHeight * ( key_num - m_startKey + 1 ); + - m_keyLineHeight * ( key_num - m_startKey + 1 ); if( y > keyAreaBottom() ) { break; } - p.fillRect( WHITE_KEY_WIDTH + 1, y - s_keyLineHeight / 2, width() - 10, s_keyLineHeight + 1, + p.fillRect( WHITE_KEY_WIDTH + 1, y - m_keyLineHeight / 2, width() - 10, m_keyLineHeight + 1, markedSemitoneColor() ); } } @@ -3221,7 +3220,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) height() - PR_TOP_MARGIN ); const int visible_keys = ( keyAreaBottom()-keyAreaTop() ) / - s_keyLineHeight + 2; + m_keyLineHeight + 2; QPolygonF editHandles; @@ -3260,7 +3259,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // we've done and checked all, let's draw the // note drawNoteRect( p, x + WHITE_KEY_WIDTH, - y_base - key * s_keyLineHeight, + y_base - key * m_keyLineHeight, note_width, note, ghostNoteColor(), ghostNoteTextColor(), selectedNoteColor(), ghostNoteOpacity(), ghostNoteBorders(), drawNoteNames ); } @@ -3302,7 +3301,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // we've done and checked all, let's draw the // note drawNoteRect( p, x + WHITE_KEY_WIDTH, - y_base - key * s_keyLineHeight, + y_base - key * m_keyLineHeight, note_width, note, noteColor(), noteTextColor(), selectedNoteColor(), noteOpacity(), noteBorders(), drawNoteNames ); } @@ -3353,7 +3352,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) { drawDetuningInfo( p, note, x + WHITE_KEY_WIDTH, - y_base - key * s_keyLineHeight ); + y_base - key * m_keyLineHeight ); p.setClipRect(WHITE_KEY_WIDTH, PR_TOP_MARGIN, width() - WHITE_KEY_WIDTH, height() - PR_TOP_MARGIN); @@ -3389,7 +3388,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // we've done and checked all, let's draw the note drawNoteRect( p, x + WHITE_KEY_WIDTH, - y_base - key * s_keyLineHeight, + y_base - key * m_keyLineHeight, note_width, note, m_stepRecorder.curStepNoteColor(), noteTextColor(), selectedNoteColor(), noteOpacity(), noteBorders(), drawNoteNames ); } @@ -3420,8 +3419,8 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) MidiTime::ticksPerBar(); int w = ( ( ( sel_pos_end - m_currentPosition ) * m_ppb ) / MidiTime::ticksPerBar() ) - x; - int y = (int) y_base - sel_key_start * s_keyLineHeight; - int h = (int) y_base - sel_key_end * s_keyLineHeight - y; + int y = (int) y_base - sel_key_start * m_keyLineHeight; + int h = (int) y_base - sel_key_end * m_keyLineHeight - y; p.setPen( selectedNoteColor() ); p.setBrush( Qt::NoBrush ); p.drawRect( x + WHITE_KEY_WIDTH, y, w, h ); @@ -3447,8 +3446,8 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) if( hasValidPattern() ) { int key_num = getKey( mapFromGlobal( QCursor::pos() ).y() ); - p.fillRect( 10, keyAreaBottom() + 3 - s_keyLineHeight * - ( key_num - m_startKey + 1 ), width() - 10, s_keyLineHeight - 7, currentKeyCol ); + p.fillRect( 10, keyAreaBottom() + 3 - m_keyLineHeight * + ( key_num - m_startKey + 1 ), width() - 10, m_keyLineHeight - 7, currentKeyCol ); } // bar to resize note edit area @@ -3669,7 +3668,7 @@ int PianoRoll::getKey(int y ) const { int key_line_y = keyAreaBottom() - 1; // pressed key on piano - int key_num = ( key_line_y - y ) / s_keyLineHeight; + int key_num = ( key_line_y - y ) / m_keyLineHeight; key_num += m_startKey; // some range-checking-stuff @@ -4308,11 +4307,11 @@ void PianoRoll::zoomingChanged() void PianoRoll::zoomingYChanged() { - s_keyLineHeight = m_zoomYLevels[m_zoomingYModel.value()] * DEFAULT_KEY_LINE_HEIGHT; - m_octaveHeight = s_keyLineHeight * KeysPerOctave; - m_whiteKeySmallHeight = round(s_keyLineHeight * 1.5); - m_whiteKeyBigHeight = round(s_keyLineHeight * 2); - m_blackKeyHeight = round(s_keyLineHeight * 1.3333); + m_keyLineHeight = m_zoomYLevels[m_zoomingYModel.value()] * DEFAULT_KEY_LINE_HEIGHT; + m_octaveHeight = m_keyLineHeight * KeysPerOctave; + m_whiteKeySmallHeight = round(m_keyLineHeight * 1.5); + m_whiteKeyBigHeight = round(m_keyLineHeight * 2); + m_blackKeyHeight = round(m_keyLineHeight * 1.3333); updateYScroll(); update(); From ff519e4a723f96d910f61af3d1dd7c18ca7ad085 Mon Sep 17 00:00:00 2001 From: akimaze Date: Tue, 14 Apr 2020 17:00:09 +0200 Subject: [PATCH 04/10] Unnecessary round() when multiplying by 2. --- src/gui/editors/PianoRoll.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 5214b086529..1fc549b7ad9 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -176,7 +176,7 @@ PianoRoll::PianoRoll() : m_keyLineHeight(DEFAULT_KEY_LINE_HEIGHT), m_octaveHeight(m_keyLineHeight * KeysPerOctave), m_whiteKeySmallHeight(round(m_keyLineHeight * 1.5)), - m_whiteKeyBigHeight(round(m_keyLineHeight * 2)), + m_whiteKeyBigHeight(m_keyLineHeight * 2), m_blackKeyHeight(round(m_keyLineHeight * 1.3333)), m_lenOfNewNotes( MidiTime( 0, DefaultTicksPerBar/4 ) ), m_lastNoteVolume( DefaultVolume ), @@ -4310,7 +4310,7 @@ void PianoRoll::zoomingYChanged() m_keyLineHeight = m_zoomYLevels[m_zoomingYModel.value()] * DEFAULT_KEY_LINE_HEIGHT; m_octaveHeight = m_keyLineHeight * KeysPerOctave; m_whiteKeySmallHeight = round(m_keyLineHeight * 1.5); - m_whiteKeyBigHeight = round(m_keyLineHeight * 2); + m_whiteKeyBigHeight = m_keyLineHeight * 2; m_blackKeyHeight = round(m_keyLineHeight * 1.3333); updateYScroll(); From 460ffd90071df38080c2f0d59d1b9fff925cd686 Mon Sep 17 00:00:00 2001 From: akimaze Date: Thu, 16 Apr 2020 16:47:20 +0200 Subject: [PATCH 05/10] Center note text vertically. --- src/gui/editors/PianoRoll.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 1fc549b7ad9..d57b7bca78a 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -1009,7 +1009,7 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, int const distanceToBorder = 2; int const xOffset = borderWidth + distanceToBorder; - int const yOffset = (noteHeight + noteTextHeight) / 2; + int const yOffset = ((noteHeight + fontMetrics.capHeight()) * 8 + 8) / 16; if (textSize.width() < noteWidth - xOffset) { From c1ddc58a1ca3402dc167e5f5b10c8a988480800b Mon Sep 17 00:00:00 2001 From: akimaze Date: Thu, 16 Apr 2020 18:17:07 +0200 Subject: [PATCH 06/10] Simplification of calculations. --- src/gui/editors/PianoRoll.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index d57b7bca78a..4249486c53a 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -1009,7 +1009,7 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, int const distanceToBorder = 2; int const xOffset = borderWidth + distanceToBorder; - int const yOffset = ((noteHeight + fontMetrics.capHeight()) * 8 + 8) / 16; + int const yOffset = ((noteHeight + fontMetrics.capHeight()) + 1) / 2; if (textSize.width() < noteWidth - xOffset) { From 4de220f924247192e8d6ebad2ab01f26e800cf64 Mon Sep 17 00:00:00 2001 From: akimaze Date: Mon, 20 Apr 2020 17:34:30 +0200 Subject: [PATCH 07/10] Better note text height calculation (proposed by PhysSong). --- src/gui/editors/PianoRoll.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 4249486c53a..254ce3f2b33 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -1009,7 +1009,12 @@ void PianoRoll::drawNoteRect( QPainter & p, int x, int y, int const distanceToBorder = 2; int const xOffset = borderWidth + distanceToBorder; - int const yOffset = ((noteHeight + fontMetrics.capHeight()) + 1) / 2; + + // 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; if (textSize.width() < noteWidth - xOffset) { From 101c0d290d24dad43ab4b31cfb23c473c5711208 Mon Sep 17 00:00:00 2001 From: akimaze Date: Tue, 21 Apr 2020 17:55:47 +0200 Subject: [PATCH 08/10] Fixed white keys names positions. --- src/gui/editors/PianoRoll.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 254ce3f2b33..99f5ab16cd0 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -2867,6 +2867,8 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // set font-size to 8 p.setFont( pointSize<8>( p.font() ) ); + QFontMetrics fontMetrics(p.font()); + int const fontHeight = fontMetrics.boundingRect(QChar::fromLatin1('H')).height(); // y_offset is used to align the piano-keys on the key-lines int y_offset = 0; @@ -2961,20 +2963,22 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) int yCorrectionForNoteLabels = 0; int keyCode = key % KeysPerOctave; - switch( keyCode ) + switch (keyCode) { - case 0: - case 5: - yCorrectionForNoteLabels = -4; + case 0: // C + case 5: // F + yCorrectionForNoteLabels = (m_whiteKeySmallHeight - fontHeight + 1) / -2; break; - case 2: - case 7: - case 9: - yCorrectionForNoteLabels = -2; + case 2: // D + case 7: // G + case 9: // A + yCorrectionForNoteLabels = (m_whiteKeyBigHeight / 2 - fontHeight + 1) / -2; break; - case 4: - case 11: - yCorrectionForNoteLabels = 2; + case 4: // E + case 11: // B + // calculate center point of key and move half of text + yCorrectionForNoteLabels = -(((m_whiteKeySmallHeight - (m_whiteKeySmallHeight * 2 + 3) / 6) / 4) + - fontHeight / 2); break; } From 78f835e4cf53b99b5ba4fb6a26356c67c074851e Mon Sep 17 00:00:00 2001 From: akimaze Date: Thu, 23 Apr 2020 18:58:24 +0200 Subject: [PATCH 09/10] Change fontMetrics.boundingRect().height() to - boundingRect.top() - boundingRect.bottom() because height() may give a different value for some fonts --- src/gui/editors/PianoRoll.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 99f5ab16cd0..b4ba83d9f5c 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -2868,7 +2868,8 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) // set font-size to 8 p.setFont( pointSize<8>( p.font() ) ); QFontMetrics fontMetrics(p.font()); - int const fontHeight = fontMetrics.boundingRect(QChar::fromLatin1('H')).height(); + QRect const boundingRect = fontMetrics.boundingRect(QChar::fromLatin1('H')); + int const fontHeight = - boundingRect.top() - boundingRect.bottom(); // y_offset is used to align the piano-keys on the key-lines int y_offset = 0; From 1153549cb90f4b66d72e3400452640fa23858ba7 Mon Sep 17 00:00:00 2001 From: akimaze Date: Wed, 29 Apr 2020 16:31:41 +0200 Subject: [PATCH 10/10] Changed name from fontHeight to labelHeight. --- src/gui/editors/PianoRoll.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index b4ba83d9f5c..510fc800ea3 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -2869,7 +2869,9 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) p.setFont( pointSize<8>( p.font() ) ); QFontMetrics fontMetrics(p.font()); QRect const boundingRect = fontMetrics.boundingRect(QChar::fromLatin1('H')); - int const fontHeight = - boundingRect.top() - boundingRect.bottom(); + // This is two times of the y coordinate of the center of the bounding rectangle + // (-(top+bottom)=-2(center)) but labelHeight is more intuitive/describing name + int const labelHeight = - boundingRect.top() - boundingRect.bottom(); // y_offset is used to align the piano-keys on the key-lines int y_offset = 0; @@ -2968,18 +2970,18 @@ void PianoRoll::paintEvent(QPaintEvent * pe ) { case 0: // C case 5: // F - yCorrectionForNoteLabels = (m_whiteKeySmallHeight - fontHeight + 1) / -2; + yCorrectionForNoteLabels = (m_whiteKeySmallHeight - labelHeight + 1) / -2; break; case 2: // D case 7: // G case 9: // A - yCorrectionForNoteLabels = (m_whiteKeyBigHeight / 2 - fontHeight + 1) / -2; + yCorrectionForNoteLabels = (m_whiteKeyBigHeight / 2 - labelHeight + 1) / -2; break; case 4: // E case 11: // B // calculate center point of key and move half of text yCorrectionForNoteLabels = -(((m_whiteKeySmallHeight - (m_whiteKeySmallHeight * 2 + 3) / 6) / 4) - - fontHeight / 2); + - labelHeight / 2); break; }