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 Sample-Based Play Position Control (m_playposition_samples) #13822

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

urek69mazino
Copy link

This PR introduces a new sample-based control for tracking the play position in samples (m_playposition_samples) within the EngineBuffer class. This enhancement provides more granular access to the play position, simplifying position-based comparisons and calculations in scripts and plugins.

Key Changes
New Sample-Based Control:

Added ControlObject m_playposition_samples in EngineBuffer.
This control provides the play position in samples, facilitating precise playback and position tracking in scripts.
Integration with updateIndicators:

The updateIndicators method now updates m_playposition_samples with the exact play position in samples. This ensures m_playposition_samples is always synchronized with the play position, improving accuracy in playback tracking.
Script Simplification:

This new control simplifies script calculations that previously required manual conversions from fractional play positions to sample positions, streamlining position comparisons and enhancing usability for developers.
Benefits
Improved Accuracy: The new sample-based control provides a finer level of detail than the fractional play position.
Ease of Use for Scripts: Developers can directly access the play position in samples, reducing the need for conversions in scripts.
Backward Compatibility: This change does not affect existing fractional play position controls, maintaining compatibility with prior functionality.
Testing
Verified that m_playposition_samples accurately reflects the play position in samples during playback and seek operations.
Confirmed that m_playposition_samples updates consistently in sync with updateIndicators.

@github-actions github-actions bot added the engine label Nov 2, 2024
@cr7pt0gr4ph7
Copy link
Contributor

cr7pt0gr4ph7 commented Nov 2, 2024

I'd kindly suggest formating your PR messages with Markdown. Especially:

  • code formatting for identifiers like ControlObject or EngineBuffer,
  • bold formatting,
  • headings, and

  • list items

would improve readability :)

(PS: You can edit existing comments/PR messages)

@cr7pt0gr4ph7
Copy link
Contributor

cr7pt0gr4ph7 commented Nov 2, 2024

Just as an example (feel free to copy):


This PR introduces a new sample-based control for tracking the play position in samples (m_playposition_samples) within the EngineBuffer class. This enhancement provides more granular access to the play position, simplifying position-based comparisons and calculations in scripts and plugins.

Key Changes

  • New Sample-Based Control

    Added ControlObject m_playposition_samples in EngineBuffer. This control provides the play position in samples, facilitating precise playback and position tracking in scripts.

  • Integration with updateIndicators

    The updateIndicators method now updates m_playposition_samples with the exact play position in samples. This ensures m_playposition_samples is always synchronized with the play position, improving accuracy in playback tracking.

  • Script Simplification:

    This new control simplifies script calculations that previously required manual conversions from fractional play positions to sample positions, streamlining position comparisons and enhancing usability for developers.

Benefits

  • Improved Accuracy: The new sample-based control provides a finer level of detail than the fractional play position.
  • Ease of Use for Scripts: Developers can directly access the play position in samples, reducing the need for conversions in scripts.
  • Backward Compatibility: This change does not affect existing fractional play position controls, maintaining compatibility with prior functionality.
  • Testing: Verified that m_playposition_samples accurately reflects the play position in samples during playback and seek operations. Confirmed that m_playposition_samples updates consistently in sync with updateIndicators.

Copy link
Contributor

@cr7pt0gr4ph7 cr7pt0gr4ph7 left a comment

Choose a reason for hiding this comment

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

It seems like you're missing the changes to enginebuffer.h in this commit.

@@ -464,6 +466,7 @@ void EngineBuffer::setNewPlaypos(mixxx::audio::FramePos position) {
if (kLogger.traceEnabled()) {
kLogger.trace() << m_group << "EngineBuffer::setNewPlaypos" << position;
}
m_playposition_samples->set(m_playPos.toEngineSamplePos());
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you intend to set m_playposition_samples to the old value before the new play position is applied?

Otherwise, I'm confused why you set m_playposition_samples here instead of at the bottom of setNewPlaypos.

Although, as mentioned in the other comments, m_playposition_samples probably shouldn't even be set here at all, but only in updateIndicators.

@@ -167,6 +167,7 @@ EngineBuffer::EngineBuffer(const QString& group,

m_pRepeat = new ControlPushButton(ConfigKey(m_group, "repeat"));
m_pRepeat->setButtonMode(mixxx::control::ButtonMode::Toggle);
m_playposition_samples = new ControlObject<double>(ConfigKey(m_group, "playposition_samples"));
Copy link
Contributor

@cr7pt0gr4ph7 cr7pt0gr4ph7 Nov 2, 2024

Choose a reason for hiding this comment

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

For consistency reasons, m_playposition_samples should probably intialized directly after m_playposSlider to keep playposition and playposition_samples closer together.

m_playposSlider = new ControlLinPotmeter(
ConfigKey(m_group, "playposition"), 0.0, 1.0, 0, 0, true);
connect(m_playposSlider, &ControlObject::valueChanged,
this, &EngineBuffer::slotControlSeek,
Qt::DirectConnection);

Copy link
Contributor

Choose a reason for hiding this comment

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

Additionally, I'd suggest the name m_playPositionInSamples instead to adhere to camelCase naming conventions and to make the name a bit more descriptive.

Comment on lines +726 to +727
m_playposition_samples->set(position.toEngineSamplePos());

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
m_playposition_samples->set(position.toEngineSamplePos());

m_playposition_samples should only be set in updateIndicators to ensure consistent behavior with the other indicators (see comment above).

Comment on lines +718 to +719
m_playposition_samples->set(position.toEngineSamplePos());

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
m_playposition_samples->set(position.toEngineSamplePos());

m_playposition_samples should only be set in updateIndicators to ensure consistent behavior with the other indicators.

@@ -1457,6 +1464,7 @@ void EngineBuffer::updateIndicators(double speed, int iBufferSize) {
// called yet.
return;
}
m_playposition_samples->set(m_playPos.toEngineSamplePos());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
m_playposition_samples->set(m_playPos.toEngineSamplePos());
// Update playposition_samples CO
m_playposition_samples->set(m_playPos.toEngineSamplePos());

@cr7pt0gr4ph7
Copy link
Contributor

cr7pt0gr4ph7 commented Nov 2, 2024

In general, what is the exact use case of exposing the sample-level play position to controller scripts?

There's a reason why the play position indicators is only updated 15 times/second instead of thousands of times per second.

In general, the sample-level position you obtain in a controller script will probably be outdated before you even have a chance to send it to a controler device...

// Rate at which the playpos slider is updated
constexpr int kPlaypositionUpdateRate = 15; // updates per second

@urek69mazino
Copy link
Author

thankyou for suggesting the changes , i will improve my pull request for the upcoming commits

@urek69mazino
Copy link
Author

I have made the changes suggested by you, but I don't know why when i commit the changes i have made to specific files, other commits also get added , kindly help me

@cr7pt0gr4ph7
Copy link
Contributor

I have made the changes suggested by you, but I don't know why when i commit the changes i have made to specific files, other commits also get added , kindly help me

I'll try :) Push your changes as they are to some branch in your GitHub repository and I'll help & try investigate.

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.

4 participants