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

add halve/double controls for beatjump size #4269

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 29 additions & 2 deletions src/engine/controls/loopingcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ LoopingControl::LoopingControl(const QString& group,
this, &LoopingControl::slotBeatJump, Qt::DirectConnection);
m_pCOBeatJumpSize = new ControlObject(ConfigKey(group, "beatjump_size"),
true, false, false, 4.0);

m_pCOBeatJumpSizeHalve = new ControlPushButton(ConfigKey(group, "beatjump_size_halve"));
Copy link
Member

Choose a reason for hiding this comment

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

The delete call is missing if you wish to match the existing code.
A better solution would be using a unique_ptr to manage the live-time

Copy link
Member Author

Choose a reason for hiding this comment

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

for now, I added the delete call and a TODO for unique_ptr.

I could change all controls here to unique_ptr, though, how would I deal with the controls in lists like QList<BeatLoopingControl*> m_beatLoops;? They'd remain regular pointers, right?

Copy link
Member

Choose a reason for hiding this comment

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

QList does not support unique_ptr we may change to std::vector to work around this.

connect(m_pCOBeatJumpSizeHalve,
&ControlObject::valueChanged,
this,
&LoopingControl::slotBeatJumpSizeHalve);
m_pCOBeatJumpSizeDouble = new ControlPushButton(ConfigKey(group, "beatjump_size_double"));
connect(m_pCOBeatJumpSizeDouble,
&ControlObject::valueChanged,
this,
&LoopingControl::slotBeatJumpSizeDouble);

m_pCOBeatJumpForward = new ControlPushButton(ConfigKey(group, "beatjump_forward"));
connect(m_pCOBeatJumpForward, &ControlObject::valueChanged,
this, &LoopingControl::slotBeatJumpForward);
Expand Down Expand Up @@ -211,6 +223,7 @@ LoopingControl::LoopingControl(const QString& group,
}

LoopingControl::~LoopingControl() {
// TODO Use unique_ptr to manage lifetime
delete m_pLoopOutButton;
delete m_pLoopOutGotoButton;
delete m_pLoopInButton;
Expand All @@ -236,6 +249,8 @@ LoopingControl::~LoopingControl() {

delete m_pCOBeatJump;
delete m_pCOBeatJumpSize;
delete m_pCOBeatJumpSizeHalve;
delete m_pCOBeatJumpSizeDouble;
delete m_pCOBeatJumpForward;
delete m_pCOBeatJumpBackward;
while (!m_beatJumps.isEmpty()) {
Expand Down Expand Up @@ -1431,14 +1446,26 @@ void LoopingControl::slotBeatJump(double beats) {
}
}

void LoopingControl::slotBeatJumpSizeHalve(double pressed) {
if (pressed > 0) {
m_pCOBeatJumpSize->set(m_pCOBeatJumpSize->get() / 2);
}
}

void LoopingControl::slotBeatJumpSizeDouble(double pressed) {
if (pressed > 0) {
m_pCOBeatJumpSize->set(m_pCOBeatJumpSize->get() * 2);
}
}

void LoopingControl::slotBeatJumpForward(double pressed) {
if (pressed != 0) {
if (pressed > 0) {
slotBeatJump(m_pCOBeatJumpSize->get());
}
}

void LoopingControl::slotBeatJumpBackward(double pressed) {
if (pressed != 0) {
if (pressed > 0) {
slotBeatJump(-1.0 * m_pCOBeatJumpSize->get());
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/engine/controls/loopingcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class LoopingControl : public EngineControl {

// Jump forward or backward by beats.
void slotBeatJump(double beats);
void slotBeatJumpSizeHalve(double pressed);
void slotBeatJumpSizeDouble(double pressed);
void slotBeatJumpForward(double pressed);
void slotBeatJumpBackward(double pressed);

Expand Down Expand Up @@ -180,6 +182,8 @@ class LoopingControl : public EngineControl {

ControlObject* m_pCOBeatJump;
ControlObject* m_pCOBeatJumpSize;
ControlPushButton* m_pCOBeatJumpSizeHalve;
ControlPushButton* m_pCOBeatJumpSizeDouble;
ControlPushButton* m_pCOBeatJumpForward;
ControlPushButton* m_pCOBeatJumpBackward;
QList<BeatJumpControl*> m_beatJumps;
Expand Down