QT : add repeat touch option

Hello,

Recently, I needed to hold a key pressed, and only fire the up event when it truely finish it.
Actually it seems impossible, since the key repeat fires the both event continuously.

So, I just changed the cpp source to add the QT isAutoRepeat option.
Since I dont know really how the arguments are passed, I just overrided the ‘key’ flag, the last one in the key down callback, that I never use.

key - An Integer denoting a key, corresponding to the "Key" enum of the Qt C++ API. Comparing this value is the most reliable way to check which key was pressed. For a list of possible values, see: http://qt-project.org/doc/qt-4.8/qt.html#Key-enum.

What is the real use of this argument ? Considering how more crucial it could be to have a real key repeat information, should we not consider replace it ?

Or we could add it in the QWidget Proxy, but I don’t know how hard it could be ?

edit:
the result of the code below

(
View(nil, 200@200).front
.keyDownAction_{arg ...args;
	"down".post;
	args.postln;
}
.keyUpAction_{arg ...args;
	"up".post;
	args.postln;
}
)

is (the auto repeat is the last arg)

//first touch
down[ a View, d, 0, 100, 100, 0 ]
up[ a View, d, 0, 100, 100, 1 ]
down[ a View, d, 0, 100, 100, 1 ]
up[ a View, d, 0, 100, 100, 1 ]
down[ a View, d, 0, 100, 100, 1 ]
up[ a View, d, 0, 100, 100, 1 ]
down[ a View, d, 0, 100, 100, 1 ]
up[ a View, d, 0, 100, 100, 1 ]
down[ a View, d, 0, 100, 100, 1 ]
up[ a View, d, 0, 100, 100, 1 ]
down[ a View, d, 0, 100, 100, 1 ]
up[ a View, d, 0, 100, 100, 1 ]
down[ a View, d, 0, 100, 100, 1 ]
up[ a View, d, 0, 100, 100, 1 ]
down[ a View, d, 0, 100, 100, 1 ]
up[ a View, d, 0, 100, 100, 1 ]
down[ a View, d, 0, 100, 100, 1 ]
up[ a View, d, 0, 100, 100, 1 ]
down[ a View, d, 0, 100, 100, 1 ]
up[ a View, d, 0, 100, 100, 1 ]
down[ a View, d, 0, 100, 100, 1 ]
up[ a View, d, 0, 100, 100, 0 ]
//release
1 Like

I also really need this!

If your OK with compilation, just pull this branch on github and build it:

git clone https://github.com/simdax/supercollider/
git checkout adding_key_auto_repeat
mkdir build; cd build 
cmake .. && make && sudo make install
1 Like

Just curious: if you overwrite the key argument, how do you know which key is pressed?

Nevermind, I wasn’t aware there are other options.

|doc, char, mod, unicode, keycode, key|

Thanks! For portability I’ll use a workaround until a version of this is merged into master. Also, I don’t know how the Qt code interacts with the supercollider code, but it seems to me that adding an additional argument for whether the key is a repeat would break less code (the helpfile seems to encourage the use of the key argument as is).

yes sure, for now the argument is just added.
Qt is pretty good, it was just about saying : “now you give mw this !” :slight_smile:

I think lots of users may need it.
As far as I understand, you have developed an SC build, is it right?
Is it possible to write a Quark instead of it?
I am sorry if I am misunderstanding here something.

A real no repeat option have to be before any SC_IDE event. It has to be at system level. If we are SC_IDE side, we have to intercept it and deal with it.
For now, the better solution is to solve the problem where the problem is, i. e., in the source code of the lang interpreter.
the other Hack proposed in the first thread I opened could make it. But I’m not sure it’s working now, since I think the waiting time between each event is susceptible to change/or being different in different computers.

(~myview = {
	var keyUpRepeatRoutines, processes;
	var waitingTime = 0.02;
	var w = Window("Process World Keypresses", Rect(0, 0, 1000, 500)).front;
	
	// The routines are a workaround to avoid repeated keypresses
	keyUpRepeatRoutines = Dictionary[];
	
	w.view.keyDownAction = {
		|doc, char, mod, unicode, keycode, key|
		char.postln;
		~processes.do { |proc|
			if(proc.key == char) {
				~keyUpRepeatRoutines[char.asSymbol].stop;
				proc.start();
			};
			
		};
	};
	
	w.view.keyUpAction = {
		|doc, char, mod, unicode, keycode, key|
		processes.do { |proc|
			if(proc.key == char) {
				
				// suspend the process only if the routine isn't stopped first (which is the case if the key is repeated)
				keyUpRepeatRoutines[char.asSymbol] = Routine({
					waitingTime.wait;
					proc.suspend();
				}).play;
			};
			
		};
	};
	w
}
)
a = ~myview.()