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

Refactor to move positionChanged signal to Timeline #7454

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
07c47b5
Add positionChanged signal to Timeline and alter PianoRoll connection
regulus79 Aug 14, 2024
241eedb
Remove SLOT and SIGNAL macros
regulus79 Sep 1, 2024
4efe2b8
Merge branch 'master' into fix-record-play-pianoroll-new
regulus79 Dec 8, 2024
4e4b8d8
Initial changes
regulus79 Dec 9, 2024
e8f5ddb
Cleaning up
regulus79 Dec 11, 2024
840d991
Add getters and setters, do not expose PlayPos for writing without em…
regulus79 Dec 11, 2024
3032b04
Cleaning up again
regulus79 Dec 11, 2024
e22f925
Update include/Timeline.h
regulus79 Dec 12, 2024
f66b9b9
Update include/PlayPos.h
regulus79 Dec 12, 2024
83be137
Change timeline() to model() in TimeLineWidget.h
regulus79 Dec 12, 2024
6467cf6
Rename timeline() to model() in editors
regulus79 Dec 12, 2024
5d2d367
Forgot to change one occurance
regulus79 Dec 12, 2024
4adfe5a
Remove bufferProcessed signal and updatePosition slot
regulus79 Dec 12, 2024
375a6b0
Add return
regulus79 Dec 12, 2024
b80cb42
Specify Qt::DirectConnection
regulus79 Dec 12, 2024
a9e4c0c
Remove TODO
regulus79 Dec 12, 2024
af1e1e2
Change DirectConnection to QueuedConnection and remove argument from …
regulus79 Dec 15, 2024
6ef9b4e
Fix formatting in Song.cpp
regulus79 Dec 16, 2024
f29ad42
Fix more formatting in Song.cpp
regulus79 Dec 16, 2024
1b3c761
Update src/core/Song.cpp
regulus79 Dec 16, 2024
2a50a8c
Pass Timeline to TimeLineWIdget as a pointer
regulus79 Dec 17, 2024
010d649
Replace accidentally-removed connects
regulus79 Dec 17, 2024
4ce6eba
Update src/gui/editors/PianoRoll.cpp
regulus79 Dec 17, 2024
8f7484c
Forgot to add
regulus79 Dec 17, 2024
2e7234f
Remove PlayPos and put frame count and jumped in Timeline
regulus79 Jan 17, 2025
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
2 changes: 1 addition & 1 deletion include/AutomationEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected slots:
void setProgressionType(int type);
void setTension();

void updatePosition( const lmms::TimePos & t );
void updatePosition();

void zoomingXChanged();
void zoomingYChanged();
Expand Down
4 changes: 2 additions & 2 deletions include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ protected slots:
void pasteNotes();
bool deleteSelectedNotes();

void updatePosition(const lmms::TimePos & t );
void updatePositionAccompany(const lmms::TimePos & t );
void updatePosition();
void updatePositionAccompany();
void updatePositionStepRecording(const lmms::TimePos & t );

void zoomingChanged();
Expand Down
60 changes: 7 additions & 53 deletions include/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,36 +103,6 @@ class LMMS_EXPORT Song : public TrackContainer
bool hasErrors();
QString errorSummary();

class PlayPos : public TimePos
{
public:
PlayPos( const int abs = 0 ) :
TimePos( abs ),
m_currentFrame( 0.0f )
{
}
inline void setCurrentFrame( const float f )
{
m_currentFrame = f;
}
inline float currentFrame() const
{
return m_currentFrame;
}
inline void setJumped( const bool jumped )
{
m_jumped = jumped;
}
inline bool jumped() const
{
return m_jumped;
}

private:
float m_currentFrame;
bool m_jumped;
};

void processNextBuffer();

inline int getLoadingTrackCount() const
Expand All @@ -147,7 +117,7 @@ class LMMS_EXPORT Song : public TrackContainer

inline int getMilliseconds(PlayMode playMode) const
{
return m_elapsedMilliSeconds[static_cast<std::size_t>(playMode)];
return 1000 * getFrames() / Engine::audioEngine()->outputSampleRate();
}

inline void setToTime(TimePos const & pos)
Expand All @@ -157,8 +127,7 @@ class LMMS_EXPORT Song : public TrackContainer

inline void setToTime(TimePos const & pos, PlayMode playMode)
{
m_elapsedMilliSeconds[static_cast<std::size_t>(playMode)] = pos.getTimeInMilliseconds(getTempo());
getPlayPos(playMode).setTicks(pos.getTicks());
getTimeline(playMode).setTicks(pos.getTicks());
}

inline void setToTimeByTicks(tick_t ticks)
Expand All @@ -168,8 +137,7 @@ class LMMS_EXPORT Song : public TrackContainer

inline void setToTimeByTicks(tick_t ticks, PlayMode playMode)
{
m_elapsedMilliSeconds[static_cast<std::size_t>(playMode)] = TimePos::ticksToMilliseconds(ticks, getTempo());
getPlayPos(playMode).setTicks(ticks);
getTimeline(playMode).setTicks(ticks);
}

inline int getBars() const
Expand Down Expand Up @@ -257,19 +225,11 @@ class LMMS_EXPORT Song : public TrackContainer
return m_playMode;
}

inline PlayPos & getPlayPos( PlayMode pm )
{
return m_playPos[static_cast<std::size_t>(pm)];
}
inline const PlayPos & getPlayPos( PlayMode pm ) const
inline const TimePos & getPlayPos( PlayMode pm ) const
{
return m_playPos[static_cast<std::size_t>(pm)];
return getTimeline(pm).getPlayPos();
}
inline PlayPos & getPlayPos()
{
return getPlayPos(m_playMode);
}
inline const PlayPos & getPlayPos() const
inline const TimePos & getPlayPos() const
{
return getPlayPos(m_playMode);
}
Expand Down Expand Up @@ -433,8 +393,7 @@ private slots:

inline f_cnt_t currentFrame() const
{
return getPlayPos(m_playMode).getTicks() * Engine::framesPerTick() +
getPlayPos(m_playMode).currentFrame();
return getTimeline(m_playMode).getTicks() * Engine::framesPerTick() + getTimeline(m_playMode).getFrameOffset();
}

void setPlayPos( tick_t ticks, PlayMode playMode );
Expand Down Expand Up @@ -492,16 +451,11 @@ private slots:
std::array<Timeline, PlayModeCount> m_timelines;

PlayMode m_playMode;
PlayPos m_playPos[PlayModeCount];
bar_t m_length;

const MidiClip* m_midiClipToPlay;
bool m_loopMidiClip;

double m_elapsedMilliSeconds[PlayModeCount];
tick_t m_elapsedTicks;
bar_t m_elapsedBars;

VstSyncController m_vstSyncController;

int m_loopRenderCount;
Expand Down
2 changes: 1 addition & 1 deletion include/SongEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public slots:
void setEditModeSelect();
void toggleProportionalSnap();

void updatePosition( const lmms::TimePos & t );
void updatePosition();
void updatePositionLine();
void selectAllClips( bool select );

Expand Down
15 changes: 6 additions & 9 deletions include/TimeLineWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class TimeLineWidget : public QWidget
Disabled
};

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

Expand Down Expand Up @@ -131,11 +131,6 @@ class TimeLineWidget : public QWidget
m_cursorSelectRight = QCursor{m_cursorSelectRight.pixmap(), s.width(), s.height()};
}

inline Song::PlayPos & pos()
{
return( m_pos );
}

AutoScrollState autoScroll() const
{
return m_autoScroll;
Expand All @@ -157,13 +152,16 @@ class TimeLineWidget : public QWidget
m_ppb / TimePos::ticksPerBar() );
}

Timeline* model()
{
return m_timeline;
}

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

public slots:
void updatePosition();
void setSnapSize( const float snapSize )
{
m_snapSize = snapSize;
Expand Down Expand Up @@ -219,7 +217,6 @@ public slots:
int m_xOffset;
float m_ppb;
float m_snapSize = 1.f;
Song::PlayPos & m_pos;
Timeline* m_timeline;
// Leftmost position visible in parent editor
const TimePos & m_begin;
Expand Down
27 changes: 27 additions & 0 deletions include/Timeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ class Timeline : public QObject, public JournallingObject
KeepPosition
};

auto getPlayPos() const -> const TimePos& { return m_pos; }

void setPlayPos(TimePos pos)
{
m_pos = pos;
emit positionChanged();
}

auto getTicks() const -> tick_t { return m_pos.getTicks(); }

void setTicks(tick_t ticks)
{
m_pos.setTicks(ticks);
emit positionChanged();
}

auto getFrameOffset() const -> f_cnt_t { return m_frameOffset; }
void setFrameOffset(const f_cnt_t frame) { m_frameOffset = frame; }

auto getJumped() const -> bool { return m_jumped; }
void setJumped(const bool jumped) { m_jumped = jumped; }

auto loopBegin() const -> TimePos { return m_loopBegin; }
auto loopEnd() const -> TimePos { return m_loopEnd; }
auto loopEnabled() const -> bool { return m_loopEnabled; }
Expand All @@ -63,6 +85,7 @@ class Timeline : public QObject, public JournallingObject
signals:
void loopEnabledChanged(bool enabled);
void stopBehaviourChanged(lmms::Timeline::StopBehaviour behaviour);
void positionChanged();

protected:
void saveSettings(QDomDocument& doc, QDomElement& element) override;
Expand All @@ -72,6 +95,10 @@ class Timeline : public QObject, public JournallingObject
TimePos m_loopBegin = TimePos{0};
TimePos m_loopEnd = TimePos{DefaultTicksPerBar};
bool m_loopEnabled = false;
TimePos m_pos = TimePos{0};

f_cnt_t m_frameOffset = 0;
bool m_jumped = false;

StopBehaviour m_stopBehaviour = StopBehaviour::BackToStart;
TimePos m_playStartPosition = TimePos{-1};
Expand Down
49 changes: 19 additions & 30 deletions src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,10 @@ Song::Song() :
m_length( 0 ),
m_midiClipToPlay( nullptr ),
m_loopMidiClip( false ),
m_elapsedTicks( 0 ),
m_elapsedBars( 0 ),
m_loopRenderCount(1),
m_loopRenderRemaining(1),
m_oldAutomatedValues()
{
for (double& millisecondsElapsed : m_elapsedMilliSeconds) { millisecondsElapsed = 0; }
connect( &m_tempoModel, SIGNAL(dataChanged()),
this, SLOT(setTempo()), Qt::DirectConnection );
connect( &m_tempoModel, SIGNAL(dataUnchanged()),
Expand Down Expand Up @@ -257,11 +254,11 @@ void Song::processNextBuffer()
if (loopEnabled) { enforceLoop(timeline.loopBegin(), timeline.loopEnd()); }

// Inform VST plugins and sample tracks if the user moved the play head
if (getPlayPos().jumped())
if (timeline.getJumped())
{
m_vstSyncController.setPlaybackJumped(true);
emit updateSampleTracks();
getPlayPos().setJumped(false);
getTimeline().setJumped(false);
}

const auto framesPerTick = Engine::framesPerTick();
Expand All @@ -271,16 +268,16 @@ void Song::processNextBuffer()

while (frameOffsetInPeriod < framesPerPeriod)
{
auto frameOffsetInTick = getPlayPos().currentFrame();
auto frameOffsetInTick = timeline.getFrameOffset();

// If a whole tick has elapsed, update the frame and tick count, and check any loops
if (frameOffsetInTick >= framesPerTick)
{
// Transfer any whole ticks from the frame count to the tick count
const auto elapsedTicks = static_cast<int>(frameOffsetInTick / framesPerTick);
getPlayPos().setTicks(getPlayPos().getTicks() + elapsedTicks);
getTimeline().setTicks(getPlayPos().getTicks() + elapsedTicks);
frameOffsetInTick -= elapsedTicks * framesPerTick;
getPlayPos().setCurrentFrame(frameOffsetInTick);
getTimeline().setFrameOffset(frameOffsetInTick);

// If we are playing a pattern track, or a MIDI clip with no loop enabled,
// loop back to the beginning when we reach the end
Expand Down Expand Up @@ -324,7 +321,7 @@ void Song::processNextBuffer()
// This must be done after we've corrected the frame/tick count,
// but before actually playing any frames.
m_vstSyncController.setAbsolutePosition(getPlayPos().getTicks()
+ getPlayPos().currentFrame() / static_cast<double>(framesPerTick));
+ timeline.getFrameOffset() / static_cast<double>(framesPerTick));
m_vstSyncController.update();
}

Expand All @@ -343,10 +340,7 @@ void Song::processNextBuffer()
// Update frame counters
frameOffsetInPeriod += framesToPlay;
frameOffsetInTick += framesToPlay;
getPlayPos().setCurrentFrame(frameOffsetInTick);
m_elapsedMilliSeconds[static_cast<std::size_t>(m_playMode)] += TimePos::ticksToMilliseconds(framesToPlay / framesPerTick, getTempo());
m_elapsedBars = getPlayPos(PlayMode::Song).getBar();
m_elapsedTicks = (getPlayPos(PlayMode::Song).getTicks() % ticksPerBar()) / 48;
getTimeline().setFrameOffset(frameOffsetInTick);
}
}

Expand Down Expand Up @@ -599,14 +593,11 @@ void Song::updateLength()

void Song::setPlayPos( tick_t ticks, PlayMode playMode )
{
tick_t ticksFromPlayMode = getPlayPos(playMode).getTicks();
m_elapsedTicks += ticksFromPlayMode - ticks;
m_elapsedMilliSeconds[static_cast<std::size_t>(playMode)] += TimePos::ticksToMilliseconds( ticks - ticksFromPlayMode, getTempo() );
getPlayPos(playMode).setTicks( ticks );
getPlayPos(playMode).setCurrentFrame( 0.0f );
getPlayPos(playMode).setJumped( true );

// send a signal if playposition changes during playback
getTimeline(playMode).setTicks(ticks);
getTimeline(playMode).setFrameOffset(0.0f);
getTimeline(playMode).setJumped(true);

// send a signal if playposition changes during playback
if( isPlaying() )
{
emit playbackPositionChanged();
Expand Down Expand Up @@ -660,14 +651,13 @@ void Song::stop()
switch (timeline.stopBehaviour())
{
case Timeline::StopBehaviour::BackToZero:
getPlayPos().setTicks(0);
m_elapsedMilliSeconds[static_cast<std::size_t>(m_playMode)] = 0;
getTimeline().setTicks(0);
break;

case Timeline::StopBehaviour::BackToStart:
if (timeline.playStartPosition() >= 0)
{
getPlayPos().setTicks(timeline.playStartPosition().getTicks());
getTimeline().setTicks(timeline.playStartPosition().getTicks());
setToTime(timeline.playStartPosition());

timeline.setPlayStartPosition(-1);
Expand All @@ -678,15 +668,14 @@ void Song::stop()
break;
}

m_elapsedMilliSeconds[static_cast<std::size_t>(PlayMode::None)] = m_elapsedMilliSeconds[static_cast<std::size_t>(m_playMode)];
getPlayPos(PlayMode::None).setTicks(getPlayPos().getTicks());
getTimeline(PlayMode::None).setTicks(getPlayPos().getTicks());

getPlayPos().setCurrentFrame( 0 );
getTimeline().setFrameOffset(0);

m_vstSyncController.setPlaybackState( m_exporting );
m_vstSyncController.setAbsolutePosition(
getPlayPos().getTicks()
+ getPlayPos().currentFrame()
+ timeline.getFrameOffset()
/ (double) Engine::framesPerTick() );

// remove all note-play-handles that are active
Expand Down Expand Up @@ -726,7 +715,7 @@ void Song::startExport()
m_exportSongBegin = m_exportLoopBegin = timeline.loopBegin();
m_exportSongEnd = m_exportLoopEnd = timeline.loopEnd();

getPlayPos(PlayMode::Song).setTicks(timeline.loopBegin().getTicks());
getTimeline(PlayMode::Song).setTicks(timeline.loopBegin().getTicks());
}
else
{
Expand All @@ -749,7 +738,7 @@ void Song::startExport()
? timeline.loopEnd()
: TimePos{0};

getPlayPos(PlayMode::Song).setTicks( 0 );
getTimeline(PlayMode::Song).setTicks(0);
}

m_exportEffectiveLength = (m_exportLoopBegin - m_exportSongBegin) + (m_exportLoopEnd - m_exportLoopBegin)
Expand Down
Loading
Loading