Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Piano Roll scroll bar improvement #6818

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8a65f98
Move scroll bar range update out of paint event
messmerd Jul 3, 2023
77d8950
I forgot the header
messmerd Jul 3, 2023
5b4f2f9
Set Piano Roll scrollbar based on mouse position over clip
messmerd Jul 16, 2023
fc28f3c
Fix scrollbar position at different zoom levels
messmerd Aug 21, 2023
f6d4619
Slight adjustment
messmerd Aug 21, 2023
332df54
Fix scrollbar when opening clip for 1st time; minor refactoring
messmerd Aug 21, 2023
79ef065
Remove magic value in openInPianoRoll parameter
messmerd Aug 23, 2023
dadbd19
Adjust scrollbar position calculation
messmerd Aug 23, 2023
1e752d8
Fix scrollbar position inaccuracy
messmerd Aug 24, 2023
c9cb14a
Clamp max pos to 1.0; Better naming
messmerd Aug 24, 2023
6eaaebd
Set scrollbar to far left if entire clip can fit on screen
messmerd Aug 26, 2023
cb24111
Merge branch 'master' into piano-roll-scrollbar-dev
messmerd Aug 26, 2023
409b288
Fix build
messmerd Aug 26, 2023
bf4d18f
Fix tests
messmerd Aug 26, 2023
21f34b4
Simplify since scrollbar minimum value is always zero
messmerd Aug 27, 2023
7c265cc
Small adjustment
messmerd Aug 30, 2023
5ff0ffd
Merge branch 'LMMS:master' into piano-roll-scrollbar-dev
messmerd Sep 24, 2023
4050704
Adjust horizontal scrollbar extent in Piano Roll
messmerd Nov 12, 2023
3ff2d8e
Move Automation Editor scrollbar range update out of paint event
messmerd Nov 12, 2023
7200406
Merge remote-tracking branch 'refs/remotes/origin/piano-roll-scrollba…
messmerd Nov 12, 2023
eba4046
Merge branch 'LMMS:master' into piano-roll-scrollbar-dev
messmerd Nov 12, 2023
91e68a3
Adjust horizontal scrollbar extent in Automation Editor
messmerd Nov 15, 2023
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
8 changes: 6 additions & 2 deletions include/AutomationEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
class QPainter;
class QPixmap;
class QScrollBar;
class QGraphicsView;

namespace lmms
{
Expand Down Expand Up @@ -159,6 +160,8 @@ protected slots:
/// Updates the clip's quantization using the current user selected value.
void setQuantization();

void updateLeftRightScrollRange();

private:

enum class Action
Expand Down Expand Up @@ -214,8 +217,9 @@ protected slots:
void centerTopBottomScroll();
void updateTopBottomLevels();

QScrollBar * m_leftRightScroll;
QScrollBar * m_topBottomScroll;
QScrollBar* m_leftRightScroll;
QScrollBar* m_topBottomScroll;
QGraphicsView* m_cornerSquare;

TimePos m_currentPosition;

Expand Down
4 changes: 2 additions & 2 deletions include/Clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class LMMS_EXPORT Clip : public Model, public JournallingObject
return sp + m_length;
}

inline const TimePos & length() const
inline TimePos length() const
{
return m_length;
}
Expand Down Expand Up @@ -129,7 +129,7 @@ class LMMS_EXPORT Clip : public Model, public JournallingObject
}

virtual void movePosition( const TimePos & pos );
virtual void changeLength( const TimePos & length );
virtual void changeLength(TimePos length);

virtual gui::ClipView * createView( gui::TrackView * tv ) = 0;

Expand Down
2 changes: 1 addition & 1 deletion include/ClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ClipView : public selectableObject, public ModelView
ClipView( Clip * clip, TrackView * tv );
~ClipView() override;

bool fixedClips();
bool fixedClips() const;

inline Clip * getClip()
{
Expand Down
9 changes: 7 additions & 2 deletions include/MidiClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class LMMS_EXPORT MidiClip : public Clip
return m_notes;
}

//! Returns exact length (in ticks) instead of length rounded to next bar
inline TimePos exactLength() const
{
return m_exactLength;
}

Note * addStepNote( int step );
void setStep( int step, bool enabled );

Expand Down Expand Up @@ -127,8 +133,6 @@ protected slots:


private:
TimePos beatClipLength() const;

void setType( Type _new_clip_type );
void checkType();

Expand All @@ -141,6 +145,7 @@ protected slots:
// data-stuff
NoteVector m_notes;
int m_steps;
TimePos m_exactLength = 0;

MidiClip * adjacentMidiClipByOffset(int offset) const;

Expand Down
5 changes: 4 additions & 1 deletion include/MidiClipView.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public slots:


protected slots:
void openInPianoRoll();
void openInPianoRoll(double scrollX = 0.0);
void setGhostInPianoRoll();

void resetName();
Expand All @@ -85,6 +85,9 @@ protected slots:


private:
//! Width in pixels of the area where notes are drawn over the clip
float noteAreaWidth() const;

static QPixmap * s_stepBtnOn0;
static QPixmap * s_stepBtnOn200;
static QPixmap * s_stepBtnOff;
Expand Down
7 changes: 6 additions & 1 deletion include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class QScrollBar;
class QString;
class QMenu;
class QToolButton;
class QGraphicsView;

namespace lmms
{
Expand Down Expand Up @@ -125,6 +126,7 @@ class PianoRoll : public QWidget
void setGhostMidiClip( MidiClip* newMidiClip );
void loadGhostNotes( const QDomElement & de );
void loadMarkedSemiTones(const QDomElement & de);
void setScrollbarPos(double posX); //!< posX is in range [0, 1]

inline void stopRecording()
{
Expand Down Expand Up @@ -200,6 +202,7 @@ class PianoRoll : public QWidget
// for entering values with dblclick in the vol/pan bars
void enterValue( NoteVector* nv );

void updateXScroll();
void updateYScroll();

protected slots:
Expand Down Expand Up @@ -249,7 +252,6 @@ protected slots:

void changeSnapMode();


signals:
void currentMidiClipChanged();
void ghostClipSet(bool);
Expand Down Expand Up @@ -372,6 +374,7 @@ protected slots:

QScrollBar * m_leftRightScroll;
QScrollBar * m_topBottomScroll;
QGraphicsView* m_cornerSquare;

TimePos m_currentPosition;
bool m_recording;
Expand Down Expand Up @@ -540,6 +543,8 @@ class PianoRollWindow : public Editor, SerializingObject
QSize sizeHint() const override;
bool hasFocus() const;

void setScrollbarPos(double posX); //!< posX is in range [0, 1]

signals:
void currentMidiClipChanged();

Expand Down
2 changes: 1 addition & 1 deletion include/SampleClip.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SampleClip : public Clip

SampleClip& operator=( const SampleClip& that ) = delete;

void changeLength( const TimePos & _length ) override;
void changeLength(TimePos length) override;
const QString & sampleFile() const;

void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
Expand Down
2 changes: 1 addition & 1 deletion include/TrackView.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class TrackView : public QWidget, public ModelView, public JournallingObject
return m_track;
}

inline TrackContainerView* trackContainerView()
inline TrackContainerView* trackContainerView() const
{
return m_trackContainerView;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ void Clip::movePosition( const TimePos & pos )
* If the clip's length has changed, update it. We
* also add a journal entry for undo and update the display.
*
* \param _length The new length of the clip.
* \param length The new length of the clip in ticks.
*/
void Clip::changeLength( const TimePos & length )
void Clip::changeLength(TimePos length)
{
m_length = length;
Engine::getSong()->updateLength();
Expand Down
4 changes: 2 additions & 2 deletions src/core/SampleClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ SampleClip::~SampleClip()



void SampleClip::changeLength( const TimePos & _length )
void SampleClip::changeLength(TimePos length)
{
Clip::changeLength(std::max(static_cast<int>(_length), 1));
Clip::changeLength(std::max(static_cast<int>(length), 1));
}


Expand Down
2 changes: 1 addition & 1 deletion src/gui/clips/ClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void ClipView::update()
*
* \todo In what circumstance are they fixed?
*/
bool ClipView::fixedClips()
bool ClipView::fixedClips() const
{
return m_trackView->trackContainerView()->fixedClips();
}
Expand Down
18 changes: 12 additions & 6 deletions src/gui/clips/MidiClipView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ void MidiClipView::update()



void MidiClipView::openInPianoRoll()
void MidiClipView::openInPianoRoll(double scrollX)
{
getGUI()->pianoRoll()->setCurrentMidiClip( m_clip );
getGUI()->pianoRoll()->setCurrentMidiClip(m_clip);
getGUI()->pianoRoll()->setScrollbarPos(scrollX);
getGUI()->pianoRoll()->parentWidget()->show();
getGUI()->pianoRoll()->show();
getGUI()->pianoRoll()->setFocus();
Expand Down Expand Up @@ -313,7 +314,9 @@ void MidiClipView::mouseDoubleClickEvent(QMouseEvent *_me)
}
if( m_clip->m_clipType == MidiClip::Type::MelodyClip || !fixedClips() )
{
openInPianoRoll();
// Local X position of mouse over clip's note drawing area, normalized to range of [0, 1]
const auto scrollX = std::min(_me->localPos().x() / noteAreaWidth(), 1.0);
openInPianoRoll(scrollX);
}
}

Expand Down Expand Up @@ -373,6 +376,11 @@ void MidiClipView::wheelEvent(QWheelEvent * we)
}


float MidiClipView::noteAreaWidth() const
{
return fixedClips() ? parentWidget()->width() - 2 * BORDER_WIDTH : width() - BORDER_WIDTH;
}

static int computeNoteRange(int minKey, int maxKey)
{
return (maxKey - minKey) + 1;
Expand Down Expand Up @@ -447,9 +455,7 @@ void MidiClipView::paintEvent( QPaintEvent * )
}

// Compute pixels per bar
const int baseWidth = fixedClips() ? parentWidget()->width() - 2 * BORDER_WIDTH
: width() - BORDER_WIDTH;
const float pixelsPerBar = baseWidth / (float) m_clip->length().getBar();
const float pixelsPerBar = noteAreaWidth() / static_cast<float>(m_clip->length().getBar());

// Length of one bar/beat in the [0,1] x [0,1] coordinate system
const float barLength = 1. / m_clip->length().getBar();
Expand Down
45 changes: 30 additions & 15 deletions src/gui/editors/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <QScrollBar>
#include <QStyleOption>
#include <QToolTip>
#include <QGraphicsView>

#ifndef __USE_XOPEN
#define __USE_XOPEN
Expand Down Expand Up @@ -158,6 +159,9 @@ AutomationEditor::AutomationEditor() :
this, SLOT( updatePosition( const lmms::TimePos& ) ) );

// init scrollbars
m_cornerSquare = new QGraphicsView{this};
m_cornerSquare->setSceneRect(0, 0, SCROLLBAR_SIZE, SCROLLBAR_SIZE);

m_leftRightScroll = new QScrollBar( Qt::Horizontal, this );
m_leftRightScroll->setSingleStep( 1 );
connect( m_leftRightScroll, SIGNAL(valueChanged(int)), this,
Expand Down Expand Up @@ -226,6 +230,7 @@ void AutomationEditor::setCurrentClip(AutomationClip * new_clip )
if (m_clip != nullptr)
{
connect(m_clip, SIGNAL(dataChanged()), this, SLOT(update()));
connect(m_clip, &AutomationClip::lengthChanged, this, &AutomationEditor::updateLeftRightScrollRange);
}

emit currentClipChanged();
Expand Down Expand Up @@ -1379,16 +1384,6 @@ void AutomationEditor::paintEvent(QPaintEvent * pe )
"the context menu of a control!" ) );
}

// TODO: Get this out of paint event
int l = validClip() ? (int) m_clip->length() : 0;

// reset scroll-range
if( m_leftRightScroll->maximum() != l )
{
m_leftRightScroll->setRange( 0, l );
m_leftRightScroll->setPageStep( l );
}

if(validClip() && GuiApplication::instance()->automationEditor()->m_editor->hasFocus())
{
drawCross( p );
Expand Down Expand Up @@ -1528,13 +1523,20 @@ void AutomationEditor::centerTopBottomScroll()
// responsible for moving/resizing scrollbars after window-resizing
void AutomationEditor::resizeEvent(QResizeEvent * re)
{
m_leftRightScroll->setGeometry( VALUES_WIDTH, height() - SCROLLBAR_SIZE,
width() - VALUES_WIDTH,
SCROLLBAR_SIZE );
m_leftRightScroll->setGeometry(
VALUES_WIDTH,
height() - SCROLLBAR_SIZE,
width() - VALUES_WIDTH - SCROLLBAR_SIZE,
SCROLLBAR_SIZE
);

int grid_height = height() - TOP_MARGIN - SCROLLBAR_SIZE;
m_topBottomScroll->setGeometry( width() - SCROLLBAR_SIZE, TOP_MARGIN,
SCROLLBAR_SIZE, grid_height );
m_topBottomScroll->setGeometry(
width() - SCROLLBAR_SIZE,
TOP_MARGIN,
SCROLLBAR_SIZE,
grid_height
);

int half_grid = grid_height / 2;
int total_pixels = (int)( ( m_maxLevel - m_minLevel ) * m_y_delta + 1 );
Expand All @@ -1553,6 +1555,8 @@ void AutomationEditor::resizeEvent(QResizeEvent * re)
}
centerTopBottomScroll();

m_cornerSquare->move(width() - SCROLLBAR_SIZE - 1, height() - SCROLLBAR_SIZE - 1);

if( Engine::getSong() )
{
Engine::getSong()->getPlayPos( Song::PlayMode::AutomationClip
Expand Down Expand Up @@ -1874,6 +1878,17 @@ void AutomationEditor::setQuantization()



void AutomationEditor::updateLeftRightScrollRange()
{
const int length = validClip() ? static_cast<int>(m_clip->length()) : 0;
if (m_leftRightScroll->maximum() != length)
{
m_leftRightScroll->setRange(0, length);
m_leftRightScroll->setPageStep(length);
}
}


void AutomationEditor::updateTopBottomLevels()
{
if( m_y_auto )
Expand Down
Loading