Exemplo n.º 1
0
Arquivo: command.c Projeto: daaang/mpc
int
cmd_volume(int argc, char **argv, struct mpd_connection *conn)
{
	struct int_value_change ch;

	if (argc == 1) {
		if (!parse_int_value_change(argv[0], &ch))
			DIE("\"%s\" is not an integer\n", argv[0]);
	} else {
		struct mpd_status *status = getStatus(conn);

		if (mpd_status_get_volume(status) >= 0)
			printf("volume:%3i%c\n",
			       mpd_status_get_volume(status), '%');
		else
			printf("volume: n/a\n");

		mpd_status_free(status);
		return 0;
	}

	if (ch.is_relative) {
#if LIBMPDCLIENT_CHECK_VERSION(2,9,0)
		if (mpd_connection_cmp_server_version(conn, 0, 18, 0) >= 0) {
			/* MPD 0.18 knows the "volume" command for
			   relative changes */
			if (!mpd_run_change_volume(conn, ch.value))
				printErrorAndExit(conn);
			return 1;
		}
#endif

		struct mpd_status *status = getStatus(conn);
		int old_volume = mpd_status_get_volume(status);
		mpd_status_free(status);

		ch.value += old_volume;
		if (ch.value < 0)
			ch.value = 0;
		else if (ch.value > 100)
			ch.value = 100;

		if (ch.value == old_volume)
			return 1;
	}

	if (!mpd_run_set_volume(conn, ch.value))
		printErrorAndExit(conn);
	return 1;
}
Exemplo n.º 2
0
int getVolume(Config* config, int status) {
	if(!config->mpd_status) {
		return -1;
	}
	int volume = mpd_status_get_volume(config->mpd_status);
	return volume;
}
Exemplo n.º 3
0
void mpd_put_state(void)
{
    struct mpd_status *status;
    int len;
    unsigned queue_len;
    int song_pos, next_song_pos;

    status = mpd_run_status(mpd.conn);
    
    if (!status) {
        syslog(LOG_ERR, "%s mpd_run_status: %s\n", __func__, mpd_connection_get_error_message(mpd.conn));
        mpd.conn_state = MPD_FAILURE;
        return;
    }

    mpd.song_pos = mpd_status_get_song_pos(status);
    mpd.next_song_pos = song_pos+1; //TODO: mpd_status_get_next_song_pos(status);
    mpd.queue_len = mpd_status_get_queue_length(status);
    mpd.volume = mpd_status_get_volume(status);
    mpd.state = mpd_status_get_state(status);
    mpd.repeat = mpd_status_get_repeat(status);
    mpd.single = mpd_status_get_single(status);
    mpd.consume = mpd_status_get_consume(status);
    mpd.random = mpd_status_get_random(status);
    mpd.elapsed_time = mpd_status_get_elapsed_time(status);
    mpd.total_time = mpd_status_get_total_time(status);
    mpd.song_id = mpd_status_get_song_id(status);

//    printf("%d\n", mpd.song_id);

    mpd_status_free(status);
}
Exemplo n.º 4
0
int mpd_put_state(char *buffer, int *current_song_id, unsigned *queue_version)
{
    struct mpd_status *status;
    int len;

    status = mpd_run_status(mpd.conn);
    if (!status) {
        fprintf(stderr, "MPD mpd_run_status: %s\n", mpd_connection_get_error_message(mpd.conn));
        mpd.conn_state = MPD_FAILURE;
        return 0;
    }

    len = snprintf(buffer, MAX_SIZE,
        "{\"type\":\"state\", \"data\":{"
        " \"state\":%d, \"volume\":%d, \"repeat\":%d,"
        " \"single\":%d, \"consume\":%d, \"random\":%d, "
        " \"songpos\": %d, \"elapsedTime\": %d, \"totalTime\":%d, "
        " \"currentsongid\": %d"
        "}}", 
        mpd_status_get_state(status),
        mpd_status_get_volume(status), 
        mpd_status_get_repeat(status),
        mpd_status_get_single(status),
        mpd_status_get_consume(status),
        mpd_status_get_random(status),
        mpd_status_get_song_pos(status),
        mpd_status_get_elapsed_time(status),
        mpd_status_get_total_time(status),
        mpd_status_get_song_id(status));

    *current_song_id = mpd_status_get_song_id(status);
    *queue_version = mpd_status_get_queue_version(status);
    mpd_status_free(status);
    return len;
}
Exemplo n.º 5
0
int mpd_status_set_volume(MpdObj *mi,int volume)
{
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return MPD_NOT_CONNECTED;
	}
	/* making sure volume is between 0 and 100 */
	volume = (volume < 0)? 0:(volume>100)? 100:volume;

	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR,"lock failed\n");
		return MPD_LOCK_FAILED;
	}

	/* send the command */
	mpd_sendSetvolCommand(mi->connection , volume);
	mpd_finishCommand(mi->connection);
	/* check for errors */

	mpd_unlock_conn(mi);
	/* update status, because we changed it */
	mpd_status_queue_update(mi);
	/* return current volume */
	return mpd_status_get_volume(mi);
}
Exemplo n.º 6
0
int
gimmix_get_volume (MpdObj *mo)
{
	int volume;

	volume = mpd_status_get_volume (mo);
	return volume;
}
Exemplo n.º 7
0
int cmd_volume ( int argc, char ** argv, struct mpd_connection *conn )
{
        struct int_value_change ch;
	struct mpd_status *status;

	if(argc==1) {
                if(!parse_int_value_change(argv[0], &ch))
			DIE("\"%s\" is not an integer\n", argv[0]);
	} else {
		status = getStatus(conn);

		if (mpd_status_get_volume(status) >= 0)
			printf("volume:%3i%c\n",
			       mpd_status_get_volume(status), '%');
		else
			printf("volume: n/a\n");

		mpd_status_free(status);

		return 0;
	}

	if (ch.is_relative) {
		int old_volume;

		status = getStatus(conn);
		old_volume = mpd_status_get_volume(status);
		mpd_status_free(status);

		ch.value += old_volume;
		if (ch.value < 0)
			ch.value = 0;
		else if (ch.value > 100)
			ch.value = 100;

		if (ch.value == old_volume)
			return 1;
	}

	if (!mpd_run_set_volume(conn, ch.value))
		printErrorAndExit(conn);
	return 1;
}
Exemplo n.º 8
0
static void
gimmix_update_volume ()
{
	gint 			volume;
	GtkAdjustment	*volume_adj;
	
	volume_adj = gtk_range_get_adjustment (GTK_RANGE(volume_scale));
	volume = mpd_status_get_volume (gmo);
	gtk_adjustment_set_value (GTK_ADJUSTMENT(volume_adj), volume);
	
	return;
}
Exemplo n.º 9
0
void status_changed(MpdObj *mi, ChangedStatusType what)
{
    pthread_mutex_lock(&lockit);

    mpd_Song *song = mpd_playlist_get_current_song(mi);
    if(song) {
        if (song->artist!=NULL) {
            strncpy(track_info.artist,song->artist,99);
        } else {
            track_info.artist[0] = 0;
        }
        if (song->title!=NULL) {
            strncpy(track_info.title,song->title,99);
        } else {
            track_info.title[0] = 0;
        }
    }

    if(what&MPD_CST_CROSSFADE){
        // printf(GREEN"X-Fade:"RESET" %i sec.\n",mpd_status_get_crossfade(mi));
    }

    if(what&MPD_CST_PLAYLIST)
    {
        // printf(GREEN"Playlist changed"RESET"\n");
        track_info.totalsongs_in_playlist = mpd_playlist_get_playlist_length(mi);

    }

    if(what&MPD_CST_ELAPSED_TIME && !voltimeout){
        track_info.elapsed = mpd_status_get_elapsed_song_time(mi);
        track_info.total = mpd_status_get_total_song_time(mi);
    }

    if(what&MPD_CST_VOLUME){
        voltimeout=100;
        track_info.volume = mpd_status_get_volume(mi);
    }

    if(what&MPD_CST_STATE) {
        track_info.playstate = mpd_player_get_state(mi);
    }

    track_info.repeat = mpd_player_get_repeat(obj);
    track_info.random = mpd_player_get_random(obj);

    pthread_mutex_unlock(&lockit);
    usleep(10*1000);
}
Exemplo n.º 10
0
static void volume_set(gpointer data, const char *param)
{
	int cur_volume = mpd_status_get_volume(connection);
	/* if volume is disabled (current_volume < 0) ignore this command */
	if (strlen(param) > 0 && current_volume >= 0)
	{
		int volume = 0;
		if (param[0] == '-' || param[0] == '+')
		{
			volume = cur_volume;
		}
		volume += atoi(param);
		mpd_status_set_volume(connection, volume);
	}
}
Exemplo n.º 11
0
/**
 * Mixer event function.
 * @param conn: mpd connection
 * @param status: mpd status
 * @return This function should return MPDCRON_RUN_SUCCESS on success.
 *         This function should return MPDCRON_RUN_RECONNECT to schedule
 *           a reconnection to mpd server.
 *         This function should return MPDCRON_RUN_RECONNECT_NOW to
 *           schedule a reconnection by cancelling to run any of the next
 *           modules in the queue.
 *         This function should return MPDCRON_RUN_UNLOAD when the
 *           module needs to be unloaded.
 */
int run(G_GNUC_UNUSED const struct mpd_connection *conn, const struct mpd_status *status)
{
	int volume;

	if (count-- <= 0)
		return MPDCRON_EVENT_UNLOAD;

	volume = mpd_status_get_volume(status);

	if (last_volume < 0)
		mpdcron_log(LOG_INFO, "Volume set to: %d%%", volume);
	else
		mpdcron_log(LOG_INFO, "Volume %s from: %d to: %d%%",
				(last_volume < volume) ? "increased" : "decreased",
				last_volume, volume);

	last_volume = volume;
	return MPDCRON_EVENT_SUCCESS;
}
Exemplo n.º 12
0
void
Mpd_status::assign_status(struct mpd_status * status)
{
	const struct mpd_audio_format	*format;
	uint32_t ms;

	volume			= mpd_status_get_volume(status);
	repeat			= mpd_status_get_repeat(status);
	single			= mpd_status_get_single(status);
	random			= mpd_status_get_random(status);
	consume			= mpd_status_get_consume(status);
	playlist_length		= mpd_status_get_queue_length(status);
	playlist		= mpd_status_get_queue_version(status);
	state			= mpd_status_get_state(status);
	crossfade		= mpd_status_get_crossfade(status);
	song			= mpd_status_get_song_pos(status);
	songid			= mpd_status_get_song_id(status);
	time_total		= mpd_status_get_total_time(status);
	db_updating		= mpd_status_get_update_id(status);

	/* Time elapsed */
#if LIBMPDCLIENT_CHECK_VERSION(2, 1, 0)
	ms = mpd_status_get_elapsed_ms(status);
#else
	ms = mpd_status_get_elapsed(status) * 1000;
#endif
	set_time_elapsed_ms(ms);

	/* Audio format */
	bitrate			= mpd_status_get_kbit_rate(status);
	format			= mpd_status_get_audio_format(status);

	if (!format) {
		return;
	}

	samplerate		= format->sample_rate;
	bits			= format->bits;
	channels		= format->channels;
}
Exemplo n.º 13
0
static int lmpdstatus_index(lua_State *L)
{
	const char *key;
	const struct mpd_audio_format *audio_format;
	struct mpd_status **status;

	status = luaL_checkudata(L, 1, MPD_STATUS_T);
	key = luaL_checkstring(L, 2);

	assert(*status != NULL);

	if (strncmp(key, "volume", 7) == 0) {
		lua_pushinteger(L, mpd_status_get_volume(*status));
		return 1;
	}
	else if (strncmp(key, "repeat", 7) == 0) {
		lua_pushinteger(L, mpd_status_get_repeat(*status));
		return 1;
	}
	else if (strncmp(key, "random", 7) == 0) {
		lua_pushinteger(L, mpd_status_get_random(*status));
		return 1;
	}
	else if (strncmp(key, "single", 7) == 0) {
		lua_pushinteger(L, mpd_status_get_single(*status));
		return 1;
	}
	else if (strncmp(key, "consume", 8) == 0) {
		lua_pushinteger(L, mpd_status_get_consume(*status));
		return 1;
	}
	else if (strncmp(key, "queue_length", 16) == 0) {
		lua_pushnumber(L, mpd_status_get_queue_length(*status));
		return 1;
	}
	else if (strncmp(key, "queue_version", 17) == 0) {
		lua_pushnumber(L, mpd_status_get_queue_version(*status));
		return 1;
	}
	else if (strncmp(key, "state", 6) == 0) {
		lua_pushinteger(L, mpd_status_get_state(*status));
		return 1;
	}
	else if (strncmp(key, "crossfade", 10) == 0) {
		lua_pushinteger(L, mpd_status_get_crossfade(*status));
		return 1;
	}
	else if (strncmp(key, "song_pos", 5) == 0) {
		lua_pushinteger(L, mpd_status_get_song_pos(*status));
		return 1;
	}
	else if (strncmp(key, "song_id", 7) == 0) {
		lua_pushinteger(L, mpd_status_get_song_id(*status));
		return 1;
	}
	else if (strncmp(key, "elapsed_time", 13) == 0) {
		lua_pushinteger(L, mpd_status_get_elapsed_time(*status));
		return 1;
	}
	else if (strncmp(key, "total_time", 11) == 0) {
		lua_pushinteger(L, mpd_status_get_total_time(*status));
		return 1;
	}
	else if (strncmp(key, "kbit_rate", 10) == 0) {
		lua_pushinteger(L, mpd_status_get_kbit_rate(*status));
		return 1;
	}
	else if (strncmp(key, "audio_format", 13) == 0) {
		audio_format = mpd_status_get_audio_format(*status);
		lua_newtable(L);

		lua_pushinteger(L, audio_format->sample_rate);
		lua_setfield(L, -2, "sample_rate");

		lua_pushinteger(L, audio_format->bits);
		lua_setfield(L, -2, "bits");

		lua_pushinteger(L, audio_format->channels);
		lua_setfield(L, -2, "channels");

		return 1;
	}
	else if (strncmp(key, "update_id", 11) == 0) {
		lua_pushinteger(L, mpd_status_get_update_id(*status));
		return 1;
	}
	else if (strncmp(key, "error", 6) == 0) {
		lua_pushstring(L, mpd_status_get_error(*status));
		return 1;
	}
	else
		return luaL_error(L, "Invalid key `%s'", key);
}
Exemplo n.º 14
0
void *Lkeys_thread() {
    int keystate = 0;
    int volume;
    struct pollfd fds;
    char ver[5];

    strncpy(ver,G15DAEMON_VERSION,3);
    float g15v;
    sscanf(ver,"%f",&g15v);

    fds.fd = g15screen_fd;
    fds.events = POLLIN;

    while(!leaving){
        int foo=0;
        current_fg_check = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo);
        static int last_fg_check = 0;
        if(playlist_mode && last_fg_check != current_fg_check){
            if(own_keyboard){
                if(current_fg_check==0){
                    own_keyboard=0;
                }
            }else if(current_fg_check && !own_keyboard) {
                own_keyboard=1;
            }
            last_fg_check = current_fg_check;   
        }


        /* g15daemon series 1.2 need key request packets */
        pthread_mutex_lock(&daemon_mutex);
        if((g15v*10)<=18) {
            keystate = g15_send_cmd (g15screen_fd, G15DAEMON_GET_KEYSTATE, foo);
        } else {
            if ((poll(&fds, 1, 5)) > 0)
                read (g15screen_fd, &keystate, sizeof (keystate));
        }
        pthread_mutex_unlock(&daemon_mutex);

        if (keystate)
        {
            switch (keystate)
            {
                case G15_KEY_L1:
                    exit(1); // FIXME quick hack to exit
                    break;
                case G15_KEY_L2:
                    menulevel++;
                    if(menulevel>=MAX_MENU_MODES)
                        menulevel=0;
                    break;
                case G15_KEY_L3:
                    if(!own_keyboard){
                        own_keyboard=playlist_mode=1;
                        mpd_Song *song = mpd_playlist_get_current_song(obj);
                        if(song)
                            if(song->pos)
                                track_info.currentsong=song->pos;
                    }else{ //de-activate
                        own_keyboard=playlist_mode=0;
                    }
                    break;
                case G15_KEY_L4:
                    if(menulevel==MENU_MODE1){
                        mpd_player_set_random(obj,mpd_player_get_random(obj)^1);
                    }
                    if(menulevel==MENU_MODE2){
                        volume=mpd_status_get_volume(obj);
                        if(volume>0)
                            volume-=10;
                        mpd_status_set_volume (obj,volume);
                    }
                    break;
                case G15_KEY_L5:
                    if(menulevel==MENU_MODE1){
                        mpd_player_set_repeat(obj, mpd_player_get_repeat(obj)^1);
                    }
                    if(menulevel==MENU_MODE2){
                        volume=mpd_status_get_volume(obj);
                        if(volume<100)
                            volume+=10;
                        mpd_status_set_volume (obj,volume);
                    }
                    break;
                default:
                    break;
            }
            keystate = 0;
        }
        usleep(100*1000);
    }
    return NULL;
}
Exemplo n.º 15
0
int main(int argc, char **argv)
{
    int fdstdin = 0;
    pthread_t Lkeys;
    pthread_t g15display;
    pthread_t EKeys;
    int volume;
    int volume_new;
    char devname[256] = "Unknown";
    int iport = 6600;
    char *hostname = getenv("MPD_HOST");
    char *port = getenv("MPD_PORT");
    char *password = getenv("MPD_PASSWORD");
    int eventdev;
    char evdev_name[128];
    pthread_mutex_init(&lockit,NULL);
    pthread_mutex_init(&daemon_mutex,NULL);
    int i;
      
    for (i=0;i<argc;i++) {
    char argument[20];
    memset(argument,0,20);
    strncpy(argument,argv[i],19);
    if (!strncmp(argument, "-q",2) || !strncmp(argument, "--quickscroll",13)) {
        quickscroll=1;
    }
    if (!strncmp(argument, "-h",2) || !strncmp(argument, "--help",6)) {
        printf("  %s version %s\n  (c)2006-2007 Mike Lampard\n\n",argv[0],VERSION);
        printf("%s -q or --quickscroll	Use volume control to scroll through the playlist\n",argv[0]);
        printf("%s -v or --version	Show program version\n",argv[0]);
        printf("%s -h or --help		This help text\n\n",argv[0]);
        exit(0);
    }
    if (!strncmp(argument, "-v",2) || !strncmp(argument, "--version",9)) {
      printf("%s version %s\n",argv[0],VERSION);
      exit(0);     
    }    
  }

    
    for(eventdev=0;eventdev<127;eventdev++) {
        snprintf(evdev_name,127,"/dev/input/event%i",eventdev);
        if ((mmedia_fd = open(evdev_name, O_NONBLOCK|O_RDONLY)) < 0) {
            // ignore errors when opening devices
            //printf("error opening interface %i\n",eventdev);
        } else {
            ioctl(mmedia_fd, EVIOCGNAME(sizeof(devname)), devname);
            printf("Device Name %s on %s\n", devname, evdev_name);
            if(0==strncmp(devname,"Logitech Logitech Gaming Keyboard",256)){
                printf("Found device: \"%s\" on %s ", devname,evdev_name);
                break;
            } else if(0==strncmp(devname,"G15 Gaming Keyboard",256)){
                printf("Found device: \"%s\" on %s ", devname,evdev_name);
                break;
            }else
                close(mmedia_fd);
        }
    }
    if (mmedia_fd) { // we assume that the next event device is the multimedia keys
        close(mmedia_fd);
        snprintf(evdev_name,127,"/dev/input/event%i",++eventdev);
        printf("and %s\n",evdev_name);
        if ((mmedia_fd = open(evdev_name, O_NONBLOCK|O_RDONLY)) < 0) {
            printf("error opening interface %i",eventdev);
        }
    }else {
        printf("Unable to find Keyboard via EVENT interface... is /dev/input/event[0-9] readable??\n");
    }

    /* set correct hostname */	
    if(!hostname) {
        hostname = "localhost";
    }
    if(port){
        iport = atoi(port);
    }

    if((g15screen_fd = new_g15_screen(G15_G15RBUF))<0){
        printf("Sorry, cant connect to the G15daemon\n");
        return 1;
    }

    canvas = (g15canvas *) malloc (sizeof (g15canvas));
    if (canvas != NULL) {
        memset(canvas->buffer, 0, G15_BUFFER_LEN);
        canvas->mode_cache = 0;
        canvas->mode_reverse = 0;
        canvas->mode_xor = 0;
    }

    /* Create mpd object */
    obj = mpd_new(hostname, iport,password); 
    /* Connect signals */
    mpd_signal_connect_error(obj,(ErrorCallback)error_callback, NULL);
    mpd_signal_connect_status_changed(obj,(StatusChangedCallback)status_changed, NULL);
    /* Set timeout */
    mpd_set_connection_timeout(obj, 10);

    if(0==mpd_connect(obj))
    {
        char buffer[20];
        pthread_attr_t attr;

        mpd_send_password(obj);
        memset(buffer, '\0', 20);
        pthread_attr_init(&attr);
        pthread_attr_setstacksize(&attr,32*1024); /* set stack to 64k - dont need 8Mb !! */

        pthread_create(&Lkeys, &attr, Lkeys_thread, NULL);
        pthread_create(&EKeys, &attr,event_key_thread, NULL);
        pthread_create(&g15display, &attr, g15display_thread, NULL);

        do{
            pthread_mutex_lock(&daemon_mutex);
            if(voltimeout) 
               --voltimeout;
            if(mute){
                volume_adjust = 0;
                mute = 0;
                if (muted_volume == 0) {
                    //printf("mute\n");
                    muted_volume = mpd_status_get_volume(obj);
                    mpd_status_set_volume (obj,0);
                } else {
                    //printf("unmute\n");
                    if (mpd_status_get_volume(obj) == 0) { /* if no other client has set volume up */
                        mpd_status_set_volume (obj,muted_volume);
                    }
                    muted_volume = 0;
                }
            }
            if(volume_adjust != 0){
                if (muted_volume != 0) {
                    volume=muted_volume;
                } else {
                    volume=mpd_status_get_volume(obj);
                }
                volume_new = volume + volume_adjust;
                volume_adjust = 0;
                if(volume_new < 0)
                    volume_new = 0;
                if(volume_new > 100)
                    volume_new = 100;
                if(volume != volume_new || muted_volume){
                    //printf("volume %d -> %d\n", volume, volume_new);
                    mpd_status_set_volume (obj,volume_new);
                }
                voltimeout=100;
                muted_volume=0;
            }
            mpd_status_update(obj);
            pthread_mutex_unlock(&daemon_mutex);

        }while(!usleep(5000) &&  !leaving);
      leaving = 1;
      pthread_join(Lkeys,NULL);
      pthread_join(g15display,NULL);
    }else
      printf("Unable to connect to MPD server. Exiting\n");

    if(obj)
      mpd_free(obj);
    close(fdstdin);

    if(canvas!=NULL)
        free(canvas);

    close(g15screen_fd);
    close(mmedia_fd);

    pthread_mutex_destroy(&lockit);

    return 1;
}
Exemplo n.º 16
0
void
gimmix_init (void)
{
	GtkWidget 		*widget;
	GtkWidget		*progressbox;
	GtkAdjustment		*vol_adj;
	GdkPixbuf		*app_icon;
	gchar			*path;
	
	/* Set the application icon */
	main_window = glade_xml_get_widget (xml, "main_window");
	g_signal_connect (G_OBJECT(main_window), "delete-event", G_CALLBACK(cb_gimmix_main_window_delete_event), NULL);
	gtk_window_set_default_size (GTK_WINDOW(main_window), -1, 80);
	gtk_window_resize (GTK_WINDOW(main_window), atoi(cfg_get_key_value(conf, "window_width")), atoi(cfg_get_key_value(conf, "window_height")));
	gtk_window_move (GTK_WINDOW(main_window), atoi(cfg_get_key_value(conf, "window_xpos")), atoi(cfg_get_key_value(conf, "window_ypos")));
	path = gimmix_get_full_image_path (GIMMIX_APP_ICON);
	app_icon = gdk_pixbuf_new_from_file_at_size (path, 48, 48, NULL);
	gtk_window_set_icon (GTK_WINDOW(main_window), app_icon);
	g_object_unref (app_icon);
	g_free (path);
	
	/* connect the key press signal */
	g_signal_connect (G_OBJECT(main_window), "key-press-event", G_CALLBACK(cb_gimmix_key_press), NULL);
	
	g_signal_connect (G_OBJECT(main_window), "configure-event", G_CALLBACK(cb_gimmix_main_window_configure_event), (gpointer)glade_xml_get_widget(xml, "volume_window"));
	
	/* connect the destroy signal */
	g_signal_connect(G_OBJECT(main_window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
	
	/* set icons for buttons */
	gtk_image_set_from_stock (GTK_IMAGE(glade_xml_get_widget(xml, "image_prev")), "gtk-media-previous", GTK_ICON_SIZE_BUTTON);
	gtk_image_set_from_stock (GTK_IMAGE(glade_xml_get_widget(xml, "image_play")), "gtk-media-play", GTK_ICON_SIZE_BUTTON);
	gtk_image_set_from_stock (GTK_IMAGE(glade_xml_get_widget(xml, "image_next")), "gtk-media-next", GTK_ICON_SIZE_BUTTON);
	gtk_image_set_from_stock (GTK_IMAGE(glade_xml_get_widget(xml, "image_stop")), "gtk-media-stop", GTK_ICON_SIZE_BUTTON);
	
	g_signal_connect (G_OBJECT(glade_xml_get_widget (xml, "prev_button")), "clicked", G_CALLBACK(cb_prev_button_clicked), NULL);

	g_signal_connect (G_OBJECT(glade_xml_get_widget (xml, "play_button")), "clicked", G_CALLBACK(cb_play_button_clicked), NULL);
	
	g_signal_connect (G_OBJECT(glade_xml_get_widget (xml, "next_button")), "clicked", G_CALLBACK(cb_next_button_clicked), NULL);
	
	g_signal_connect (G_OBJECT(glade_xml_get_widget (xml, "stop_button")), "clicked", G_CALLBACK(cb_stop_button_clicked), NULL);
	
	g_signal_connect (G_OBJECT(glade_xml_get_widget (xml, "pref_button")), "clicked", G_CALLBACK(cb_pref_button_clicked), NULL);
	
	shuffle_toggle_button = glade_xml_get_widget (xml, "shuffle_toggle");
	repeat_toggle_button = glade_xml_get_widget (xml, "repeat_toggle");
	volume_window = glade_xml_get_widget (xml, "volume_window");
	volume_scale = glade_xml_get_widget (xml, "volume_scale");
	volume_button = glade_xml_get_widget (xml, "volume_button");
	playlist_button = glade_xml_get_widget (xml, "playlist_button");
	playlist_box = glade_xml_get_widget (xml, "playlistbox");
	song_label = glade_xml_get_widget (xml, "song_label");
	artist_label = glade_xml_get_widget (xml, "artist_label");
	search_entry = glade_xml_get_widget (xml, "search_label");
	play_button = glade_xml_get_widget (xml, "play_button");
	image_play = glade_xml_get_widget (xml, "image_play");
	
	g_signal_connect (G_OBJECT(playlist_button), "button-press-event", G_CALLBACK(cb_playlist_button_press), NULL);

	if (is_gimmix_repeat (gmo))
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(repeat_toggle_button), TRUE);
	g_signal_connect (G_OBJECT(repeat_toggle_button), "toggled", G_CALLBACK(cb_repeat_button_toggled), NULL);
	
	if (is_gimmix_shuffle (gmo))
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(shuffle_toggle_button), TRUE);
	g_signal_connect (G_OBJECT(shuffle_toggle_button), "toggled", G_CALLBACK(cb_shuffle_button_toggled), NULL);

	widget = glade_xml_get_widget (xml, "info_button");
	g_signal_connect (G_OBJECT(widget), "button-release-event", G_CALLBACK(cb_info_button_press), NULL);

	g_signal_connect (G_OBJECT(volume_scale), "value_changed", G_CALLBACK(cb_volume_scale_changed), NULL);
	g_signal_connect (G_OBJECT(volume_scale), "scroll_event", G_CALLBACK(cb_volume_slider_scroll), NULL);
	vol_adj = gtk_range_get_adjustment (GTK_RANGE(volume_scale));
	gtk_adjustment_set_value (GTK_ADJUSTMENT(vol_adj), mpd_status_get_volume (gmo));
	g_signal_connect (G_OBJECT(volume_button), "clicked", G_CALLBACK(cb_volume_button_clicked), volume_window);
	g_signal_connect (G_OBJECT(volume_button), "scroll_event", G_CALLBACK(cb_volume_slider_scroll), NULL);

	progress = glade_xml_get_widget (xml,"progress");
	progressbox = glade_xml_get_widget (xml,"progress_event_box");
	g_signal_connect (G_OBJECT(progressbox), "button_press_event", G_CALLBACK(cb_gimmix_progress_seek), NULL);
	
	play_button_tooltip = gtk_tooltips_new ();
	
	if (strncasecmp(cfg_get_key_value(conf, "enable_systray"), "true", 4) == 0)
	{
		gimmix_create_systray_icon ();
	}
	if (strncasecmp(cfg_get_key_value(conf, "full_view_mode"), "true", 4) == 0)
	{	
		gtk_widget_show (playlist_box);
		gtk_window_set_resizable (GTK_WINDOW(main_window), TRUE);
	}
	else
	{	
		gtk_widget_hide (playlist_box);
		gtk_window_set_resizable (GTK_WINDOW(main_window), FALSE);
	}
	
	mpd_status_update (gmo);
	status = mpd_player_get_state (gmo);

	if (status == MPD_PLAYER_PLAY)
	{
		gimmix_set_song_info ();
		status = -1;
		gtk_image_set_from_stock (GTK_IMAGE(image_play), "gtk-media-pause", GTK_ICON_SIZE_BUTTON);
		gtk_tooltips_set_tip (play_button_tooltip, play_button, _("Pause <x or c>"), NULL);
	}
	else if (status == MPD_PLAYER_PAUSE)
	{
		gimmix_set_song_info ();
	}
	else if (status == MPD_PLAYER_STOP)
	{
		gtk_progress_bar_set_text (GTK_PROGRESS_BAR(progress), _("Stopped"));
		if (strncasecmp(cfg_get_key_value(conf, "enable_systray"), "true", 4) == 0)
		gtk_progress_bar_set_text (GTK_PROGRESS_BAR(tooltip->progressbar), _("Stopped"));
		gimmix_show_ver_info ();
	}

	g_timeout_add (300, (GSourceFunc)gimmix_timer, NULL);

	/* connect the main mpd callbacks */
	mpd_signal_connect_status_changed (gmo, (StatusChangedCallback)gimmix_status_changed, NULL);
	mpd_signal_connect_error (gmo, (ErrorCallback)gimmix_mpd_error, NULL);
	
	/* initialize playlist and tag editor */
	gimmix_playlist_init ();
	gimmix_tag_editor_init ();
	gimmix_update_current_playlist ();
	
	/* initialize preferences dialog */
	gimmix_prefs_init ();
	
	g_object_unref (xml);
	
	/* show the main window */
	gtk_widget_show (main_window);
	
	/* check if library needs to be updated on startup */
	if (strncasecmp(cfg_get_key_value(conf, "update_on_startup"), "true", 4) == 0)
	gimmix_library_update ();
	
	return;
}
Exemplo n.º 17
0
static void
env_export_status(struct mpd_status *status)
{
	char *envstr;
	const struct mpd_audio_format *fmt;

	envstr = g_strdup_printf("%d", mpd_status_get_volume(status));
	g_setenv("MPD_STATUS_VOLUME", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_repeat(status));
	g_setenv("MPD_STATUS_REPEAT", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_random(status));
	g_setenv("MPD_STATUS_RANDOM", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_single(status));
	g_setenv("MPD_STATUS_SINGLE", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_consume(status));
	g_setenv("MPD_STATUS_CONSUME", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_queue_length(status));
	g_setenv("MPD_STATUS_QUEUE_LENGTH", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_queue_version(status));
	g_setenv("MPD_STATUS_QUEUE_VERSION", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_crossfade(status));
	g_setenv("MPD_STATUS_CROSSFADE", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_song_pos(status));
	g_setenv("MPD_STATUS_SONG_POS", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_song_id(status));
	g_setenv("MPD_STATUS_SONG_ID", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%u", mpd_status_get_elapsed_time(status));
	g_setenv("MPD_STATUS_ELAPSED_TIME", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%u", mpd_status_get_elapsed_ms(status));
	g_setenv("MPD_STATUS_ELAPSED_MS", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%u", mpd_status_get_total_time(status));
	g_setenv("MPD_STATUS_TOTAL_TIME", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%u", mpd_status_get_kbit_rate(status));
	g_setenv("MPD_STATUS_KBIT_RATE", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%u", mpd_status_get_update_id(status));
	g_setenv("MPD_STATUS_UPDATE_ID", envstr, 1);
	g_free(envstr);

	g_setenv("MPD_STATUS_STATE", env_strstate(mpd_status_get_state(status)), 1);

	if ((fmt = mpd_status_get_audio_format(status)) == NULL)
		g_setenv("MPD_STATUS_AUDIO_FORMAT", "0", 1);
	else {
		g_setenv("MPD_STATUS_AUDIO_FORMAT", "1", 1);

		envstr = g_strdup_printf("%u", fmt->sample_rate);
		g_setenv("MPD_STATUS_AUDIO_FORMAT_SAMPLE_RATE", envstr, 1);
		g_free(envstr);

		envstr = g_strdup_printf("%u", fmt->bits);
		g_setenv("MPD_STATUS_AUDIO_FORMAT_BITS", envstr, 1);
		g_free(envstr);

		envstr = g_strdup_printf("%u", fmt->channels);
		g_setenv("MPD_STATUS_AUDIO_FORMAT_CHANNELS", envstr, 1);
		g_free(envstr);
	}
}
Exemplo n.º 18
0
void
updatempdstatus(void) {
    char statustext[STEXTSIZE];
    struct mpd_status *s = NULL;
    struct mpd_song *so = NULL;
    int s_volume,
        s_flagmask,
        s_queuelength,
        s_songpos,
        s_state,
        s_songlen,
        s_songtime;
    int s_time_r, s_time_min, s_time_sec;
    const char *artist, *title;

    if(mpdcmd_connect() != 0)
        return;

    s = mpd_run_status(mpdc);
    if(s == NULL)
        return;

    // retrieve status information

    if((s_state = mpd_status_get_state(s)) == MPD_STATE_STOP ||
        (so = mpd_run_current_song(mpdc)) == NULL)
        goto EXIT;

    s_volume = mpd_status_get_volume(s);
    s_queuelength = mpd_status_get_queue_length(s);
    s_songpos = mpd_status_get_song_pos(s);
    s_songlen = mpd_status_get_total_time(s);
    s_songtime = mpd_status_get_elapsed_time(s);
    s_time_r = s_songlen - s_songtime;
    s_time_sec = s_time_r % 60;
    s_time_min = (s_time_r - s_time_sec) / 60;
    if(mpd_status_get_consume(s) == 1)
        s_flagmask |= MpdFlag_Consume;
    if(mpd_status_get_single(s) == 1)
        s_flagmask |= MpdFlag_Single;
    if(mpd_status_get_random(s) == 1)
        s_flagmask |= MpdFlag_Random;
    if(mpd_status_get_repeat(s) == 1)
        s_flagmask |= MpdFlag_Repeat;
    artist = mpd_song_get_tag(so, MPD_TAG_ARTIST, 0);
    title = mpd_song_get_tag(so, MPD_TAG_TITLE, 0);


    //%artist - %title (-%total-%elapsed) [$flags] [#%pos/%queuelength]

    snprintf(statustext, STEXTSIZE,
            "%s - %s  (-%d:%02d)",
            artist != NULL ? artist : "名無し",
            title != NULL ? title : "曲名無し",
            s_time_min,
            s_time_sec);
    strncpy(stext, statustext, STEXTSIZE);

EXIT:;
    mpd_song_free(so);
    mpd_status_free(s);
    return;
}
Exemplo n.º 19
0
int main(int argc, char ** argv) {
	struct mpd_connection *conn;

	conn = mpd_connection_new(NULL, 0, 30000);

	if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
		return handle_error(conn);

	{
		int i;
		for(i=0;i<3;i++) {
			printf("version[%i]: %i\n",i,
			       mpd_connection_get_server_version(conn)[i]);
		}
	}

	if(argc==1) {
		struct mpd_status * status;
		struct mpd_song *song;
		const struct mpd_audio_format *audio_format;

		mpd_command_list_begin(conn, true);
		mpd_send_status(conn);
		mpd_send_current_song(conn);
		mpd_command_list_end(conn);

		status = mpd_recv_status(conn);
		if (status == NULL)
			return handle_error(conn);

		printf("volume: %i\n", mpd_status_get_volume(status));
		printf("repeat: %i\n", mpd_status_get_repeat(status));
		printf("queue version: %u\n", mpd_status_get_queue_version(status));
		printf("queue length: %i\n", mpd_status_get_queue_length(status));
		if (mpd_status_get_error(status) != NULL)
			printf("error: %s\n", mpd_status_get_error(status));

		if (mpd_status_get_state(status) == MPD_STATE_PLAY ||
		    mpd_status_get_state(status) == MPD_STATE_PAUSE) {
			printf("song: %i\n", mpd_status_get_song_pos(status));
			printf("elaspedTime: %i\n",mpd_status_get_elapsed_time(status));
			printf("elasped_ms: %u\n", mpd_status_get_elapsed_ms(status));
			printf("totalTime: %i\n", mpd_status_get_total_time(status));
			printf("bitRate: %i\n", mpd_status_get_kbit_rate(status));
		}

		audio_format = mpd_status_get_audio_format(status);
		if (audio_format != NULL) {
			printf("sampleRate: %i\n", audio_format->sample_rate);
			printf("bits: %i\n", audio_format->bits);
			printf("channels: %i\n", audio_format->channels);
		}

		mpd_status_free(status);

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
			return handle_error(conn);

		mpd_response_next(conn);

		while ((song = mpd_recv_song(conn)) != NULL) {
			printf("uri: %s\n", mpd_song_get_uri(song));
			print_tag(song, MPD_TAG_ARTIST, "artist");
			print_tag(song, MPD_TAG_ALBUM, "album");
			print_tag(song, MPD_TAG_TITLE, "title");
			print_tag(song, MPD_TAG_TRACK, "track");
			print_tag(song, MPD_TAG_NAME, "name");
			print_tag(song, MPD_TAG_DATE, "date");

			if (mpd_song_get_duration(song) > 0) {
				printf("time: %u\n", mpd_song_get_duration(song));
			}

			printf("pos: %u\n", mpd_song_get_pos(song));

			mpd_song_free(song);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	}
	else if(argc==3 && strcmp(argv[1],"lsinfo")==0) {
		struct mpd_entity * entity;

		if (!mpd_send_list_meta(conn, argv[2]))
			return handle_error(conn);

		while ((entity = mpd_recv_entity(conn)) != NULL) {
			const struct mpd_song *song;
			const struct mpd_directory *dir;
			const struct mpd_playlist *pl;

			switch (mpd_entity_get_type(entity)) {
			case MPD_ENTITY_TYPE_UNKNOWN:
				break;

			case MPD_ENTITY_TYPE_SONG:
				song = mpd_entity_get_song(entity);
				printf("uri: %s\n", mpd_song_get_uri(song));
				print_tag(song, MPD_TAG_ARTIST, "artist");
				print_tag(song, MPD_TAG_ALBUM, "album");
				print_tag(song, MPD_TAG_TITLE, "title");
				print_tag(song, MPD_TAG_TRACK, "track");
				break;

			case MPD_ENTITY_TYPE_DIRECTORY:
				dir = mpd_entity_get_directory(entity);
				printf("directory: %s\n", mpd_directory_get_path(dir));
				break;

			case MPD_ENTITY_TYPE_PLAYLIST:
				pl = mpd_entity_get_playlist(entity);
				printf("playlist: %s\n",
				       mpd_playlist_get_path(pl));
				break;
			}

			mpd_entity_free(entity);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	}
	else if(argc==2 && strcmp(argv[1],"artists")==0) {
		struct mpd_pair *pair;

		if (!mpd_search_db_tags(conn, MPD_TAG_ARTIST) ||
		    !mpd_search_commit(conn))
			return handle_error(conn);

		while ((pair = mpd_recv_pair_tag(conn,
						 MPD_TAG_ARTIST)) != NULL) {
			printf("%s\n", pair->value);
			mpd_return_pair(conn, pair);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	} else if (argc == 2 && strcmp(argv[1], "playlists") == 0) {
		if (!mpd_send_list_playlists(conn))
			return handle_error(conn);

		struct mpd_playlist *playlist;
		while ((playlist = mpd_recv_playlist(conn)) != NULL) {
			printf("%s\n",
			       mpd_playlist_get_path(playlist));
			mpd_playlist_free(playlist);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	} else if (argc == 2 && strcmp(argv[1], "idle") == 0) {
		enum mpd_idle idle = mpd_run_idle(conn);
		if (idle == 0 &&
		    mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
			return handle_error(conn);

		for (unsigned j = 0;; ++j) {
			enum mpd_idle i = 1 << j;
			const char *name = mpd_idle_name(i);

			if (name == NULL)
				break;

			if (idle & i)
				printf("%s\n", name);
		}
	} else if (argc == 3 && strcmp(argv[1], "subscribe") == 0) {
		/* subscribe to a channel and print all messages */

		if (!mpd_run_subscribe(conn, argv[2]))
			return handle_error(conn);

		while (mpd_run_idle_mask(conn, MPD_IDLE_MESSAGE) != 0) {
			if (!mpd_send_read_messages(conn))
				return handle_error(conn);

			struct mpd_message *msg;
			while ((msg = mpd_recv_message(conn)) != NULL) {
				printf("%s\n", mpd_message_get_text(msg));
				mpd_message_free(msg);
			}

			if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
			    !mpd_response_finish(conn))
				return handle_error(conn);
		}

		return handle_error(conn);
	} else if (argc == 2 && strcmp(argv[1], "channels") == 0) {
		/* print a list of channels */

		if (!mpd_send_channels(conn))
			return handle_error(conn);

		struct mpd_pair *pair;
		while ((pair = mpd_recv_channel_pair(conn)) != NULL) {
			printf("%s\n", pair->value);
			mpd_return_pair(conn, pair);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	} else if (argc == 4 && strcmp(argv[1], "message") == 0) {
		/* send a message to a channel */

		if (!mpd_run_send_message(conn, argv[2], argv[3]))
			return handle_error(conn);
	}

	mpd_connection_free(conn);

	return 0;
}
Exemplo n.º 20
0
Arquivo: evmpd.c Projeto: hawx/evmpd
int main(int argc, char const *argv[])
{
  if (argc < 5) {
    printf("Usage: evmpd HOSTNAME PORT DEVICE HALT_COMMAND\n");
    return EXIT_FAILURE;
  }

  struct mpd_connection *client = connect(argv[1], strtol(argv[2], NULL, 10));

  struct libevdev *dev = NULL;
  int fd;
  int rc = 1;

  fd = open(argv[3], O_RDONLY | O_NONBLOCK);
  rc = libevdev_new_from_fd(fd, &dev);
  if (rc < 0) {
    fprintf(stderr, "Failed to init libevdev (%d)\n", strerror(-rc));
    return EXIT_FAILURE;
  }
  printf("Input device name: \"%s\"\n", libevdev_get_name(dev));
  printf("Input device ID: bus %#x vendor %#x product %#x\n",
         libevdev_get_id_bustype(dev),
         libevdev_get_id_vendor(dev), libevdev_get_id_product(dev));

  do {
    struct input_event ev;

    rc = libevdev_next_event(dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);

    if (rc == 0 && ev.value == 0) {
      if (libevdev_event_is_code(&ev, EV_KEY, KEY_F4)) {
        system(argv[4]);
        printf("shutdown\n");

      } else if (libevdev_event_is_code(&ev, EV_KEY, KEY_PLAYPAUSE)) {
        struct mpd_status *status = mpd_run_status(client);
        enum mpd_state state = mpd_status_get_state(status);

        if (state != MPD_STATE_PLAY && state != MPD_STATE_PAUSE) {
          mpd_run_play(client);
          printf("play\n");
        } else {
          mpd_run_toggle_pause(client);
          printf("toggle-pause\n");
        }

      } else if (libevdev_event_is_code(&ev, EV_KEY, KEY_STOPCD)) {
        mpd_run_stop(client);
        printf("stop\n");

      } else if (libevdev_event_is_code(&ev, EV_KEY, KEY_PREVIOUSSONG)) {
        mpd_run_previous(client);
        printf("previous\n");

      } else if (libevdev_event_is_code(&ev, EV_KEY, KEY_NEXTSONG)) {
        mpd_run_next(client);
        printf("next\n");

      } else if (libevdev_event_is_code(&ev, EV_KEY, KEY_VOLUMEUP)) {
        struct mpd_status *status = mpd_run_status(client);
        int volume = mpd_status_get_volume(status);

        volume += 5;
        if (volume > 100) {
          volume = 100;
        }

        mpd_run_set_volume(client, volume);
        printf("set-volume %d\n", volume);

      } else if (libevdev_event_is_code(&ev, EV_KEY, KEY_VOLUMEDOWN)) {
        struct mpd_status *status = mpd_run_status(client);
        int volume = mpd_status_get_volume(status);

        volume -= 5;
        if (volume < 0) {
          volume = 0;
        }

        mpd_run_set_volume(client, volume);
        printf("set-volume %d\n", volume);
      } else {
        printf("Event: %s %s %d\n",
               libevdev_event_type_get_name(ev.type),
               libevdev_event_code_get_name(ev.type, ev.code),
               ev.value);
      }
    }

  }
  while (rc == LIBEVDEV_READ_STATUS_SUCCESS ||
         rc == LIBEVDEV_READ_STATUS_SYNC ||
         rc == -EAGAIN);

  printf("rc: %d\n", rc);

  if (client != NULL) {
    mpd_connection_free(client);
  }
  return EXIT_SUCCESS;
}
Exemplo n.º 21
0
void mpd_query_status(struct mpd_connection *conn)
{
    struct mpd_status *status;
    struct mpd_song *song;
    const struct mpd_audio_format *audio;

    if (!conn)
	return;

    if (!mpd_command_list_begin(conn, true) ||
	!mpd_send_status(conn) || !mpd_send_current_song(conn) || !mpd_command_list_end(conn)) {
	mpd_printerror("queue_commands");
	return;
    }

    status = mpd_recv_status(conn);
    if (status == NULL) {
	mpd_printerror("recv_status");
	return;
    }
    if (currentSong != NULL) {
	mpd_song_free(currentSong);
	currentSong = NULL;
    }

    if (!mpd_response_next(conn)) {
	mpd_printerror("response_next");
	return;
    }

    song = mpd_recv_song(conn);
    if (song != NULL) {
	currentSong = mpd_song_dup(song);
	mpd_song_free(song);

	l_elapsedTimeSec = mpd_status_get_elapsed_time(status);
	l_totalTimeSec = mpd_status_get_total_time(status);
	l_bitRate = mpd_status_get_kbit_rate(status);
    } else {
	l_elapsedTimeSec = 0;
	l_totalTimeSec = 0;
	l_bitRate = 0;
    }
    l_state = mpd_status_get_state(status);

    l_repeatEnabled = mpd_status_get_repeat(status);
    l_randomEnabled = mpd_status_get_random(status);
    l_singleEnabled = mpd_status_get_single(status);
    l_consumeEnabled = mpd_status_get_consume(status);

    l_volume = mpd_status_get_volume(status);

    l_currentSongPos = mpd_status_get_song_pos(status) + 1;
    l_playlistLength = mpd_status_get_queue_length(status);


    audio = mpd_status_get_audio_format(status);
    if (audio) {
	l_sampleRate = audio->sample_rate;
	l_channels = audio->channels;
    } else {
	l_sampleRate = 0;
	l_channels = 0;
    }

    if (mpd_status_get_error(status) != NULL)
	error("[MPD] query status : %s", charset_from_utf8(mpd_status_get_error(status)));

    mpd_status_free(status);

    if (!mpd_response_finish(conn)) {
	mpd_printerror("response_finish");
	return;
    }
}
Exemplo n.º 22
0
void control_window_status_update(MpdObj * mi, ChangedStatusType what, GtkWidget *base)
{
    GtkWidget *volume_button, *progress, *play_image;
    /* Bail out of base == NULL */
    if(base == NULL) return;
    /* Get the different subwidgets from the parent */
    volume_button   = g_object_get_data(G_OBJECT(base), "vol");
    progress        = g_object_get_data(G_OBJECT(base), "progress");
    play_image      = g_object_get_data(G_OBJECT(base), "play_image");

    if (what & MPD_CST_STATE)
    {
        int state = mpd_player_get_state(mi);
        switch (state)
        {
            case MPD_PLAYER_PLAY:
                gtk_image_set_from_stock(GTK_IMAGE(play_image),
                    "gtk-media-pause", GTK_ICON_SIZE_BUTTON);
                break;
            case MPD_PLAYER_PAUSE:
                gtk_image_set_from_stock(GTK_IMAGE(play_image),
                    "gtk-media-play", GTK_ICON_SIZE_BUTTON);
                break;
            default:
                gtk_image_set_from_stock(GTK_IMAGE(play_image),
                    "gtk-media-play", GTK_ICON_SIZE_BUTTON);
                /* Make sure it's reset correctly */
                gmpc_progress_set_time(GMPC_PROGRESS(progress), 0, 0);
        }
    }
    if (what & MPD_CST_ELAPSED_TIME)
    {
        if (mpd_check_connected(connection))
        {
            int totalTime = mpd_status_get_total_song_time(connection);
            int elapsedTime = mpd_status_get_elapsed_song_time(connection);
            gmpc_progress_set_time(GMPC_PROGRESS(progress), totalTime, elapsedTime);
        } else
        {
            gmpc_progress_set_time(GMPC_PROGRESS(progress), 0, 0);
        }
    }
    if (what & MPD_CST_VOLUME)
    {
        int volume = gtk_scale_button_get_value(GTK_SCALE_BUTTON(volume_button))*100;
        int new_volume = mpd_status_get_volume(connection);
        if (new_volume >= 0 &&
            mpd_server_check_command_allowed(connection, "setvol") ==
            MPD_SERVER_COMMAND_ALLOWED
           )
        {
            gtk_widget_set_sensitive(volume_button, TRUE);
            /* don't do anything if nothing is changed */
            if (new_volume != volume)
            {
                gtk_scale_button_set_value(GTK_SCALE_BUTTON(volume_button), new_volume/100.0);
            }
        } else
        {
            gtk_widget_set_sensitive(volume_button, FALSE);
        }
    }
}
Exemplo n.º 23
0
/*
 * Returns: 0 - error; 1 - ok 
 */
int mgr_mpd_fetch_status( struct mpd_connection *conn, int dump_status ) {
	struct mpd_status *status;
	struct mpd_stats *stats;

        if (DEBUG > 1)
                fprintf(stderr, "DEBUG: [mgr-thread] mpd: -status fetching...\n");

	if (conn == NULL) {
                fprintf(stderr, "ERROR: MPD: Unable to retrieve the MPD status: not connected\n");
		return 0;
	}

	if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {
                fprintf(stderr, "ERROR: MPD: Unable to retrieve MPD status: connection error\n");
		return 0;
	}

	if (DEBUG > 1)
		fprintf(stderr, "DEBUG: [mgr-thread] mpd: run status\n");

	status = mpd_run_status(conn);
	if (!status) {
                fprintf(stderr, "ERROR: MPD: Unable to retrieve MPD status\n");
		return 0;
	}

	cur_mpd_player_status = mpd_status_get_state(status);

	if (DEBUG > 1) {
		fprintf(stderr, "DEBUG: [mgr-thread] mpd: +status received:\n");
	}


	if (DEBUG && dump_status) {
		fprintf(stderr, "DEBUG: [mgr-thread] mpd status: => mode      : %s\n", (cur_mpd_player_status == MPD_STATE_PLAY ? "Play" : "Other"));
		fprintf(stderr, "DEBUG: [mgr-thread] mpd status: => random    : %d\n", mpd_status_get_random(status));
		fprintf(stderr, "DEBUG: [mgr-thread] mpd status: => repeat    : %d\n", mpd_status_get_random(status));
		fprintf(stderr, "DEBUG: [mgr-thread] mpd status: => volume    : %d\n", mpd_status_get_volume(status));
		fprintf(stderr, "DEBUG: [mgr-thread] mpd status: => queue ver : %d\n", mpd_status_get_queue_version(status));
		fprintf(stderr, "DEBUG: [mgr-thread] mpd status: => queue len : %d\n", mpd_status_get_queue_length(status));
	}

	cur_mpd_random = mpd_status_get_random(status) ? 1 : 0;
	cur_mpd_volume = mpd_status_get_volume(status);
	cur_mpd_status_queue_len = mpd_status_get_queue_length(status);

	if (DEBUG > 1)
		fprintf(stderr, "DEBUG: [mgr-thread] mpd: release status\n");

	if (mpd_status_get_error(status) != NULL) {
		fprintf(stderr, "WARNING: MPD: Error Received from MPD: %s\n", mpd_status_get_error(status));
		// TODO - clear error
	}

	mpd_status_free(status);
	mpd_response_finish(conn);

	stats = mpd_run_stats(conn);
	if (stats == NULL) {
                fprintf(stderr, "ERROR: MPD: Unable to retrieve MPD statistics\n");
		return 0;
	}

	cur_mpd_stats_number_of_songs = mpd_stats_get_number_of_songs( stats );
	if (DEBUG && dump_status) {
		fprintf(stderr, "DEBUG: [mgr-thread] mpd stats : => # of songs: %d\n", cur_mpd_stats_number_of_songs);
	}

	mpd_stats_free( stats );

	return 1;
}
Exemplo n.º 24
0
/**
 * Constructor
 */
GtkWidget *create_control_window(GtkWidget *parent)
{
    GtkWidget *pp_button, *next_button, *prev_button, *ff_button;
    GtkWidget *vol, *progress, *hbox, *play_image;
    int new_volume;
    /* Create window */
    GtkWidget *base = gtk_event_box_new();
    GtkWidget *ali = gtk_alignment_new(0.5,0,0.6,1);
    g_signal_connect(G_OBJECT(base), "enter-notify-event" ,
            G_CALLBACK(control_window_enter_notify_event), NULL);
    g_signal_connect(G_OBJECT(base), "leave-notify-event" ,
            G_CALLBACK(control_window_leave_notify_event), NULL);
    /* Overwrite background drawing */
    gtk_widget_set_app_paintable(base, TRUE);
    g_signal_connect(G_OBJECT(base), "draw",
        G_CALLBACK(expose_window), NULL);

    hbox = gtk_hbox_new(FALSE, 6);
    g_object_set_data(G_OBJECT(base), "hbox" , hbox);
    gtk_container_add(GTK_CONTAINER(base), ali);
    gtk_container_add(GTK_CONTAINER(ali), hbox);
    gtk_container_set_border_width(GTK_CONTAINER(ali), 1);

    /* Previous button */
    ff_button = gtk_button_new();
    gtk_container_add(GTK_CONTAINER(ff_button),
        gtk_image_new_from_stock(GTK_STOCK_LEAVE_FULLSCREEN,
        GTK_ICON_SIZE_BUTTON));
    gtk_button_set_relief(GTK_BUTTON(ff_button), GTK_RELIEF_NONE);
    gtk_box_pack_start(GTK_BOX(hbox), ff_button, FALSE, FALSE, 0);
    g_signal_connect(G_OBJECT(ff_button), "clicked",
        G_CALLBACK(control_window_leave_fullscreen), parent);
    /* Volume button */
    vol = (GtkWidget *)gtk_volume_button_new();
    gtk_box_pack_end(GTK_BOX(hbox), vol, FALSE, FALSE, 0);
    new_volume = mpd_status_get_volume(connection);
    gtk_scale_button_set_value(GTK_SCALE_BUTTON(vol), new_volume/100.0);
    g_object_set_data(G_OBJECT(base), "vol", vol);
    g_signal_connect(G_OBJECT(vol), "value_changed",
        G_CALLBACK(playlist_player_volume_changed), NULL);
    /* Progress */
    progress = (GtkWidget *)gmpc_progress_new();
    gmpc_progress_set_hide_text(GMPC_PROGRESS(progress), FALSE);
    gtk_box_pack_start(GTK_BOX(hbox), progress, TRUE, TRUE, 0);
    g_object_set_data(G_OBJECT(base), "progress", progress);
    g_signal_connect(G_OBJECT(progress), "seek-event", G_CALLBACK(pl3_pb_seek_event),
            NULL);

    /* Previous button */
    prev_button = gtk_button_new();
    gtk_container_add(GTK_CONTAINER(prev_button),
        gtk_image_new_from_stock("gtk-media-previous", GTK_ICON_SIZE_BUTTON));
    gtk_activatable_set_related_action(GTK_ACTIVATABLE(prev_button),
        GTK_ACTION(gtk_builder_get_object(pl3_xml, "MPDPrevious")));
    gtk_button_set_relief(GTK_BUTTON(prev_button), GTK_RELIEF_NONE);
    gtk_box_pack_start(GTK_BOX(hbox), prev_button, FALSE, FALSE, 0);

    /* Play button */
    pp_button = gtk_button_new();
    if(mpd_player_get_state(connection) == MPD_PLAYER_PLAY)
    {
        play_image = gtk_image_new_from_stock("gtk-media-pause", GTK_ICON_SIZE_BUTTON);
    }
    else
    {
        play_image = gtk_image_new_from_stock("gtk-media-play", GTK_ICON_SIZE_BUTTON);
    }
    gtk_container_add(GTK_CONTAINER(pp_button), play_image);
    g_object_set_data(G_OBJECT(base), "play_image", play_image);

    gtk_activatable_set_related_action(GTK_ACTIVATABLE(pp_button),
        GTK_ACTION(gtk_builder_get_object(pl3_xml, "MPDPlayPause")));
    gtk_button_set_relief(GTK_BUTTON(pp_button), GTK_RELIEF_NONE);
    gtk_box_pack_start(GTK_BOX(hbox), pp_button, FALSE, FALSE, 0);

    /* Next */
    next_button = gtk_button_new();
    gtk_container_add(GTK_CONTAINER(next_button),
        gtk_image_new_from_stock("gtk-media-next", GTK_ICON_SIZE_BUTTON));
    gtk_activatable_set_related_action(GTK_ACTIVATABLE(next_button),
        GTK_ACTION(gtk_builder_get_object(pl3_xml, "MPDNext")));
    gtk_button_set_relief(GTK_BUTTON(next_button), GTK_RELIEF_NONE);
    gtk_box_pack_start(GTK_BOX(hbox), next_button, FALSE, FALSE, 0);

    /* Change colors */
    control_window_modify_colors(base);
    gtk_widget_show_all(base);

    timeout = g_timeout_add_seconds(5, (GSourceFunc) gtk_widget_hide, hbox);
    return base;
}
Exemplo n.º 25
0
void status_changed(MpdObj *mi, ChangedStatusType what,  thread_data *my_data)
{
    if(what&MPD_CST_SONGID)
    {
        mpd_Song *song = mpd_playlist_get_current_song(mi);
        if(song)
        {
            printf( "Song:"" %s - %s\n", song->artist, song->title);
        }
    }

    if(what&MPD_CST_REPEAT){
        printf("Repeat:"" %s\n", mpd_player_get_repeat(mi)? "On":"Off");
    }
    if(what&MPD_CST_RANDOM){
        printf("Random:"" %s\n", mpd_player_get_random(mi)? "On":"Off");
    }
    if(what&MPD_CST_VOLUME){
        printf("Volume:"" %03i%%\n",
               mpd_status_get_volume(mi));

        my_data->mainLCD->printVolume(mpd_status_get_volume(mi));
        try
        {
            my_data->ptr_MPD_info->volume= mpd_status_get_volume(mi);
        }
        catch (...)
        {
            log_file_mutex.mutex_lock();
            log_file_cout << ERROR << "problem z wpisaniem volume "<<   std::endl;
            log_file_mutex.mutex_unlock();
        }
    }
    if(what&MPD_CST_CROSSFADE){
        printf("X-Fade:"" %i sec.\n",
               mpd_status_get_crossfade(mi));
    }
    if(what&MPD_CST_UPDATING)
    {
        if(mpd_status_db_is_updating(mi))
        {
            printf("Started updating DB""\n");
        }
        else
        {
            printf("Updating DB finished""\n");
        }
    }
    if(what&MPD_CST_DATABASE)
    {
        printf("Databased changed""\n");
    }
    if(what&MPD_CST_PLAYLIST)
    {
        printf("Playlist changed2""\n");
        if (check_title_song_to==true)
        {
            mpd_Song *song = mpd_playlist_get_current_song(mi);
            // std::cout <<" SONG: " << song->artist<<" "<< song->title << std::endl;
            printf("aktualnie gramy:"" %s - %s\n", song->artist, song->title);

            try
            {
                my_data->ptr_MPD_info->title = std::string( song->title);
            }
            catch (...)
            {
                my_data->myEventHandler.run("mpd")->addEvent("wrong title");
                my_data->ptr_MPD_info->title = "no data";
            }
            try
            {
                my_data->ptr_MPD_info->artist = std::string( song->artist);
            }
            catch (...)
            {
                my_data->myEventHandler.run("mpd")->addEvent("wrong artist");
                my_data->ptr_MPD_info->artist = "no data";
            }

            if (song->name != NULL){
                _msg =  song->name;

                try
                {
                    my_data->ptr_MPD_info->radio = _msg;
                }
                catch (...)
                {
                    my_data->myEventHandler.run("mpd")->addEvent("wrong radio station name");
                }
                my_data->mainLCD->printRadioName(true,0,0,_msg);
                my_data->mainLCD->set_lcd_STATE(5);
                std::string temp_str="";
                temp_str = send_to_arduino(my_data,"temperature:2;");
                temp_str.erase(temp_str.size()-2,temp_str.size());
                my_data->mainLCD->printString(false,0,1,"temp:"+temp_str+" c");

                updatePlayList(mi,my_data);
            }

            if (song->title != NULL ){
                _msg =  song->title;
                if (_msg.size() < 7 )
                {
                    _msg =  song->name;
                    _msg += " -     brak nazwy                ";
                }
            }
            else if (song->artist != NULL){
                _msg = song->artist;
            }
            else
            {
                _msg += " -     brak nazwy      ";
            }
            // my_data->ptr_MPD_info->title = _msg;
            my_data->mainLCD->printSongName(_msg);
        }
    }
    if(what&MPD_CST_STATE)
    {
        printf("State:");
        switch(mpd_player_get_state(mi))
        {
        case MPD_PLAYER_PLAY:
            printf("Playing\n");
            check_title_song_to=true;
            my_data->mainLCD->play_Y_N=true;
            my_data->ptr_MPD_info->isPlay=true;
            digitalWrite(GPIO_SPIK, LOW);
            my_data->mainLCD->set_lcd_STATE(1);
            my_data->mainLCD->song_printstr();
            updatePlayList(mi,my_data);
            my_data->myEventHandler.run("mpd")->addEvent("MPD playing");
            break;
        case MPD_PLAYER_PAUSE:
            printf("Paused\n");
            my_data->mainLCD->set_lcd_STATE( -1);
            my_data->mainLCD->printString(true ,0,1,"    PAUSE");
            my_data->myEventHandler.run("mpd")->addEvent("MPD pause");
            break;
        case MPD_PLAYER_STOP:
            printf("Stopped\n");
            if (my_data->ptr_MPD_info->isPlay ==true){
                send_to_arduino(my_data,"LED_CLEAR:44;");
            }
            check_title_song_to=false;
            my_data->mainLCD->play_Y_N=false;
            my_data->ptr_MPD_info->isPlay=false;
            my_data->ptr_MPD_info->title="* * * *";
            digitalWrite(GPIO_SPIK,HIGH);
            my_data->mainLCD->noBacklight();
            sleep(1);
            my_data->myEventHandler.run("mpd")->addEvent("MPD stopped");
            break;
        default:
            break;
        }
    }
    /* not yet implemented signals */
    if(what&MPD_CST_AUDIO){
        printf("Audio Changed""\n");
    }
    if(what&MPD_CST_TOTAL_TIME){
        printf("Total song time changed:"" %02i:%02i\n",
               mpd_status_get_total_song_time(mi)/60,
               mpd_status_get_total_song_time(mi)%60);
    }
    if(what&MPD_CST_ELAPSED_TIME){
        /*  printf(GREEN"Time elapsed changed:"RESET" %02i:%02i\n",
mpd_status_get_elapsed_song_time(mi)/60,
mpd_status_get_elapsed_song_time(mi)%60);
*/  }
    if(what&MPD_CST_PERMISSION){
        printf( "Permission:"" Changed\n");
    }
}
Exemplo n.º 26
0
void
basic_state_checking(void)
{
  int rep, ran, sgl, len, crt, vol, ply, btr;
  struct mpd_status *status;

  status = getStatus(conn);

  rep = mpd_status_get_repeat(status);
  ran = mpd_status_get_random(status);
  sgl = mpd_status_get_single(status);
  len = mpd_status_get_queue_length(status);
  crt = mpd_status_get_song_id(status);
  vol = mpd_status_get_volume(status);
  ply = mpd_status_get_state(status);
  btr = mpd_status_get_kbit_rate(status);

  basic_info->crt_time = mpd_status_get_elapsed_time(status);
  basic_info->total_time = mpd_status_get_total_time(status);
  
  mpd_status_free(status);

  if(rep != basic_info->repeat || ran != basic_info->random
	 || sgl != basic_info->single || len != basic_info->total
	 || crt != basic_info->current || vol != basic_info->volume
	 || ply != basic_info->state)
	{
	  basic_info->repeat = rep;
	  basic_info->random = ran;
	  basic_info->single = sgl;
	  basic_info->total = len;
	  basic_info->current = crt;
	  basic_info->volume = vol;
	  basic_info->state = ply;

	  signal_all_wins();
	}

  /* as many songs's bit rate varies while playing
	 we refresh the bit rate display only when the 
	 relevant change greater than 0.2 */
  if(abs(basic_info->bit_rate - btr) / (float)(btr + 1) > 0.2)
	{
	  basic_info->bit_rate = btr;
	  signal_win(BASIC_INFO);
	}

  
  /* get current song's name */
  status = init_mpd_status(conn);

  strncpy(basic_info->format, "null", 16);
  *basic_info->crt_name = '\0';
	
  if (basic_info->state == MPD_STATE_PLAY ||
	  basic_info->state == MPD_STATE_PAUSE) {
	struct mpd_song *song;

	if (!mpd_response_next(conn))
	  printErrorAndExit(conn);

	song = mpd_recv_song(conn);
	if (song != NULL) {
	  strncpy(basic_info->crt_name, get_song_tag(song, MPD_TAG_TITLE), 512);
	  strncpy(basic_info->format, get_song_format(song), 16);
	}

	mpd_song_free(song);
  }

  mpd_status_free(status);
  my_finishCommand(conn);	
}
Exemplo n.º 27
0
void MpdWidget::psMpdHB()
{

	timerMpd->stop();


	QString dataSender, dataVol, dataTitle;

	struct mpd_connection *conn;
	struct mpd_status * status;
	struct mpd_song *song;
//	const struct mpd_audio_format *audio_format;

	conn = mpd_connection_new(NULL, 0, 30000);


	if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
	{
		timerMpd->start();
		return;
	}

	if (aktPlay)
	{
		aktPlay = false;
		mpd_send_command(conn, "play", NULL);
		timerMpd->start();
		return;
	}

	if (aktStop)
	{
		aktStop = false;
		mpd_send_command(conn, "stop", NULL);
		timerMpd->start();
		return;
	}


	mpd_command_list_begin(conn, true);
	mpd_send_status(conn);
	mpd_send_current_song(conn);
	mpd_command_list_end(conn);


// Status
	status = mpd_recv_status(conn);
	if (status == NULL)
	{
		timerMpd->start();
		return ;
	}



// Volume
	dataVol.number(mpd_status_get_volume(status));
	if (labelVol->text().compare(dataVol) != 0)
		labelVol->setText(dataVol);

	if (mpd_status_get_error(status) != NULL)
		new QListWidgetItem(QString("status error: %1").
				arg(mpd_status_get_error(status)));



	mpd_status_free(status);
// Status

	mpd_response_next(conn);

// Song
	song = mpd_recv_song(conn);
	if (song == NULL)
	{
		handle_error(conn);
		timerMpd->start();
		return ;
	}


// Title
	dataTitle = mpd_song_get_uri(song);
	if (labelTitle->text().compare(dataTitle) != 0)
		labelTitle->setText(dataTitle);




	unsigned int i = 0;
	QString value;

	while ((value = mpd_song_get_tag(song, MPD_TAG_TITLE, i++)) != NULL)
	{
		if (i > 0)
			dataSender.append("  ");
		dataSender.append(value);
	}

	if (labelSender->text().compare(dataSender) != 0)
	{
		labelSender->setText(dataSender);
		qDebug() << "refresh";
	}

	mpd_song_free(song);
// Song

	mpd_connection_free(conn);

	timerMpd->start();
}
Exemplo n.º 28
0
void  *main_mpd_cli(void *data )
{
    blockQueue char_queue; // kolejka polecen
    thread_data  *my_data;
    my_data = (thread_data*)data;

    ////////////////////////////// LCD PART ///////////////////////
    my_data->mainLCD->set_print_song_state(0);
    ///////////////////////////////////////////////////////////////////
    int   iport = 6600, button_counter =0;
    char *hostname = getenv("MPD_HOST");
    char *port = getenv("MPD_PORT");
    char *password = getenv("MPD_PASSWORD");
    MpdObj *obj = NULL;


    std::cout << " adres hosta to " << hostname << std::endl;
    if(!hostname) {
        std::cout << " ip mpd to " <<  my_data->server_settings->MPD_IP << " ! \n";
        hostname = (char*)my_data->server_settings->MPD_IP.c_str();
    }
    if(port){
        iport = std::stoi(port);
    }
    /* Create mpd object */
    obj = mpd_new(hostname, iport,password);
    /* Connect signals */
    mpd_signal_connect_error(obj,(ErrorCallback)error_callback, NULL);
    mpd_signal_connect_status_changed(obj,(StatusChangedCallback)status_changed , my_data );
    /* Set timeout */
    mpd_set_connection_timeout(obj, 10);

    int work;
    work = mpd_connect(obj);

    while (work){
        log_file_mutex.mutex_lock();
        log_file_cout << ERROR << "nie udalo sie polaczyc z MPD "<<   std::endl;
        log_file_mutex.mutex_unlock();
        system("service mpd stop");
        sleep(1);
        system("service mpd start");
        log_file_mutex.mutex_lock();
        log_file_cout << INFO << "restart MPD "<<   std::endl;
        log_file_cout << INFO << "nawiazuje nowe polaczenie z MPD "<<   std::endl;
        log_file_mutex.mutex_unlock();
        my_data->myEventHandler.run("mpd")->addEvent("restart MPD");
        work = mpd_connect(obj);
    }

    std::cout << " stop "<<std::endl;

    if(!work)
    {
        char buffer;
        do{
            if(char_queue._size() > 0)
            {
                //digitalWrite(LED7,1);
                buffer = char_queue._get();
                switch(buffer)
                {
                case '\n':
                    break;
                case 'D':
                    mpd_player_next(obj);
                    break;
                case 'U':
                    mpd_player_prev(obj);
                    break;
                case 't':
                    mpd_player_play(obj);
                    break;
                case 'A':
                    mpd_player_pause(obj);
                    break;
                case 'P':
                    mpd_player_pause(obj);
                    mpd_player_stop(obj);
                    break;
                case 'q':
                    printf("Quitting....\n");
                    break;
                case 'R':
                    mpd_player_set_repeat(obj, !mpd_player_get_repeat(obj));
                    break;
                case 's':
                    mpd_player_set_random(obj, !mpd_player_get_random(obj));
                    break;

                case 'p':
                    /*if(char_queue._size() > 0)
{
buffer = char_queue._get();
int id = atoi(buffer);
printf(GREEN"Playing:"RESET" %i\n", id);
mpd_player_play_id(obj,id);
}
break;*/

                case '+':
                    mpd_status_set_volume(obj, mpd_status_get_volume(obj)+1);
                    break;
                case '-':
                    mpd_status_set_volume(obj, mpd_status_get_volume(obj)-1);
                    break;
                case '%':
                    mpd_status_set_volume(obj, my_data->ptr_MPD_info->volume);
                    break;
                case '2':
                    debug_level = (debug_level > 0)?0:3;
                    printf( "Debug:"" %s\n", (debug_level >0)? "Enabled":"Disabled");
                    break;
                case 'I':
                    mpd_player_play_id(obj,my_data->currentSongID);
                    break;
                case 'h':
                    printf("\th:\t\tHelp\n"\
                           "\td:\t\tToggle debug on/off\n"\
                           "\t+:\t\tIncrease volume\n"\
                           "\t-:\t\tDecrease volume\n"\
                           "\ta <pass>:\t Authentificate with pass\n"\
                           "\tp <id>:\t Play song with id\n"\
                           "\tl:\t\tList the playlist\n"\
                           "\ts:\t\tToggle shuffle mode\n"\
                           "\tr:\t\tToggle repeat\n"\
                           "\tq:\t\tQuit\n"\
                           "\tv:\t\tStop\n"\
                           "\tc:\t\tPause\n"\
                           "\tx:\t\tPlay\n"\
                           "\tz:\t\tPrevious\n"\
                           "\tb:\t\tNext\n");
                    break;
                default:
                    printf("buffer: %c\n", buffer);
                }
            }
            if (!mpd_check_connected(obj))
            {
                log_file_mutex.mutex_lock();
                log_file_cout << WARNING << "utracono polacznie z  MPD "<<   std::endl;
                log_file_cout << INFO << "restart MPD" << std::endl;
                log_file_mutex.mutex_unlock();
                system ("service mpd restart");
                mpd_connect(obj);
            }

            mpd_status_update(obj);
            my_data->mainLCD->checkState();

            if ( digitalRead(BUTTON_PIN) == HIGH )
            {
                std::cout << " wcisnieta pin !" << std::endl;
                if (check_title_song_to == true && button_counter ==4)
                {
                    char_queue._add('P');
                    std::cout << " \n\ngasze !" << std::endl;
                }
                else if (check_title_song_to == false && button_counter ==4)
                {
                    char_queue._add('t');
                    std::cout << " \n\n\n zapalam !" << std::endl;
                }
                else if (check_title_song_to == false && button_counter ==10)
                {
                    std::cout << " \n\n\n koniec programu z przyciska !" << std::endl;
                    go_while = false;
                }
                std::cout << " \n\n\n licznik guzika wskazuje "<< button_counter << std::endl;
                ++button_counter;
            }
            else
            {
                button_counter =0;
            }


        } while(!usleep(500000) &&  go_while);
        mpd_player_stop(obj);
        sleep (3);
    }
    else{
        std::cout << " NIE UDALO SIE POłączyć "<<std::endl;
    }
    mpd_free(obj);
    log_file_mutex.mutex_lock();
    log_file_cout << INFO << " koniec watku klient MPD  "<<   std::endl;
    log_file_mutex.mutex_unlock();
    return 0;
}
Exemplo n.º 29
0
/*
 * pgmpc_status
 *
 * Show current song and status.
 */
Datum
pgmpc_status(PG_FUNCTION_ARGS)
{
#define PGMPC_STATUS_COLUMNS 7
	Datum		values[PGMPC_STATUS_COLUMNS];
	bool		nulls[PGMPC_STATUS_COLUMNS];
	TupleDesc	tupdesc;
	HeapTuple	tuple;
	Datum		result;

	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
		elog(ERROR, "return type must be a row type");

	pgmpc_init();

	/* Initialize the values of return tuple */
	MemSet(values, 0, sizeof(values));
	MemSet(nulls, true, sizeof(nulls));

	/*
	 * Send all necessary commands at once to avoid unnecessary round
	 * trips. The following information is obtained in an aync way:
	 * - current status of server
	 * - current song run on server
	 */
	if (!mpd_command_list_begin(mpd_conn, true) ||
		!mpd_send_status(mpd_conn) ||
		!mpd_send_current_song(mpd_conn) ||
		!mpd_command_list_end(mpd_conn))
		pgmpc_print_error();

	/* Obtain status from server and check it */
	mpd_status = mpd_recv_status(mpd_conn);
	if (mpd_status == NULL)
		pgmpc_print_error();

	/* Show current song if any */
	if (mpd_status_get_state(mpd_status) == MPD_STATE_PLAY ||
		mpd_status_get_state(mpd_status) == MPD_STATE_PAUSE)
	{
		struct mpd_song *song;

		/* There should be a next response, in this case a song */
		if (!mpd_response_next(mpd_conn))
			pgmpc_print_error();

		/* And now get it */
		song = mpd_recv_song(mpd_conn);
		if (song != NULL)
		{
			/* Get information about the current song */
			const char *title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
			const char *artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
			const char *album = mpd_song_get_tag(song, MPD_TAG_ALBUM, 0);
			unsigned int elapsed_time = mpd_status_get_elapsed_time(mpd_status);
			unsigned int total_time = mpd_status_get_total_time(mpd_status);
			int song_pos = mpd_status_get_song_pos(mpd_status) + 1;
			int volume = mpd_status_get_volume(mpd_status);

			/* Build tuple using this information */
			if (title)
			{
				nulls[0] = false;
				values[0] =  CStringGetTextDatum(title);
			}
			else
				nulls[0] = true;
			if (artist)
			{
				nulls[1] = false;
				values[1] =  CStringGetTextDatum(artist);
			}
			else
				nulls[1] = true;
			if (album)
			{
				nulls[2] = false;
				values[2] =  CStringGetTextDatum(album);
			}
			else
				nulls[2] = true;
			nulls[3] = false;
			values[3] = UInt32GetDatum(elapsed_time);
			nulls[4] = false;
			values[4] = UInt32GetDatum(total_time);
			nulls[5] = false;
			values[5] = Int32GetDatum(song_pos);
			nulls[6] = false;
			values[6] = Int32GetDatum(volume);

			/* Song data is no more needed */
			mpd_song_free(song);
		}

		if (!mpd_response_finish(mpd_conn))
			pgmpc_print_error();
	}

	/* Cleanup MPD status */
	pgmpc_reset();

	/* Form result and return it */
	tuple = heap_form_tuple(tupdesc, values, nulls);
	result = HeapTupleGetDatum(tuple);

	PG_RETURN_DATUM(result);
}
Exemplo n.º 30
0
Arquivo: status.c Projeto: GGbaba/mpc
void
print_status(struct mpd_connection *conn)
{
	if (!mpd_command_list_begin(conn, true) ||
	    !mpd_send_status(conn) ||
	    !mpd_send_current_song(conn) ||
	    !mpd_command_list_end(conn))
		printErrorAndExit(conn);

	struct mpd_status *status = mpd_recv_status(conn);
	if (status == NULL)
		printErrorAndExit(conn);

	if (mpd_status_get_state(status) == MPD_STATE_PLAY ||
	    mpd_status_get_state(status) == MPD_STATE_PAUSE) {
		if (!mpd_response_next(conn))
			printErrorAndExit(conn);

		struct mpd_song *song = mpd_recv_song(conn);
		if (song != NULL) {
			pretty_print_song(song);
			printf("\n");

			mpd_song_free(song);
		}

		if (mpd_status_get_state(status) == MPD_STATE_PLAY)
			printf("[playing]");
		else
			printf("[paused] ");

		printf(" #%i/%u %3i:%02i/%i:%02i (%u%%)\n",
		       mpd_status_get_song_pos(status) + 1,
		       mpd_status_get_queue_length(status),
		       mpd_status_get_elapsed_time(status) / 60,
		       mpd_status_get_elapsed_time(status) % 60,
		       mpd_status_get_total_time(status) / 60,
		       mpd_status_get_total_time(status) % 60,
		       elapsed_percent(status));
	}

	if (mpd_status_get_update_id(status) > 0)
		printf("Updating DB (#%u) ...\n",
		       mpd_status_get_update_id(status));

	if (mpd_status_get_volume(status) >= 0)
		printf("volume:%3i%c   ", mpd_status_get_volume(status), '%');
	else {
		printf("volume: n/a   ");
	}

	printf("repeat: ");
	if (mpd_status_get_repeat(status))
		printf("on    ");
	else printf("off   ");

	printf("random: ");
	if (mpd_status_get_random(status))
		printf("on    ");
	else printf("off   ");

	printf("single: ");
	if (mpd_status_get_single(status))
		printf("on    ");
	else printf("off   ");

	printf("consume: ");
	if (mpd_status_get_consume(status))
		printf("on \n");
	else printf("off\n");

	if (mpd_status_get_error(status) != NULL)
		printf("ERROR: %s\n",
		       charset_from_utf8(mpd_status_get_error(status)));

	mpd_status_free(status);

	if (!mpd_response_finish(conn))
		printErrorAndExit(conn);
}