Skip to content

Commit

Permalink
max working set comes from preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Small committed Mar 23, 2010
1 parent 4127b99 commit 530f54d
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 21 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes in 0.3.1
* Fixed bug where frequency ranges were all 0
* Various fixes in frequency analysis by Frank V
* Added FLAC support based on Rob Norris' code SF#1443646
* max working set is set at preferences based on kweinder's patch SF#1052970

Changes in 0.3.0
================
Expand Down
1 change: 1 addition & 0 deletions constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

/* For prefs */
#define DEFAULT_PLAYLIST_TIME 72
#define DEFAULT_MAX_WORKING_SET 1500

#define HELP_TEXT "USAGE: gjay [--help] [-hdvpux] [-l length] [-c color]\n" \
"\t--help, -h : Display this help message\n" \
Expand Down
5 changes: 1 addition & 4 deletions playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ static void remove_repeats ( song * s, GList * list);

#define PATH_DIST_FACTOR 0.5

/* Limit size of working set to 1500 songs */
#define MAX_WORKING_SET 1500

/**
* Generate a playlist (list of song *) no longer than the specified
* time, in minutes
Expand Down Expand Up @@ -149,7 +146,7 @@ GList * generate_playlist ( guint minutes ) {
/* Regretably, we must winnow the working set to something reasonable.
If there were 10,000 songs, this would take ~20 seconds on a fast
machine. */
for (len = g_list_length(working); len > MAX_WORKING_SET; len--) {
for (len = g_list_length(working); len > gjay->prefs->max_working_set; len--) {
s = SONG(g_list_nth(working, rand() % len));
working = g_list_remove(working, s);
}
Expand Down
12 changes: 12 additions & 0 deletions prefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* <path_weight>...
* <color type="hsv">float float float</color>
* <time>int</time>
* <max_working_set>int</max_working_set>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -63,6 +64,7 @@ typedef enum {
PE_PATH_WEIGHT,
PE_COLOR,
PE_TIME,
PE_MAX_WORKING_SET,
/* attributes */
PE_EXTENSION_FILTER,
PE_HIDE_TIP,
Expand Down Expand Up @@ -97,6 +99,7 @@ char * pref_element_strs[PE_LAST] = {
"path_weight",
"color",
"time",
"max_working_set",
"extension_filter",
"hide_tip",
"wander",
Expand Down Expand Up @@ -144,6 +147,7 @@ load_prefs ( void ) {
prefs->rating = DEFAULT_RATING;
prefs->use_ratings = FALSE;
prefs->time = DEFAULT_PLAYLIST_TIME;
prefs->max_working_set = DEFAULT_MAX_WORKING_SET;
prefs->variance =
prefs->hue =
prefs->brightness =
Expand Down Expand Up @@ -241,6 +245,11 @@ void save_prefs ( void ) {
prefs->time,
pref_element_strs[PE_TIME]);

fprintf(f, "<%s>%d</%s>\n",
pref_element_strs[PE_MAX_WORKING_SET],
prefs->max_working_set,
pref_element_strs[PE_MAX_WORKING_SET]);

fprintf(f, "<%s %s=\"hsv\">%f %f %f</%s>\n",
pref_element_strs[PE_COLOR],
pref_element_strs[PE_TYPE],
Expand Down Expand Up @@ -432,6 +441,9 @@ void data_text ( GMarkupParseContext *context,
break;
default:
break;
case PE_MAX_WORKING_SET:
gjay->prefs->max_working_set = atoi(buffer);
break;
}
*element = PE_LAST;
}
Expand Down
1 change: 1 addition & 0 deletions prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ typedef struct {
gboolean start_color;
gboolean wander;
gboolean rating_cutoff;
int max_working_set;

/* Playlist len, in minutes */
guint time;
Expand Down
73 changes: 56 additions & 17 deletions ui_prefs_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "gjay.h"
#include "ui.h"
#include "ipc.h"
#include "i18n.h"


static char * welcome_str =
Expand Down Expand Up @@ -56,11 +57,14 @@ static void tooltips_toggled ( GtkToggleButton *togglebutton,
gpointer user_data );
static void useratings_toggled ( GtkToggleButton *togglebutton,
gpointer user_data );
static void max_working_set_callback (GtkWidget *widget,
gpointer user_data);

GtkWidget * make_prefs_view ( void ) {
GtkWidget * vbox1, * vbox2, * alignment, *dir_label, * button, *label;
GtkWidget * radio1, * radio2, * radio3;
GtkWidget * hseparator;
GtkWidget * hseparator, * hbox1, *max_working_set_entry;
char buffer[BUFFER_SIZE];

vbox1 = gtk_vbox_new (FALSE, 2);

Expand All @@ -70,7 +74,7 @@ GtkWidget * make_prefs_view ( void ) {
gtk_container_add(GTK_CONTAINER(alignment), vbox2);

dir_label = gtk_label_new(NULL);
gtk_label_set_markup(GTK_LABEL(dir_label),"<b>Base Directory</b>");
gtk_label_set_markup(GTK_LABEL(dir_label),_("<b>Base Directory</b>"));
gtk_box_pack_start(GTK_BOX(vbox2), dir_label, TRUE, TRUE, 2);


Expand All @@ -79,7 +83,7 @@ GtkWidget * make_prefs_view ( void ) {
vbox2 = gtk_vbox_new (FALSE, 2);
gtk_container_add(GTK_CONTAINER(alignment), vbox2);

button = gtk_file_chooser_button_new("Set base music directory",
button = gtk_file_chooser_button_new(_("Set base music directory"),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(button),
(gjay->prefs->song_root_dir?gjay->prefs->song_root_dir:g_get_home_dir()));
Expand All @@ -101,14 +105,14 @@ GtkWidget * make_prefs_view ( void ) {
gtk_container_add(GTK_CONTAINER(alignment), vbox2);


label = gtk_label_new("When you quit, song analysis should...");
radio1 = gtk_radio_button_new_with_label (NULL, "Stop");
label = gtk_label_new(_("When you quit, song analysis should..."));
radio1 = gtk_radio_button_new_with_label (NULL, _("Stop"));
radio2 = gtk_radio_button_new_with_label_from_widget (
GTK_RADIO_BUTTON (radio1),
"Continue in background");
_("Continue in background"));
radio3 = gtk_radio_button_new_with_label_from_widget (
GTK_RADIO_BUTTON (radio2),
"Ask");
_("Ask"));
if (gjay->prefs->daemon_action == PREF_DAEMON_QUIT)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio1), TRUE);
else if (gjay->prefs->daemon_action == PREF_DAEMON_DETACH)
Expand Down Expand Up @@ -136,28 +140,46 @@ GtkWidget * make_prefs_view ( void ) {
alignment = gtk_alignment_new(0, 0, 0, 0);
gtk_box_pack_start(GTK_BOX(vbox1), alignment, TRUE, TRUE, 0);

button = gtk_check_button_new_with_label("Show popup tips");
/*button = gtk_check_button_new_with_label("Show popup tips");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
!(gjay->prefs->hide_tips));
g_signal_connect (G_OBJECT (button), "toggled",
G_CALLBACK (tooltips_toggled), NULL);
gtk_container_add(GTK_CONTAINER(alignment), button);

*/

hseparator = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox1), hseparator, TRUE, TRUE, 2);

alignment = gtk_alignment_new(0, 0, 0, 0);
gtk_box_pack_start(GTK_BOX(vbox1), alignment, TRUE, TRUE, 0);

button = gtk_check_button_new_with_label("Use song ratings");
button = gtk_check_button_new_with_label(_("Use song ratings"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
gjay->prefs->use_ratings);
g_signal_connect (G_OBJECT (button), "toggled",
G_CALLBACK (useratings_toggled), NULL);
gtk_container_add(GTK_CONTAINER(alignment), button);


hseparator = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox1), hseparator, TRUE, TRUE, 2);

label = gtk_label_new(_("Max working set"));
max_working_set_entry = gtk_entry_new_with_max_length (6);
snprintf(buffer, BUFFER_SIZE, "%d", gjay->prefs->max_working_set);
gtk_entry_set_text(GTK_ENTRY(max_working_set_entry), buffer);
gtk_widget_set_tooltip_text (max_working_set_entry,
_("On large collections, building playlists can take a long time. So gjay first picks this number of songs randomly, then continues the selection from that subset. Increase this number if you're willing to tolerate longer waiting times for increased accuracy."));

gtk_widget_set_size_request(max_working_set_entry, 60, -1);
g_signal_connect (G_OBJECT (max_working_set_entry), "changed",
G_CALLBACK (max_working_set_callback), NULL);
hbox1 = gtk_hbox_new(FALSE, 2);
gtk_box_pack_start(GTK_BOX(hbox1), label, FALSE, FALSE, 2);
gtk_box_pack_start(GTK_BOX(hbox1), max_working_set_entry, FALSE, FALSE, 2);
gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0);

hseparator = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(vbox1), hseparator, TRUE, TRUE, 2);

Expand Down Expand Up @@ -201,7 +223,7 @@ GtkWidget * make_no_root_view ( void ) {

vbox2 = gtk_vbox_new (FALSE, 2);
gtk_container_add(GTK_CONTAINER(alignment), vbox2);
button = new_button_label_pixbuf("Choose base music directory",
button = new_button_label_pixbuf(_("Choose base music directory"),
PM_BUTTON_DIR);
gtk_signal_connect(GTK_OBJECT(button), "clicked",
G_CALLBACK (choose_base_dir), NULL);
Expand All @@ -212,7 +234,7 @@ GtkWidget * make_no_root_view ( void ) {
static void choose_base_dir (GtkWidget *button, gpointer user_data) {
GtkWidget *dialog;

dialog = gtk_file_chooser_dialog_new("Set base music directory",
dialog = gtk_file_chooser_dialog_new(_("Set base music directory"),
GTK_WINDOW(gjay->main_window), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
Expand Down Expand Up @@ -244,7 +266,7 @@ static void set_base_dir ( char *path ) {
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error getting status of directory '%s': %s",
_("Error getting status of directory '%s': %s"),
path, g_strerror(errno));
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
Expand All @@ -255,7 +277,7 @@ static void set_base_dir ( char *path ) {
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Path '%s' is not a directory.",
_("Path '%s' is not a directory."),
path);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
Expand All @@ -271,7 +293,7 @@ static void set_base_dir ( char *path ) {
prefs_update_song_dir();
gtk_idle_add(explore_view_set_root_idle, NULL);

set_add_files_progress("Scanning tree...", 0);
set_add_files_progress(_("Scanning tree..."), 0);
set_analysis_progress_visible(FALSE);
set_add_files_progress_visible(TRUE);
}
Expand All @@ -293,10 +315,10 @@ void prefs_update_song_dir ( void ) {
char buffer[BUFFER_SIZE];
if (gjay->prefs->song_root_dir) {
snprintf(buffer, BUFFER_SIZE,
"Base directory is '%s'", gjay->prefs->song_root_dir);
_("Base directory is '%s'"), gjay->prefs->song_root_dir);
save_prefs();
} else {
snprintf(buffer, BUFFER_SIZE, "No base directory set");
snprintf(buffer, BUFFER_SIZE, _("No base directory set"));
}
}

Expand Down Expand Up @@ -332,4 +354,21 @@ static void useratings_toggled ( GtkToggleButton *togglebutton,
save_prefs();
}

static void max_working_set_callback ( GtkWidget *widget,
gpointer user_data ) {
const gchar * text;
unsigned int val;
char *buffer;

text = gtk_entry_get_text(GTK_ENTRY(widget));
if ( (val = strtoul(text, NULL, 10)) == 0)
{
val = DEFAULT_MAX_WORKING_SET;
buffer = g_strdup_printf("%u", val);
gtk_entry_set_text(GTK_ENTRY(widget), buffer);
g_free(buffer);
}
gjay->prefs->max_working_set = val;
save_prefs();
}

0 comments on commit 530f54d

Please sign in to comment.