📄 guicontrol.c
字号:
/* this file is a part of amp software, (C) tomislav uzelac 1996,1997
*/
/* guicontrol.c
*
* Edouard Lafargue, 12 May 1997
*/
#ifndef OS_SunOS
#include "amp.h"
#include <sys/types.h>
#include <sys/stat.h>
#ifndef __BEOS__
#include <sys/uio.h>
#endif
#include <sys/socket.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include "audio.h"
#include "formats.h"
#include "getbits.h"
#include "huffman.h"
#include "layer2.h"
#include "layer3.h"
#include "position.h"
#include "rtbuf.h"
#include "transform.h"
#include "controldata.h"
#ifndef __BEOS__
typedef int bool;
#endif
typedef struct __nextsong
{
bool avail;
int fd;
int type;
} TNextSong, *PNextSong;
TNextSong nextSong;
void send_msg(PControlMsg msg, bool safe)
{
if(send_fd != -1)
{
if(safe)
while(write(send_fd, msg, sizeof(TControlMsg)) < 0 &&
errno == EAGAIN)
;
else
write(send_fd, msg, sizeof(TControlMsg));
}
}
int get_msg(PControlMsg msg)
{
return read(receive_fd, msg, sizeof(TControlMsg));
}
void seek_rewind(int pos)
{
fprintf(stderr,"Seek rewind\n");
}
/* This routine sends the current frame,
* and where we are in the file (in percent)
*/
void GUIstatusDisplay(int frameno)
{
TControlMsg message;
message.type = MSG_FRAMES;
message.data = frameno;
send_msg(&message,TRUE);
message.type = MSG_POSITION;
message.data = frameno*419;
send_msg(&message,TRUE);
}
void next_song(int fd, int type)
{
nextSong.avail = TRUE;
nextSong.fd = fd;
nextSong.type = type;
}
/* parse_msg returns the current "cnt" (it may have been modified
* if we did "ffwd" or "rew")
* Large chunks of this routine were taken from "sajberplay",
* the mpeg part of the original sajber jukebox.
* The Sajber Jukebox was written by
* Joel Lindholm <wizball@kewl.campus.luth.se>
*/
int parse_msg(PControlMsg msg, struct AUDIO_HEADER *header, int cnt)
{
switch(msg->type) {
case MSG_BUFFER:
/* fprintf(stderr, "MSG_BUFFER %d\n", msg->data); */
break;
case MSG_BUFAHEAD:
/* fprintf(stderr, "MSG_PLAYAHEAD %d\n", msg->data); */
break;
case MSG_SEEK:
break;
case MSG_RELEASE:
break;
case MSG_PRIORITY:
break;
case MSG_QUERY:
/* fprintf(stderr,"MSG_QUERY\n"); */
{
TControlMsg rmsg;
rmsg.type = MSG_RESPONSE;
switch(msg->data)
{
case QUERY_PLAYING:
rmsg.data = GUI_PLAYING; /* No need to synch. */
/* fprintf(stderr, "Reply to query playing\n"); */
send_msg(&rmsg, TRUE);
break;
case QUERY_PAUSED:
/* fprintf(stderr, "Reply to QUERY_PAUSED\n"); */
rmsg.data = GUI_PAUSE;
send_msg(&rmsg, TRUE);
break;
}
}
break;
case MSG_CTRL:
switch(msg->data)
{
case PLAY_PAUSE:
/* fprintf(stderr, "MSG_CTRL - PLAY_PAUSE\n"); */
if(GUI_PAUSE)
GUI_PAUSE= FALSE;
else {
GUI_PAUSE=TRUE ;
/*
if (GUI_PLAYING) audioBufferFlush();
*/
}
break;
case PLAY_STOP:
/* fprintf(stderr, "MSG_CTRL - PLAY_STOP\n"); */
GUI_STOP = TRUE;
if (GUI_PLAYING) audioBufferFlush();
break;
case FORWARD_BEGIN:
/* fprintf(stderr, "FORWARD_BEGIN\n"); */
/* forward(8); */
{
TControlMsg rmsg;
rmsg.type = MSG_RESPONSE;
rmsg.data = FORWARD_BEGIN;
send_msg(&rmsg, TRUE);
}
break;
case FORWARD_STEP:
{
/* fprintf(stderr, "FORWARD_STEP\n"); */
if(ffwd(header, 10)==10) cnt+=10;
{
TControlMsg rmsg;
rmsg.type = MSG_RESPONSE;
rmsg.data = FORWARD_STEP;
send_msg(&rmsg, TRUE);
}
if (GUI_PLAYING) audioBufferFlush();
}
break;
case FORWARD_END:
/* fprintf(stderr, "FORWARD_END\n"); */
break;
case REWIND_BEGIN:
/* fprintf(stderr, "REWIND_BEGIN\n"); */
{
TControlMsg rmsg;
rmsg.type = MSG_RESPONSE;
rmsg.data = REWIND_BEGIN;
send_msg(&rmsg, TRUE);
}
break;
case REWIND_STEP:
{
int result;
/* fprintf(stderr, "REWIND_STEP\n"); */
if (cnt>10){
if ((result = rew(header, 10))!= -1) {
cnt-=result;
}
}
{
TControlMsg rmsg;
rmsg.type = MSG_RESPONSE;
rmsg.data = REWIND_STEP;
send_msg(&rmsg, TRUE);
}
if (GUI_PLAYING) audioBufferFlush();
}
break;
case REWIND_END:
/* fprintf(stderr, "REWIND_END\n"); */
break;
}
break;
case MSG_QUIT:
fprintf(stderr, "MSG_QUIT\n");
if (GUI_PLAYING) audioBufferFlush();
break;
case MSG_SONG:
{
int fd;
struct msghdr hdr;
struct m_cmsghdr fdhdr;
struct iovec iov[1];
char data[2];
iov[0].iov_base = data;
iov[0].iov_len = 2;
/* fprintf(stderr, "MSG_SONG\n"); */
hdr.msg_iov = iov;
hdr.msg_iovlen = 1;
hdr.msg_name = NULL;
hdr.msg_namelen = 0;
fdhdr.cmsg_len = sizeof(struct m_cmsghdr);
fdhdr.cmsg_level = SOL_SOCKET;
fdhdr.cmsg_type = SCM_RIGHTS;
fdhdr.fd = 0;
hdr.msg_control = &fdhdr;
hdr.msg_controllen = sizeof(struct m_cmsghdr);
if(recvmsg(receive_fd, &hdr, 0) < 0)
perror("recvmsg");
fd = fdhdr.fd;
/* fprintf(stderr, "FILEFD READ=%d\n", fd); */
GUI_FD_TO_PLAY = fd;
if (GUI_PLAYING) audioBufferFlush();
}
break;
}
return cnt;
}
void gui_control(void)
{
int flags,dummy;
TControlMsg msg;
struct AUDIO_HEADER head;
/* fprintf(stderr,"Amp est contr鬺
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -