void ImportMusicDialog::setTrack(void) { Metadata *data = m_tracks->at(m_currentTrack)->metadata; data->setTrack(data->Track() + 100); fillWidgets(); }
void Ripper::updateTrackList(void) { if (m_tracks->isEmpty()) return; QString tmptitle; if (m_trackList) { m_trackList->Reset(); int i; for (i = 0; i < (int)m_tracks->size(); i++) { if (i >= m_tracks->size()) break; RipTrack *track = m_tracks->at(i); Metadata *metadata = track->metadata; MythUIButtonListItem *item = new MythUIButtonListItem(m_trackList,""); item->setCheckable(true); item->SetData(qVariantFromValue(track)); if (track->isNew) item->DisplayState("new", "yes"); else item->DisplayState("new", "no"); if (track->active) item->setChecked(MythUIButtonListItem::FullChecked); else item->setChecked(MythUIButtonListItem::NotChecked); item->SetText(QString::number(metadata->Track()), "track"); item->SetText(metadata->Title(), "title"); item->SetText(metadata->Artist(), "artist"); int length = track->length / 1000; if (length > 0) { int min, sec; min = length / 60; sec = length % 60; QString s; s.sprintf("%02d:%02d", min, sec); item->SetText(s, "length"); } else item->SetText("", "length"); // if (i == m_currentTrack) // m_trackList->SetItemCurrent(i); } } }
void ImportMusicDialog::fillWidgets() { if (m_tracks->size() > 0) { // update current m_currentText->SetText(QString("%1 of %2") .arg(m_currentTrack + 1).arg(m_tracks->size())); Metadata *meta = m_tracks->at(m_currentTrack)->metadata; m_filenameText->SetText(meta->Filename()); m_compilationCheck->SetCheckState(meta->Compilation()); m_compartistText->SetText(meta->CompilationArtist()); m_artistText->SetText(meta->Artist()); m_albumText->SetText(meta->Album()); m_titleText->SetText(meta->Title()); m_genreText->SetText(meta->Genre()); m_yearText->SetText(QString::number(meta->Year())); m_trackText->SetText(QString::number(meta->Track())); if (m_tracks->at(m_currentTrack)->isNewTune) { m_coverartButton->SetVisible(false); m_statusText->SetText(tr("New File")); } else { m_coverartButton->SetVisible(true); m_statusText->SetText(tr("Already in Database")); } } else { // update current m_currentText->SetText(tr("Not found")); m_filenameText->Reset(); m_compilationCheck->SetCheckState(false); m_compartistText->Reset(); m_artistText->Reset(); m_albumText->Reset(); m_titleText->Reset(); m_genreText->Reset(); m_yearText->Reset(); m_trackText->Reset(); m_statusText->Reset(); m_coverartButton->SetVisible(false); } }
int Playlist::writeTree(GenericTree *tree_to_write_to, int a_counter) { // compute max/min playcount,lastplay for this playlist int playcountMin = 0; int playcountMax = 0; double lastplayMin = 0.0; double lastplayMax = 0.0; typedef map<QString, uint32_t> AlbumMap; AlbumMap album_map; AlbumMap::iterator Ialbum; QString album; typedef map<QString, uint32_t> ArtistMap; ArtistMap artist_map; ArtistMap::iterator Iartist; QString artist; uint idx = 0; SongList::const_iterator it = songs.begin(); for (; it != songs.end(); ++it, ++idx) { if (!(*it)->getCDFlag()) { if ((*it)->getValue() == 0) { VERBOSE(VB_IMPORTANT, LOC_ERR + kID0err); } if ((*it)->getValue() > 0) { // Normal track Metadata *tmpdata = all_available_music->getMetadata((*it)->getValue()); if (tmpdata) { if (tmpdata->isVisible()) { if (0 == idx) { // first song playcountMin = playcountMax = tmpdata->PlayCount(); lastplayMin = lastplayMax = tmpdata->LastPlay().toTime_t(); } else { if (tmpdata->PlayCount() < playcountMin) playcountMin = tmpdata->PlayCount(); else if (tmpdata->PlayCount() > playcountMax) playcountMax = tmpdata->PlayCount(); if (tmpdata->LastPlay().toTime_t() < lastplayMin) lastplayMin = tmpdata->LastPlay().toTime_t(); else if (tmpdata->LastPlay().toTime_t() > lastplayMax) lastplayMax = tmpdata->LastPlay().toTime_t(); } } // pre-fill the album-map with the album name. // This allows us to do album mode in album order album = tmpdata->Album(); // pre-fill the artist map with the artist name and song title artist = tmpdata->Artist() + "~" + tmpdata->Title(); } if ((Ialbum = album_map.find(album)) == album_map.end()) album_map.insert(AlbumMap::value_type(album,0)); if ((Iartist = artist_map.find(artist)) == artist_map.end()) artist_map.insert(ArtistMap::value_type(artist,0)); } } } // populate the sort id into the album map uint32_t album_count = 1; for (Ialbum = album_map.begin(); Ialbum != album_map.end(); Ialbum++) { Ialbum->second = album_count; album_count++; } // populate the sort id into the artist map uint32_t count = 1; for (Iartist = artist_map.begin(); Iartist != artist_map.end(); Iartist++) { Iartist->second = count; count++; } int RatingWeight = 2; int PlayCountWeight = 2; int LastPlayWeight = 2; int RandomWeight = 2; parent->FillIntelliWeights(RatingWeight, PlayCountWeight, LastPlayWeight, RandomWeight); for (it = songs.begin(); it != songs.end(); ++it) { if (!(*it)->getCDFlag()) { if ((*it)->getValue() == 0) { VERBOSE(VB_IMPORTANT, LOC_ERR + kID0err); } if ((*it)->getValue() > 0) { // Normal track Metadata *tmpdata = all_available_music->getMetadata((*it)->getValue()); if (tmpdata && tmpdata->isVisible()) { QString a_string = QString("%1 ~ %2") .arg(tmpdata->FormatArtist()) .arg(tmpdata->FormatTitle()); GenericTree *added_node = tree_to_write_to->addNode( a_string, (*it)->getValue(), true); ++a_counter; added_node->setAttribute(0, 1); added_node->setAttribute(1, a_counter); // regular order added_node->setAttribute(2, rand()); // random order // // Compute "intelligent" weighting // int rating = tmpdata->Rating(); int playcount = tmpdata->PlayCount(); double lastplaydbl = tmpdata->LastPlay().toTime_t(); double ratingValue = (double)(rating) / 10; double playcountValue, lastplayValue; if (playcountMax == playcountMin) playcountValue = 0; else playcountValue = ((playcountMin - (double)playcount) / (playcountMax - playcountMin) + 1); if (lastplayMax == lastplayMin) lastplayValue = 0; else lastplayValue = ((lastplayMin - lastplaydbl) / (lastplayMax - lastplayMin) + 1); double rating_value = (RatingWeight * ratingValue + PlayCountWeight * playcountValue + LastPlayWeight * lastplayValue + RandomWeight * (double)rand() / (RAND_MAX + 1.0)); uint32_t integer_rating = (int) (4000001 - rating_value * 10000); // "intelligent" order added_node->setAttribute(3, integer_rating); // "intellegent/album" order uint32_t album_order; album = tmpdata->Album(); if ((Ialbum = album_map.find(album)) == album_map.end()) { // we didn't find this album in the map, // yet we pre-loaded them all. we are broken, // but we just set the track order to 1, since there // is no real point in reporting an error album_order = 1; } else { album_order = Ialbum->second * 100; } album_order += tmpdata->Track(); added_node->setAttribute(4, album_order); // "artist" order, sorts by artist name then track title // uses the pre-prepared artist map to do this uint32_t integer_order; artist = tmpdata->Artist() + "~" + tmpdata->Title(); if ((Iartist = artist_map.find(artist)) == artist_map.end()) { // we didn't find this track in the map, // yet we pre-loaded them all. we are broken, // but we just set the track order to 1, since there // is no real point in reporting an error integer_order = 1; } else { integer_order = Iartist->second; } added_node->setAttribute(5, integer_order); } } if ((*it)->getValue() < 0) { // it's a playlist, recurse (mildly) Playlist *level_down = parent->getPlaylist(((*it)->getValue()) * -1); if (level_down) { a_counter = level_down->writeTree(tree_to_write_to, a_counter); } } } else { Metadata *tmpdata = all_available_music->getMetadata((*it)->getValue()); if (tmpdata) { QString a_string = QString("(CD) %1 ~ %2") .arg(tmpdata->FormatArtist()).arg(tmpdata->FormatTitle()); if (tmpdata->FormatArtist().length() < 1 || tmpdata->FormatTitle().length() < 1) { a_string = QString("(CD) Track %1").arg(tmpdata->Track()); } GenericTree *added_node = tree_to_write_to->addNode(a_string, (*it)->getValue(), true); ++a_counter; added_node->setAttribute(0, 1); added_node->setAttribute(1, a_counter); // regular order added_node->setAttribute(2, rand()); // random order added_node->setAttribute(3, rand()); // "intelligent" order } } } return a_counter; }