summaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2020-04-17 21:00:53 +0200
committerGitHub <noreply@github.com>2020-04-17 21:00:53 +0200
commit163e3b72a4f1e7306973f59171bba80cd8ac1c55 (patch)
treeea8222e085e2eaaeecfc1366e3247e46d7970b58 /res
parent009598fa8e05148fb191b83023f3344bbc518319 (diff)
parent246b9c2f4d04d6f0d0c89da250cf4590b41eb27c (diff)
Merge pull request #2594 from Swiftb0y/tapButtonFix
Fixed bpm.tapButton in common-controller-script.js
Diffstat (limited to 'res')
-rw-r--r--res/controllers/common-controller-scripts.js71
1 files changed, 47 insertions, 24 deletions
diff --git a/res/controllers/common-controller-scripts.js b/res/controllers/common-controller-scripts.js
index c1d2d09f58..7355649ee1 100644
--- a/res/controllers/common-controller-scripts.js
+++ b/res/controllers/common-controller-scripts.js
@@ -268,13 +268,13 @@ script.absoluteNonLinInverse = function(value, low, mid, high, min, max) {
if (!max) {
max = 127
}
- var center = (max - min) / 2
- var result
+ var center = (max - min) / 2;
+ var result;
- if (value == mid) {
- return center
+ if (value === mid) {
+ return center;
} else if (value < mid) {
- result = (center / (mid - low)) * (value - low)
+ result = (center / (mid - low)) * (value - low);
} else {
result = center + (center / (high - mid)) * (value - mid)
}
@@ -405,8 +405,9 @@ script.softStart = function(channel, control, value, status, group, factor) {
bpm = function() {
}
-bpm.tapTime = 0.0
-bpm.tap = [] // Tap sample values
+bpm.tapTime = 0.0;
+bpm.previousTapDelta = 0.0;
+bpm.tap = []; // Tap sample values
/* -------- ------------------------------------------------------
bpm.tapButton
@@ -418,29 +419,51 @@ bpm.tap = [] // Tap sample values
Output: -
-------- ------------------------------------------------------ */
bpm.tapButton = function(deck) {
- var now = new Date() / 1000 // Current time in seconds
- var tapDelta = now - bpm.tapTime
- bpm.tapTime = now
- if (tapDelta > 2.0) { // reset if longer than two seconds between taps
- bpm.tap = []
- return
- }
- bpm.tap.push(60 / tapDelta)
- if (bpm.tap.length > 8) bpm.tap.shift() // Keep the last 8 samples for averaging
- var sum = 0
- for (i = 0; i < bpm.tap.length; i++) {
- sum += bpm.tap[i]
+ var now = new Date() / 1000; // Current time in seconds
+ var tapDelta = now - bpm.tapTime;
+ bpm.tapTime = now;
+
+ // assign tapDelta in cases where the button has not been pressed previously
+ if (bpm.tap.length < 1) {
+ bpm.previousTapDelta = tapDelta;
+ }
+ // reset if longer than two seconds between taps
+ if (tapDelta > 2.0) {
+ bpm.tap = [];
+ return;
+ }
+ // reject occurences of accidental double or missed taps
+ // a tap is considered missed when the delta of this press is 80% longer than the previous one
+ // and a tap is considered double when the delta is shorter than 40% of the previous one.
+ // these numbers are just guesses that produced good results in practice
+ if ((tapDelta > bpm.previousTapDelta * 1.8)||(tapDelta < bpm.previousTapDelta * 0.6)) {
+ return;
+ }
+ bpm.previousTapDelta = tapDelta;
+ bpm.tap.push(60 / tapDelta);
+ // Keep the last 8 samples for averaging
+ if (bpm.tap.length > 8) bpm.tap.shift();
+ var sum = 0;
+ for (i=0; i<bpm.tap.length; i++) {
+ sum += bpm.tap[i];
}
var average = sum / bpm.tap.length
- var fRateScale = average / engine.getValue("[Channel" + deck + "]", "bpm")
+ var group = "[Channel" + deck + "]";
+
+ // "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.
+ var fRateScale = average/engine.getValue(group, "file_bpm");
// Adjust the rate:
- fRateScale = (fRateScale - 1.) / engine.getValue("[Channel" + deck + "]", "rateRange")
+ fRateScale = (fRateScale - 1.) / engine.getValue(group, "rateRange")
- engine.setValue("[Channel" + deck + "]", "rate", fRateScale * engine.getValue("[Channel" + deck + "]", "rate_dir"))
-// print("Script: BPM="+average+" setting to "+fRateScale);
-}
+ engine.setValue(
+ group, "rate",
+ fRateScale * engine.getValue(group, "rate_dir"));
+};
// ----------------- Common regular expressions --------------------------
script.samplerRegEx = /^\[Sampler(\d+)\]$/