⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui_main.c

📁 Aqualung is an advanced music player primarily targeted for the GNU/Linux operating system, but als
💻 C
📖 第 1 页 / 共 5 页
字号:
/*                                                     -*- linux-c -*-    Copyright (C) 2004 Tom Szilagyi    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    $Id: gui_main.c,v 1.140 2006/09/25 18:17:28 peterszilagyi Exp $*/#include <config.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <unistd.h>#include <math.h>#include <sys/stat.h>#include <errno.h>#include <gtk/gtk.h>#include <gdk/gdkkeysyms.h>#include <libxml/xmlmemory.h>#include <libxml/parser.h>#ifdef _WIN32#include <glib.h>#else#include <pthread.h>#endif /* _WIN32 */#ifdef HAVE_LADSPA#include <lrdf.h>#endif /* HAVE_LADSPA */#ifdef HAVE_JACK#include <jack/jack.h>#endif /* HAVE_JACK */#ifdef HAVE_SNDFILE#include <sndfile.h>#endif /* HAVE_SNDFILE */#ifdef HAVE_SRC#include <samplerate.h>#endif /* HAVE_SRC */#ifdef HAVE_MPC#include <mpcdec/mpcdec.h>#endif /* HAVE_MPC */#include "common.h"#include "core.h"#include "rb.h"#include "cover.h"#include "transceiver.h"#include "decoder/file_decoder.h"#include "about.h"#include "options.h"#include "skin.h"#include "search.h"#include "ports.h"#include "music_browser.h"#include "playlist.h"#include "plugin.h"#include "file_info.h"#include "i18n.h"#include "gui_main.h"#include "version.h"/* receive at most this much remote messages in one run of timeout_callback() */#define MAX_RCV_COUNT 32/* period of main timeout callback [ms] */#define TIMEOUT_PERIOD 100extern options_t options;char pl_color_active[14];char pl_color_inactive[14];PangoFontDescription *fd_playlist;PangoFontDescription *fd_browser;PangoFontDescription *fd_bigtimer;PangoFontDescription *fd_smalltimer;PangoFontDescription *fd_songtitle;PangoFontDescription *fd_songinfo;PangoFontDescription *fd_statusbar;/* Communication between gui thread and disk thread */extern AQUALUNG_MUTEX_DECLARE(disk_thread_lock)extern AQUALUNG_COND_DECLARE(disk_thread_wake)extern rb_t * rb_gui2disk;extern rb_t * rb_disk2gui;#ifdef HAVE_JACKextern jack_client_t * jack_client;extern char * client_name;extern int jack_is_shutdown;#endif /* HAVE_JACK */extern volatile int vol_cancelled;extern int aqualung_socket_fd;extern int aqualung_session_id;extern GtkListStore * ms_pathlist_store;extern GtkTreeStore * play_store;extern GtkListStore * running_store;extern GtkWidget * play_list;extern GtkWidget * plist_menu;void init_plist_menu(GtkWidget *append_menu);/* the physical name of the file that is playing, or a '\0'. */char current_file[MAXLEN];/* default window title */char win_title[MAXLEN];char send_cmd, recv_cmd;char command[RB_CONTROL_SIZE];fileinfo_t fileinfo;status_t status;unsigned long out_SR;extern int output;unsigned long rb_size;unsigned long long total_samples;unsigned long long sample_pos;#ifdef HAVE_SRCextern int src_type;extern int src_type_parsed;#elseint src_type = 0;int src_type_parsed = 0;#endif /* HAVE_SRC *//* this flag set to 1 in core.c if --play   for current instance is specified. */int immediate_start = 0; int search_pl_flags = 0;int search_ms_flags = SEARCH_F_AN | SEARCH_F_RT | SEARCH_F_TT | SEARCH_F_CO;#ifdef HAVE_SNDFILEextern char * valid_extensions_sndfile[];#endif /* HAVE_SNDFILE */#ifdef HAVE_MPEGextern char * valid_extensions_mpeg[];#endif /* HAVE_MPEG */#ifdef HAVE_MODextern char * valid_extensions_mod[];#endif /* HAVE_MOD *//* volume & balance sliders */double vol = 0.0f;double vol_prev = 0.0f;double vol_lin = 1.0f;double bal = 0.0f;double bal_prev = 0.0f;extern double left_gain;extern double right_gain;/* label/display data */fileinfo_t disp_info;unsigned long disp_samples;unsigned long disp_pos;/* tooltips group */GtkTooltips * aqualung_tooltips;GtkWidget * main_window;extern GtkWidget * browser_window;extern GtkWidget * playlist_window;extern GtkWidget * fxbuilder_window;extern GtkWidget * ports_window;extern GtkWidget * info_window;extern GtkWidget * vol_window;extern GtkWidget * build_prog_window;extern GtkWidget * browser_paned;int main_pos_x;int main_pos_y;int main_size_x;int main_size_y;extern int music_store_changed;extern int browser_pos_x;extern int browser_pos_y;extern int browser_size_x;extern int browser_size_y;extern int browser_on;extern int browser_paned_pos;extern int playlist_pos_x;extern int playlist_pos_y;extern int playlist_size_x;extern int playlist_size_y;extern int playlist_on;extern int fxbuilder_on;GtkObject * adj_pos;GtkObject * adj_vol;GtkObject * adj_bal;GtkWidget * scale_pos;GtkWidget * scale_vol;GtkWidget * scale_bal;GtkWidget * time_labels[3];int time_idx[3] = { 0, 1, 2 };int refresh_time_label = 1;gulong play_id;gulong pause_id;GtkWidget * play_button;GtkWidget * pause_button;GtkWidget * prev_button;GtkWidget * stop_button;GtkWidget * next_button;GtkWidget * repeat_button;GtkWidget * repeat_all_button;GtkWidget * shuffle_button;int repeat_on = 0;int repeat_all_on = 0;int shuffle_on = 0;GtkWidget * label_title;GtkWidget * label_format;GtkWidget * label_samplerate;GtkWidget * label_bps;GtkWidget * label_mono;GtkWidget * label_output;GtkWidget * label_src_type;int shift_state;int x_scroll_start;int x_scroll_pos;int scroll_btn;GtkWidget * plugin_toggle;GtkWidget * musicstore_toggle;GtkWidget * playlist_toggle;guint timeout_tag;guint vol_bal_timeout_tag = 0;gint timeout_callback(gpointer data);/* whether we are refreshing the scale on STATUS commands recv'd from disk thread */int refresh_scale = 1;/* suppress scale refreshing after seeking (discard this much STATUS packets).   Prevents position slider to momentarily jump back to original position. */int refresh_scale_suppress = 0;/* whether we allow seeks (depending on if we are at the end of the track) */int allow_seeks = 1;/* controls when to load the new file's data on display */int fresh_new_file = 1;int fresh_new_file_prev = 1;/* whether we have a file loaded, that is currently playing (or paused) */int is_file_loaded = 0;/* whether playback is paused */int is_paused = 0;/* popup menu for configuration */GtkWidget * conf_menu;GtkWidget * conf__options;GtkWidget * conf__skin;GtkWidget * conf__jack;GtkWidget * conf__fileinfo;GtkWidget * conf__about;GtkWidget * conf__quit;GtkWidget * bigtimer_label;GtkWidget * smalltimer_label_1;GtkWidget * smalltimer_label_2;/* systray stuff */#ifdef HAVE_SYSTRAYGtkStatusIcon * systray_icon;GtkWidget * systray_menu;GtkWidget * systray__show;GtkWidget * systray__hide;GtkWidget * systray__play;GtkWidget * systray__pause;GtkWidget * systray__stop;GtkWidget * systray__prev;GtkWidget * systray__next;GtkWidget * systray__quit;int warn_wm_not_systray_capable = 0;int systray_semaphore = 0;void hide_all_windows(gpointer data);#endif /* HAVE_SYSTRAY */int systray_main_window_on = 1;void create_main_window(char * skin_path);gint prev_event(GtkWidget * widget, GdkEvent * event, gpointer data);gint play_event(GtkWidget * widget, GdkEvent * event, gpointer data);gint pause_event(GtkWidget * widget, GdkEvent * event, gpointer data);gint stop_event(GtkWidget * widget, GdkEvent * event, gpointer data);gint next_event(GtkWidget * widget, GdkEvent * event, gpointer data);void load_config(void);void playlist_toggled(GtkWidget * widget, gpointer data);void assign_audio_fc_filters(GtkFileChooser *fc);void assign_playlist_fc_filters(GtkFileChooser *fc);GtkWidget * c_event_box;GtkWidget * cover_image_area;gint cover_show_flag;void set_buttons_relief(void);/* externs form playlist.c */extern void clear_playlist_selection(void);extern void cut__sel_cb(gpointer data);extern void plist__search_cb(gpointer data);extern void direct_add(GtkWidget * widget, gpointer * data);extern void start_playback_from_playlist(GtkTreePath * path);extern void show_active_position_in_playlist(void);extern void show_last_position_in_playlist(void);extern char fileinfo_name[MAXLEN];extern char fileinfo_file[MAXLEN];extern GtkWidget * plist__fileinfo;extern GtkWidget * plist__rva;extern gint playlist_state;extern gint browser_state;gintaqualung_dialog_run(GtkDialog * dialog) {#ifdef HAVE_SYSTRAY	int ret;	systray_semaphore++;	ret = gtk_dialog_run(dialog);	systray_semaphore--;	return ret;#else	return gtk_dialog_run(dialog);#endif /* HAVE_SYSTRAY */}voiddeflicker(void) {	while (g_main_context_iteration(NULL, FALSE));}voidtry_waking_disk_thread(void) {	if (AQUALUNG_MUTEX_TRYLOCK(disk_thread_lock)) {		AQUALUNG_COND_SIGNAL(disk_thread_wake)		AQUALUNG_MUTEX_UNLOCK(disk_thread_lock)	}}/* returns (hh:mm:ss) or (mm:ss) format time string from sample position */voidsample2time(unsigned long SR, unsigned long long sample, char * str, int sign) {	int h;	char m, s;	if (!SR)		SR = 1;	h = (sample / SR) / 3600;	m = (sample / SR) / 60 - h * 60;	s = (sample / SR) - h * 3600 - m * 60;	if (h > 0)		sprintf(str, (sign)?("-%02d:%02d:%02d"):("%02d:%02d:%02d"), h, m, s);	else		sprintf(str, (sign)?("-%02d:%02d"):("%02d:%02d"), m, s);}/* converts a length measured in seconds to the appropriate string */voidtime2time(float seconds, char * str) {	int d, h;	char m, s;        d = seconds / 86400;	h = seconds / 3600;	m = seconds / 60 - h * 60;	s = seconds - h * 3600 - m * 60;        h = h - d * 24;        if (d > 0) {                if (d == 1 && h > 9) {                        sprintf(str, "%d %s, %2d:%02d:%02d", d, _("day"), h, m, s);                } else if (d == 1 && h < 9) {                        sprintf(str, "%d %s, %1d:%02d:%02d", d, _("day"), h, m, s);                } else if (d != 1 && h > 9) {                        sprintf(str, "%d %s, %2d:%02d:%02d", d, _("days"), h, m, s);                } else {                        sprintf(str, "%d %s, %1d:%02d:%02d", d, _("days"), h, m, s);                }        } else if (h > 0) {		if (h > 9) {			sprintf(str, "%02d:%02d:%02d", h, m, s);		} else {			sprintf(str, "%1d:%02d:%02d", h, m, s);		}	} else {		sprintf(str, "%02d:%02d", m, s);	}}/* pack 2 strings into one * output format: 4 hex digits -> length of 1st string (N) *                4 hex digits -> length of 2nd string (M) *                N characters of 1st string (w/o trailing zero) *                M characters of 2nd string (w/o trailing zero) *                trailing zero * sum: length(str1) + length(str2) + 4 + 4 + 1 * result should point to an area with sufficient space */voidpack_strings(char * str1, char * str2, char * result) {	sprintf(result, "%04X%04X%s%s", strlen(str1), strlen(str2), str1, str2);}/* inverse of pack_strings() * str1 and str2 should point to areas of sufficient space */voidunpack_strings(char * packed, char * str1, char * str2) {	int len1, len2;	if (strlen(packed) < 8) {		str1[0] = '\0';		str2[0] = '\0';		return;	}	sscanf(packed, "%04X%04X", &len1, &len2);	strncpy(str1, packed + 8, len1);	strncpy(str2, packed + 8 + len1, len2);	str1[len1] = '\0';	str2[len2] = '\0';}voidset_title_label(char * str) {	gchar default_title[MAXLEN];        char tmp[MAXLEN];	if (is_file_loaded) {		if (GTK_IS_LABEL(label_title)) {			gtk_label_set_text(GTK_LABEL(label_title), str);			if (options.show_sn_title) {				strncpy(tmp, str, MAXLEN-1);				strncat(tmp, " - ", MAXLEN-1);				strncat(tmp, win_title, MAXLEN-1);				gtk_window_set_title(GTK_WINDOW(main_window), tmp);#ifdef HAVE_SYSTRAY				gtk_status_icon_set_tooltip(systray_icon, tmp);#endif /* HAVE_SYSTRAY */			} else {				gtk_window_set_title(GTK_WINDOW(main_window), win_title);#ifdef HAVE_SYSTRAY				gtk_status_icon_set_tooltip(systray_icon, win_title);#endif /* HAVE_SYSTRAY */			}		}	} else {		if (GTK_IS_LABEL(label_title)) {                        sprintf(default_title, "Aqualung %s", aqualung_version);			gtk_label_set_text(GTK_LABEL(label_title), default_title);			gtk_window_set_title(GTK_WINDOW(main_window), win_title);#ifdef HAVE_SYSTRAY			gtk_status_icon_set_tooltip(systray_icon, win_title);#endif /* HAVE_SYSTRAY */                }                 }}voidassembly_format_label(char * str, int v_major, int v_minor) {	switch (v_major) {	case 0:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -