Esempio n. 1
0
/*
 * Private stuff
 */
static CdIo_t *
open_cd (xmms_xform_t *xform)
{
	CdIo_t *cdio;
	xmms_config_property_t *val;
	const gchar *device;
	const gchar *accessmode;

	cdio_log_set_handler (log_handler);

	val = xmms_xform_config_lookup (xform, "device");
	device = xmms_config_property_get_string (val);

	val = xmms_xform_config_lookup (xform, "accessmode");
	accessmode = xmms_config_property_get_string (val);

	XMMS_DBG ("Trying to open device '%s', using '%s' access mode.",
	          device, accessmode);

	if (g_ascii_strcasecmp (accessmode, "default") == 0) {
		cdio = cdio_open (device, DRIVER_UNKNOWN);
	} else {
		cdio = cdio_open_am (device, DRIVER_UNKNOWN, accessmode);
	}

	if (!cdio) {
		xmms_log_error ("Failed to open device '%s'.", device);
	} else {
		cdio_set_speed (cdio, 1);
		xmms_log_info ("Opened device '%s'.", device);
	}

	return cdio;
}
Esempio n. 2
0
static s4_t *
xmms_medialib_database_convert (const gchar *database_name,
                                const gchar *indices[])
{
	const gchar *coll_conf, *conv_conf;
	gchar *cmdline, *new_name, *obsolete_name;
	xmms_config_property_t *cfg;
	gint exit_status;
	s4_t *s4;

	cfg = xmms_config_lookup ("collection.directory");
	coll_conf = xmms_config_property_get_string (cfg);

	cfg = xmms_config_lookup ("sqlite2s4.path");
	conv_conf = xmms_config_property_get_string (cfg);

	new_name = xmms_medialib_database_converted_name (database_name);

	cmdline = g_strjoin (" ", conv_conf, database_name,
	                     new_name, coll_conf, NULL);

	xmms_log_info ("Attempting to migrate database to new format.");

	if (!g_spawn_command_line_sync (cmdline, NULL, NULL, &exit_status, NULL) || exit_status) {
		xmms_log_fatal ("Could not run \"%s\", try to run it manually", cmdline);
	}

	g_free (cmdline);

	s4 = s4_open (new_name, indices, 0);
	/* Now we give up */
	if (s4 == NULL) {
		xmms_log_fatal ("Could not open the S4 database");
	}

	xmms_log_info ("Migration successful.");

	/* Move the sqlite database */
	obsolete_name = g_strconcat (database_name, ".obsolete", NULL);
	g_rename (database_name, obsolete_name);
	g_free (obsolete_name);

	/* Update the config path */
	cfg = xmms_config_lookup ("medialib.path");
	xmms_config_property_set_data (cfg, new_name);

	g_free (new_name);

	return s4;
}
Esempio n. 3
0
File: main.c Progetto: chrippa/xmms2
/**
 * @internal Destroy the main object
 * @param[in] object The object to destroy
 */
static void
xmms_main_destroy (xmms_object_t *object)
{
	xmms_main_t *mainobj = (xmms_main_t *) object;
	xmms_config_property_t *cv;

	cv = xmms_config_lookup ("core.shutdownpath");
	do_scriptdir (xmms_config_property_get_string (cv), "stop");

	xmms_object_unref (mainobj->xform_object);
	xmms_object_unref (mainobj->visualization_object);
	xmms_object_unref (mainobj->output_object);
	xmms_object_unref (mainobj->bindata_object);
	xmms_object_unref (mainobj->playlist_object);
	xmms_object_unref (mainobj->colldag_object);
	xmms_object_unref (mainobj->medialib_object);
	xmms_object_unref (mainobj->mediainfo_object);
	xmms_object_unref (mainobj->plsupdater_object);
	xmms_object_unref (mainobj->collsync_object);

	xmms_config_save ();

	xmms_config_shutdown ();

	xmms_plugin_shutdown ();

	xmms_main_unregister_ipc_commands ();

	xmms_ipc_shutdown ();

	xmms_log_shutdown ();
}
Esempio n. 4
0
static xmms_xform_t *
add_effects (xmms_xform_t *last, xmms_medialib_entry_t entry,
             GList *goal_formats)
{
	gint effect_no;

	for (effect_no = 0; TRUE; effect_no++) {
		xmms_config_property_t *cfg;
		gchar key[64];
		const gchar *name;

		g_snprintf (key, sizeof (key), "effect.order.%i", effect_no);

		cfg = xmms_config_lookup (key);
		if (!cfg) {
			break;
		}

		name = xmms_config_property_get_string (cfg);

		if (!name[0]) {
			continue;
		}

		last = xmms_xform_new_effect (last, entry, goal_formats, name);
	}

	return last;
}
Esempio n. 5
0
static gboolean
xmms_cdda_browse (xmms_xform_t *xform, const gchar *url, xmms_error_t *error)
{
	track_t track_count, t;
	gchar cdda_url[XMMS_PATH_MAX];
	xmms_config_property_t *val;
	const gchar *device;
	gchar *disc_id;

	g_return_val_if_fail (xform, FALSE);

	val = xmms_xform_config_lookup (xform, "device");
	device = xmms_config_property_get_string (val);
	if (!get_disc_ids (device, &disc_id, 0, &track_count)) {
		return FALSE;
	}

	for (t = 1; t <= track_count; t++) {
		gchar trackno[3];

		g_snprintf (cdda_url, XMMS_PATH_MAX, "cdda://%s/%d", disc_id, t);
		XMMS_DBG ("Adding '%s'.", cdda_url);

		g_snprintf (trackno, sizeof (trackno), "%d", t);
		xmms_xform_browse_add_symlink (xform, trackno, cdda_url);
		xmms_xform_browse_add_entry_property_int (xform, "intsort", t);
	}
	g_free (disc_id);

	return TRUE;
}
Esempio n. 6
0
/**
 * @internal Destroy the main object
 * @param[in] object The object to destroy
 */
static void
xmms_main_destroy (xmms_object_t *object)
{
	xmms_main_t *mainobj = (xmms_main_t *) object;
	xmms_object_cmd_arg_t arg;
	xmms_config_property_t *cv;

	cv = xmms_config_lookup ("core.shutdownpath");
	do_scriptdir (xmms_config_property_get_string (cv), "stop");

	/* stop output */
	xmms_object_cmd_arg_init (&arg);

	xmms_object_cmd_call (XMMS_OBJECT (mainobj->output),
	                      XMMS_IPC_CMD_STOP, &arg);

	g_usleep (G_USEC_PER_SEC); /* wait for the output thread to end */

	xmms_object_unref (mainobj->vis);
	xmms_object_unref (mainobj->output);

	xmms_object_unref (xform_obj);

	xmms_config_save ();

	xmms_config_shutdown ();

	xmms_plugin_shutdown ();

	xmms_ipc_object_unregister (XMMS_IPC_OBJECT_MAIN);
	xmms_ipc_shutdown ();

	xmms_log_shutdown ();
}
Esempio n. 7
0
xmms_medialib_t *
xmms_medialib_init (void)
{
	xmms_config_property_t *cfg;
	xmms_medialib_t *medialib;
	const gchar *medialib_path;
	gchar *path;

	const gchar *indices[] = {
		XMMS_MEDIALIB_ENTRY_PROPERTY_URL,
		XMMS_MEDIALIB_ENTRY_PROPERTY_STATUS,
		NULL
	};

	medialib = xmms_object_new (xmms_medialib_t, xmms_medialib_destroy);

	xmms_medialib_register_ipc_commands (XMMS_OBJECT (medialib));

	path = XMMS_BUILD_PATH ("medialib.s4");
	cfg = xmms_config_property_register ("medialib.path", path, NULL, NULL);
	g_free (path);

	path = XMMS_BUILD_PATH ("collections", "${uuid}");
	xmms_config_property_register ("collection.directory", path, NULL, NULL);
	g_free (path);

	xmms_config_property_register ("sqlite2s4.path", "sqlite2s4", NULL, NULL);

	medialib_path = xmms_config_property_get_string (cfg);
	medialib->s4 = xmms_medialib_database_open (medialib_path, indices);
	medialib->default_sp = s4_sourcepref_create (xmmsv_default_source_pref);

	return medialib;
}
Esempio n. 8
0
static void
update_effect_properties (xmms_object_t *object, xmmsv_t *data,
                          gpointer userdata)
{
	gint effect_no = GPOINTER_TO_INT (userdata);
	const gchar *name;

	xmms_config_property_t *cfg;
	xmms_xform_plugin_t *xform_plugin;
	xmms_plugin_t *plugin;
	gchar key[64];

	name = xmms_config_property_get_string ((xmms_config_property_t *) object);

	if (name[0]) {
		plugin = xmms_plugin_find (XMMS_PLUGIN_TYPE_XFORM, name);
		if (!plugin) {
			xmms_log_error ("Couldn't find any effect named '%s'", name);
		} else {
			xform_plugin = (xmms_xform_plugin_t *) plugin;
			xmms_xform_plugin_config_property_register (xform_plugin, "enabled",
			                                            "1", NULL, NULL);
			xmms_object_unref (plugin);
		}

		/* setup new effect.order.n */
		g_snprintf (key, sizeof (key), "effect.order.%i", effect_no + 1);

		cfg = xmms_config_lookup (key);
		if (!cfg) {
			xmms_config_property_register (key, "", update_effect_properties,
			                               GINT_TO_POINTER (effect_no + 1));
		}
	}
}
Esempio n. 9
0
static void
xmms_replaygain_config_changed (xmms_object_t *obj, xmmsv_t *_val, gpointer udata)
{
    const gchar *name;
    xmms_xform_t *xform = udata;
    xmms_replaygain_data_t *data;
    gboolean dirty = FALSE;
    const char *value;

    data = xmms_xform_private_data_get (xform);
    g_return_if_fail (data);

    name = xmms_config_property_get_name ((xmms_config_property_t *) obj);
    value = xmms_config_property_get_string ((xmms_config_property_t *) obj);

    if (!g_ascii_strcasecmp (name, "replaygain.mode")) {
        data->mode = parse_mode (value);
        dirty = TRUE;
    } else if (!g_ascii_strcasecmp (name,
                                    "replaygain.use_anticlip")) {
        data->use_anticlip = !!atoi (value);
        dirty = TRUE;
    } else if (!g_ascii_strcasecmp (name,
                                    "replaygain.preamp")) {
        data->preamp = pow (10.0, atof (value) / 20.0);
        dirty = TRUE;
    } else if (!g_ascii_strcasecmp (name, "replaygain.enabled")) {
        data->enabled = !!atoi (value);
    }

    if (dirty) {
        compute_gain (xform, data);
    }
}
Esempio n. 10
0
static void
xmms_xform_effect_properties_update (xmms_object_t *object, xmmsv_t *data, gpointer udata)
{
	xmms_config_property_t *cfg = (xmms_config_property_t *) object;
	xmms_xform_plugin_t *plugin;
	const gchar *name;
	gchar key[64];
	gint effect_no = GPOINTER_TO_INT (udata);

	name = xmms_config_property_get_string (cfg);
	if (!name[0]) {
		return;
	}

	plugin = xmms_xform_find_plugin (name);
	if (!plugin) {
		xmms_log_error ("Couldn't find any effect named '%s'", name);
	} else {
		xmms_xform_plugin_config_property_register (plugin, "enabled",
		                                            "1", NULL, NULL);
		xmms_object_unref (plugin);
	}

	/* setup new effect.order.n */
	g_snprintf (key, sizeof (key), "effect.order.%i", effect_no + 1);
	if (!xmms_config_lookup (key)) {
		xmms_config_property_register (key, "", xmms_xform_effect_properties_update,
		                               GINT_TO_POINTER (effect_no + 1));
	}
}
Esempio n. 11
0
/**
 * Gets called when the config property "core.ipcsocket" has changed.
 */
void
on_config_ipcsocket_change (xmms_object_t *object, xmmsv_t *_data, gpointer udata)
{
	const gchar *value;

	XMMS_DBG ("Shutting down ipc server threads through config property \"core.ipcsocket\" change.");

	xmms_ipc_shutdown ();
	value = xmms_config_property_get_string ((xmms_config_property_t *) object);
	xmms_ipc_setup_server (value);
}
Esempio n. 12
0
static void
effect_callbacks_init (void)
{
	gint effect_no;

	xmms_config_property_t *cfg;
	xmms_xform_plugin_t *xform_plugin;
	xmms_plugin_t *plugin;
	gchar key[64];
	const gchar *name;

	for (effect_no = 0; ; effect_no++) {
		g_snprintf (key, sizeof (key), "effect.order.%i", effect_no);

		cfg = xmms_config_lookup (key);
		if (!cfg) {
			break;
		}
		xmms_config_property_callback_set (cfg, update_effect_properties,
		                                   GINT_TO_POINTER (effect_no));

		name = xmms_config_property_get_string (cfg);
		if (!name[0]) {
			continue;
		}

		plugin = xmms_plugin_find (XMMS_PLUGIN_TYPE_XFORM, name);
		if (!plugin) {
			xmms_log_error ("Couldn't find any effect named '%s'", name);
			continue;
		}

		xform_plugin = (xmms_xform_plugin_t *) plugin;
		xmms_xform_plugin_config_property_register (xform_plugin, "enabled",
		                                            "1", NULL, NULL);

		xmms_object_unref (plugin);
	}

	/* the name stored in the last present property was not "" or there was no
	   last present property */
	if ((!effect_no) || name[0]) {
			xmms_config_property_register (key, "", update_effect_properties,
			                               GINT_TO_POINTER (effect_no));
	}
}
Esempio n. 13
0
/**
 * @internal Switch to using another output plugin
 * @param object An object
 * @param data The name of the output plugin to switch to
 * @param userdata The #xmms_main_t object
 */
static void
change_output (xmms_object_t *object, xmmsv_t *_data, gpointer userdata)
{
	xmms_output_plugin_t *plugin;
	xmms_main_t *mainobj = (xmms_main_t*)userdata;
	const gchar *outname;

	if (!mainobj->output)
		return;

	outname = xmms_config_property_get_string ((xmms_config_property_t *) object);

	xmms_log_info ("Switching to output %s", outname);

	plugin = (xmms_output_plugin_t *)xmms_plugin_find (XMMS_PLUGIN_TYPE_OUTPUT, outname);
	if (!plugin) {
		xmms_log_error ("Baaaaad output plugin, try to change the output.plugin config variable to something usefull");
	} else {
		if (!xmms_output_plugin_switch (mainobj->output, plugin)) {
			xmms_log_error ("Baaaaad output plugin, try to change the output.plugin config variable to something usefull");
		}
	}
}
Esempio n. 14
0
static gboolean
xmms_id3v1_parse (xmms_xform_t *xform, guchar *buf)
{
	xmms_config_property_t *config;
	const char *encoding;
	const gchar *metakey;
	xmmsv_t *bb;
	unsigned char data[32];

	bb = xmmsv_new_bitbuffer_ro (buf, 128);

	xmmsv_bitbuffer_get_data (bb, data, 3);

	if (memcmp (data, "TAG", 3) != 0) {
		xmmsv_unref (bb);
		return FALSE;
	}

	XMMS_DBG ("Found ID3v1 TAG!");

	config = xmms_xform_config_lookup (xform, "id3v1_encoding");
	g_return_val_if_fail (config, FALSE);
	encoding = xmms_config_property_get_string (config);

	metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_TITLE;
	xmmsv_bitbuffer_get_data (bb, data, 30);
	xmms_id3v1_set (xform, metakey, data, 30, encoding);

	metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_ARTIST;
	xmmsv_bitbuffer_get_data (bb, data, 30);
	xmms_id3v1_set (xform, metakey, data, 30, encoding);

	metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_ALBUM;
	xmmsv_bitbuffer_get_data (bb, data, 30);
	xmms_id3v1_set (xform, metakey, data, 30, encoding);

	metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_YEAR;
	xmmsv_bitbuffer_get_data (bb, data, 4);
	xmms_id3v1_set (xform, metakey, data, 4, encoding);

	xmmsv_bitbuffer_get_data (bb, data, 30);

	/* v1.1 */
	if (data[28] == '\0' && data[29]) {
		metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_COMMENT;
		xmms_id3v1_set (xform, metakey, data, 28, encoding);
		metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_TRACKNR;
		if (!xmms_xform_metadata_has_val (xform, metakey)) {
			xmms_xform_metadata_set_int (xform, metakey, data[29]);
		}
	} else {
		metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_COMMENT;
		xmms_id3v1_set (xform, metakey, data, 30, encoding);
	}


	xmmsv_bitbuffer_get_data (bb, data, 1);
	metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_GENRE;
	if (data[0] >= G_N_ELEMENTS (id3_genres)) {
		xmms_xform_metadata_set_str (xform, metakey, "Unknown");
	} else {
		xmms_xform_metadata_set_str (xform, metakey, id3_genres[data[0]]);
	}


	xmmsv_unref (bb);
	return TRUE;
}
Esempio n. 15
0
static gboolean
xmms_cdda_init (xmms_xform_t *xform)
{
	CdIo_t *cdio = NULL;
	cdrom_drive_t *drive = NULL;
	const gchar *url;
	gchar **url_data = NULL;
	gchar *url_end;
	xmms_cdda_data_t *data;
	guint playtime;
	lsn_t first_lsn;
	track_t track;
	gchar *disc_id = NULL;
	gchar *cddb_id = NULL;
	xmms_config_property_t *val;
	const gchar *device;
	const gchar *metakey;
	gboolean ret = TRUE;

	g_return_val_if_fail (xform, FALSE);
	url = xmms_xform_indata_get_str (xform, XMMS_STREAM_TYPE_URL);

	if (g_ascii_strcasecmp (url, "cdda://") == 0) {
		xmms_xform_outdata_type_add (xform,
		                             XMMS_STREAM_TYPE_MIMETYPE,
		                             "application/x-xmms2-playlist-entries",
		                             XMMS_STREAM_TYPE_END);
		return TRUE;
	}

	val = xmms_xform_config_lookup (xform, "device");
	device = xmms_config_property_get_string (val);

	if (!get_disc_ids (device, &disc_id, &cddb_id, 0)) {
		return FALSE;
	}

	url += 7;
	url_data = g_strsplit (url, "/", 2);

	if (g_ascii_strcasecmp (url_data[0], disc_id)) {
		xmms_log_error ("Wrong disc inserted.");
		ret = FALSE;
		goto end;
	}

	if (url_data[1] == NULL) {
		xmms_log_error ("Missing track number.");
		ret = FALSE;
		goto end;
	}

	track = strtol (url_data[1], &url_end, 10);
	if (url_data[1] == url_end) {
		xmms_log_error ("Invalid track, need a number.");
		ret = FALSE;
		goto end;
	}

	cdio = open_cd (xform);
	if (!cdio) {
		ret = FALSE;
		goto end;
	}

	drive = cdio_cddap_identify_cdio (cdio, 1, NULL);
	if (!drive) {
		xmms_log_error ("Failed to identify drive.");
		ret = FALSE;
		goto end;
	}

	if (cdio_cddap_open (drive)) {
		xmms_log_error ("Unable to open disc.");
		ret = FALSE;
		goto end;
	}

	first_lsn = cdio_cddap_track_firstsector (drive, track);
	if (first_lsn == -1) {
		xmms_log_error ("No such track.");
		ret = FALSE;
		goto end;
	}

	data = g_new (xmms_cdda_data_t, 1);
	data->cdio = cdio;
	data->drive = drive;
	data->track = track;
	data->first_lsn = first_lsn;
	data->last_lsn = cdio_cddap_track_lastsector (drive, data->track);
	data->current_lsn = first_lsn;
	data->buf_used = CDIO_CD_FRAMESIZE_RAW;

	playtime = (data->last_lsn - data->first_lsn) *
	           1000.0 / CDIO_CD_FRAMES_PER_SEC;

	metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_DURATION;
	xmms_xform_metadata_set_int (xform, metakey, playtime);

	metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_BITRATE;
	xmms_xform_metadata_set_int (xform, metakey, 141120);

	xmms_xform_metadata_set_str (xform, "disc_id", url_data[0]);
	xmms_xform_metadata_set_str (xform, "cddb_id", cddb_id);

	metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_TRACKNR;
	xmms_xform_metadata_set_int (xform, metakey, track);

	xmms_xform_private_data_set (xform, data);

	xmms_xform_outdata_type_add (xform,
	                             XMMS_STREAM_TYPE_MIMETYPE,
	                             "audio/pcm",
	                             XMMS_STREAM_TYPE_FMT_FORMAT,
	                             XMMS_SAMPLE_FORMAT_S16,
	                             XMMS_STREAM_TYPE_FMT_CHANNELS,
	                             2,
	                             XMMS_STREAM_TYPE_FMT_SAMPLERATE,
	                             44100,
	                             XMMS_STREAM_TYPE_END);

end:
	/* These are to be destroyed in every cases... */
	g_free (cddb_id);
	g_free (disc_id);
	g_strfreev (url_data);

	/* destroy cdio/drive in case of failure */
	if (!ret) {
		if (drive) {
			cdio_cddap_close_no_free_cdio (drive);
		}
		if (cdio) {
			cdio_destroy (cdio);
		}
	}

	return ret;
}
Esempio n. 16
0
/**
 * The xmms2 daemon main initialisation function
 */
int
main (int argc, char **argv)
{
	xmms_output_plugin_t *o_plugin;
	xmms_config_property_t *cv;
	xmms_main_t *mainobj;
	int loglevel = 1;
	xmms_playlist_t *playlist;
	gchar default_path[XMMS_PATH_MAX + 16], *tmp;
	gboolean verbose = FALSE;
	gboolean quiet = FALSE;
	gboolean version = FALSE;
	gboolean nologging = FALSE;
	gboolean runasroot = FALSE;
	gboolean showhelp = FALSE;
	const gchar *outname = NULL;
	const gchar *ipcpath = NULL;
	gchar *ppath = NULL;
	int status_fd = -1;
	GOptionContext *context = NULL;
	GError *error = NULL;

	setlocale (LC_ALL, "");

	/**
	 * The options that the server accepts.
	 */
	GOptionEntry opts[] = {
		{"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Increase verbosity", NULL},
		{"quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, "Decrease verbosity", NULL},
		{"version", 'V', 0, G_OPTION_ARG_NONE, &version, "Print version", NULL},
		{"no-logging", 'n', 0, G_OPTION_ARG_NONE, &nologging, "Disable logging", NULL},
		{"output", 'o', 0, G_OPTION_ARG_STRING, &outname, "Use 'x' as output plugin", "<x>"},
		{"ipc-socket", 'i', 0, G_OPTION_ARG_FILENAME, &ipcpath, "Listen to socket 'url'", "<url>"},
		{"plugindir", 'p', 0, G_OPTION_ARG_FILENAME, &ppath, "Search for plugins in directory 'foo'", "<foo>"},
		{"conf", 'c', 0, G_OPTION_ARG_FILENAME, &conffile, "Specify alternate configuration file", "<file>"},
		{"status-fd", 's', 0, G_OPTION_ARG_INT, &status_fd, "Specify a filedescriptor to write to when started", "fd"},
		{"yes-run-as-root", 0, 0, G_OPTION_ARG_NONE, &runasroot, "Give me enough rope to shoot myself in the foot", NULL},
		{"show-help", 'h', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &showhelp, "Use --help or -? instead", NULL},
		{NULL}
	};

	/** Check that we are running against the correct glib version */
	if (glib_major_version != GLIB_MAJOR_VERSION ||
	    glib_minor_version < GLIB_MINOR_VERSION) {
		g_print ("xmms2d is build against version %d.%d,\n"
		         "but is (runtime) linked against %d.%d.\n"
		         "Refusing to start.\n",
		         GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
		         glib_major_version, glib_minor_version);
		exit (EXIT_FAILURE);
	}

	xmms_signal_block ();

	context = g_option_context_new ("- XMMS2 Daemon");
	g_option_context_add_main_entries (context, opts, NULL);
	if (!g_option_context_parse (context, &argc, &argv, &error) || error) {
		g_print ("Error parsing options: %s\n", error->message);
		g_clear_error (&error);
		exit (EXIT_FAILURE);
	}
	if (showhelp) {
#if GLIB_CHECK_VERSION(2,14,0)
		g_print ("%s", g_option_context_get_help (context, TRUE, NULL));
		exit (EXIT_SUCCESS);
#else
		g_print ("Please use --help or -? for help\n");
		exit (EXIT_FAILURE);
#endif
	}
	g_option_context_free (context);

	if (argc != 1) {
		g_print ("There were unknown options, aborting!\n");
		exit (EXIT_FAILURE);
	}

	if (xmms_checkroot ()) {
		if (runasroot) {
			g_print ("***************************************\n");
			g_print ("Warning! You are running XMMS2D as root, this is a bad idea!\nBut I'll allow it since you asked nicely.\n");
			g_print ("***************************************\n\n");
		} else {
			g_print ("PLEASE DON'T RUN XMMS2D AS ROOT!\n\n(if you really must, read the help)\n");
			exit (EXIT_FAILURE);
		}
	}

	if (verbose) {
		loglevel++;
	} else if (quiet) {
		loglevel--;
	}

	if (version) {
		print_version ();
	}

	g_thread_init (NULL);

	g_random_set_seed (time (NULL));

	xmms_log_init (loglevel);
	xmms_ipc_init ();

	load_config ();

	cv = xmms_config_property_register ("core.logtsfmt",
	                                    "%H:%M:%S ",
	                                    NULL, NULL);

	xmms_log_set_format (xmms_config_property_get_string (cv));

	xmms_fallback_ipcpath_get (default_path, sizeof (default_path));

	cv = xmms_config_property_register ("core.ipcsocket",
	                                    default_path,
	                                    on_config_ipcsocket_change,
	                                    NULL);

	if (!ipcpath) {
		/*
		 * if not ipcpath is specifed on the cmd line we
		 * grab it from the config
		 */
		ipcpath = xmms_config_property_get_string (cv);
	}

	if (!xmms_ipc_setup_server (ipcpath)) {
		xmms_ipc_shutdown ();
		xmms_log_fatal ("IPC failed to init!");
	}

	if (!xmms_plugin_init (ppath)) {
		return 1;
	}

	playlist = xmms_playlist_init ();
	xform_obj = xmms_xform_object_init ();
	bindata_obj = xmms_bindata_init ();

	mainobj = xmms_object_new (xmms_main_t, xmms_main_destroy);

	/* find output plugin. */
	cv = xmms_config_property_register ("output.plugin",
	                                    XMMS_OUTPUT_DEFAULT,
	                                    change_output, mainobj);

	if (outname) {
		xmms_config_property_set_data (cv, outname);
	}

	outname = xmms_config_property_get_string (cv);
	xmms_log_info ("Using output plugin: %s", outname);
	o_plugin = (xmms_output_plugin_t *)xmms_plugin_find (XMMS_PLUGIN_TYPE_OUTPUT, outname);
	if (!o_plugin) {
		xmms_log_error ("Baaaaad output plugin, try to change the"
		                "output.plugin config variable to something usefull");
	}

	mainobj->output = xmms_output_new (o_plugin, playlist);
	if (!mainobj->output) {
		xmms_log_fatal ("Failed to create output object!");
	}

	mainobj->vis = xmms_visualization_new (mainobj->output);

	if (status_fd != -1) {
		write (status_fd, "+", 1);
	}

	xmms_signal_init (XMMS_OBJECT (mainobj));

	xmms_ipc_object_register (XMMS_IPC_OBJECT_MAIN,
	                          XMMS_OBJECT (mainobj));

	xmms_ipc_broadcast_register (XMMS_OBJECT (mainobj),
	                             XMMS_IPC_SIGNAL_QUIT);

	xmms_object_cmd_add (XMMS_OBJECT (mainobj),
	                     XMMS_IPC_CMD_QUIT,
	                     XMMS_CMD_FUNC (quit));
	xmms_object_cmd_add (XMMS_OBJECT (mainobj),
	                     XMMS_IPC_CMD_HELLO,
	                     XMMS_CMD_FUNC (hello));
	xmms_object_cmd_add (XMMS_OBJECT (mainobj),
	                     XMMS_IPC_CMD_PLUGIN_LIST,
	                     XMMS_CMD_FUNC (plugin_list));
	xmms_object_cmd_add (XMMS_OBJECT (mainobj),
	                     XMMS_IPC_CMD_STATS,
	                     XMMS_CMD_FUNC (stats));

	/* Save the time we started in order to count uptime */
	mainobj->starttime = time (NULL);

	/* Dirty hack to tell XMMS_PATH a valid path */
	g_strlcpy (default_path, ipcpath, sizeof (default_path));

	tmp = strchr (default_path, ';');
	if (tmp) {
		*tmp = '\0';
	}

	g_setenv ("XMMS_PATH", default_path, TRUE);

	/* Also put the full path for clients that understands */
	g_setenv("XMMS_PATH_FULL", ipcpath, TRUE);

	tmp = XMMS_BUILD_PATH ("shutdown.d");
	cv = xmms_config_property_register ("core.shutdownpath",
	                                    tmp, NULL, NULL);
	g_free (tmp);

	tmp = XMMS_BUILD_PATH ("startup.d");
	cv = xmms_config_property_register ("core.startuppath",
	                                    tmp, NULL, NULL);
	g_free (tmp);

	/* Startup dir */
	do_scriptdir (xmms_config_property_get_string (cv), "start");

	mainloop = g_main_loop_new (NULL, FALSE);

	g_main_loop_run (mainloop);

	return 0;
}
Esempio n. 17
0
static gboolean
xmms_replaygain_init (xmms_xform_t *xform)
{
    xmms_replaygain_data_t *data;
    xmms_config_property_t *cfgv;
    xmms_sample_format_t fmt;

    g_return_val_if_fail (xform, FALSE);

    data = g_new0 (xmms_replaygain_data_t, 1);
    g_return_val_if_fail (data, FALSE);

    xmms_xform_private_data_set (xform, data);

    cfgv = xmms_xform_config_lookup (xform, "mode");
    xmms_config_property_callback_set (cfgv,
                                       xmms_replaygain_config_changed,
                                       xform);

    data->mode = parse_mode (xmms_config_property_get_string (cfgv));

    cfgv = xmms_xform_config_lookup (xform, "use_anticlip");
    xmms_config_property_callback_set (cfgv,
                                       xmms_replaygain_config_changed,
                                       xform);

    data->use_anticlip = !!xmms_config_property_get_int (cfgv);

    cfgv = xmms_xform_config_lookup (xform, "preamp");
    xmms_config_property_callback_set (cfgv,
                                       xmms_replaygain_config_changed,
                                       xform);

    data->preamp = pow (10.0, atof (xmms_config_property_get_string (cfgv)) / 20.0);

    cfgv = xmms_xform_config_lookup (xform, "enabled");
    xmms_config_property_callback_set (cfgv,
                                       xmms_replaygain_config_changed,
                                       xform);

    data->enabled = !!xmms_config_property_get_int (cfgv);

    xmms_xform_outdata_type_copy (xform);

    compute_gain (xform, data);

    fmt = xmms_xform_indata_get_int (xform, XMMS_STREAM_TYPE_FMT_FORMAT);

    switch (fmt) {
    case XMMS_SAMPLE_FORMAT_S8:
        data->apply = apply_s8;
        break;
    case XMMS_SAMPLE_FORMAT_U8:
        data->apply = apply_u8;
        break;
    case XMMS_SAMPLE_FORMAT_S16:
        data->apply = apply_s16;
        break;
    case XMMS_SAMPLE_FORMAT_U16:
        data->apply = apply_u16;
        break;
    case XMMS_SAMPLE_FORMAT_S32:
        data->apply = apply_s32;
        break;
    case XMMS_SAMPLE_FORMAT_U32:
        data->apply = apply_u32;
        break;
    case XMMS_SAMPLE_FORMAT_FLOAT:
        data->apply = apply_float;
        break;
    case XMMS_SAMPLE_FORMAT_DOUBLE:
        data->apply = apply_double;
        break;
    default:
        /* we shouldn't ever get here, since we told the daemon
         * earlier about this list of supported formats.
         */
        g_assert_not_reached ();
        break;
    }

    return TRUE;
}
Esempio n. 18
0
static void
xmms_sid_get_songlength (xmms_xform_t *xform)
{
	xmms_config_property_t *config;
	const gchar *tmp, *md5sum, *songlength_path;
	gint subtune = 1;
	GIOChannel* io;
	GString *buf;

	g_return_if_fail (xform);

	config = xmms_xform_config_lookup (xform, "songlength_path");
	g_return_if_fail (config);
	songlength_path = xmms_config_property_get_string (config);
	if (!songlength_path[0])
		return;

	if (xmms_xform_metadata_get_str (xform, "subtune", &tmp)) {
		subtune = atoi (tmp);
	}

	if (!xmms_xform_metadata_get_str (xform, "HVSCfingerprint", &md5sum)) {
		return;
	}

	io = g_io_channel_new_file (songlength_path, "r", NULL);
	if (!io) {
		xmms_log_error ("Unable to load songlengths database '%s'", songlength_path);
		return;
	}

	buf = g_string_new ("");
	while (g_io_channel_read_line_string (io, buf, NULL, NULL) == G_IO_STATUS_NORMAL) {
		if (buf->len > 33 && g_ascii_strncasecmp (buf->str, md5sum, 32) == 0) {
			gint cur = 0;
			gchar *b;

			b = buf->str + 33;
			while (*b) {
				gint min, sec;

				/* read timestamp */
				if (sscanf (b, "%d:%d", &min, &sec) != 2) {
					/* no more timestamps on this line */
					break;
				} else {
					cur++;
				}

				if (cur == subtune) {
					const gchar *metakey;
					gchar ms_str[10 + 1]; /* LONG_MAX in str, \w NULL */
					glong ms;

					ms = (min * 60 + sec) * 1000;

					metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_DURATION;
					xmms_xform_metadata_set_int (xform, metakey, ms);

					if (g_snprintf (ms_str, 10 + 1, "%ld", ms) > 0) {
						metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_STARTMS;
						xmms_xform_metadata_set_str (xform, metakey, "0");

						metakey = XMMS_MEDIALIB_ENTRY_PROPERTY_STOPMS;
						xmms_xform_metadata_set_str (xform, metakey, ms_str);
					}

					goto done;
				}

				/* forward to next possible timestamp */
				b = strchr (b, ' ');
				if (!b) {
					/* no more timestamps on this line */
					break;
				}
				b++;
			}
		}
	}
	xmms_log_info ("Couldn't find sid tune in songlength.txt");
done:
	g_io_channel_unref (io);
}
Esempio n. 19
0
static void
xmms_modplug_config_changed (xmms_object_t *obj, xmmsv_t *_value,
                             gpointer udata)
{
	xmms_modplug_data_t *data = udata;
	xmms_config_property_t *prop = (xmms_config_property_t *) obj;
	const gchar *name;
	const gchar *value;
	gint intvalue;

	name = xmms_config_property_get_name (prop);

	if (!g_ascii_strcasecmp (name, "modplug.resample")) {
		value = xmms_config_property_get_string (prop);

		if (!g_ascii_strcasecmp (value, "fir")) {
			data->settings.mResamplingMode = MODPLUG_RESAMPLE_FIR;
		} else if (!g_ascii_strcasecmp (value, "spline")) {
			data->settings.mResamplingMode = MODPLUG_RESAMPLE_SPLINE;
		} else if (!g_ascii_strcasecmp (value, "linear")) {
			data->settings.mResamplingMode = MODPLUG_RESAMPLE_LINEAR;
		} else {
			data->settings.mResamplingMode = MODPLUG_RESAMPLE_NEAREST;
		}
	} else {
		intvalue = xmms_config_property_get_int (prop);

		if (!g_ascii_strcasecmp (name, "modplug.freq")) {
			data->settings.mFrequency = intvalue;
		} else if (!g_ascii_strcasecmp (name, "modplug.reverb_depth")) {
			data->settings.mReverbDepth = intvalue;
		} else if (!g_ascii_strcasecmp (name, "modplug.reverb_delay")) {
			data->settings.mReverbDelay = intvalue;
		} else if (!g_ascii_strcasecmp (name, "modplug.bass_amount")) {
			data->settings.mBassAmount = intvalue;
		} else if (!g_ascii_strcasecmp (name, "modplug.bass_range")) {
			data->settings.mBassRange = intvalue;
		} else if (!g_ascii_strcasecmp (name, "modplug.surround_depth")) {
			data->settings.mSurroundDepth = intvalue;
		} else if (!g_ascii_strcasecmp (name, "modplug.surround_delay")) {
			data->settings.mSurroundDelay = intvalue;
		} else if (!g_ascii_strcasecmp (name, "modplug.loop")) {
			data->settings.mLoopCount = intvalue;
		} else if (!g_ascii_strcasecmp (name, "modplug.enable_oversampling")) {
			if (intvalue) {
				data->settings.mFlags |= MODPLUG_ENABLE_OVERSAMPLING;
			} else {
				data->settings.mFlags &= ~MODPLUG_ENABLE_OVERSAMPLING;
			}
		} else if (!g_ascii_strcasecmp (name,
		                                "modplug.enable_noise_reduction")) {
			if (intvalue) {
				data->settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION;
			} else {
				data->settings.mFlags &= ~MODPLUG_ENABLE_NOISE_REDUCTION;
			}
		} else if (!g_ascii_strcasecmp (name, "modplug.enable_reverb")) {
			if (intvalue) {
				data->settings.mFlags |= MODPLUG_ENABLE_REVERB;
			} else {
				data->settings.mFlags &= ~MODPLUG_ENABLE_REVERB;
			}
		} else if (!g_ascii_strcasecmp (name, "modplug.enable_megabass")) {
			if (intvalue) {
				data->settings.mFlags |= MODPLUG_ENABLE_MEGABASS;
			} else {
				data->settings.mFlags &= ~MODPLUG_ENABLE_MEGABASS;
			}
		} else if (!g_ascii_strcasecmp (name, "modplug.enable_surround")) {
			if (intvalue) {
				data->settings.mFlags |= MODPLUG_ENABLE_SURROUND;
			} else {
				data->settings.mFlags &= ~MODPLUG_ENABLE_SURROUND;
			}
		}
	}

	ModPlug_SetSettings (&data->settings);
}