コード例 #1
0
ファイル: lyrics.cpp プロジェクト: bear24rw/ncmpcpp
std::string Lyrics::GenerateFilename(const MPD::Song &s)
{
	std::string filename;
	if (Config.store_lyrics_in_song_dir)
	{
		if (s.isFromDB())
		{
			filename = Config.mpd_music_dir;
			filename += "/";
			filename += s.GetFile();
		}
		else
			filename = s.GetFile();
		// replace song's extension with .txt
		size_t dot = filename.rfind('.');
		assert(dot != std::string::npos);
		filename.resize(dot);
		filename += ".txt";
	}
	else
	{
		std::string file = locale_to_utf_cpy(s.GetArtist());
		file += " - ";
		file += locale_to_utf_cpy(s.GetTitle());
		file += ".txt";
		EscapeUnallowedChars(file);
		filename = Config.lyrics_directory;
		filename += "/";
		filename += file;
	}
	return filename;
}
コード例 #2
0
void updatePlayer(MPD::Client *, MPD::StatusChanges changed, void *) {

  if (changed.SongID) {
    if (MPD::Client::GetInstance()->isPlaying()) {
#if DEBUG
      std::cout << "Song changed" << std::endl;
#endif

      MPD::Song song = MPD::Client::GetInstance()->GetCurrentSong();

      // set song parameters to storage
      Storage::GetInstance()->loadNewSong(song);

      // run agents
      AgentManager::GetInstance()->songChanged();

      // set text widgets
      GUI::MainWindow::GetInstance()->setSongLabel(song.GetArtist() + " - " + song.GetTitle());
      GUI::MainWindow::GetInstance()->setArtist(song.GetArtist());
      GUI::MainWindow::GetInstance()->setTitle(song.GetTitle());
      GUI::MainWindow::GetInstance()->setAlbum(song.GetAlbum());
      GUI::MainWindow::GetInstance()->setGenre(song.GetGenre());
      GUI::MainWindow::GetInstance()->setTimeScale(MPD::Client::GetInstance()->GetElapsedTime(), MPD::Client::GetInstance()->GetTotalTime());
    }
  }
  if (changed.ElapsedTime) {

    //    if (!Config::GetInstance()->isAgentsEnabled()) {
    //      AgentManager::GetInstance()->killAgents();
    //    }
    //
    //    AgentManager::GetInstance()->isSourcesChanged();

    // load new info to widgets
    GUI::MainWindow::GetInstance()->articlesWidget->updateArticlesWidget();
    GUI::MainWindow::GetInstance()->slideshowWidget->updateSlideshowWidget();
    //    GUI::MainWindow::GetInstance()->coverWidget->updateCoverWidget();


    GUI::MainWindow::GetInstance()->setTimeScale(MPD::Client::GetInstance()->GetElapsedTime(), MPD::Client::GetInstance()->GetTotalTime());

    if (MPD::Client::GetInstance()->isPlaying()) {
      MPD::Song song = MPD::Client::GetInstance()->GetCurrentSong();

      GUI::MainWindow::GetInstance()->setSongLabel(song.GetArtist() + " - " + song.GetTitle());

      GUI::MainWindow::GetInstance()->setStatusBar(_("IMPC Playing: ") + song.GetFile());
    }
  }
  if (changed.PlayerState) {

    MPD::PlayerState s = MPD::Client::GetInstance()->GetState();

    if (s == MPD::psPlay) {
      GUI::MainWindow::GetInstance()->on_play();
      GUI::MainWindow::GetInstance()->setPlayButtonActive(true);

      GUI::MainWindow::GetInstance()->setBitrate(MPD::Client::GetInstance()->GetBitrate());

    } else if (s == MPD::psPause) {
      GUI::MainWindow::GetInstance()->on_pause();
      GUI::MainWindow::GetInstance()->setPlayButtonActive(false);
    } else if (s == MPD::psStop) {
      GUI::MainWindow::GetInstance()->on_stop();
      GUI::MainWindow::GetInstance()->articlesWidget->clearArticlesWidget();
      GUI::MainWindow::GetInstance()->slideshowWidget->clearSlide();
    }
  }

  if (changed.DBUpdating) {
    GUI::MainWindow::GetInstance()->artistsWidget->reload();
  }

  if (changed.Volume) {
    // we set default volume
    GUI::MainWindow::GetInstance()->setVolume((double) MPD::Client::GetInstance()->GetVolume());
  }

  AgentManager::GetInstance()->checkIfAgentsEnabled();
}