Skip to content

Commit

Permalink
Enhanced snapping in song editor (#4973)
Browse files Browse the repository at this point in the history
* New default behavior: Preserves offsets when moving clips, resizes in fixed increments.

* Adds shift + drag: Snaps move start position (like current behavior) or end position (new),
based on which is closest to the real position. When moving a selection,
the grabbed clip snaps into position and the rest move relative to it.

* Adds alt + drag: Allows fine adjustment of a clip's position or size,
as an alternative to ctrl + drag.

* Adds a Q dropdown in the song editor to allow finer or coarser snapping (8 bars to 1/16th bar)

* Adds a proportional snap toggle. When enabled, snapping size/Q adjusts based on zoom,
and a label appears showing the current snap size. This is disabled by default.
  • Loading branch information
Spekular authored and PhysSong committed Jul 27, 2019
1 parent 7492e53 commit 1c715bc
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 93 deletions.
Binary file added data/themes/classic/proportional_snap.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/proportional_snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions include/MidiTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LMMS_EXPORT MidiTime
MidiTime( const tact_t tact, const tick_t ticks );
MidiTime( const tick_t ticks = 0 );

MidiTime toNearestTact() const;
MidiTime quantize(float) const;
MidiTime toAbsoluteTact() const;

MidiTime& operator+=( const MidiTime& time );
Expand Down Expand Up @@ -110,4 +110,3 @@ class LMMS_EXPORT MidiTime


#endif

12 changes: 11 additions & 1 deletion include/SongEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@ class SongEditor : public TrackContainerView
void loadSettings( const QDomElement& element );

ComboBoxModel *zoomingModel() const;
ComboBoxModel *snappingModel() const;
float getSnapSize() const;
QString getSnapSizeString() const;

public slots:
void scrolled( int new_pos );

void setEditMode( EditMode mode );
void setEditModeDraw();
void setEditModeSelect();
void toggleProportionalSnap();

void updatePosition( const MidiTime & t );
void updatePositionLine();
Expand Down Expand Up @@ -130,6 +134,8 @@ private slots:
positionLine * m_positionLine;

ComboBoxModel* m_zoomingModel;
ComboBoxModel* m_snappingModel;
bool m_proportionalSnap;

static const QVector<double> m_zoomLevels;

Expand All @@ -141,7 +147,6 @@ private slots:
EditMode m_ctrlMode; // mode they were in before they hit ctrl

friend class SongEditorWindow;

} ;


Expand Down Expand Up @@ -170,6 +175,8 @@ protected slots:
void lostFocus();
void adjustUiAfterProjectLoad();

void updateSnapLabel();

signals:
void playTriggered();
void resized();
Expand All @@ -181,13 +188,16 @@ protected slots:
QAction* m_addBBTrackAction;
QAction* m_addSampleTrackAction;
QAction* m_addAutomationTrackAction;
QAction* m_setProportionalSnapAction;

ActionGroup * m_editModeGroup;
QAction* m_drawModeAction;
QAction* m_selectModeAction;
QAction* m_crtlAction;

ComboBox * m_zoomingComboBox;
ComboBox * m_snappingComboBox;
QLabel* m_snapSizeLabel;
};

#endif
18 changes: 12 additions & 6 deletions include/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class TrackContentObjectView : public selectableObject, public ModelView
// access needsUpdate member variable
bool needsUpdate();
void setNeedsUpdate( bool b );

public slots:
virtual bool close();
void cut();
Expand Down Expand Up @@ -297,6 +297,9 @@ protected slots:
Actions m_action;
QPoint m_initialMousePos;
QPoint m_initialMouseGlobalPos;
MidiTime m_initialTCOPos;
MidiTime m_initialTCOEnd;
QVector<MidiTime> m_initialOffsets;

TextFloat * m_hint;

Expand All @@ -311,14 +314,17 @@ protected slots:
bool m_gradient;

bool m_needsUpdate;
inline void setInitialMousePos( QPoint pos )
inline void setInitialPos( QPoint pos )
{
m_initialMousePos = pos;
m_initialMouseGlobalPos = mapToGlobal( pos );
m_initialTCOPos = m_tco->startPosition();
m_initialTCOEnd = m_initialTCOPos + m_tco->length();
}
void setInitialOffsets();

bool mouseMovedDistance( QMouseEvent * me, int distance );

MidiTime draggedTCOPos( QMouseEvent * me );
} ;


Expand Down Expand Up @@ -564,13 +570,13 @@ class LMMS_EXPORT Track : public Model, public JournallingObject

using Model::dataChanged;

inline int getHeight()
inline int getHeight()
{
return m_height >= MINIMAL_TRACK_HEIGHT
? m_height
? m_height
: DEFAULT_TRACK_HEIGHT;
}
inline void setHeight( int height )
inline void setHeight( int height )
{
m_height = height;
}
Expand Down
Loading

0 comments on commit 1c715bc

Please sign in to comment.