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

Add Continuous Auto-Scrolling #7396

Merged
merged 26 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8896860
Initial Commit
regulus79 Jul 23, 2024
5227bc3
Refactor code and add new icons
regulus79 Jul 24, 2024
82f6370
Fix logical error
regulus79 Jul 24, 2024
595c212
Add smooth scrolling to Song Editor
regulus79 Jul 25, 2024
be96a8b
Remove unused variable
regulus79 Jul 25, 2024
58af412
Fix scrolling speed and scrollbar width
regulus79 Jul 25, 2024
ca6aea3
Remove QDebug and re-add a newline I deleted in an unrelated file
regulus79 Jul 25, 2024
518ffb2
Forgot to add files to commit
regulus79 Jul 25, 2024
0ae5a36
Remove unused variable
regulus79 Jul 26, 2024
b841fe9
Fix Styling
regulus79 Jul 26, 2024
4260131
Fix Styling Again
regulus79 Jul 26, 2024
ff9ffbf
Fix Styling Again
regulus79 Jul 26, 2024
a73c1b6
Fix Styling Again
regulus79 Jul 26, 2024
aa6d4bc
Add icons for classic theme
regulus79 Jul 26, 2024
0a16a93
Accidentally committed varying scroll speed with zoom -- removing
regulus79 Jul 26, 2024
87ab276
Change abs to std::abs
regulus79 Jul 26, 2024
e0fd066
Change qMax to std::max and use static_cast
regulus79 Jul 26, 2024
d755987
Simplify stepped auto scrolling
regulus79 Jul 26, 2024
cd80974
Remove unnecessary parentheses
regulus79 Jul 26, 2024
4151b2f
Remove return statement causing the play head line to stop
regulus79 Jul 26, 2024
84cfbda
Add specific tooltips to auto scrolling button states
regulus79 Jul 26, 2024
0017d27
Remove `== true` from SongEditor.cpp
regulus79 Jul 26, 2024
1a4c791
Make tooltips translatable
regulus79 Jul 26, 2024
def4fa6
Fix zooming position calculation
regulus79 Jul 30, 2024
80643b0
Rename bars to ticks
regulus79 Jul 30, 2024
9bfcea7
Fix rubberband rect size
regulus79 Jul 30, 2024
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
Binary file added data/themes/classic/autoscroll_continuous_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/themes/classic/autoscroll_stepped_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/themes/default/autoscroll_continuous_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/themes/default/autoscroll_stepped_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions include/TimeLineWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class TimeLineWidget : public QWidget

enum class AutoScrollState
{
Enabled,
Stepped,
Continuous,
Disabled
};

Expand Down Expand Up @@ -212,7 +213,7 @@ public slots:
QCursor m_cursorSelectLeft = QCursor{embed::getIconPixmap("cursor_select_left"), 0, 16};
QCursor m_cursorSelectRight = QCursor{embed::getIconPixmap("cursor_select_right"), 32, 16};

AutoScrollState m_autoScroll = AutoScrollState::Enabled;
AutoScrollState m_autoScroll = AutoScrollState::Stepped;

// Width of the unused region on the widget's left (above track labels or piano)
int m_xOffset;
Expand Down
32 changes: 19 additions & 13 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4062,7 +4062,7 @@ void PianoRoll::stop()
{
Engine::getSong()->stop();
m_recording = false;
m_scrollBack = ( m_timeLine->autoScroll() == TimeLineWidget::AutoScrollState::Enabled );
m_scrollBack = m_timeLine->autoScroll() != TimeLineWidget::AutoScrollState::Disabled;
}


Expand Down Expand Up @@ -4463,30 +4463,36 @@ bool PianoRoll::deleteSelectedNotes()
void PianoRoll::autoScroll( const TimePos & t )
{
const int w = width() - m_whiteKeyWidth;
if( t > m_currentPosition + w * TimePos::ticksPerBar() / m_ppb )
if (m_timeLine->autoScroll() == TimeLineWidget::AutoScrollState::Stepped)
{
m_leftRightScroll->setValue( t.getBar() * TimePos::ticksPerBar() );
if (t > m_currentPosition + w * TimePos::ticksPerBar() / m_ppb)
{
m_leftRightScroll->setValue(t.getBar() * TimePos::ticksPerBar());
}
else if (t < m_currentPosition)
{
TimePos t2 = std::max(t - w * TimePos::ticksPerBar() *
TimePos::ticksPerBar() / m_ppb, static_cast<tick_t>(0));
m_leftRightScroll->setValue(t2.getBar() * TimePos::ticksPerBar());
}
}
else if( t < m_currentPosition )
else if (m_timeLine->autoScroll() == TimeLineWidget::AutoScrollState::Continuous)
{
TimePos t2 = qMax( t - w * TimePos::ticksPerBar() *
TimePos::ticksPerBar() / m_ppb, (tick_t) 0 );
m_leftRightScroll->setValue( t2.getBar() * TimePos::ticksPerBar() );
m_leftRightScroll->setValue(std::max(t.getTicks() - w * TimePos::ticksPerBar() / m_ppb / 2, 0));
}
m_scrollBack = false;
}




void PianoRoll::updatePosition( const TimePos & t )
void PianoRoll::updatePosition(const TimePos & t)
{
if( ( Engine::getSong()->isPlaying()
if ((Engine::getSong()->isPlaying()
&& Engine::getSong()->playMode() == Song::PlayMode::MidiClip
&& m_timeLine->autoScroll() == TimeLineWidget::AutoScrollState::Enabled
) || m_scrollBack )
&& m_timeLine->autoScroll() != TimeLineWidget::AutoScrollState::Disabled
) || m_scrollBack)
{
autoScroll( t );
autoScroll(t);
}
// ticks relative to m_currentPosition
// < 0 = outside viewport left
Expand Down
57 changes: 30 additions & 27 deletions src/gui/editors/SongEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ SongEditor::SongEditor( Song * song ) :
static_cast<QVBoxLayout *>( layout() )->insertWidget( 0, m_timeLine );

m_leftRightScroll = new QScrollBar( Qt::Horizontal, this );
m_leftRightScroll->setMinimum( 0 );
m_leftRightScroll->setMaximum( 0 );
m_leftRightScroll->setSingleStep( 1 );
m_leftRightScroll->setPageStep( 20 );
m_leftRightScroll->setMinimum(0);
m_leftRightScroll->setMaximum(0);
m_leftRightScroll->setSingleStep(1);
m_leftRightScroll->setPageStep(20 * TimePos::ticksPerBar());
static_cast<QVBoxLayout *>( layout() )->addWidget( m_leftRightScroll );
connect( m_leftRightScroll, SIGNAL(valueChanged(int)),
this, SLOT(scrolled(int)));
Expand Down Expand Up @@ -325,7 +325,7 @@ QString SongEditor::getSnapSizeString() const
void SongEditor::scrolled( int new_pos )
{
update();
emit positionChanged( m_currentPosition = TimePos( new_pos, 0 ) );
emit positionChanged(m_currentPosition = TimePos(new_pos));
}


Expand Down Expand Up @@ -384,7 +384,7 @@ void SongEditor::updateRubberband()
}

//take care of the scrollbar position
int hs = (m_leftRightScroll->value() - m_scrollPos.x()) * pixelsPerBar();
int hs = (m_leftRightScroll->value() - m_scrollPos.x()) * pixelsPerBar() / TimePos::ticksPerBar();
int vs = contentWidget()->verticalScrollBar()->value() - m_scrollPos.y();

//the adjusted origin point
Expand Down Expand Up @@ -522,18 +522,18 @@ void SongEditor::wheelEvent( QWheelEvent * we )
if ((we->modifiers() & Qt::ControlModifier) && (position(we).x() > m_trackHeadWidth))
{
int x = position(we).x() - m_trackHeadWidth;
// bar based on the mouse x-position where the scroll wheel was used
int bar = x / pixelsPerBar();
// tick based on the mouse x-position where the scroll wheel was used
int tick = x / pixelsPerBar() * TimePos::ticksPerBar();

// move zoom slider (pixelsPerBar will change automatically)
int step = we->modifiers() & Qt::ShiftModifier ? 1 : 5;
// when Alt is pressed, wheelEvent returns delta for x coordinate (mimics horizontal mouse wheel)
int direction = (we->angleDelta().y() + we->angleDelta().x()) > 0 ? 1 : -1;
m_zoomingModel->incValue(step * direction);

// scroll to zooming around cursor's bar
int newBar = static_cast<int>(x / pixelsPerBar());
m_leftRightScroll->setValue(m_leftRightScroll->value() + bar - newBar);
// scroll to zooming around cursor's tick
int newTick = static_cast<int>(x / pixelsPerBar() * TimePos::ticksPerBar());
m_leftRightScroll->setValue(m_leftRightScroll->value() + tick - newTick);

// update timeline
m_timeLine->setPixelsPerBar(pixelsPerBar());
Expand All @@ -542,15 +542,15 @@ void SongEditor::wheelEvent( QWheelEvent * we )
}

// FIXME: Reconsider if determining orientation is necessary in Qt6.
else if(abs(we->angleDelta().x()) > abs(we->angleDelta().y())) // scrolling is horizontal
else if (std::abs(we->angleDelta().x()) > std::abs(we->angleDelta().y())) // scrolling is horizontal
{
m_leftRightScroll->setValue(m_leftRightScroll->value() -
we->angleDelta().x() /30);
m_leftRightScroll->setValue(m_leftRightScroll->value()
- we->angleDelta().x());
}
else if(we->modifiers() & Qt::ShiftModifier)
else if (we->modifiers() & Qt::ShiftModifier)
{
m_leftRightScroll->setValue(m_leftRightScroll->value() -
we->angleDelta().y() / 30);
m_leftRightScroll->setValue(m_leftRightScroll->value()
- we->angleDelta().y());
}
else
{
Expand Down Expand Up @@ -711,9 +711,9 @@ void SongEditor::hideMasterPitchFloat( void )



void SongEditor::updateScrollBar( int len )
void SongEditor::updateScrollBar(int len)
{
m_leftRightScroll->setMaximum( len );
m_leftRightScroll->setMaximum(len * TimePos::ticksPerBar());
}


Expand Down Expand Up @@ -756,22 +756,25 @@ void SongEditor::updatePosition( const TimePos & t )
const auto widgetWidth = compactTrackButtons ? DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT : DEFAULT_SETTINGS_WIDGET_WIDTH;
const auto trackOpWidth = compactTrackButtons ? TRACK_OP_WIDTH_COMPACT : TRACK_OP_WIDTH;

if( ( m_song->isPlaying() && m_song->m_playMode == Song::PlayMode::Song
&& m_timeLine->autoScroll() == TimeLineWidget::AutoScrollState::Enabled) ||
m_scrollBack == true )
if ((m_song->isPlaying() && m_song->m_playMode == Song::PlayMode::Song)
|| m_scrollBack)
{
m_smoothScroll = ConfigManager::inst()->value( "ui", "smoothscroll" ).toInt();
const int w = width() - widgetWidth
- trackOpWidth
- contentWidget()->verticalScrollBar()->width(); // width of right scrollbar
if( t > m_currentPosition + w * TimePos::ticksPerBar() /
pixelsPerBar() )

if (m_timeLine->autoScroll() == TimeLineWidget::AutoScrollState::Stepped)
{
animateScroll( m_leftRightScroll, t.getBar(), m_smoothScroll );
const auto nextPosition = m_currentPosition + w * TimePos::ticksPerBar() / pixelsPerBar();
if (t > nextPosition || t < m_currentPosition)
{
animateScroll(m_leftRightScroll, t.getTicks(), m_smoothScroll);
}
}
else if( t < m_currentPosition )
else if (m_timeLine->autoScroll() == TimeLineWidget::AutoScrollState::Continuous)
{
animateScroll( m_leftRightScroll, t.getBar(), m_smoothScroll );
animateScroll(m_leftRightScroll, std::max(t.getTicks() - w * TimePos::ticksPerBar() / pixelsPerBar() / 2, 0.0f), m_smoothScroll);
}
m_scrollBack = false;
}
Expand Down
7 changes: 4 additions & 3 deletions src/gui/editors/TimeLineWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ void TimeLineWidget::setXOffset(const int x)
void TimeLineWidget::addToolButtons( QToolBar * _tool_bar )
{
auto autoScroll = new NStateButton(_tool_bar);
autoScroll->setGeneralToolTip( tr( "Auto scrolling" ) );
autoScroll->addState( embed::getIconPixmap( "autoscroll_on" ) );
autoScroll->addState( embed::getIconPixmap( "autoscroll_off" ) );
autoScroll->setGeneralToolTip(tr("Auto scrolling"));
autoScroll->addState(embed::getIconPixmap("autoscroll_stepped_on"), tr("Stepped auto scrolling"));
autoScroll->addState(embed::getIconPixmap("autoscroll_continuous_on"), tr("Continuous auto scrolling"));
autoScroll->addState(embed::getIconPixmap("autoscroll_off"), tr("Auto scrolling disabled"));
connect( autoScroll, SIGNAL(changedState(int)), this,
SLOT(toggleAutoScroll(int)));

Expand Down
5 changes: 3 additions & 2 deletions src/gui/tracks/TrackContentWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ void TrackContentWidget::changePosition( const TimePos & newPos )
setUpdatesEnabled( true );

// redraw background
updateBackground();
// update();
}

Expand Down Expand Up @@ -628,8 +629,8 @@ void TrackContentWidget::paintEvent( QPaintEvent * pe )
// Don't draw background on Pattern Editor
if (m_trackView->trackContainerView() != getGUI()->patternEditor()->m_editor)
{
p.drawTiledPixmap( rect(), m_background, QPoint(
tcv->currentPosition().getBar() * ppb, 0 ) );
p.drawTiledPixmap(rect(), m_background, QPoint(
tcv->currentPosition().getTicks() * ppb / TimePos::ticksPerBar(), 0));
}
}

Expand Down
Loading