Skip to content

Commit

Permalink
GUI-less player
Browse files Browse the repository at this point in the history
New configure option --disable-gui
Won't link to gtk and has no GUI option. OK to make playlists
or to start a player- except the -P option is broken with or without
this flag
  • Loading branch information
Craig Small committed Jul 15, 2012
1 parent e26685c commit e804dce
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 46 deletions.
38 changes: 28 additions & 10 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,40 @@ SUBDIRS = po doc icons

bin_PROGRAMS = gjay

gjay_LDADD = $(GTK_LIBS) $(DBUS_GLIB_LIBS) $(GSL_LIBS)
AM_CFLAGS = -Wall $(GTK_CFLAGS) $(DBUS_GLIB_CFLAGS) $(GSL_CFLAGS)
gjay_LDADD = $(GLIB_LIBS) $(GTK_LIBS) $(DBUS_GLIB_LIBS) $(GSL_LIBS)
AM_CFLAGS = -Wall $(GLIB_CFLAGS) $(GTK_CFLAGS) $(DBUS_GLIB_CFLAGS) $(GSL_CFLAGS)

gjay_SOURCES = gjay.h songs.h prefs.h ui.h rgbhsv.h analysis.h playlist.h \
extra_DIST =
gjay_SOURCES = gjay.h songs.h prefs.h rgbhsv.h analysis.h playlist.h \
ipc.h constants.h vorbis.h mp3.h flac.h i18n.h \
dbus.h util.h \
gjay.c dbus.c ipc.c prefs.c songs.c rgbhsv.c ui.c \
ui_explore_view.c ui_prefs_view.c ui_selection_view.c \
ui_playlist_view.c ui_colorwheel.c \
ui_menubar.c analysis.c playlist.c \
gjay.c dbus.c ipc.c prefs.c songs.c rgbhsv.c \
analysis.c playlist.c \
vorbis.c mp3.c flac.c util.c \
play_common.c play_common.h \
play_audacious.c play_audacious.h \
play_mpdclient.c play_mpdclient.h
play_common.c play_common.h
#play_exaile.h play_exaile.c

if WITH_GUI
gjay_SOURCES += ui.h ui.c ui_menubar.c\
ui_explore_view.c ui_prefs_view.c ui_selection_view.c \
ui_playlist_view.c ui_colorwheel.c
else
extra_DIST += ui.c \
ui_explore_view.c ui_prefs_view.c ui_selection_view.c \
ui_playlist_view.c ui_colorwheel.c
endif

if WITH_AUDCLIENT
gjay_SOURCES += play_audacious.c play_audacious.h
else
extra_DIST += play_audacious.c play_audacious.h
endif

if WITH_MPDCLIENT
gjay_SOURCES += play_mpdclient.c play_mpdclient.h
else
extra_DIST += play_mpdclient.c play_mpdclient.h
endif
#ddui_colorbox.c

ACLOCAL_AMFLAGS = -I m4
Expand Down
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@
/* Build with dbus-glib */
#undef WITH_DBUSGLIB

/* Enable Gtk graphical interface */
#undef WITH_GUI

/* Enable mpd music player */
#undef WITH_MPDCLIENT
16 changes: 15 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ dnl Options
# Don't require D-Bus unless building a component that needs it:
enable_dbus=no

AC_SUBST([WITH_GUI])
AC_ARG_ENABLE([gui],
AS_HELP_STRING([--disable-gui], [Disable the Gtk graphical interface]),
[enable_gui=$enableval],
[enable_gui="yes"])
if test "$enable_gui" = "yes"; then
AC_DEFINE([WITH_GUI], [1], [Enable Gtk graphical interface])
PKG_CHECK_MODULES([GTK], [gtk+-2.0])
else
PKG_CHECK_MODULES([GLIB], [glib-2.0])
fi
AM_CONDITIONAL([WITH_GUI], [test "$enable_gui" = "yes"])

AC_SUBST([WITH_MPDCLIENT])
AC_ARG_ENABLE([mpdclient],
AS_HELP_STRING([--with-mpdclient], [Enable mpd client(default is YES)]),
Expand All @@ -26,6 +39,7 @@ if test "$enable_mpdclient" = "yes"; then
AC_DEFINE([WITH_MPDCLIENT], [1], [Enable mpd music player])
PKG_CHECK_MODULES([MPDCLIENT], [libmpdclient])
fi
AM_CONDITIONAL([WITH_MPDCLIENT], [test "$enable_mpdclient" = "yes"])

AC_SUBST([WITH_AUDCLIENT])
AC_ARG_ENABLE([audclient],
Expand All @@ -37,13 +51,13 @@ if test "$enable_audclient" = "yes"; then
AC_DEFINE([WITH_AUDCLIENT], [1], [Enable Audacious music player])
PKG_CHECK_MODULES([AUDACIOUS], [audacious])
fi
AM_CONDITIONAL([WITH_AUDCLIENT], [test "$enable_audclient" = "yes"])

dnl Check for language stuff
AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION([0.18.1])

# Checks for libraries.
PKG_CHECK_MODULES([GTK], [gtk+-2.0])

if test "$enable_dbus" = "yes"; then
AC_DEFINE([WITH_DBUSGLIB], [1], [Build with dbus-glib])
Expand Down
13 changes: 13 additions & 0 deletions gjay.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "vorbis.h"
#include "flac.h"
#include "ui.h"

#include "i18n.h"
#include "play_common.h"

Expand All @@ -75,7 +76,9 @@ static gint ping_daemon ( gpointer data );
static gboolean create_ui_daemon_pipe(void);
static gboolean mode_attached ( gjay_mode m );
static void fork_or_connect_to_daemon(void);
#ifdef WITH_GUI
static void run_as_ui (int argc, char * argv[]);
#endif /* WITH_GUI */
static void run_as_playlist ( guint playlist_minutes,
gboolean m3u_format,
gboolean player_autostart );
Expand Down Expand Up @@ -247,17 +250,21 @@ int main( int argc, char *argv[] ) {
if (verbosity)
printf(_("FLAC not supported.\n"));

#ifdef WITH_GUI
if (mode == UI) {
/* UI needs a daemon */
fork_or_connect_to_daemon();
}
#endif /* WITH_GUI */

switch(mode) {
#ifdef WITH_GUI
case UI:
read_data_file();
sleep(1);
run_as_ui(argc, argv);
break;
#endif /* WITH_GUI */
case PLAYLIST:
read_data_file();
run_as_playlist(playlist_minutes, m3u_format, player_autostart);
Expand Down Expand Up @@ -453,6 +460,7 @@ fork_or_connect_to_daemon(void)
}
}

#ifdef WITH_GUI

static void run_as_ui(int argc, char *argv[] )
{
Expand Down Expand Up @@ -520,6 +528,7 @@ static void run_as_ui(int argc, char *argv[] )
close(daemon_pipe_fd);
close(ui_pipe_fd);
}
#endif /* WITH_GUI */


/* Playlist mode */
Expand Down Expand Up @@ -548,13 +557,16 @@ void gjay_message_log(const gchar *log_domain,
const gchar *message,
gpointer user_data)
{
#ifdef WITH_GUI
GtkWidget *msg_window = GTK_WIDGET(user_data);
GtkWidget *msg_text_view;
GtkTextBuffer *buffer;

if (mode != UI) {
#endif /* WITH_GUI */
printf("%s\n", message);
return;
#ifdef WITH_GUI
}
msg_text_view = GTK_WIDGET(g_object_get_data(G_OBJECT(msg_window), "text_view"));

Expand All @@ -564,5 +576,6 @@ void gjay_message_log(const gchar *log_domain,
strlen(message));
gtk_text_buffer_insert_at_cursor(buffer, "\n", 1);
gtk_widget_show_all (GTK_WIDGET(msg_window));
#endif /* WITH_GUI */
}

12 changes: 8 additions & 4 deletions gjay.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
#include "util.h"

/* Global definitions */
#define AUDACIOUS_BIN "/usr/bin/audacious2"
#define AUDACIOUS_BIN "/usr/bin/audacious"
#define EXAILE_BIN "/usr/bin/exaile"

#include <stdio.h>
#include <gtk/gtk.h>
#include <glib.h>
#ifdef WITH_GUI
#include <gtk/gtk.h>
#endif /* WITH_GUI */
#include <assert.h>
#include <limits.h>
#include <math.h>
Expand All @@ -44,7 +46,6 @@ extern GjayApp *gjay;
#include "rgbhsv.h"
#include "songs.h"
#include "prefs.h"
//#include "ui.h"

/* Helper programs */
#define OGG_DECODER_APP "ogg123"
Expand Down Expand Up @@ -91,23 +92,26 @@ struct _GjayApp {
#endif /* WITH_MPDCLIENT */


//GdkPixbuf * pixbufs[PM_LAST];
#ifdef WITH_GUI
GdkPixbuf * pixbufs[50]; //FIXME
GtkTooltips * tips;
GtkWidget * explore_view, * selection_view, * playlist_view,
* no_root_view, * prefs_view, * about_view;
#endif /* WITH_GUI */
GList * selected_songs, * selected_files;
/* We store a list of the directories which contain new songs (ie. lack
* rating/color info */
GList * new_song_dirs;
GHashTable * new_song_dirs_hash;
gint tree_depth; /* How deep does the tree go */

#ifdef WITH_GUI
/* Various Windows */
GtkWidget *main_window;
GtkWidget *notebook;
GtkWidget * prefs_window;
GtkWidget * message_window;
#endif /* WITH_GUI */


/* Songs */
Expand Down
4 changes: 3 additions & 1 deletion play_audacious.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <dlfcn.h>
#include <audacious/dbus.h>
#include <audacious/audctrl.h>
#include <gio/gio.h>
#include "gjay.h"
#include "songs.h"
#include "dbus.h"
Expand All @@ -57,7 +58,8 @@ audacious_init(void)

if ( (lib = dlopen("libaudclient.so.2", RTLD_GLOBAL | RTLD_LAZY)) == NULL)
{
gjay_error_dialog(_("Unable to open audcious client library, defaulting to no play."));
gjay_error_dialog(
_("Unable to open audcious client library, defaulting to no play."));
return FALSE;
}
if ( (gjaud_get_playlist_pos = gjay_dlsym(lib, "audacious_remote_get_playlist_pos")) == NULL)
Expand Down
9 changes: 9 additions & 0 deletions play_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void play_songs (GList *slist) {

if (!gjay->player_is_running())
{
#ifdef WITH_GUI
GtkWidget *dialog;
gint result;
gchar *msg;
Expand Down Expand Up @@ -124,6 +125,14 @@ void play_songs (GList *slist) {
}
} else /* user clicked no */
return;
#else
/* with no GUI assume you want it started */
if (gjay->player_start() == FALSE)
{
g_warning(_("Unable to start %s"), gjay->prefs->music_player_name);
return;
}
#endif /* WITH_GUI */
}
gjay->player_play_files(list);
}
Expand Down
6 changes: 5 additions & 1 deletion play_mpdclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mpdclient_init(void)

if ( (lib = dlopen("libmpdclient.so.2", RTLD_GLOBAL | RTLD_LAZY)) == NULL)
{
gjay_error_dialog(_("Unable to open mpd client library"));
gjay_error_dialog( _("Unable to open mpd client library"));
return FALSE;
}

Expand Down Expand Up @@ -144,7 +144,11 @@ mpdclient_play_files ( GList *list) {
if ( (*gjmpd_run_stop)(gjay->mpdclient_connection) == FALSE) {
errmsg = g_strdup_printf(_("Cannot stop Music Player Daemon: %s"),
(*gjmpd_connection_get_error_message)(gjay->mpdclient_connection));
#ifdef WITH_GUI
gjay_error_dialog(errmsg);
#else
g_error(errmsg);
#endif /* WITH_GUI */
g_free(errmsg);
}
if ( (*gjmpd_run_clear)(gjay->mpdclient_connection) == FALSE) {
Expand Down
3 changes: 3 additions & 0 deletions rgbhsv.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
#ifndef _RGBHSB_H_
#define _RGBHSB_H_

#include <glib.h>
#ifdef WITH_GUI
#include <gtk/gtk.h>
#endif /* WITH_GUI */

typedef struct {float R, G, B;} RGB;
typedef struct {float H, S, V;} HSV;
Expand Down
15 changes: 12 additions & 3 deletions songs.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include "mp3.h"
#include "vorbis.h"
#include "flac.h"
#include "ui.h"
#include "i18n.h"
#include "ui.h"


typedef enum {
Expand Down Expand Up @@ -139,10 +139,12 @@ song * create_song ( void ) {
}

void delete_song (song * s) {
#ifdef WITH_GUI
if(s->freq_pixbuf)
gdk_pixbuf_unref(s->freq_pixbuf);
if(s->color_pixbuf)
gdk_pixbuf_unref(s->color_pixbuf);
#endif /* WITH_GUI */
g_free(s->path);
g_free(s->title);
g_free(s->artist);
Expand All @@ -167,6 +169,7 @@ song * song_set_path ( song * s,
}


#ifdef WITH_GUI
/**
* If the song does not have a pixbuf for its frequency, and it has been
* analyzed, create a pixbuf for its frequency.
Expand Down Expand Up @@ -239,6 +242,7 @@ void song_set_color_pixbuf ( song * s) {
}
}
}
#endif /* WITH_GUI */


/**
Expand Down Expand Up @@ -267,8 +271,10 @@ void song_set_repeats ( song * s, song * original ) {
s->fname = fname;
s->repeat_prev = NULL;
s->repeat_next = NULL;
#ifdef WITH_GUI
s->freq_pixbuf = NULL;
s->color_pixbuf = NULL;
#endif /* WITH_GUI */

for (ll = original; ll->repeat_next; ll = ll->repeat_next)
;
Expand Down Expand Up @@ -933,7 +939,7 @@ gdouble song_force ( song * a, song * b ) {
/* Attraction is a value -1...1 for the affinity between A and B,
with criteria weighed by prefs */
gdouble song_attraction (song * a, song * b ) {
gdouble a_hue, a_saturation, a_brightness, a_freq, a_bpm, a_path;
gdouble a_hue, a_saturation, a_brightness, a_freq, a_bpm;
gdouble d, ba, bb, v_diff, a_max, attraction = 0;
gint i;
GjayPrefs *prefs = gjay->prefs;
Expand All @@ -951,7 +957,6 @@ gdouble song_attraction (song * a, song * b ) {
a_saturation = prefs->saturation / a_max;
a_freq = prefs->freq / a_max;
a_bpm = prefs->bpm / a_max;
a_path = prefs->path_weight / a_max;

if (!(a->no_color || b->no_color)) {
/* Hue is 0...6 */
Expand Down Expand Up @@ -1009,14 +1014,18 @@ gdouble song_attraction (song * a, song * b ) {
attraction += d * a_freq;
}

#ifdef WITH_GUI
/* FIXME - This is not really a GUI thing but a function using Gtk */
if (gjay->tree_depth && a->path && b->path) {
gdouble a_path = prefs->path_weight / a_max;
d = explore_files_depth_distance(a->path, b->path);
if (d >= 0) {
d = 1.0 - 2.0 * (d / gjay->tree_depth);
/* d = -1 ... 1, where 1 is more similiar */
attraction += d * a_path;
}
}
#endif /* WITH_GUI */
return attraction;
}

Expand Down
Loading

0 comments on commit e804dce

Please sign in to comment.