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

lp1336866: Fixed bpm.tapButton in common-controller-script.js #1811

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions res/controllers/common-controller-scripts.js
Expand Up @@ -406,8 +406,8 @@ bpm = function() {
}

bpm.tapTime = 0.0
bpm.previousTapDelta = 0.0
bpm.tap = [] // Tap sample values

/* -------- ------------------------------------------------------
bpm.tapButton
Purpose: Sets the tempo of the track on a deck by tapping the desired beats,
Expand All @@ -421,10 +421,18 @@ bpm.tapButton = function(deck) {
var now = new Date() / 1000 // Current time in seconds
var tapDelta = now - bpm.tapTime
bpm.tapTime = now
if (bpm.tap.length < 1.0) {
Copy link
Member

@Holzhaus Holzhaus Jan 20, 2020

Choose a reason for hiding this comment

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

Isn't bpm.tap.length an integer?

Suggested change
if (bpm.tap.length < 1.0) {
if (bpm.tap.length < 1) {

bpm.previousTapDelta=tapDelta
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bpm.previousTapDelta=tapDelta
bpm.previousTapDelta = tapDelta;

}
// assign tapDelta in cases where the button has not been pressed previously
if (tapDelta > 2.0) { // reset if longer than two seconds between taps
bpm.tap = []
return
}
if ((tapDelta > bpm.previousTapDelta*1.8) || (tapDelta < bpm.previousTapDelta*0.4)) {
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment that explains where these constants come from.

return
}
bpm.previousTapDelta = tapDelta
bpm.tap.push(60 / tapDelta)
if (bpm.tap.length > 8) bpm.tap.shift() // Keep the last 8 samples for averaging
var sum = 0
Expand All @@ -433,7 +441,11 @@ bpm.tapButton = function(deck) {
}
var average = sum / bpm.tap.length

var fRateScale = average / engine.getValue("[Channel" + deck + "]", "bpm")
var fRateScale = average / engine.getValue("[Channel" + deck + "]", "bpm")
// "bpm" was changed in 1.10 to reflect the *adjusted* bpm, but I presume it
// was supposed to return the tracks bpm (which it did before the change).
// "file_bpm" is supposed to return the set BPM of the loaded track of the
// channel.

// Adjust the rate:
fRateScale = (fRateScale - 1.) / engine.getValue("[Channel" + deck + "]", "rateRange")
Expand Down