Scratching with buttons

Excuse my poor English… How can I do a JS-function while a button on the controller is pressed? I want the scratching with a fixed speed for a button on the Hercules P32 DJ. The following is not working:

[code]
unshift: function () {
var isPressed = false;
this.input = function (channel, control, value, status, group) {

			    if (value === 127) { // do something when this button is pressed
					var alpha = 1.0/8;
					var beta = alpha/32;
					engine.scratchEnable(channel, 128, 33+1/3, alpha, beta);
					isPressed = true;
				}
				if (value === 0) {
					engine.scratchDisable(channel);
					isPressed = false;
				}
				if (isPressed) {
					engine.scratchTick(channel, -20);	// scratch back
				}
        };
	},[/code]

I don’t understand what you’re expecting to happen. Scratching with a button doesn’t make sense. If you want to scratch with a controller, the Hercules P32 is not the right controller for that.

What do you mean by “scratching at a fixed speed”?

The Scratch button/toggle would usually work in conjunction with another control, most often the jog wheel.

I’m guessing you mean you want a forwards/backwards/forwards type scratch to continue while the button is held right? Well you are going to need to add a timer in there as at the moment it looks like your forwards/backwards are basically going to be instantaneous and thus seem like nothing is happening at all…

Toggling between forward and reverse play might be an easier way to start. I don’t know if scratch.enable will really work otherwise…

Right, I will not really scratch, but go back/forward while the button is pressed. I wrote “scratch” because I don’t know, how to describe that.

But in generally: How can I handle functions while a button is pressed?

You’ll need to do one operation for x number of milliseconds (eg play forwards) and then the other for the same time.

Start by reading this: mixxx.org/wiki/doku.php/midi_sc … _reactions

Once you get it working with forward and reverse play you can probably play with the settings of the engine.break() (as per the engine.spinback() does) to get something sounding a little more natural…

Shift + turning the encoders can be used for beatjumping as documented on the wiki.

I think the word you are looking for is “seek”, not “scratch”.

Doing something while a button is held down can be done with a push type Button as documented on the Components wiki page.

Thanks kazakore and Be., so I have to try… :slight_smile:

Thanks! Finaly, I got it:

unshift: function () { this.input = function (channel, control, value, status, group) { var alpha = 1.0/8; var beta = alpha/32; engine.scratchEnable(channel, 128, 33+1/3, alpha, beta); if (this.isPress(channel, control, value, status)) { myTimer = engine.beginTimer(10, function () { engine.scratchTick(channel, -2); }); } else { engine.scratchDisable(channel); engine.stopTimer(myTimer); } }; },

And, thanks Be. for the controller scripting :slight_smile: