📄 wav_frontend.c
字号:
/* wav_frontend.c 4.6.99 tn*/#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <sys/wait.h>#include <gtk/gtk.h>#include <gdk/gdk.h>#include <gdk_imlib.h>#include "xcdroast.h"#include "main.h"#include "xpms/snd_play.xpm"#include "xpms/snd_stop.xpm"#include "xpms/snd_pause.xpm"#include "xpms/snd_next.xpm"#include "xpms/snd_prev.xpm"#include "xpms/snd_quit.xpm"#include "xpms/snd_mixer.xpm"extern GtkCList *play_clist;extern setup_data_t setupdata;extern GList *imagelist;extern gchar sharedir[MAXLINE];gint wav_out, wav_in, wavplay_quit;GtkWidget *drawa, *timer_label, *wavplay_text;GtkWidget *playb, *stopb, *nextb, *wav_quit_button;gint playhdl, stophdl, nexthdl, prevhdl;GdkPixmap *pixmap = NULL;gint maxseconds;gint curseconds;gint maxpixels;gint ptimer;gint callback_tag;gint error_flag;void read_wav_out(gpointer data, gint source, GdkInputCondition cond);gint draw_ticks (gpointer data);/* updates the text-window */void update_text(gchar *txt) { /* delete text-window first */ gtk_text_backward_delete(GTK_TEXT(wavplay_text), gtk_text_get_length(GTK_TEXT(wavplay_text))); gtk_text_insert(GTK_TEXT(wavplay_text), NULL,NULL,NULL, txt, strlen(txt));}/* draw the text-info for current playing track */ void trackinfo_text(gchar *file) {GList *loop;image_files_t *entry;gchar tmp[MAXLINE];gchar tmp2[MAXLINE];gint count; strcpy(tmp,""); /* search current file in imagelist */ count = 1; loop = g_list_first(imagelist); while (loop) { entry = loop->data; if (entry->type == 1) { if (strcmp(entry->path,file) == 0) { /* found match */ convert_frames2minstring( (entry->size)/CDDAFRAME, tmp2); if (entry->title && entry->artist && strcmp(entry->title,"") && strcmp(entry->artist,"")) { g_snprintf(tmp,MAXLINE, "%d. %s / %s [%s]", count, entry->title, entry->artist, tmp2); } else if (entry->title && strcmp(entry->title,"")) { g_snprintf(tmp,MAXLINE, "%d. %s [%s]", count, entry->title, tmp2); } else if (entry->cddb_ttitle && strcmp(entry->cddb_ttitle,"")) { g_snprintf(tmp,MAXLINE, "%d. %s [%s]", count, entry->cddb_ttitle, tmp2); } else { g_snprintf(tmp,MAXLINE,"%d. %s [%s]", count, file, tmp2); } break; } count++; } loop = loop->next; } update_text(tmp); }/* loads a wav-file and starts playing */void start_play(gchar *filename) {gchar cmd[MAXLINE];gchar tmptmp[MAXLINE]; /* already playing? */ if (wav_in != -1) { return; } /* have we got an audiodevice? */ if (strcmp(setupdata.dsp_device,"") == 0) { update_text(text(143)); return; } strcpy(tmptmp,filename); g_snprintf(cmd,MAXLINE,"%s/%s -g -d %s \"%s\" 2>&1", sharedir, WAVPLAY, setupdata.dsp_device, convert_escape(tmptmp)); dodebug(1, "spawning shell: %s\n",cmd); dolog(3, "Executing: %s\n", cmd); /* start child and get new fds */ full_dpl_pipe_shell(&wav_out,&wav_in,cmd); /* catch output of child */ callback_tag = gdk_input_add(wav_out, GDK_INPUT_READ, (GdkInputFunction) read_wav_out, NULL);}/* ends the wavplay-process and cleans up */void stop_play() { if (wav_in == -1) { /* we are not playing right now */ return; } dodebug(8,"wavplay: stop_play\n"); /* ok, at this point the child terminated */ gtk_input_remove(callback_tag); wav_out = -1; wav_in = -1; maxseconds = 60; maxpixels = 1; curseconds = 0; /* update screen */ if (wavplay_quit == 0) ptimer=gtk_timeout_add (100, draw_ticks, drawa); /* if no error-condition, clear up text-window */ if (error_flag == 0) { update_text(""); } else { error_flag = 0; }}/* get current selected track-name */void get_sel_trackname(gchar *tname) {GList *sel;gint row;gchar *text; sel = play_clist->selection; if (sel != NULL) { row = GPOINTER_TO_INT(sel->data); gtk_clist_get_text(play_clist,row,4, &text); strncpy(tname,text,MAXLINE); return; } strcpy(tname,""); return;}/* autoselect next track */void select_next_track() {gint rows;gint row;GList *sel; /* get data from clist */ row = -1; rows = play_clist->rows; sel = play_clist->selection; if (sel != NULL) { row = GPOINTER_TO_INT(sel->data); } /* nothing selected? */ if (row == -1) { row = 0; } else { row++; if (row >= rows) row = 0; } gtk_clist_select_row(play_clist,row,0);}/* autoselect prev track */void select_prev_track() {gint rows;gint row;GList *sel; /* get data from clist */ row = -1; rows = play_clist->rows; sel = play_clist->selection; if (sel != NULL) { row = GPOINTER_TO_INT(sel->data); } /* nothing selected? */ if (row == -1) { row = rows-1; } else { row--; if (row < 0) row = rows-1; } gtk_clist_select_row(play_clist,row,0);}/* Create a new backing pixmap of the appropriate size */gint configure_event (GtkWidget *widget, GdkEventConfigure *event) { if (pixmap) gdk_pixmap_unref(pixmap); pixmap = gdk_pixmap_new(widget->window, widget->allocation.width, widget->allocation.height, -1); /* set background to white */ gdk_draw_rectangle (pixmap, widget->style->white_gc, TRUE, 0, 0, widget->allocation.width, widget->allocation.height); return TRUE;}/* Redraw the screen from the backing pixmap */gint expose_event (GtkWidget *widget, GdkEventExpose *event) { gdk_draw_pixmap(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], pixmap, event->area.x, event->area.y, event->area.x, event->area.y, event->area.width, event->area.height); return FALSE;}/* catch a click on the drawarea */ static gint button_press_event (GtkWidget *widget, GdkEventButton *event) {gint sec;gchar tmp[MAXLINE]; if (event->button == 1 && pixmap != NULL) { sec = (((gint) event->x)-5)*maxseconds/maxpixels; if (sec < 0) sec = 0; if (sec > maxseconds) sec = maxseconds; /* pipes not yet set up */ if (wav_in == -1) return TRUE; g_snprintf(tmp,MAXLINE,"set%d\n",sec); dodebug(8,"wavplay: sending command %s\n", tmp); if (write(wav_in, tmp, strlen(tmp)) != strlen(tmp)) { g_warning("write error to pipe\n"); } } return TRUE;}/* button callbacks */void doplay(GtkWidget *widget, gpointer data) {gchar tmp[MAXLINE]; /* get trackname from selection */ get_sel_trackname(tmp); /* if nothing selected force select first row */ if (strcmp(tmp,"") == 0) { gtk_clist_select_row(play_clist,0,0); get_sel_trackname(tmp); } /* got a valid selection? start play it */ if (strcmp(tmp,"") != 0) { start_play(tmp); } /* pipes not yet set up */ if (wav_in == -1) { /* detoggle button */ gtk_signal_handler_block(GTK_OBJECT(playb),playhdl); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(playb),0); gtk_signal_handler_unblock(GTK_OBJECT(playb),playhdl); return; } /* draw text-info */ trackinfo_text(tmp); dodebug(8,"wavplay: sending command play\n"); if (write(wav_in, "play\n", 5) != 5) { g_warning("write error to pipe\n"); }}void dostop(GtkWidget *widget, gpointer data) { /* pipes not yet set up */ if (wav_in == -1) { /* detoggle button */ gtk_signal_handler_block(GTK_OBJECT(stopb),stophdl); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(stopb),0); gtk_signal_handler_unblock(GTK_OBJECT(stopb),stophdl); return; } dodebug(8,"wavplay: sending command stop\n"); if (write(wav_in, "stop\n", 5) != 5) { g_warning("write error to pipe\n"); }}void dopause(GtkWidget *widget, gpointer data) { /* pipes not yet set up */ if (wav_in == -1) return; dodebug(8,"wavplay: sending command pause\n"); if (write(wav_in, "pause\n", 6) != 6) { g_warning("write error to pipe\n"); }}void doquit(GtkWidget *widget, gpointer data) { /* pipes not yet set up */ if (wav_in == -1) return; dodebug(8,"wavplay: sending command quit\n"); if (write(wav_in, "quit\n", 5) != 5) { g_warning("write error to pipe\n"); } /* clean up will be done automatically when child quits */}void doprev(GtkWidget *widget, gpointer data) { /* lock button as long its doing it work */ gtk_signal_handler_block(GTK_OBJECT(widget),prevhdl); select_prev_track(); /* ok..stop play current track and play previous */ gtk_button_clicked(GTK_BUTTON(wav_quit_button)); /* now wait until we are really finished */ while (wav_in != -1) { wait_and_process_events(); } gtk_button_clicked(GTK_BUTTON(playb)); gtk_signal_handler_unblock(GTK_OBJECT(widget),prevhdl);}void donext(GtkWidget *widget, gpointer data) { /* lock button as long its doing it work */ gtk_signal_handler_block(GTK_OBJECT(widget),nexthdl); select_next_track();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -