Ejemplo n.º 1
0
/* -------------------------------------------------------------------------- */
static void mpd_key_handler(const char *str, void *cookie)
{
    struct lcd_stuff_mpd *mpd = (struct lcd_stuff_mpd *)cookie;

    if (g_ascii_strcasecmp(str, "Up") == 0) {
        /* if playing, next song */
        if (mpd->current_state == MPD_PLAYER_PLAY) {
            mpd_player_next(mpd->mpd);
        } else {
            mpd_player_stop(mpd->mpd);
        }
    } else {
        if (mpd->current_state == MPD_PLAYER_PLAY) {
            mpd_player_pause(mpd->mpd);
        } else {
            mpd_player_play(mpd->mpd);
        }
    }
}
Ejemplo n.º 2
0
/* -------------------------------------------------------------------------- */
static void mpd_menu_handler(const char *event, const char *id, const char *arg, void *cookie)
{
    char **ids;
    struct lcd_stuff_mpd *mpd = (struct lcd_stuff_mpd *)cookie;

    if (strlen(id) == 0)
        return;

    ids = g_strsplit(id, "_", 2);

    if ((g_ascii_strcasecmp(ids[0], "pl") == 0) && (ids[1] != NULL)) {
        int no = atoi(ids[1]) - 1;

        if (no == -1) {
            mpd_playlist_clear(mpd->mpd);
            mpd_playlist_queue_commit(mpd->mpd);
        } else if (mpd->current_list && (no < (int)mpd->current_list->len)) {
            char *list;
            list = g_strconcat(mpd->current_list->pdata[no], NULL);
            mpd_playlist_queue_load(mpd->mpd, list);
            mpd_playlist_queue_commit(mpd->mpd);

            if (mpd->current_state != MPD_PLAYER_PLAY)
                mpd_player_play(mpd->mpd);

            g_free(list);
        }
    } else if ((g_ascii_strcasecmp(ids[0], "standby") == 0)) {
        int min = atoi(arg) * 15;
        if (min == 0) {
            mpd->stop_time = INT_MAX;
        } else {
            mpd->stop_time = time(NULL) + 60 * min;
        }
    }

    g_strfreev(ids);
}
Ejemplo n.º 3
0
bool
gimmix_play (MpdObj *mo)
{
	if (mpd_playlist_get_playlist_length (mo))
	{
		int state;

		state = mpd_player_get_state (mo);

		if (state == MPD_PLAYER_PAUSE || state == MPD_PLAYER_STOP)
		{	
			mpd_player_play (mo);
			return true;
		}

		else if (state == MPD_PLAYER_PLAY)
		{
			mpd_player_pause (mo);
			return false;
		}
	}
	
	return false;
}
Ejemplo n.º 4
0
void *event_key_thread() {

    struct input_event *event;
    event=malloc(sizeof(struct input_event));
    struct pollfd fds;

    int retval;    
    while(!leaving) {

        event->value=0;
        event->code=0;
        fds.fd=mmedia_fd;
        fds.events=POLLIN;

        if(poll(&fds,1,500)<1)
            continue;

        retval=read(mmedia_fd,event,sizeof(struct input_event));

        if(event->value==0||current_fg_check==0) 
            continue;

        int keycode = event->code;
        int code_audio_play = KEY_PLAYPAUSE;
        int code_audio_stop = KEY_STOPCD;
        int code_audio_next = KEY_NEXTSONG;
        int code_audio_prev = KEY_PREVIOUSSONG;
        int code_audio_raisevol = KEY_VOLUMEUP;
        int code_audio_lowervol = KEY_VOLUMEDOWN;
        int code_audio_mute = KEY_MUTE;

        /*     printf("keycode = %d\n", keycode); */

        if(keycode == code_audio_play) {
            if(playing && !playlist_mode) {
                if (paused==1)  {
                    mpd_player_play(obj);
                    paused = 0;
                } else {
                    mpd_player_pause(obj);
                    paused = 1;
                    
                }

            } else {
                mpd_player_play(obj);
                playing = 1;
            }
            if(playlist_mode){
                mpd_player_play_id(obj, item_selected);
            }
        }

        if(keycode == code_audio_stop) {
            mpd_player_stop(obj);
            playing = 0;
            continue;
        }

        if(keycode == code_audio_next) {
          if(playlist_mode)
            playlist_selection+=1;
          else
            mpd_player_next(obj);
          continue;
        }

        if(keycode == code_audio_prev) {
          if(playlist_mode)
            playlist_selection-=1;
          else
            mpd_player_prev(obj);
          continue;
        }

        if(keycode == code_audio_raisevol){
          if(playlist_mode && quickscroll)
            playlist_selection+=1;
          else {
            pthread_mutex_lock(&daemon_mutex);
            volume_adjust+=1;
            pthread_mutex_unlock(&daemon_mutex);
            continue;
          }
        }
        if(keycode == code_audio_lowervol){
          if(playlist_mode && quickscroll)
            playlist_selection-=1;
          else {
            pthread_mutex_lock(&daemon_mutex);
            volume_adjust-=1;
            pthread_mutex_unlock(&daemon_mutex);
            continue;
          }
        }

        if(keycode == code_audio_mute){
            pthread_mutex_lock(&daemon_mutex);
            mute = 1;
            pthread_mutex_unlock(&daemon_mutex);
            continue;
        }

        /* now the default stuff */
        if(own_keyboard) {
            menulevel=MENU_MODE1;
            continue;
        }
    }
    free(event);
    return NULL;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
0
static void gmpc_meta_data_widgets_similar_songs_replace_clicked (GmpcMetaDataWidgetsSimilarSongs* self, GtkWidget* item) {
	gboolean found;
	GtkTreeView* _tmp0_;
	GtkTreeView* tree;
	GtkTreeSelection* _tmp1_ = NULL;
	GtkTreeSelection* _tmp2_;
	GtkTreeSelection* sel;
	GtkTreeModel* model;
	GtkTreeIter iter = {0};
	GtkTreeModel* _tmp3_ = NULL;
	GList* _tmp4_ = NULL;
	GtkTreeModel* _tmp5_;
	GList* list;
	g_return_if_fail (self != NULL);
	g_return_if_fail (item != NULL);
	found = FALSE;
	_tmp0_ = _g_object_ref0 (GTK_TREE_VIEW (self->priv->pchild));
	tree = _tmp0_;
	_tmp1_ = gtk_tree_view_get_selection (tree);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	sel = _tmp2_;
	model = NULL;
	_tmp4_ = gtk_tree_selection_get_selected_rows (sel, &_tmp3_);
	_g_object_unref0 (model);
	_tmp5_ = _g_object_ref0 (_tmp3_);
	model = _tmp5_;
	list = _tmp4_;
	{
		GList* path_collection;
		GList* path_it;
		path_collection = list;
		for (path_it = path_collection; path_it != NULL; path_it = path_it->next) {
			GtkTreePath* _tmp6_;
			GtkTreePath* path;
			_tmp6_ = _gtk_tree_path_copy0 ((GtkTreePath*) path_it->data);
			path = _tmp6_;
			{
				GtkTreeIter _tmp7_ = {0};
				gboolean _tmp8_;
				_tmp8_ = gtk_tree_model_get_iter (model, &_tmp7_, path);
				iter = _tmp7_;
				if (_tmp8_) {
					const mpd_Song* song;
					song = NULL;
					gtk_tree_model_get (model, &iter, 0, &song, -1, -1);
					if (song != NULL) {
						mpd_playlist_queue_add (connection, song->file);
						found = TRUE;
					}
				}
				_gtk_tree_path_free0 (path);
			}
		}
	}
	if (found) {
		mpd_playlist_clear (connection);
		mpd_playlist_queue_commit (connection);
		mpd_player_play (connection);
	}
	gmpc_meta_data_widgets_similar_songs_play_clicked (self, item);
	__g_list_free__gtk_tree_path_free0_0 (list);
	_g_object_unref0 (model);
	_g_object_unref0 (sel);
	_g_object_unref0 (tree);
}