int mpd_player_seek(MpdObj * mi, int sec) { int cur_song = mpd_player_get_current_song_pos(mi); if (cur_song < 0) { debug_printf(DEBUG_ERROR, "mpd_player_get_current_song_pos returned error\n"); return cur_song; } if (!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING, "not connected\n"); return MPD_NOT_CONNECTED; } if (mpd_lock_conn(mi)) { debug_printf(DEBUG_WARNING, "lock failed\n"); return MPD_LOCK_FAILED; } debug_printf(DEBUG_INFO, "seeking in song %i to %i sec\n", cur_song, sec); mpd_sendSeekCommand(mi->connection, cur_song, sec); mpd_finishCommand(mi->connection); mpd_unlock_conn(mi); if (mpd_status_update(mi)) { return MPD_STATUS_FAILED; } return MPD_OK; }
int mpd_player_pause(MpdObj * mi) { if (!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING, "not connected\n"); return MPD_NOT_CONNECTED; } if (mpd_lock_conn(mi)) { debug_printf(DEBUG_WARNING, "lock failed\n"); return MPD_LOCK_FAILED; } if (mpd_player_get_state(mi) == MPD_PLAYER_PAUSE) { mpd_sendPauseCommand(mi->connection, 0); mpd_finishCommand(mi->connection); } else if (mpd_player_get_state(mi) == MPD_PLAYER_PLAY) { mpd_sendPauseCommand(mi->connection, 1); mpd_finishCommand(mi->connection); } mpd_unlock_conn(mi); if (mpd_status_update(mi)) { return MPD_STATUS_FAILED; } return MPD_OK; }
void gimmix_get_progress_status (MpdObj *mo, float *fraction, char *time) { int state; int total, elapsed; state = mpd_player_get_state (mo); switch (state) { case MPD_PLAYER_PLAY: case MPD_PLAYER_PAUSE: mpd_status_update(mo); total = mpd_status_get_total_song_time (mo); elapsed = mpd_status_get_elapsed_song_time (mo); snprintf (time, 20, "%02i:%02i / %02i:%02i", elapsed/60, elapsed%60, total/60, total%60); *fraction = (float)((float)elapsed/(float)total); break; case MPD_PLAYER_STOP: case MPD_PLAYER_UNKNOWN: time = NULL; return; } return; }
int mpd_playlist_queue_commit(MpdObj *mi) { if(mi->queue == NULL) { debug_printf(DEBUG_WARNING,"mi->queue is empty"); return MPD_PLAYLIST_QUEUE_EMPTY; } if(!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING,"not connected\n"); return MPD_NOT_CONNECTED; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_WARNING,"lock failed\n"); return MPD_LOCK_FAILED; } mpd_sendCommandListBegin(mi->connection); /* get first item */ mi->queue = mi->queue->first; while(mi->queue != NULL) { if(mi->queue->type == MPD_QUEUE_ADD) { if(mi->queue->path != NULL) { mpd_sendAddCommand(mi->connection, mi->queue->path); } } else if(mi->queue->type == MPD_QUEUE_LOAD) { if(mi->queue->path != NULL) { mpd_sendLoadCommand(mi->connection, mi->queue->path); } } else if (mi->queue->type == MPD_QUEUE_DELETE_ID) { if(mi->queue->id >= 0) { mpd_sendDeleteIdCommand(mi->connection, mi->queue->id); } } else if (mi->queue->type == MPD_QUEUE_DELETE_POS) { if(mi->queue->id >= 0) { mpd_sendDeleteCommand(mi->connection, mi->queue->id); } } mpd_queue_get_next(mi); } mpd_sendCommandListEnd(mi->connection); mpd_finishCommand(mi->connection); mpd_unlock_conn(mi); mpd_status_update(mi); return MPD_OK; }
int mpd_database_update_dir(MpdObj *mi, char *path) { if(path == NULL || !strlen(path)) { debug_printf(DEBUG_ERROR, "path != NULL and strlen(path) > 0 failed"); return MPD_ARGS_ERROR; } if(!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING,"not connected\n"); return MPD_NOT_CONNECTED; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_ERROR,"lock failed\n"); return MPD_LOCK_FAILED; } mpd_sendUpdateCommand(mi->connection,path); mpd_finishCommand(mi->connection); /* I have no idea why do this ?? it even makes gmpc very very unhappy. * Because it doesnt trigger an signal anymore when updating starts * mi->CurrentState.updatingDb = mpd_getUpdateId(mi->connection); */ /* unlock */ mpd_unlock_conn(mi); /* What I think you should do is to force a direct status updated */ mpd_status_update(mi); return MPD_OK; }
int main() { if(daemon(0, 0) < 0) { exit(1); } signal(SIGHUP, handler); signal(SIGTERM, handler); signal(SIGINT, handler); signal(SIGQUIT, handler); char *home = getenv("HOME"); int size = snprintf(NULL, 0, "%s/.mpdnp.pipe", home) + 1; path = malloc(size); snprintf(path, size, "%s/.mpdnp.pipe", home); mkfifo(path, 0666); fd = open(path, O_WRONLY | O_NONBLOCK); if(path != NULL) { free(path); } write(fd, " ", 2); char *host = getenv("MPD_HOST"); char *port = getenv("MPD_PORT"); if(host == NULL) { host = "localhost"; } if(port == NULL) { port = "6600"; } // New object obj = mpd_new(host, atoi(port), NULL); // Connect the signal mpd_signal_connect_status_changed(obj, (StatusChangedCallback) status_changed, NULL); // Timeout mpd_set_connection_timeout(obj, 10); if(!mpd_connect(obj)) { while(!usleep(100000)) { if(obj == NULL) { break; } else { mpd_status_update(obj); } } } tidyUp(); return 0; }
static void gimmix_tag_editor_save (GtkWidget *button, gpointer data) { gint year; gint track; gchar *genre = NULL; gchar *title = NULL; gchar *artist = NULL; gchar *album = NULL; gchar *comment = NULL; year = gtk_spin_button_get_value (GTK_SPIN_BUTTON(tag_year_spin)); taglib_tag_set_year (tag, year); track = gtk_spin_button_get_value (GTK_SPIN_BUTTON(tag_track_spin)); taglib_tag_set_track (tag, track); title = g_strdup (gtk_entry_get_text (GTK_ENTRY(tag_title))); artist = g_strdup (gtk_entry_get_text (GTK_ENTRY(tag_artist))); album = g_strdup (gtk_entry_get_text (GTK_ENTRY(tag_album))); comment = g_strdup (gtk_entry_get_text (GTK_ENTRY(tag_comment))); genre = gtk_combo_box_get_active_text (GTK_COMBO_BOX(tag_genre)); if (title) { taglib_tag_set_title (tag, g_strchomp(title)); } if (artist) { taglib_tag_set_artist (tag, g_strchomp(artist)); } if (album) { taglib_tag_set_album (tag, g_strchomp(album)); } if (comment) { taglib_tag_set_comment (tag, g_strchomp(comment)); } taglib_tag_set_genre (tag, genre); /* update the mpd database */ mpd_database_update_dir (gmo, "/"); /* set the song info a few seconds after update */ mpd_status_update (gmo); /* free the strings */ taglib_tag_free_strings (); taglib_file_save (file); g_free (title); g_free (artist); g_free (album); g_free (comment); return; }
GimmixStatus gimmix_get_status (MpdObj *mo) { int status; mpd_status_update (mo); status = mpd_player_get_state (mo); if (status == MPD_PLAYER_PAUSE) return PAUSE; else if (status == MPD_PLAYER_PLAY) return PLAY; else if (status == MPD_PLAYER_STOP) return STOP; return UNKNOWN; }
/* returns TRUE when status is availible, when not availible and connected it tries to grab it */ int mpd_status_check(MpdObj *mi) { if(!mpd_check_connected(mi)) { debug_printf(DEBUG_INFO,"not connected\n"); return MPD_NOT_CONNECTED; } if(mi->status == NULL) { /* try to update */ if(mpd_status_update(mi)) { debug_printf(DEBUG_INFO, "failed to update status\n"); return MPD_STATUS_FAILED; } } return MPD_OK; }
int mpd_player_prev(MpdObj * mi) { if (!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING, "not connected\n"); return MPD_NOT_CONNECTED; } if (mpd_lock_conn(mi)) { debug_printf(DEBUG_WARNING, "lock failed\n"); return MPD_LOCK_FAILED; } mpd_sendPrevCommand(mi->connection); mpd_finishCommand(mi->connection); mpd_unlock_conn(mi); if (mpd_status_update(mi)) { return MPD_STATUS_FAILED; } return MPD_OK; }
SongInfo * gimmix_get_song_info (MpdObj *mo) { mpd_Song *ms; SongInfo *s = (SongInfo *)malloc(sizeof(SongInfo)); mpd_status_update(mo); ms = mpd_playlist_get_current_song(mo); s->file = (ms->file) ? strdup (ms->file) : NULL; s->title = (ms->title) ? strdup (ms->title) : NULL; s->artist = (ms->artist) ? strdup (ms->artist) : NULL; s->album = (ms->album) ? strdup (ms->album) : NULL; s->genre = (ms->genre) ? strdup (ms->genre) : NULL; s->length = ms->time; if (gimmix_get_status(mo) == PLAY) s->bitrate = mpd_status_get_bitrate (mo); else s->bitrate = -1; return s; }
int mpd_playlist_clear(MpdObj *mi) { if(!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING,"not connected\n"); return MPD_NOT_CONNECTED; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_WARNING,"lock failed\n"); return MPD_LOCK_FAILED; } mpd_sendClearCommand(mi->connection); mpd_finishCommand(mi->connection); /* hack to make it update correctly when replacing 1 song */ mi->CurrentState.songid = -1; /* unlock */ mpd_unlock_conn(mi); mpd_status_update(mi); return FALSE; }
int mpd_player_play_id(MpdObj * mi, int id) { debug_printf(DEBUG_INFO, "trying to play id: %i\n", id); if (!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING, "not connected\n"); return MPD_NOT_CONNECTED; } if (mpd_lock_conn(mi)) { debug_printf(DEBUG_WARNING, "lock failed\n"); return MPD_LOCK_FAILED; } mpd_sendPlayIdCommand(mi->connection, id); mpd_finishCommand(mi->connection); mpd_unlock_conn(mi); if (mpd_status_update(mi)) { return MPD_STATUS_FAILED; } return MPD_OK; }
SongInfo * gimmix_get_song_info (MpdObj *mo) { mpd_Song *ms; SongInfo *s = (SongInfo *)malloc(sizeof(SongInfo)); mpd_status_update (mo); ms = mpd_playlist_get_current_song (mo); if (ms->file != NULL) s->file = strdup (ms->file); else s->file = NULL; if (ms->title != NULL) s->title = strdup (ms->title); else s->title = NULL; if (ms->artist != NULL) s->artist = strdup (ms->artist); else s->artist = NULL; if (ms->album != NULL) s->album = strdup (ms->album); else s->album = NULL; if (ms->genre != NULL) s->genre = strdup (ms->genre); else s->genre = NULL; return s; }
bool gimmix_play (MpdObj *mo) { mpd_status_update (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; }
int main(int argc, const char *argv[]) { uint8_t ret; uint8_t init = 1; cfg_t *cfg; int32_t adc_channel = -1; uint32_t val_cur[MCP32XX_MAX_CHANNEL], val_old[MCP32XX_MAX_CHANNEL]; int32_t diff; struct mcp32xx_dev mcp_dev; struct volume_handle v_handle = {0}; struct mpd_handle m_handle = {0}; struct lcd_handle l_handle = {0}; useconds_t sleep_usec; uint8_t song_update_count_max; uint8_t song_update_count = 0; cfg_opt_t opts[] = { CFG_INT("UpdateInterval", 300000, CFGF_NONE), CFG_INT("SongUpdateInterval", 2000000, CFGF_NONE), CFG_INT("ChannelUsed", 2, CFGF_NONE), CFG_INT("VolumeChannel", 0, CFGF_NONE), CFG_INT("TunerChannel", 1, CFGF_NONE), CFG_INT("MaxLineChar", 16, CFGF_NONE), CFG_INT("MaxLineBuf", 80, CFGF_NONE), CFG_STR("HostName", "localhost", CFGF_NONE), CFG_INT("Port", 6600, CFGF_NONE), CFG_INT("MaxTunerPos", 12, CFGF_NONE), CFG_INT("MaxVolSteps", 50, CFGF_NONE), CFG_STR("RadioPlaylistName", "stations", CFGF_NONE), CFG_INT("LCD-Pin_RS", 25, CFGF_NONE), CFG_INT("LCD-Pin_E", 24, CFGF_NONE), CFG_INT("LCD-Pin_DB4", 23, CFGF_NONE), CFG_INT("LCD-Pin_DB5", 17, CFGF_NONE), CFG_INT("LCD-Pin_DB6", 27, CFGF_NONE), CFG_INT("LCD-Pin_DB7", 22, CFGF_NONE), CFG_STR("FillPatternFirstLine", " ++ ", CFGF_NONE), CFG_STR("FillPatternSecondLine", " ** ", CFGF_NONE), CFG_INT("MaxLineLength", 16, CFGF_NONE), CFG_INT("MaxLineBufferLength", 80, CFGF_NONE), CFG_END() }; cfg = cfg_init(opts, CFGF_NONE); ret = cfg_parse(cfg, "/etc/radioberry.conf"); if(ret == CFG_FILE_ERROR) { perror("/etc/radioberry.conf"); printf("WARN: could not read /etc/radioberry.conf," " process with default values\n"); } else if (ret == CFG_PARSE_ERROR) { printf("configuration parse error\n"); goto out; } /* get configuration values */ channel_used = (uint8_t)cfg_getint(cfg, "ChannelUsed"); volume_chan = (uint8_t)cfg_getint(cfg, "VolumeChannel"); tuner_chan = (uint8_t)cfg_getint(cfg, "TunerChannel"); sleep_usec = cfg_getint(cfg, "UpdateInterval") / channel_used; printf("sleep_usec %d\n", sleep_usec); song_update_count_max = cfg_getint(cfg, "SongUpdateInterval") / sleep_usec; /* pass over pointer to handles of mpd, lcd and volume */ m_handle.lh = &l_handle; v_handle.mh = &m_handle; m_handle.cfg = cfg; l_handle.cfg = cfg; signal(SIGINT, sigintterm_handler); signal(SIGTERM, sigintterm_handler); ret = lcd_init(&l_handle); if (ret) { printf("failed to initialize lcd, lcd control disabled \n"); lcd_control_enabled = 0; } if (lcd_control_enabled) { lcd_print_string("Radioberry"); lcd_move_cursor_down(); lcd_print_string("=== Welcome ==="); } ret = mcp32xx_init(&mcp_dev); if (ret) { printf("failed to initialize spi device, analog control" " devices disabled\n"); tuner_control_enabled = 0; vol_control_enabled = 0; } ret = init_mpd_handle(&m_handle); if (ret) { printf("could not initialize mpd client," " tuner control disabled\n"); tuner_control_enabled = 0; } /* disable tuner control if we cannot get any station at all. If one * station fails, let's process and wait for tuner changes */ ret = load_stations_playlist(&m_handle); if (ret == 1) { printf("could not load radio stations list," " tuner control disabled\n"); tuner_control_enabled = 0; } ret = init_vol_control(&v_handle); if (ret) { printf("could not initialize volume control," " volumen control disabled\n"); vol_control_enabled = 0; } running = 1; while ( running ) { usleep(sleep_usec); if (adc_channel + 1 == channel_used) { adc_channel = 0; mpd_status_update(m_handle.mpd_obj); /* detect if initial loop is done. Start update lcd * after initial loop */ if (init) init = 0; else { if (lcd_control_enabled) lcd_update_screen(&l_handle); } } else adc_channel++; if (song_update_count == song_update_count_max) { update_song_info(&m_handle); song_update_count = 0; } else song_update_count++; /* loop over all channels in singel ended mode * and reset counter in the last loop. */ val_cur[adc_channel] = mcp32xx_get_val(&mcp_dev, adc_channel); /* fill the old value buffer and intialize the player with * current settings*/ if (init) { val_old[adc_channel] = val_cur[adc_channel]; ret = process_value(&v_handle, &m_handle, val_cur[adc_channel], adc_channel); /* skip comparing old/new values while intializing */ if (ret) { printf("unrecoverable error, quit now\n"); break; } else continue; } diff = val_old[adc_channel] - val_cur[adc_channel]; #ifdef DEBUG printf("adc_channel: %u, old %u, new %u, diff %d\n", adc_channel, val_cur[adc_channel], val_old[adc_channel], diff); #endif if (abs(diff) < TOLERANT_THRESHOLD) continue; #ifdef DEBUG if (diff > 0) printf("Poti %u was turned left, current val: %d\n", adc_channel + 1, val_cur[adc_channel]); else printf("Poti %u was turned right, current Pos: %d\n", adc_channel + 1, val_cur[adc_channel]); #endif process_value(&v_handle, &m_handle, val_cur[adc_channel], adc_channel); val_old[adc_channel] = val_cur[adc_channel]; } out: lcd_clear_screen(); lcd_close(&l_handle); mcp32xx_close(&mcp_dev); close_vol_ctl(&v_handle); close_mpd_handle(&m_handle); exit(ret); }
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; }
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; }
/* updates title_text, sb_text and tt strings */ gboolean update_info(gpointer data) { char *state_string; int current_time, song_time; int play_state; if(mpd_info.msi.connected) { // connected play_state = mpd_play_state(); current_time = mpd_get_current_play_time(); song_time = mpd_get_current_song_time(); if(!mpd_info.mps.update) { switch(play_state) { /* playing */ case 1: state_string = "playing"; do_string(FMT_TITLE, state_string, current_time, song_time); do_string(FMT_STATUSBAR, state_string, current_time, song_time); #ifdef APPLET do_string(FMT_TOOLTIP, state_string, current_time, song_time); if(musicus_applet.show_text) do_string(FMT_APPLET, state_string, current_time, song_time); else snprintf(ap_text, 255, "[MPD]"); #endif break; case 2: state_string = "paused"; do_string(FMT_TITLE, state_string, current_time, song_time); do_string(FMT_STATUSBAR, state_string, current_time, song_time); #ifdef APPLET do_string(FMT_TOOLTIP, state_string, current_time, song_time); if(musicus_applet.show_text) do_string(FMT_APPLET, state_string, current_time, song_time); else snprintf(ap_text, 255, "[MPD]"); #endif break; default: snprintf(title_text, 255, "MPD [stopped]"); snprintf(sb_text, 255, "[stopped]"); #ifdef APPLET snprintf(tt_text, 255, "MPD [stopped]"); snprintf(ap_text, 255, "MPD"); #endif } } /* update MpdObj status */ if(!mpd_check_connected(mpd_info.obj)) { if(mpd_connect(mpd_info.obj)!=MPD_OK) { msi_clear(&mpd_info); mpd_info.msi.connected = FALSE; return FALSE; } msi_fill(&mpd_info); mpd_info.msi.connected = TRUE; } mpd_status_update(mpd_info.obj); return ((mpd_info.update_interval != *(int*)data) ? FALSE : TRUE); } #ifdef APPLET snprintf(ap_text, 255, "MPD"); #endif return FALSE; }
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; }