commit ff9aa5d55ba41c336f52100e294a2c40ccf3d265
parent abcd809f86cfdefa8da5afa63dc2b54a7fc6fa2c
Author: lostd <lostd@2f30.org>
Date: Wed, 8 Jun 2016 12:57:28 +0200
Remove keypress duration emulation boilerplate
Diffstat:
M | README | | | 20 | ++++++-------------- |
M | ncmixer.c | | | 51 | +-------------------------------------------------- |
2 files changed, 7 insertions(+), 64 deletions(-)
diff --git a/README b/README
@@ -1,20 +1,12 @@
visual:
- /tmp/ch0= /tmp/ch1=
- state: play state: idle
- monitor: off monitor: on
+ pos: -1.0000
|||------------+--------------
- speed: 10
- pos: -1.00
-
movement:
- h,l -- move crossfader left/right at set speed
- J,K -- move crossfader left/right by fixed steps
- j,k -- decrease/increase speed by one second
- H,L -- start auto crossfading left/right at set speed
+ h,l -- move crossfader left/right by one step
^H,^L -- snap to leftmost, center, rightmost positions
monitor control:
@@ -22,13 +14,10 @@ monitor control:
1 -- toggle monitor on channel 1
2 -- toggle monitor on channel 2
-Speed is measured in seconds it takes to do a full crossfade from one side to
-the other. Movement keys stop auto crossfade and speed changes affect it.
-
caveats:
The correct way to do movement is to get keyboard press and release events,
-and move the crossfader at the set speed in the meantime. We emulate this
+and move the crossfader at the set speed in the meantime. We can emulate this
assuming the default auto-repeat settings for X: a delay of 660ms and a rate
of 25Hz:
@@ -43,3 +32,6 @@ if current key is right:
start crossfade to right for 660ms
if previous key is right and still crossfading:
continue crossfade to right for another 40ms
+
+Currently we don't do anything about that. We suffer the initial 660ms delay
+and then we move by one step every 40ms.
diff --git a/ncmixer.c b/ncmixer.c
@@ -34,8 +34,6 @@
#define RATE 44100
#define CHANS 2
#define NSAMPLES 2048
-#define KEY_DELAY_MS 660
-#define KEY_REPEAT_MS 40
#define STEP 0.0625f
#define ROUND(xfpos) ((int)((xfpos) / STEP) * STEP)
@@ -52,10 +50,6 @@
/* mixer state */
float xfpos = 0.; /* values in [-1.0, 1.0] */
-int speed = 10;
-int xfading;
-int xftimeout; /* in milliseconds */
-enum { NONE, LEFT, RIGHT } direction;
/* forward decls */
struct input;
@@ -203,54 +197,23 @@ key_cb(int fd)
DPRINTF_D(c);
switch (c) {
case 'h':
- xfading = 1;
- direction = LEFT;
- xftimeout = KEY_DELAY_MS;
- break;
- case 'l':
- xfading = 1;
- direction = RIGHT;
- xftimeout = KEY_DELAY_MS;
- break;
- case 'J':
- xfading = 0;
xfpos = MAX(ROUND(xfpos) - STEP, -1.0f);
break;
- case 'K':
- xfading = 0;
+ case 'l':
xfpos = MIN(ROUND(xfpos) + STEP, 1.0f);
break;
- case 'H':
- xfading = 1;
- direction = LEFT;
- xftimeout = 0;
- break;
- case 'L':
- xfading = 1;
- direction = RIGHT;
- xftimeout = 0;
- break;
case CONTROL('H'):
- xfading = 0;
if (xfpos > 0.)
xfpos = 0.;
else
xfpos = -1.;
break;
case CONTROL('L'):
- xfading = 0;
if (xfpos < 0.)
xfpos = 0.;
else
xfpos = 1.;
break;
- case 'j':
- if (speed > 1)
- speed--;
- break;
- case 'k':
- speed++;
- break;
case '1':
inputs[0].monitor = !inputs[0].monitor;
break;
@@ -383,19 +346,7 @@ draw(void)
printw("ch1_monitor: %d\n", inputs[1].monitor);
printw("ch0_connected: %d\n", inputs[0].clifd != -1);
printw("ch1_connected: %d\n", inputs[1].clifd != -1);
- printw("speed: %d\n", speed);
printw("pos: %0.4f\n", xfpos);
- printw("xfading: %d\n", xfading);
- switch (direction) {
- case LEFT:
- printw("direction: left\n");
- break;
- case RIGHT:
- printw("direction: right\n");
- break;
- default:
- printw("direction: none\n");
- }
printw("\n");
draw_xfader();
refresh();