Skip to content

Commit

Permalink
Split TimeLineWidget into core and GUI parts (#7004)
Browse files Browse the repository at this point in the history
  • Loading branch information
DomClark authored Dec 16, 2023
1 parent 8136b70 commit f3d3a14
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 375 deletions.
1 change: 0 additions & 1 deletion include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ private slots:
void onExportProject();
void onExportProjectTracks();
void onImportProject();
void onSongStopped();
void onSongModified();
void onProjectFileNameChanged();

Expand Down
15 changes: 5 additions & 10 deletions include/NStateButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,20 @@ class NStateButton : public ToolButton


public slots:
void changeState( int _n );

void changeState(int state);

signals:
void changedState( int _n );

void changedState(int state);

protected:
void mousePressEvent( QMouseEvent * _me ) override;

void mousePressEvent(QMouseEvent* me) override;

private:
QVector<QPair<QPixmap, QString> > m_states;
QVector<QPair<QPixmap, QString>> m_states;
QString m_generalToolTip;

int m_curState;

} ;

};

} // namespace lmms::gui

Expand Down
18 changes: 12 additions & 6 deletions include/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@
#ifndef LMMS_SONG_H
#define LMMS_SONG_H

#include <array>
#include <memory>

#include <QHash>
#include <QString>

#include "TrackContainer.h"
#include "AudioEngine.h"
#include "Controller.h"
#include "lmms_constants.h"
#include "MeterModel.h"
#include "Timeline.h"
#include "TrackContainer.h"
#include "VstSyncController.h"

namespace lmms
Expand Down Expand Up @@ -105,7 +107,6 @@ class LMMS_EXPORT Song : public TrackContainer
public:
PlayPos( const int abs = 0 ) :
TimePos( abs ),
m_timeLine( nullptr ),
m_currentFrame( 0.0f )
{
}
Expand All @@ -125,13 +126,11 @@ class LMMS_EXPORT Song : public TrackContainer
{
return m_jumped;
}
gui::TimeLineWidget * m_timeLine;

private:
float m_currentFrame;
bool m_jumped;

} ;
};

void processNextBuffer();

Expand Down Expand Up @@ -274,6 +273,11 @@ class LMMS_EXPORT Song : public TrackContainer
return getPlayPos(m_playMode);
}

auto getTimeline(PlayMode mode) -> Timeline& { return m_timelines[static_cast<std::size_t>(mode)]; }
auto getTimeline(PlayMode mode) const -> const Timeline& { return m_timelines[static_cast<std::size_t>(mode)]; }
auto getTimeline() -> Timeline& { return getTimeline(m_playMode); }
auto getTimeline() const -> const Timeline& { return getTimeline(m_playMode); }

void updateLength();
bar_t length() const
{
Expand Down Expand Up @@ -402,7 +406,7 @@ private slots:

void masterVolumeChanged();

void savePos();
void savePlayStartPosition();

void updateFramesPerTick();

Expand Down Expand Up @@ -481,6 +485,8 @@ private slots:

QHash<QString, int> m_errors;

std::array<Timeline, PlayModeCount> m_timelines;

PlayMode m_playMode;
PlayPos m_playPos[PlayModeCount];
bar_t m_length;
Expand Down
103 changes: 14 additions & 89 deletions include/TimeLineWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
class QPixmap;
class QToolBar;

namespace lmms {

class Timeline;

} // namespace lmms

namespace lmms::gui
{

Expand All @@ -42,7 +48,7 @@ class TextFloat;
class SongEditor;


class TimeLineWidget : public QWidget, public JournallingObject
class TimeLineWidget : public QWidget
{
Q_OBJECT
public:
Expand All @@ -60,24 +66,10 @@ class TimeLineWidget : public QWidget, public JournallingObject
{
Enabled,
Disabled
} ;

enum class LoopPointState
{
Disabled,
Enabled
} ;

enum class BehaviourAtStopState
{
BackToZero,
BackToStart,
KeepStopPosition
} ;

};

TimeLineWidget(int xoff, int yoff, float ppb, Song::PlayPos & pos,
const TimePos & begin, Song::PlayMode mode, QWidget * parent);
TimeLineWidget(int xoff, int yoff, float ppb, Song::PlayPos& pos, Timeline& timeline,
const TimePos& begin, Song::PlayMode mode, QWidget* parent);
~TimeLineWidget() override;

inline QColor const & getBarLineColor() const { return m_barLineColor; }
Expand Down Expand Up @@ -117,42 +109,6 @@ class TimeLineWidget : public QWidget, public JournallingObject
return m_autoScroll;
}

BehaviourAtStopState behaviourAtStop() const
{
return m_behaviourAtStop;
}

void setBehaviourAtStop (int state)
{
emit loadBehaviourAtStop (state);
}

bool loopPointsEnabled() const
{
return m_loopPoints == LoopPointState::Enabled;
}

inline const TimePos & loopBegin() const
{
return ( m_loopPos[0] < m_loopPos[1] ) ?
m_loopPos[0] : m_loopPos[1];
}

inline const TimePos & loopEnd() const
{
return ( m_loopPos[0] > m_loopPos[1] ) ?
m_loopPos[0] : m_loopPos[1];
}

inline void savePos( const TimePos & pos )
{
m_savedPos = pos;
}
inline const TimePos & savedPos() const
{
return m_savedPos;
}

inline void setPixelsPerBar( float ppb )
{
m_ppb = ppb;
Expand All @@ -163,40 +119,24 @@ class TimeLineWidget : public QWidget, public JournallingObject

void addToolButtons(QToolBar* _tool_bar );


void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
void loadSettings( const QDomElement & _this ) override;
inline QString nodeName() const override
{
return "timeline";
}

inline int markerX( const TimePos & _t ) const
{
return m_xOffset + static_cast<int>( ( _t - m_begin ) *
m_ppb / TimePos::ticksPerBar() );
}

signals:

void positionChanged(const lmms::TimePos& postion);
void regionSelectedFromPixels( int, int );
void selectionFinished();


public slots:
void updatePosition( const lmms::TimePos & );
void updatePosition()
{
updatePosition( TimePos() );
}
void updatePosition();
void setSnapSize( const float snapSize )
{
m_snapSize = snapSize;
}
void toggleAutoScroll( int _n );
void toggleLoopPoints( int _n );
void toggleBehaviourAtStop( int _n );


protected:
void paintEvent( QPaintEvent * _pe ) override;
Expand All @@ -222,8 +162,6 @@ public slots:
QColor m_barNumberColor;

AutoScrollState m_autoScroll;
LoopPointState m_loopPoints;
BehaviourAtStopState m_behaviourAtStop;

bool m_changedPosition;

Expand All @@ -232,12 +170,9 @@ public slots:
float m_ppb;
float m_snapSize;
Song::PlayPos & m_pos;
Timeline* m_timeline;
const TimePos & m_begin;
const Song::PlayMode m_mode;
TimePos m_loopPos[2];

TimePos m_savedPos;


TextFloat * m_hint;
int m_initalXSelect;
Expand All @@ -253,17 +188,7 @@ public slots:
} m_action;

int m_moveXOff;


signals:
void positionChanged( const lmms::TimePos & _t );
void loopPointStateLoaded( int _n );
void positionMarkerMoved();
void loadBehaviourAtStop( int _n );

} ;


};

} // namespace lmms::gui

Expand Down
82 changes: 82 additions & 0 deletions include/Timeline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Timeline.h
*
* Copyright (c) 2023 Dominic Clark
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*/

#ifndef LMMS_TIMELINE_H
#define LMMS_TIMELINE_H

#include <QObject>

#include "JournallingObject.h"
#include "TimePos.h"

namespace lmms {

class Timeline : public QObject, public JournallingObject
{
Q_OBJECT

public:
enum class StopBehaviour
{
BackToZero,
BackToStart,
KeepPosition
};

auto loopBegin() const -> TimePos { return m_loopBegin; }
auto loopEnd() const -> TimePos { return m_loopEnd; }
auto loopEnabled() const -> bool { return m_loopEnabled; }

void setLoopBegin(TimePos begin);
void setLoopEnd(TimePos end);
void setLoopPoints(TimePos begin, TimePos end);
void setLoopEnabled(bool enabled);

auto playStartPosition() const -> TimePos { return m_playStartPosition; }
auto stopBehaviour() const -> StopBehaviour { return m_stopBehaviour; }

void setPlayStartPosition(TimePos position) { m_playStartPosition = position; }
void setStopBehaviour(StopBehaviour behaviour);

auto nodeName() const -> QString override { return "timeline"; }

signals:
void loopEnabledChanged(bool enabled);
void stopBehaviourChanged(lmms::Timeline::StopBehaviour behaviour);

protected:
void saveSettings(QDomDocument& doc, QDomElement& element) override;
void loadSettings(const QDomElement& element) override;

private:
TimePos m_loopBegin = TimePos{0};
TimePos m_loopEnd = TimePos{DefaultTicksPerBar};
bool m_loopEnabled = false;

StopBehaviour m_stopBehaviour = StopBehaviour::BackToStart;
TimePos m_playStartPosition = TimePos{-1};
};

} // namespace lmms

#endif // LMMS_TIMELINE_H
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ set(LMMS_SRCS
core/SerializingObject.cpp
core/Song.cpp
core/TempoSyncKnobModel.cpp
core/Timeline.cpp
core/TimePos.cpp
core/ToolPlugin.cpp
core/Track.cpp
Expand Down
8 changes: 1 addition & 7 deletions src/core/SampleClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,10 @@ SampleClip::SampleClip( Track * _track ) :
connect( Engine::getSong(), SIGNAL(timeSignatureChanged(int,int)),
this, SLOT(updateLength()));

//care about positionmarker
gui::TimeLineWidget* timeLine = Engine::getSong()->getPlayPos( Song::PlayMode::Song ).m_timeLine;
if( timeLine )
{
connect( timeLine, SIGNAL(positionMarkerMoved()), this, SLOT(playbackPositionChanged()));
}
//playbutton clicked or space key / on Export Song set isPlaying to false
connect( Engine::getSong(), SIGNAL(playbackStateChanged()),
this, SLOT(playbackPositionChanged()), Qt::DirectConnection );
//care about loops
//care about loops and jumps
connect( Engine::getSong(), SIGNAL(updateSampleTracks()),
this, SLOT(playbackPositionChanged()), Qt::DirectConnection );
//care about mute Clips
Expand Down
Loading

0 comments on commit f3d3a14

Please sign in to comment.