Skip to content

Commit

Permalink
Better keyboard navigation in song editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
teknopaul committed Feb 3, 2017
1 parent da9ba68 commit 1f9a610
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/SongEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private slots:
virtual void wheelEvent( QWheelEvent * we );

virtual bool allowRubberband() const;

void scrollToPos( const MidiTime & t );

Song * m_song;

Expand Down
2 changes: 0 additions & 2 deletions src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,6 @@ void Song::setPlayPos( tick_t ticks, PlayModes playMode )
}




void Song::togglePause()
{
if( m_paused == true )
Expand Down
2 changes: 1 addition & 1 deletion src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,7 @@ void TrackOperationsWidget::disableGroove()
//engine::getMixer()->unlock();
}

/*! \brief Turns off the groove
/*! \brief Turns on the groove
*
*/
void TrackOperationsWidget::enableGroove()
Expand Down
62 changes: 60 additions & 2 deletions src/gui/editors/SongEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "SongEditor.h"

#include <QDebug>

#include <QTimeLine>
#include <QAction>
#include <QButtonGroup>
Expand Down Expand Up @@ -57,7 +59,6 @@
#include "PianoRoll.h"



positionLine::positionLine( QWidget * parent ) :
QWidget( parent )
{
Expand Down Expand Up @@ -344,9 +345,35 @@ void SongEditor::keyPressEvent( QKeyEvent * ke )
m_song->setPlayPos( t, Song::Mode_PlaySong );
}
}
// above don't work onmy machine below does
else if( ke->key() == Qt::Key_Home )
{
m_song->setPlayPos( 0, Song::Mode_PlaySong );
MidiTime mTime = MidiTime(0, 0);
m_song->setPlayPos(mTime.getTicks(), Song::Mode_PlaySong );
m_timeLine->updatePosition( mTime );
this->scrollToPos( mTime );
}
else if( ke->key() == Qt::Key_PageUp || ke->key() == Qt::Key_MediaPrevious )
{
int tact = m_song->m_playPos[Song::Mode_PlaySong].getTact() - 1;
MidiTime mTime = MidiTime(tact > 0 ? tact : 0, 0);
m_song->setPlayPos(mTime.getTicks(), Song::Mode_PlaySong );
m_timeLine->updatePosition( mTime );
this->scrollToPos( mTime );
}
else if( ke->key() == Qt::Key_PageDown || ke->key() == Qt::Key_MediaNext )
{
MidiTime mTime = MidiTime(m_song->m_playPos[Song::Mode_PlaySong].getTact() + 1, 0);
m_song->setPlayPos(mTime.getTicks(), Song::Mode_PlaySong );
m_timeLine->updatePosition( mTime );
this->scrollToPos( mTime );
}
else if( ke->key() == Qt::Key_End )
{
MidiTime mTime = MidiTime(m_song->length(), 0);
m_song->setPlayPos(mTime.getTicks(), Song::Mode_PlaySong );
m_timeLine->updatePosition( mTime );
this->scrollToPos( mTime );
}
else
{
Expand Down Expand Up @@ -608,6 +635,36 @@ bool SongEditor::allowRubberband() const
}


void SongEditor::scrollToPos( const MidiTime & t )
{
int widgetWidth, trackOpWidth;
if( ConfigManager::inst()->value( "ui", "compacttrackbuttons" ).toInt() )
{
widgetWidth = DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT;
trackOpWidth = TRACK_OP_WIDTH_COMPACT;
}
else
{
widgetWidth = DEFAULT_SETTINGS_WIDGET_WIDTH;
trackOpWidth = TRACK_OP_WIDTH;
}

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 * MidiTime::ticksPerTact() /
pixelsPerTact() )
{
animateScroll( m_leftRightScroll, t.getTact(), m_smoothScroll );
}
else if( t < m_currentPosition )
{
animateScroll( m_leftRightScroll, t.getTact(), m_smoothScroll );
}
m_scrollBack = false;
}



ComboBoxModel *SongEditor::zoomingModel() const
Expand Down Expand Up @@ -750,3 +807,4 @@ void SongEditorWindow::adjustUiAfterProjectLoad()
qobject_cast<QMdiSubWindow *>( parentWidget() ) );
m_editor->scrolled(0);
}

0 comments on commit 1f9a610

Please sign in to comment.