ncmixer

ncurses audio mixer for DJ'ing
git clone git://git.2f30.org/ncmixer
Log | Files | Refs | README | LICENSE

commit d18d04c2a45eb75c34f633f47d72254360bda216
parent fea82081b0c7b9833fc6cdef5093fdeef6ee047a
Author: lostd <lostd@2f30.org>
Date:   Wed,  8 Jun 2016 01:10:41 +0100

Move crossfader at discrete steps

Also fix some position rounding problems.

Diffstat:
MREADME | 1+
Mncmixer.c | 41+++++++++++++++++++++++++----------------
2 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/README b/README @@ -12,6 +12,7 @@ visual: 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 -- snap to leftmost, center, rightmost positions diff --git a/ncmixer.c b/ncmixer.c @@ -7,6 +7,7 @@ #include <err.h> #include <errno.h> #include <fcntl.h> +#include <math.h> #include <poll.h> #include <signal.h> #include <sndio.h> @@ -209,6 +210,14 @@ key_cb(int fd) direction = RIGHT; xftimeout = KEY_DELAY_MS; break; + case 'J': + xfading = 0; + xfpos = MAX(xfpos - 0.0625f, -1.0f); + break; + case 'K': + xfading = 0; + xfpos = MIN(xfpos + 0.0625f, 1.0f); + break; case 'H': xfading = 1; direction = LEFT; @@ -341,30 +350,30 @@ server_listen(char *name) void draw_xfader(void) { - int i, start, end, len, center; - float pos; + int start, end, len, center, pos, i; - if (COLS < strlen(" -|+|- ")) + if (COLS < strlen(" -|x|- ")) return; start = 2; end = ISODD(COLS) ? COLS - 2 : COLS - 3; len = end - start; - center = start + (len - 1) / 2; + center = start + (len / 2); + if (xfpos <= 0.0f) + pos = center - ceil((len / 2) * fabsf(xfpos)); + else + pos = center + ceil((len / 2) * fabsf(xfpos)); + move(getcury(stdscr), start); for (i = 0; i < len; i++) printw("-"); - - pos = xfpos + 1.0; /* make it positive */ - pos /= 2.0; /* scale it */ - i = start + (len - 1) * pos; - move(getcury(stdscr), i - 1); - printw("|||"); - - if (i != center - 1 && i != center + 1) { - move(getcury(stdscr), center); - printw("+"); - } + move(getcury(stdscr), center); + printw("+"); + move(getcury(stdscr), pos - 1); + if (pos == center) + printw("|x|"); + else + printw("|||"); } void @@ -376,7 +385,7 @@ draw(void) 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.2f\n", xfpos); + printw("pos: %0.4f\n", xfpos); printw("xfading: %d\n", xfading); switch (direction) { case LEFT: