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

Sync Lock: minor refactoring. #3695

Merged
merged 1 commit into from
Mar 14, 2021
Merged

Conversation

ywwg
Copy link
Member

@ywwg ywwg commented Mar 12, 2021

This refactoring sets up a major major patching coming in for sync lock! Get hyped.
This is mostly a noop PR

@ywwg
Copy link
Member Author

ywwg commented Mar 12, 2021

There are also a couple of debug trace additions that were useful during testing

src/engine/sync/basesyncablelistener.h Outdated Show resolved Hide resolved
src/engine/sync/enginesync.h Outdated Show resolved Hide resolved
@ywwg ywwg mentioned this pull request Mar 12, 2021
@ywwg
Copy link
Member Author

ywwg commented Mar 12, 2021

However I'm not doing the huge master -> Leader rename just yet. I want to wait until the big patch goes in, and then I'll do a mass rename.

@ywwg
Copy link
Member Author

ywwg commented Mar 12, 2021

The moment the Big Patch (#3698) is approved that will happen

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

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

What is the case this PR shall fix?

In my test, I have set the reverse control of one or both track. My expectation is that the beats are in sync in the same way as if the track where played forward.

The tempo sync works flawlessly. However the phase sync fails.
I have tested the quantize play and seeks using the waveform overview.
In forward mode it stays in sync, in backward mode it fails.

@ywwg
Copy link
Member Author

ywwg commented Mar 12, 2021

I'll check that. This fix was for an obsolete situation with one-track-scratching-another, so it only really applies when both tracks are moving forward or backward together. Maybe I should just remove that bit?

@@ -470,6 +470,11 @@ double BpmControl::calcSyncAdjustment(bool userTweakingSync) {
double syncTargetBeatDistance = m_dSyncTargetBeatDistance.getValue();
Copy link
Member

Choose a reason for hiding this comment

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

This can make use of a comment.
// This is the distance from the last beat in forward direction.

I am not sure if it is a good idea to use the forward direction in a "beat_distance" control.
We need here the distance from the last beat in play direction. I think it can be expected that the "beat_distance" control does this natively. Otherwise we need here the play direction of the sync target.

Copy link
Member

Choose a reason for hiding this comment

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

No, I think it should always use the forward direction, like this:

|---|  -> 0.0/1.0
^   
|---|  -> 0.75
 ^   
|---|  -> 0.5
  ^   
|---|  -> 0.25
   ^   
|---|  -> 0.0/1.0
    ^   

Copy link
Member

Choose a reason for hiding this comment

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

What else do we use "beat_distance" for?
If we need to know in every single place the direction as well to make use of this value, it is a good indicator that the current forward only implementation is too unhandy and error prone.

Copy link
Member

Choose a reason for hiding this comment

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

My mapping uses it for the glowing ring around the jog wheels: 876cd47

Copy link
Member

Choose a reason for hiding this comment

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

It looks like your code is also broken in reverse direction an will benefit from the change.
When I got it right it re-implements the "beat_active" control which will be fixed with #3608.

Copy link
Member

@Holzhaus Holzhaus Mar 13, 2021

Choose a reason for hiding this comment

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

What it does is it calculates the position in the bar (or rather: the position in a series of 4 beats) and transforms it into a Midi value between 0x00 and 0x7F. That illuminates to a led indicator around the jog wheels where 0x00 is the 12 o'clock position, 0x20 is 3 o'clock, 0x40 is 6 o'clock, and so on.

You can see it in this video on left deck: https://youtu.be/2QqVZkZuA0g

It doesn't work correctly when playing backwards, but that's unrelated to beat_distance. The issue is that I just count up beat indices to get the beat in the measure because we don't have that yet. If we had something like current_beat_index_in_measure CO, it would work perfectly.

If we suddenly change the beat distance value when the playback direction changes, it wouldn't work and it would be impossible to fix it at all, even if we had - measure detection COs.

Copy link
Member Author

Choose a reason for hiding this comment

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

This should be fixable by changing the getBeatDistance code in syncable.cpp. Much like the half/double calculation, if we do all the conversion in the syncable code, the rest of the program can pretend that all the decks are moving forwards and it should work fine

@@ -470,6 +470,11 @@ double BpmControl::calcSyncAdjustment(bool userTweakingSync) {
double syncTargetBeatDistance = m_dSyncTargetBeatDistance.getValue();
// We want the untweaked beat distance, so we have to add the offset here.
double thisBeatDistance = m_pThisBeatDistance->get() + m_dUserOffset.getValue();
// If we are moving backwards, we have to invert the calculations.
if (reversed) {
syncTargetBeatDistance = 1.0 - syncTargetBeatDistance;
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be applied if the sync target plays reverse, not the follower.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah. removing

@@ -470,6 +470,11 @@ double BpmControl::calcSyncAdjustment(bool userTweakingSync) {
double syncTargetBeatDistance = m_dSyncTargetBeatDistance.getValue();
// We want the untweaked beat distance, so we have to add the offset here.
double thisBeatDistance = m_pThisBeatDistance->get() + m_dUserOffset.getValue();
Copy link
Member

Choose a reason for hiding this comment

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

Below (line 496) we aim to undo the added offset. This will move in the opposite direction if we are in reverse mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

oo good point

@daschuer
Copy link
Member

I'll check that. This fix was for an obsolete situation with one-track-scratching-another, so it only really applies when both tracks are moving forward or backward together. Maybe I should just remove that bit?

For my understanding you have discovered a bug, that should be fixed. Even though it is a rare situation, the sync should be rock solid.

@ywwg
Copy link
Member Author

ywwg commented Mar 13, 2021

I agree. But this is not the PR to do it. I'm going to remove the backwards fix, because it's incomplete. So this PR will only be a slight rename / refactor

@ywwg
Copy link
Member Author

ywwg commented Mar 13, 2021

I'll file a bug

@ywwg
Copy link
Member Author

ywwg commented Mar 13, 2021

@daschuer
Copy link
Member

Thank you for adopting the bug. Will you add a solution here or in a separate PR. In the later case, I suggest to rebase this PR without the first commit.

@ywwg ywwg force-pushed the synclock-fixandrefactor branch from 4e0006f to c8a2300 Compare March 14, 2021 20:50
@ywwg
Copy link
Member Author

ywwg commented Mar 14, 2021

I'll fix it in a later PR. I had to squash all the commits to do it right

Copy link
Member

@Holzhaus Holzhaus left a comment

Choose a reason for hiding this comment

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

Does this PR contain any functional changes?

  • Replace "Bpm" with "BaseBpm" in some method/variable names
  • Add isFollower helper method
  • Rename snake_case variables with camelCase
  • Add some trace logging
  • Add a few comments

If I didn't miss anything, I think this is good to merge, despite the misleading PR title.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

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

LGTM, Thank you.

@daschuer daschuer changed the title Sync Lock: fix bad sync in reverse. Also minor refactoring. Sync Lock: minor refactoring. Mar 14, 2021
@daschuer daschuer merged commit c938e6f into mixxxdj:main Mar 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants