Skip to content

Commit

Permalink
S4 Mk3: compare scratch functions engine.scratch.. vs engine.setValue…
Browse files Browse the repository at this point in the history
…(group, "scratch2..")
  • Loading branch information
ronso0 committed Dec 9, 2024
1 parent 80fd83d commit 9e448ff
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
18 changes: 18 additions & 0 deletions res/controllers/Traktor Kontrol S4 MK3.hid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@
</devices>
</info>
<settings>
<group label="TEST scratch modes">
<row orientation="vertical">
<option
variable="scratchModeScratchTick"
type="boolean"
default="false"
label="Use 'engine.scratch..' functions">
<description>Use 'engine.scratchEnable()/disable()' and 'engine.scratchTick()' instead of engine.setValue(group, "scratch2..")</description>
</option>
<option
variable="scratchSyncToWheelLED"
type="boolean"
default="false"
label="Sync scratch speed with wheel LED speed">
</option>
</row>
</group>

<group label="Deck Lighting">
<row orientation="vertical">
<option
Expand Down
42 changes: 36 additions & 6 deletions res/controllers/Traktor-Kontrol-S4-MK3.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const DefaultPadLayoutKeyboard = "keyboard";
* Change settings in the preferences
*/

// For testing: switch between engine.scratch.. functions and engine.setValue(.., "scratch2..")
const useEngineScratch = !!engine.getSetting("scratchModeScratchTick");

const DeckColors = [
LedColors[engine.getSetting("deckA")] || LedColors.red,
LedColors[engine.getSetting("deckB")] || LedColors.blue,
Expand Down Expand Up @@ -117,6 +120,13 @@ const BeatLoopRolls = [
// the motor if enable. Recommended value are 33 + 1/3 or 45.
// Default: 33 + 1/3
const BaseRevolutionsPerMinute = engine.getSetting("baseRevolutionsPerMinute") || 33 + 1/3;
// alpha and beta are the recommended start values from
// https://github.com/mixxxdj/mixxx/wiki/midi%20scripting#scratching-and-jog-wheels
const ScratchSyncToWheelLED = !!engine.getSetting("scratchSyncToWheelLED");
const ScratchAlpha = 1.0/8;
const ScratchBeta = ScratchAlpha/32;
const ScratchIntervalsPerRev = ScratchSyncToWheelLED ? 2150 : 6750;
const ScratchSpeedFactor = ScratchSyncToWheelLED ? 2.14 : 1;

// Define whether or not to use motors.
// This is a BETA feature! Please use at your own risk. Setting this off means that below settings are inactive
Expand Down Expand Up @@ -2413,8 +2423,16 @@ class S4Mk3Deck extends Deck {
this.touched = touched;
if (this.deck.wheelMode === wheelModes.vinyl || this.deck.wheelMode === wheelModes.motor) {
if (touched) {
engine.setValue(this.group, "scratch2_enable", true);
} else {
if (useEngineScratch) {
engine.scratchEnable(this.deck.currentDeckNumber,
ScratchIntervalsPerRev,
BaseRevolutionsPerMinute,
ScratchAlpha,
ScratchBeta); // ramoing true by default
} else {
engine.setValue(this.group, "scratch2_enable", true);
}
} else { // release
this.stopScratchWhenOver();
}
}
Expand All @@ -2427,9 +2445,17 @@ class S4Mk3Deck extends Deck {
if (engine.getValue(this.group, "play") &&
engine.getValue(this.group, "scratch2") < 1.5 * baseRevolutionsPerSecond &&
engine.getValue(this.group, "scratch2") > 0) {
engine.setValue(this.group, "scratch2_enable", false);
if (useEngineScratch) {
engine.scratchDisable(this.deck.currentDeckNumber);
} else {
engine.setValue(this.group, "scratch2_enable", false);
}
} else if (engine.getValue(this.group, "scratch2") === 0) {
engine.setValue(this.group, "scratch2_enable", false);
if (useEngineScratch) {
engine.scratchDisable(this.deck.currentDeckNumber);
} else {
engine.setValue(this.group, "scratch2_enable", false);
}
} else {
engine.beginTimer(100, this.stopScratchWhenOver.bind(this), true);
}
Expand Down Expand Up @@ -2471,7 +2497,7 @@ class S4Mk3Deck extends Deck {
speed = currentSpeed;
}
this.oldValue = [value, timestamp, speed];
this.speed = wheelAbsoluteMax*speed*10;
this.speed = wheelAbsoluteMax*speed*10*ScratchSpeedFactor;

if (this.speed === 0 &&
engine.getValue(this.group, "scratch2") === 0 &&
Expand Down Expand Up @@ -2509,7 +2535,11 @@ class S4Mk3Deck extends Deck {
break;
case wheelModes.vinyl:
if (this.deck.wheelTouch.touched || engine.getValue(this.group, "scratch2") !== 0) {
engine.setValue(this.group, "scratch2", this.speed);
if (useEngineScratch) {
engine.scratchTick(this.deck.currentDeckNumber, diff);
} else {
engine.setValue(this.group, "scratch2", this.speed);
}
} else {
engine.setValue(this.group, "jog", this.speed);
}
Expand Down

0 comments on commit 9e448ff

Please sign in to comment.