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 20 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
54 changes: 54 additions & 0 deletions include/PlayPos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* PlayPos.h - declaration of class PlayPos, a TimePos with additional features useful for Timelines
*
Copy link
Contributor

@sakertooth sakertooth Dec 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest removing PlayPos and using TimePos directly in Timeline. This class mostly is just a container for data and does not do anything special really.

TimePos can be refactored to store frames as its smallest unit of time (or just store the frame position maybe? do we even need a class just to store the frame position within the tick?). The member functions should then be changed accordingly to account for that as necessary. This might be okay in a separate PR if you feel its out of scope, but I think its minor enough that it shouldn't matter too much to do it in here. Up to you.

Then for the jumped variable, from what I can tell, this just lets us know if the timeline didn't change through time progressively but instead jumped in time. What would it mean for the jumped variable to be true even when the timeline is not jumping? This should be a parameter for the positionChanged signal. You might have to refactor the VST sync controller code for its invocation to be event-based and not executed within Song::processNextBuffer though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure TimePos can easily be refactored to store frames as its smallest unit of time, unless we allow for fractional frames. If the number of frames in a bar is not a whole number, then it will have to be rounded. That's fine, but if the bpm is changed, then every single TimePos will have to be updated at once so that the number of frames matches the correct tick amount. I feel like a better long-term solution would be to allow float tick values, but that's just me.

But I agree, the jumped variable can probably be combined with the positionChanged signal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just storing the frame position directly and still removing PlayPos?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed PlayPos. Now each Timeline stores it's current frame offset and jumped state. I will see if I can get jumped to be passed in the positionChanged signal instead.

* Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* 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_PLAYPOS_H
#define LMMS_PLAYPOS_H

#include "TimePos.h"

namespace lmms
{

class PlayPos : public TimePos
{
public:
PlayPos(const int absolutePosition = 0)
: TimePos{absolutePosition}
, m_currentFrame{0.f}
{
}

auto currentFrame() const -> float { return m_currentFrame; }
void setCurrentFrame( const float f ) { m_currentFrame = f; }
auto jumped() const -> bool { return m_jumped; }
void setJumped(const bool jumped) { m_jumped = jumped; }

private:
float m_currentFrame;
bool m_jumped;
};

} // namespace lmms

#endif // LMMS_PLAYPOS_H
46 changes: 4 additions & 42 deletions include/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "AudioEngine.h"
#include "Controller.h"
#include "Metronome.h"
#include "PlayPos.h"
#include "lmms_constants.h"
#include "MeterModel.h"
#include "Timeline.h"
Expand Down Expand Up @@ -103,36 +104,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 @@ -158,7 +129,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());
regulus79 marked this conversation as resolved.
Show resolved Hide resolved
}

inline void setToTimeByTicks(tick_t ticks)
Expand All @@ -169,7 +140,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,17 +228,9 @@ 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
{
return m_playPos[static_cast<std::size_t>(pm)];
}
inline PlayPos & getPlayPos()
{
return getPlayPos(m_playMode);
return getTimeline(pm).getPlayPos();
}
inline const PlayPos & getPlayPos() const
{
Expand Down Expand Up @@ -492,7 +455,6 @@ private slots:
std::array<Timeline, PlayModeCount> m_timelines;

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

const MidiClip* m_midiClipToPlay;
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,
regulus79 marked this conversation as resolved.
Show resolved Hide resolved
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
34 changes: 33 additions & 1 deletion include/Timeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <QObject>

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

namespace lmms {

Expand All @@ -43,6 +43,36 @@ class Timeline : public QObject, public JournallingObject
KeepPosition
};

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

void setPlayPos(PlayPos 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 currentFrame() const -> float { return m_pos.currentFrame(); }

void setCurrentFrame(const float f)
{
m_pos.setCurrentFrame(f);
}

auto jumped() const -> bool { return m_pos.jumped(); }

void setJumped(const bool jumped)
{
m_pos.setJumped(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 +93,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 +103,7 @@ class Timeline : public QObject, public JournallingObject
TimePos m_loopBegin = TimePos{0};
TimePos m_loopEnd = TimePos{DefaultTicksPerBar};
bool m_loopEnabled = false;
PlayPos m_pos = PlayPos{0};

StopBehaviour m_stopBehaviour = StopBehaviour::BackToStart;
TimePos m_playStartPosition = TimePos{-1};
Expand Down
26 changes: 13 additions & 13 deletions src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void Song::processNextBuffer()
{
m_vstSyncController.setPlaybackJumped(true);
emit updateSampleTracks();
getPlayPos().setJumped(false);
getTimeline().setJumped(false);
}

const auto framesPerTick = Engine::framesPerTick();
Expand All @@ -278,9 +278,9 @@ void Song::processNextBuffer()
{
// 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().setCurrentFrame(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 @@ -343,7 +343,7 @@ void Song::processNextBuffer()
// Update frame counters
frameOffsetInPeriod += framesToPlay;
frameOffsetInTick += framesToPlay;
getPlayPos().setCurrentFrame(frameOffsetInTick);
getTimeline().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;
Expand Down Expand Up @@ -602,9 +602,9 @@ 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 );
getTimeline(playMode).setTicks(ticks);
getTimeline(playMode).setCurrentFrame(0.0f);
getTimeline(playMode).setJumped(true);

// send a signal if playposition changes during playback
if( isPlaying() )
Expand Down Expand Up @@ -660,14 +660,14 @@ void Song::stop()
switch (timeline.stopBehaviour())
{
case Timeline::StopBehaviour::BackToZero:
getPlayPos().setTicks(0);
getTimeline().setTicks(0);
m_elapsedMilliSeconds[static_cast<std::size_t>(m_playMode)] = 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 @@ -679,9 +679,9 @@ void Song::stop()
}

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().setCurrentFrame(0);

m_vstSyncController.setPlaybackState( m_exporting );
m_vstSyncController.setAbsolutePosition(
Expand Down Expand Up @@ -726,7 +726,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 +749,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