4
copyright ?-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
5
see COPYING and AUTHORS files in distribution or http://mpg123.de
6
initially written by Michael Hipp
16
#include <sys/types.h>
24
extern int buffer_pid;
26
static int term_enable = 0;
27
static struct termios old_tio;
29
/* initialze terminal */
37
if(tcgetattr(0,&tio) < 0) {
38
fprintf(stderr,"Can't get terminal attributes\n");
42
tio.c_lflag &= ~(ICANON|ECHO);
46
if(tcsetattr(0,TCSANOW,&tio) < 0) {
47
fprintf(stderr,"Can't set terminal attributes\n");
55
static long term_handle_input(struct frame *,int);
57
static int stopped = 0;
58
static int paused = 0;
59
static int pause_cycle;
61
long term_control(struct frame *fr)
71
pause_cycle=(int)(LOOP_CYCLES/compute_tpf(fr));
76
while(paused && xfermem_get_usedspace(buffermem)) {
78
buffer_ignore_lowmem();
79
offset += term_handle_input(fr, TRUE);
82
offset += pause_cycle;
88
offset += term_handle_input(fr, stopped);
96
static long term_handle_input(struct frame *fr, int do_delay)
100
extern struct audio_info_struct ai;
108
t.tv_usec=(do_delay) ? 1000 : 0;
112
n = select(1,&r,NULL,NULL,&t);
113
if(n > 0 && FD_ISSET(0,&r)) {
114
if(read(0,&val,1) <= 0)
117
switch(tolower(val)) {
119
if(!param.usebuffer) audio_queueflush(&ai);
121
* NOTE: rd->rewind() calls buffer_resync() that blocks until
122
* buffer process returns ACK. If buffer process is stopped, we
123
* end up in a deadlock. The only acceptable workaround was to
124
* resume playing as soon as BACK_KEY is pressed. This is not
125
* necessary when running non-buffered but I chose to remain
132
fprintf(stderr, "%s", EMPTY_STRING);
135
pause_cycle=(int)(LOOP_CYCLES/compute_tpf(fr));
140
if(!param.usebuffer) audio_queueflush(&ai);
142
kill(buffer_pid, SIGINT);
147
kill(buffer_pid, SIGTERM);
148
kill(getpid(), SIGTERM);
153
pause_cycle=(int)(LOOP_CYCLES/compute_tpf(fr));
154
offset -= pause_cycle;
161
fprintf(stderr, "%s", (paused) ? PAUSED_STRING : EMPTY_STRING);
168
offset -= pause_cycle;
171
(stopped) ? buffer_stop() : buffer_start();
172
fprintf(stderr, "%s", (stopped) ? STOPPED_STRING : EMPTY_STRING);
174
case FINE_REWIND_KEY:
177
case FINE_FORWARD_KEY:
186
case FAST_REWIND_KEY:
189
case FAST_FORWARD_KEY:
193
fprintf(stderr,"\n\n -= terminal control keys =-\n[%c] or space bar\t interrupt/restart playback (i.e. 'pause')\n[%c]\t next track\n[%c]\t back to beginning of track\n[%c]\t pause while looping current sound chunk\n[%c]\t forward\n[%c]\t rewind\n[%c]\t fast forward\n[%c]\t fast rewind\n[%c]\t fine forward\n[%c]\t fine rewind\n[%c]\t this help\n[%c]\t quit\n\n",
194
STOP_KEY, NEXT_KEY, BACK_KEY, PAUSE_KEY, FORWARD_KEY, REWIND_KEY, FAST_FORWARD_KEY, FAST_REWIND_KEY, FINE_FORWARD_KEY, FINE_REWIND_KEY, HELP_KEY, QUIT_KEY);
196
case FRAME_INDEX_KEY:
197
print_frame_index(stderr);
207
void term_restore(void)
213
tcsetattr(0,TCSAFLUSH,&old_tio);