Example #1
0
static inline void file_changed(struct track_info *ti)
{
	player_info_lock();
	if (ti) {
		d_print("file: %s\n", ti->filename);
	} else {
		d_print("unloaded\n");
	}
	__file_changed(ti);
	player_info_unlock();
}
Example #2
0
void player_set_rg_preamp(double db)
{
	player_lock();
	replaygain_preamp = db;

	player_info_lock();
	update_rg_scale();
	player_info_unlock();

	player_unlock();
}
Example #3
0
void player_set_rg_limit(int limit)
{
	player_lock();
	replaygain_limit = limit;

	player_info_lock();
	update_rg_scale();
	player_info_unlock();

	player_unlock();
}
Example #4
0
/*
 * buffer-fill changed
 */
static void __producer_buffer_fill_update(void)
{
	int fill;

	player_info_lock();
	fill = buffer_get_filled_chunks();
	if (fill != player_info.buffer_fill) {
/* 		d_print("\n"); */
		player_info.buffer_fill = fill;
		player_info.buffer_fill_changed = 1;
	}
	player_info_unlock();
}
Example #5
0
void player_set_rg(enum replaygain rg)
{
	player_lock();
	/* don't mess with scale_pos if soft_vol or replaygain is already enabled */
	if (!soft_vol && !replaygain)
		scale_pos = consumer_pos;
	replaygain = rg;

	player_info_lock();
	update_rg_scale();
	player_info_unlock();

	player_unlock();
}
Example #6
0
static void player_error(const char *msg)
{
	player_info_lock();
	player_info.status = (enum player_status)consumer_status;
	player_info.pos = 0;
	player_info.current_bitrate = -1;
	player_info.buffer_fill = buffer_get_filled_chunks();
	player_info.buffer_size = buffer_nr_chunks;
	player_info.status_changed = 1;

	free(player_info.error_msg);
	player_info.error_msg = xstrdup(msg);
	player_info_unlock();

	d_print("ERROR: '%s'\n", msg);
}
Example #7
0
/*
 * something big happened (stopped/paused/unpaused...)
 */
static void __player_status_changed(void)
{
	unsigned int pos = 0;

/* 	d_print("\n"); */
	if (consumer_status == CS_PLAYING || consumer_status == CS_PAUSED)
		pos = consumer_pos / buffer_second_size();

	player_info_lock();
	player_info.status = (enum player_status)consumer_status;
	player_info.pos = pos;
	player_info.current_bitrate = -1;
	player_info.buffer_fill = buffer_get_filled_chunks();
	player_info.buffer_size = buffer_nr_chunks;
	player_info.status_changed = 1;
	player_info_unlock();
}
Example #8
0
static inline void metadata_changed(void)
{
	struct keyval *comments;
	int rc;

	player_info_lock();
	if (ip_get_metadata(ip)) {
		d_print("metadata changed: %s\n", ip_get_metadata(ip));
		memcpy(player_info.metadata, ip_get_metadata(ip),
		       255 * 16 + 1);
	}

	rc = ip_read_comments(ip, &comments);
	if (!rc) {
		if (player_info.ti->comments)
			keyvals_free(player_info.ti->comments);
		track_info_set_comments(player_info.ti, comments);
	}

	player_info.metadata_changed = 1;
	player_info_unlock();
}
Example #9
0
/*
 * playing position changed
 */
static void __consumer_position_update(void)
{
	static unsigned int old_pos = -1;
	unsigned int pos = 0;
	long bitrate;

	if (consumer_status == CS_PLAYING || consumer_status == CS_PAUSED)
		pos = consumer_pos / buffer_second_size();
	if (pos != old_pos) {
		old_pos = pos;

		player_info_lock();
		player_info.pos = pos;

		if (show_current_bitrate) {
			bitrate = ip_current_bitrate(ip);
			if (bitrate != -1)
				player_info.current_bitrate = bitrate;
		}
		player_info.position_changed = 1;
		player_info_unlock();
	}
}
Example #10
0
static int cmd_status(struct client *client)
{
	const char *export_options[] = {
		"aaa_mode",
		"continue",
		"play_library",
		"play_sorted",
		"replaygain",
		"replaygain_limit",
		"replaygain_preamp",
		"repeat",
		"repeat_current",
		"shuffle",
		"softvol",
		NULL
	};
	const struct track_info *ti;
	struct cmus_opt *opt;
	char optbuf[OPTION_MAX_SIZE];
	GBUF(buf);
	int vol_left, vol_right;
	int i, ret;
	enum player_status status;

	player_info_lock();
	gbuf_addf(&buf, "status %s\n", player_status_names[player_info.status]);
	ti = player_info.ti;
	if (ti) {
		gbuf_addf(&buf, "file %s\n", escape(ti->filename));
		gbuf_addf(&buf, "duration %d\n", ti->duration);
		gbuf_addf(&buf, "position %d\n", player_info.pos);
		for (i = 0; ti->comments[i].key; i++)
			gbuf_addf(&buf, "tag %s %s\n",
					ti->comments[i].key,
					escape(ti->comments[i].val));
	}

	/* add track metadata to cmus-status */
	status = player_info.status;
	if (status == PLAYER_STATUS_PLAYING && ti && is_http_url(player_info.ti->filename)) {
	const char *title = get_stream_title();
		if (title != NULL) {
			free(title_buf);
			title_buf = to_utf8(title, icecast_default_charset);
			// we have a stream title (probably artist/track/album info)
			gbuf_addf(&buf, "stream %s\n", escape(title_buf));
		} else if (ti->comment != NULL) {
			// fallback to the radio station name
			gbuf_addf(&buf, "stream %s\n", escape(ti->comment));
		}
	}

	/* output options */
	for (i = 0; export_options[i]; i++) {
		opt = option_find(export_options[i]);
		if (opt) {
			opt->get(opt->id, optbuf);
			gbuf_addf(&buf, "set %s %s\n", opt->name, optbuf);
		}
	}

	/* get volume (copied from ui_curses.c) */
	if (soft_vol) {
		vol_left = soft_vol_l;
		vol_right = soft_vol_r;
	} else if (!volume_max) {
		vol_left = vol_right = -1;
	} else {
		vol_left = scale_to_percentage(volume_l, volume_max);
		vol_right = scale_to_percentage(volume_r, volume_max);
	}

	/* output volume */
	gbuf_addf(&buf, "set vol_left %d\n", vol_left);
	gbuf_addf(&buf, "set vol_right %d\n", vol_right);

	gbuf_add_str(&buf, "\n");
	player_info_unlock();

	ret = write_all(client->fd, buf.buffer, buf.len);
	gbuf_free(&buf);
	return ret;
}