ncmixer

ncurses audio mixer with cross-fade support
git clone git://git.2f30.org/ncmixer.git
Log | Files | Refs | README | LICENSE

commit 01f4e171f54a0420cbecbcfe2099719a28c5bee8
parent 4ab1e4067371b9fe802f8aac0e0c021338a35e71
Author: lostd <lostd@2f30.org>
Date:   Fri Jun  3 01:54:45 +0100

Add the basic keys and print state

Diffstat:
README | 14+++++++-------
ncmixer.c | 84++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 90 insertions(+), 8 deletions(-)
diff --git a/README b/README @@ -7,19 +7,19 @@ visual: |||------------+-------------- speed: 10 + pos: -1.00 movement: - h,l -- move crossfader left/right at set speed - j,k -- decrease/increase speed by one second - H,L -- snap to leftmost, center, rightmost positions - F -- start auto crossfading at set speed + h,l -- move crossfader left/right at set speed + 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 monitor control: - 1 -- monitor plays channel 1 - 2 -- monitor plays channel 2 - 3 -- monitor plays both + 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. diff --git a/ncmixer.c b/ncmixer.c @@ -17,6 +17,7 @@ #define MIN(x, y) ((x) < (y) ? (x) : (y)) #undef MAX #define MAX(x, y) ((x) > (y) ? (x) : (y)) +#define CONTROL(c) ((c) ^ 0x40) #define SA struct sockaddr #define CH0_NAME "/tmp/ch0" #define CH1_NAME "/tmp/ch1" @@ -25,6 +26,8 @@ #define RATE 44100 #define CHANS 2 #define NSAMPLES 2048 +#define KEY_DELAY_MS 660 +#define KEY_REPEAT_MS 40 #ifdef DEBUG #define DEBUG_FD 8 @@ -40,7 +43,13 @@ /* mixer state */ float xfpos = 0.; /* values in [-1.0, 1.0] */ int speed = 10; -int autoxf = 1; +int xfading; +int xftimeout; /* in milliseconds */ +enum { NONE, LEFT, RIGHT } direction; +int ch0_active; +int ch1_active; +int ch0_monitor; +int ch1_monitor; struct sio_hdl *sio_hdl; @@ -134,6 +143,55 @@ key_cb(int fd) c = getch(); 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 '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': + ch0_monitor = !ch0_monitor; + break; + case '2': + ch1_monitor = !ch1_monitor; + break; + } return 0; } @@ -210,6 +268,28 @@ server_listen(char *name) } void +draw(void) +{ + erase(); + printw("ch0_monitor: %d\n", ch0_monitor); + printw("ch1_monitor: %d\n", ch1_monitor); + printw("speed: %d\n", speed); + printw("pos: %0.2f\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"); + } + refresh(); +} + +void loop(void) { struct sockaddr_un sun; @@ -305,6 +385,7 @@ loop(void) attenuate(); mix(); audio_play(out_buf, out_nsamples * 2); + draw(); } } @@ -339,6 +420,7 @@ main(void) { curses_init(); audio_open(); + draw(); loop(); audio_close(); curses_exit();