Skip to content

Commit

Permalink
Merge pull request #391 from ywwg/spinny-cover-art
Browse files Browse the repository at this point in the history
Show cover art in spinny underneath spinny background.
  • Loading branch information
ywwg committed Nov 18, 2014
2 parents 9d56993 + b39fd58 commit c21f0c6
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 11 deletions.
4 changes: 3 additions & 1 deletion res/skins/LateNight/spinny.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
<WidgetGroup>
<ObjectName>SpinnyContainer</ObjectName>
<Layout>horizontal</Layout>
<MinimumSize>20,20</MinimumSize>
<MinimumSize>95,95</MinimumSize>
<SizePolicy>min,min</SizePolicy>
<Children>
<Spinny>
<Group>[Channel<Variable name="channum"/>]</Group>
<PathBackground>vinyl_spinny<Variable name="color"/>_background.png</PathBackground>
<PathForeground>vinyl_spinny<Variable name="color"/>_foreground.png</PathForeground>
<PathGhost>vinyl_spinny<Variable name="color"/>_foreground_ghost.png</PathGhost>
<ShowCover>true</ShowCover>
</Spinny>
</Children>
</WidgetGroup>
Expand All @@ -27,6 +28,7 @@
<PathBackground>vinyl_spinny<Variable name="color"/>_background-s.png</PathBackground>
<PathForeground>vinyl_spinny<Variable name="color"/>_foreground-s.png</PathForeground>
<PathGhost>vinyl_spinny<Variable name="color"/>_foreground_ghost-s.png</PathGhost>
<ShowCover>true</ShowCover>
</Spinny>
</Children>
</WidgetGroup>
Expand Down
4 changes: 2 additions & 2 deletions res/skins/LateNight/style.qss
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
qproperty-layoutAlignment: 'AlignHCenter | AlignTop';
}

#RightSpinny {
qproperty-layoutAlignment: 'AlignRight | AlignTop';
#SpinnyContainer {
background-color: #0f0f0f;
}

#Library {
Expand Down
Binary file modified res/skins/LateNight/vinyl_spinny1_background-s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/skins/LateNight/vinyl_spinny1_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/skins/LateNight/vinyl_spinny1_foreground-s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/skins/LateNight/vinyl_spinny1_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/skins/LateNight/vinyl_spinny1_foreground_ghost-s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/skins/LateNight/vinyl_spinny1_foreground_ghost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/skins/LateNight/vinyl_spinny2_background-s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/skins/LateNight/vinyl_spinny2_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/skins/LateNight/vinyl_spinny2_foreground-s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/skins/LateNight/vinyl_spinny2_foreground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion src/skin/legacyskinparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ QWidget* LegacySkinParser::parseTrackProperty(QDomElement node) {
QWidget* LegacySkinParser::parseStarRating(QDomElement node) {
QString channelStr = lookupNodeGroup(node);
const char* pSafeChannelStr = safeChannelString(channelStr);

BaseTrackPlayer* pPlayer = m_pPlayerManager->getPlayer(channelStr);

if (!pPlayer)
Expand Down Expand Up @@ -1019,6 +1019,16 @@ QWidget* LegacySkinParser::parseSpinny(QDomElement node) {
connect(spinny, SIGNAL(trackDropped(QString, QString)),
m_pPlayerManager, SLOT(slotLoadToPlayer(QString, QString)));

BaseTrackPlayer* pPlayer = m_pPlayerManager->getPlayer(channelStr);
if (pPlayer != NULL) {
connect(pPlayer, SIGNAL(newTrackLoaded(TrackPointer)),
spinny, SLOT(slotLoadTrack(TrackPointer)));
connect(pPlayer, SIGNAL(unloadingTrack(TrackPointer)),
spinny, SLOT(slotReset()));
// just in case a track is already loaded
spinny->slotLoadTrack(pPlayer->getLoadedTrack());
}

spinny->setup(node, *m_pContext, pSafeChannelStr);
spinny->installEventFilter(m_pKeyboard);
spinny->installEventFilter(m_pControllerManager->getControllerLearningEventFilter());
Expand Down
96 changes: 91 additions & 5 deletions src/widget/wspinny.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
#include <QUrl>
#include <QMimeData>

#include "wimagestore.h"
#include "controlobject.h"
#include "controlobjectthread.h"
#include "library/coverartcache.h"
#include "sharedglcontext.h"
#include "visualplayposition.h"
#include "widget/wspinny.h"
#include "vinylcontrol/vinylcontrolmanager.h"
#include "vinylcontrol/vinylcontrol.h"
#include "util/dnd.h"
#include "util/math.h"
#include "visualplayposition.h"
#include "vinylcontrol/vinylcontrol.h"
#include "vinylcontrol/vinylcontrolmanager.h"
#include "widget/wspinny.h"
#include "wimagestore.h"

WSpinny::WSpinny(QWidget* parent, VinylControlManager* pVCMan)
: QGLWidget(parent, SharedGLContext::getWidget()),
Expand All @@ -32,6 +33,7 @@ WSpinny::WSpinny(QWidget* parent, VinylControlManager* pVCMan)
m_pSignalEnabled(NULL),
m_pSlipEnabled(NULL),
m_pSlipPosition(NULL),
m_bShowCover(true),
m_dInitialPos(0.),
m_iVinylInput(-1),
m_bVinylActive(false),
Expand Down Expand Up @@ -60,6 +62,15 @@ WSpinny::WSpinny(QWidget* parent, VinylControlManager* pVCMan)
qDebug() << "WSpinny(): Created QGLWidget, Context"
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();

CoverArtCache* pCache = CoverArtCache::instance();
if (pCache != NULL) {
connect(pCache, SIGNAL(coverFound(const QObject*, const int,
const CoverInfo&, QPixmap, bool)),
this, SLOT(slotCoverFound(const QObject*, const int,
const CoverInfo&, QPixmap, bool)));
}

}

WSpinny::~WSpinny() {
Expand Down Expand Up @@ -133,6 +144,8 @@ void WSpinny::setup(QDomNode node, const SkinContext& context, QString group) {
setFixedSize(m_pBgImage->size());
}

m_bShowCover = context.selectBool(node, "ShowCover", true);

#ifdef __VINYLCONTROL__
// Find the vinyl input we should listen to reports about.
if (m_pVCManager) {
Expand Down Expand Up @@ -209,13 +222,75 @@ void WSpinny::maybeUpdate() {
}
}

void WSpinny::slotLoadTrack(TrackPointer pTrack) {
if (m_loadedTrack) {
disconnect(m_loadedTrack.data(), SIGNAL(coverArtUpdated()),
this, SLOT(slotTrackCoverArtUpdated()));
}
m_lastRequestedCover = CoverInfo();
m_loadedCover = QPixmap();
m_loadedCoverScaled = QPixmap();
m_loadedTrack = pTrack;
if (m_loadedTrack) {
connect(m_loadedTrack.data(), SIGNAL(coverArtUpdated()),
this, SLOT(slotTrackCoverArtUpdated()));
}

slotTrackCoverArtUpdated();
}

void WSpinny::slotReset() {
if (m_loadedTrack) {
disconnect(m_loadedTrack.data(), SIGNAL(coverArtUpdated()),
this, SLOT(slotTrackCoverArtUpdated()));
}
m_loadedTrack = TrackPointer();
m_lastRequestedCover = CoverInfo();
m_loadedCover = QPixmap();
m_loadedCoverScaled = QPixmap();
update();
}

void WSpinny::slotTrackCoverArtUpdated() {
if (m_loadedTrack) {
m_lastRequestedCover = m_loadedTrack->getCoverInfo();
m_lastRequestedCover.trackLocation = m_loadedTrack->getLocation();
CoverArtCache* pCache = CoverArtCache::instance();
if (pCache != NULL) {
// TODO(rryan): Don't use track id.
pCache->requestCover(m_lastRequestedCover, this, m_loadedTrack->getId());
}
}
}

void WSpinny::slotCoverFound(const QObject* pRequestor, int requestReference,
const CoverInfo& info, QPixmap pixmap,
bool fromCache) {
Q_UNUSED(info);
Q_UNUSED(fromCache);

if (pRequestor == this && m_loadedTrack &&
m_loadedTrack->getId() == requestReference) {
qDebug() << "WSpinny::slotCoverFound" << pRequestor << info
<< pixmap.size();
m_loadedCover = pixmap;
m_loadedCoverScaled = scaledCoverArt(pixmap);
update();
}
}


void WSpinny::paintEvent(QPaintEvent *e) {
Q_UNUSED(e); //ditch unused param warning
m_bWidgetDirty = false;

QPainter p(this);
p.setRenderHint(QPainter::SmoothPixmapTransform);

if (m_bShowCover && !m_loadedCoverScaled.isNull()) {
p.drawPixmap(0, 0, m_loadedCoverScaled);
}

if (m_pBgImage) {
p.drawImage(0, 0, *m_pBgImage);
}
Expand Down Expand Up @@ -270,6 +345,17 @@ void WSpinny::paintEvent(QPaintEvent *e) {
}
}

QPixmap WSpinny::scaledCoverArt(const QPixmap& normal) {
if (normal.isNull()) {
return QPixmap();
}
return normal.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
}

void WSpinny::resizeEvent(QResizeEvent*) {
m_loadedCoverScaled = scaledCoverArt(m_loadedCover);
}

/* Convert between a normalized playback position (0.0 - 1.0) and an angle
in our polar coordinate system.
Returns an angle clamped between -180 and 180 degrees. */
Expand Down
20 changes: 18 additions & 2 deletions src/widget/wspinny.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include <QHideEvent>
#include <QEvent>

#include "widget/wwidget.h"
#include "vinylcontrol/vinylsignalquality.h"
#include "skin/skincontext.h"
#include "trackinfoobject.h"
#include "vinylcontrol/vinylsignalquality.h"
#include "widget/wbasewidget.h"
#include "widget/wwidget.h"

class ControlObjectThread;
class VisualPlayPosition;
Expand All @@ -29,13 +30,19 @@ class WSpinny : public QGLWidget, public WBaseWidget, public VinylSignalQualityL
void dropEvent(QDropEvent *event);

public slots:
void slotLoadTrack(TrackPointer);
void slotReset();
void updateVinylControlSpeed(double rpm);
void updateVinylControlEnabled(double enabled);
void updateVinylControlSignalEnabled(double enabled);
void updateSlipEnabled(double enabled);

protected slots:
void maybeUpdate();
void slotCoverFound(const QObject* pRequestor, int requestReference,
const CoverInfo& info, QPixmap pixmap, bool fromCache);
void slotTrackCoverArtUpdated();


signals:
void trackDropped(QString filename, QString group);
Expand All @@ -46,13 +53,15 @@ class WSpinny : public QGLWidget, public WBaseWidget, public VinylSignalQualityL
void mouseMoveEvent(QMouseEvent * e);
void mousePressEvent(QMouseEvent * e);
void mouseReleaseEvent(QMouseEvent * e);
void resizeEvent(QResizeEvent*);
void showEvent(QShowEvent* event);
void hideEvent(QHideEvent* event);
bool event(QEvent* pEvent);

double calculateAngle(double playpos);
int calculateFullRotations(double playpos);
double calculatePositionFromAngle(double angle);
QPixmap scaledCoverArt(const QPixmap& normal);

private:
QImage* m_pBgImage;
Expand All @@ -71,6 +80,13 @@ class WSpinny : public QGLWidget, public WBaseWidget, public VinylSignalQualityL
ControlObjectThread* m_pSlipEnabled;
ControlObjectThread* m_pSlipPosition;

TrackPointer m_loadedTrack;
QPixmap m_loadedCover;
QPixmap m_loadedCoverScaled;
CoverInfo m_lastRequestedCover;
bool m_bShowCover;


VinylControlManager* m_pVCManager;
double m_dInitialPos;

Expand Down

0 comments on commit c21f0c6

Please sign in to comment.