Ticket #2942: albumart.patch
File albumart.patch, 13.6 KB (added by , 17 years ago) |
---|
-
mythplugins/mythmusic/mythmusic/playbackbox.cpp
23 23 #include "decoder.h" 24 24 #include "playbackbox.h" 25 25 #include "databasebox.h" 26 #include "metaio.h" 26 27 #include "mainvisual.h" 27 28 #include "smartplaylist.h" 28 29 #include "search.h" … … 1157 1158 return; 1158 1159 1159 1160 banner_timer->start(8000); 1160 mainvisual->addInformation("\"" + mdata->Title() + "\"\n" + 1161 MetaIO *tagger = decoder->doCreateTagger(); 1162 QByteArray img_array(tagger->getAlbumArt(curMeta->Filename())); 1163 QImage image(img_array); 1164 mainvisual->addInformation(image, "\"" + mdata->Title() + "\"\n" + 1161 1165 mdata->Artist() + " - " + mdata->Album()); 1162 1166 } 1163 1167 … … 1172 1176 void PlaybackBoxMusic::bannerDisable() 1173 1177 { 1174 1178 banner_timer->stop(); 1175 mainvisual-> addInformation("");1179 mainvisual->clearInformation(); 1176 1180 } 1177 1181 1178 1182 void PlaybackBoxMusic::CycleVisualizer() -
mythplugins/mythmusic/mythmusic/visualize.cpp
11 11 12 12 #include <cmath> 13 13 #include "mainvisual.h" 14 #include "metaio.h" 14 15 #include "visualize.h" 15 16 #include "inlines.h" 16 17 #include "decoder.h" … … 18 19 #include <qpainter.h> 19 20 #include <qpixmap.h> 20 21 #include <qimage.h> 21 #include <qdir.h>22 22 #include <qurl.h> 23 23 24 24 #include <iostream> … … 327 327 return true; 328 328 329 329 if (filename != pParent->decoder()->getFilename()) { 330 QString curdir = QUrl(pParent->decoder()->getFilename()).dirPath(); 331 if (directory != curdir) 332 return true; 330 return true; 333 331 } 334 332 335 333 return false; 336 334 } 337 335 338 Q String AlbumArt::getImageFilename()336 QByteArray AlbumArt::getImage() 339 337 { 340 QString result; 341 QString curfile = pParent->decoder()->getFilename(); 342 QString curdir = QUrl(curfile).dirPath(); 343 QString namefilter = gContext->GetSetting("AlbumArtFilter", 344 "*.png;*.jpg;*.jpeg;*.gif;*.bmp"); 345 // Get directory contents based on filter 346 QDir folder(curdir, namefilter, QDir::Name | QDir::IgnoreCase, 347 QDir::Files | QDir::Hidden); 348 349 if (folder.count()) 350 result = folder[rand() % folder.count()]; 351 352 result.prepend("/"); 353 result.prepend(curdir); 354 338 QByteArray result; 339 MetaIO *tagger = pParent->decoder()->doCreateTagger(); 340 if (tagger) { 341 result = tagger->getAlbumArt(pParent->decoder()->getFilename()); 342 delete tagger; 343 } 355 344 return result; 356 345 } 357 346 … … 363 352 // If the directory has changed (new album) or the size, reload 364 353 if (needsUpdate()) 365 354 { 366 QImage art(getImage Filename());355 QImage art(getImage()); 367 356 if (art.isNull()) 368 {369 drawWarning(p, back, size, QObject::tr("?"));370 cursize = size;371 return true; 372 }373 image = art.smoothScale(size, QImage::ScaleMin);357 image.reset(); 358 else 359 image = art.smoothScale(size, QImage::ScaleMin); 360 361 // Store the new filename 362 filename = pParent->decoder()->getFilename(); 374 363 } 375 364 376 365 // Paint the image 377 366 p->fillRect(0, 0, size.width(), size.height(), back); 378 p->drawPixmap((size.width() - image.width()) / 2, 379 (size.height() - image.height()) / 2, 380 image); 367 if (image.isNull()) 368 drawWarning(p, back, size, QObject::tr("?")); 369 else 370 p->drawPixmap((size.width() - image.width()) / 2, 371 (size.height() - image.height()) / 2, 372 image); 381 373 382 374 // Store our new size 383 375 cursize = size; -
mythplugins/mythmusic/mythmusic/mainvisual.h
97 97 void setFrameRate( int newfps ); 98 98 int frameRate() const { return fps; } 99 99 100 void addInformation(const QImage &img, const QString &); 100 101 void addInformation(const QString &); 102 void clearInformation(); 101 103 102 104 static void registerVisFactory(VisFactory *); 103 105 static VisualBase *createVis(const QString &name, … … 128 130 129 131 public: 130 132 InfoWidget(QWidget *parent = 0); 131 void addInformation(const QString &); 133 void addInformation(const QString &, const QImage *img = 0); 134 void clearInformation(); 132 135 void paintEvent(QPaintEvent *); 133 136 134 137 private: -
mythplugins/mythmusic/mythmusic/metaio.h
16 16 17 17 virtual bool write(Metadata* mdata, bool exclusive = false) = 0; 18 18 virtual Metadata* read(QString filename) = 0; 19 virtual QByteArray getAlbumArt(const QString &filename); 19 20 20 21 void readFromFilename(QString filename, QString &artist, QString &album, 21 22 QString &title, QString &genre, int &tracknum); -
mythplugins/mythmusic/mythmusic/metaioid3v2.h
20 20 21 21 bool write(Metadata* mdata, bool exclusive = false); 22 22 Metadata* read(QString filename); 23 QByteArray getAlbumArt(const QString &filename); 23 24 24 25 private: 25 26 int getTrackLength(QString filename); -
mythplugins/mythmusic/mythmusic/mainvisual.cpp
373 373 visfactories->append(vis); 374 374 } 375 375 376 void MainVisual::addInformation(const QImage &img, const QString &new_info) { 377 info_widget->addInformation(new_info, &img); 378 } 379 376 380 void MainVisual::addInformation(const QString &new_info) { 377 381 info_widget->addInformation(new_info); 378 382 } 379 383 384 void MainVisual::clearInformation() { 385 info_widget->clearInformation(); 386 } 387 380 388 VisualBase *MainVisual::createVis(const QString &name, MainVisual *parent, 381 389 long int winid) 382 390 { … … 426 434 hide(); 427 435 } 428 436 429 void InfoWidget::addInformation(const QString &new_info ) {437 void InfoWidget::addInformation(const QString &new_info, const QImage *img) { 430 438 if (new_info == info) 431 439 return; 432 440 … … 440 448 info_pixmap = QPixmap(width(), height()/*, pixmap.depth ()*/); 441 449 QPainter p(&info_pixmap); 442 450 443 int indent = int(info_pixmap.width() * 0.02); 451 int text_indent = int(info_pixmap.width() * 0.02); 452 int img_indent = int(info_pixmap.width() * 0.01); 444 453 445 454 p.fillRect(0, 0, 446 455 info_pixmap.width(), info_pixmap.height(), … … 450 459 p.setFont(gContext->GetMediumFont()); 451 460 452 461 QFontMetrics fm(p.font()); 453 int width = fm.width(info);454 int height = fm.height() * (info.contains("\n") + 1);455 int x =indent;456 int y =indent;462 int text_width = fm.width(info); 463 int text_height = fm.height() * (info.contains("\n") + 1); 464 int text_x = text_indent; 465 int text_y = text_indent; 457 466 467 if (img && !img->isNull()) { 468 text_x += info_pixmap.height(); 469 int img_height = info_pixmap.height() - 2 * img_indent; 470 QRect rect(img_indent, img_indent, img_height, img_height); 471 p.drawImage(rect, img->smoothScale (rect.size(), QImage::ScaleMin)); 472 } 473 458 474 QString info_copy = info; 459 for (int offset = 0; offset < height; offset += fm.height()) {475 for (int offset = 0; offset < text_height; offset += fm.height()) { 460 476 QString l = info_copy.left(info_copy.find("\n")); 461 477 p.setPen(Qt::black); 462 p.drawText( x + 2, y + offset + 2, width,height, Qt::AlignLeft, l);478 p.drawText(text_x + 2, text_y + offset + 2, text_width, text_height, Qt::AlignLeft, l); 463 479 p.setPen(Qt::white); 464 p.drawText( x, y + offset, width,height, Qt::AlignLeft, l);480 p.drawText(text_x, text_y + offset, text_width, text_height, Qt::AlignLeft, l); 465 481 info_copy.remove(0, l.length () + 1); 466 482 } 467 483 … … 469 485 repaint(); 470 486 } 471 487 488 void InfoWidget::clearInformation() { 489 addInformation("", 0); 490 } 491 472 492 void InfoWidget::paintEvent ( QPaintEvent * ) 473 493 { 474 494 bitBlt(this, 0, 0, &info_pixmap); -
mythplugins/mythmusic/mythmusic/metaio.cpp
2 2 3 3 #include "metaio.h" 4 4 #include "metadata.h" 5 #include <qdir.h> 6 #include <qurl.h> 5 7 #include <mythtv/mythcontext.h> 6 8 7 9 //========================================================================== … … 104 106 105 107 return retdata; 106 108 } 109 110 //========================================================================== 111 /*! 112 * \brief Retrieve the albumart. 113 * 114 * The default implementation picks a random image file from the 115 * directory in which the file is. 116 * 117 * \param filename The filename to try and determin metadata for. 118 * \returns A QByteArray that can be passed to QImage or such. 119 */ 120 QByteArray MetaIO::getAlbumArt(const QString &filename) 121 { 122 QString curdir = QUrl(filename).dirPath(); 123 QString namefilter = gContext->GetSetting("AlbumArtFilter", 124 "*.png;*.jpg;*.jpeg;*.gif;*.bmp"); 125 // Get directory contents based on filter 126 QDir folder(curdir, namefilter, QDir::Name | QDir::IgnoreCase, 127 QDir::Files | QDir::Hidden); 128 129 if (!folder.count()) 130 return QByteArray(); 131 132 QString result = folder[rand() % folder.count()]; 133 result.prepend("/"); 134 result.prepend(curdir); 135 136 QFile file(result); 137 file.open(IO_ReadOnly); 138 if (!file.isOpen()) 139 return QByteArray(); 140 141 return file.readAll(); 142 } -
mythplugins/mythmusic/mythmusic/visualize.h
94 94 bool process(VisualNode *node = 0); 95 95 bool draw(QPainter *p, const QColor &back = Qt::black); 96 96 bool needsUpdate(); 97 Q String getImageFilename();97 QByteArray getImage(); 98 98 99 99 private: 100 100 QSize size, cursize; -
mythplugins/mythmusic/mythmusic/metaioid3v2.cpp
15 15 16 16 #include <mythtv/mythcontext.h> 17 17 18 id3_file *openFile(const QString &filename, id3_file_mode mode) { 19 id3_file *f = id3_file_open(filename.local8Bit(), mode); 20 if (!f) 21 f = id3_file_open(filename.ascii(), mode); 22 return f; 23 } 24 18 25 //========================================================================== 19 26 MetaIOID3v2::MetaIOID3v2(void) 20 27 : MetaIO(".mp3") … … 43 50 if (!mdata) 44 51 return false; 45 52 46 id3_file* p_input = NULL; 47 48 p_input = id3_file_open(mdata->Filename().local8Bit(), ID3_FILE_MODE_READWRITE); 53 id3_file* p_input = openFile(mdata->Filename().local8Bit(), ID3_FILE_MODE_READWRITE); 49 54 if (!p_input) 50 p_input = id3_file_open(mdata->Filename().ascii(), ID3_FILE_MODE_READWRITE);51 52 if (!p_input)53 55 return false; 54 56 55 57 // We don't like id3v1 tags... too limiting. … … 178 180 bool compilation = false; 179 181 id3_file *p_input = NULL; 180 182 181 p_input = id3_file_open(filename.local8Bit(), ID3_FILE_MODE_READONLY); 182 if (!p_input) 183 p_input = id3_file_open(filename.ascii(), ID3_FILE_MODE_READONLY); 184 183 p_input = openFile(filename, ID3_FILE_MODE_READONLY); 185 184 if (p_input) 186 185 { 187 186 id3_tag *tag = id3_file_tag(p_input); … … 596 595 597 596 return true; 598 597 } 598 599 //========================================================================== 600 /*! 601 * \brief Function to set an individual comment in an ID3v2 Tag 602 * 603 * \param pTag Pointer to a id3_file object 604 * \param pLabel The label of the comment you want 605 * \param value A reference to the data you want to write 606 * \param desc An optional description (frame type pLabel must support this) 607 * \returns Nothing 608 */ 609 QByteArray MetaIOID3v2::getAlbumArt(const QString &filename) 610 { 611 id3_file *file = openFile(filename, ID3_FILE_MODE_READONLY); 612 if (!file) 613 return MetaIO::getAlbumArt(filename); 614 615 id3_tag *tag = id3_file_tag(file); 616 if (!tag) { 617 id3_file_close(file); 618 return MetaIO::getAlbumArt(filename); 619 } 620 621 struct id3_frame *p_frame = 0; 622 for (int i=0; NULL != (p_frame = id3_tag_findframe(tag, "APIC", i)); ++i) { 623 for (unsigned int f = 0; f < p_frame->nfields; ++f) { 624 id3_field *field = &(p_frame->fields[f]); 625 if (field->type == ID3_FIELD_TYPE_BINARYDATA) { 626 QByteArray data; 627 data.duplicate((char*)field->binary.data, (size_t)field->binary.length); 628 id3_file_close(file); 629 return data; 630 } 631 } 632 } 633 634 id3_file_close(file); 635 return MetaIO::getAlbumArt(filename); 636 }