Merge branch 'master' into streamserve

This commit is contained in:
Andreas 2014-05-15 18:52:20 +02:00
commit 3452da4525
21 changed files with 141 additions and 25 deletions

View File

@ -209,3 +209,8 @@ void QtLocalPeer::receiveConnection()
emit messageReceived(uMsg); //### (might take a long time to return)
emit messageReceived(QString::fromUtf8(uMsg));
}
QtLocalPeer::~QtLocalPeer ()
{
lockFile.remove();
}

View File

@ -57,6 +57,7 @@ class QtLocalPeer : public QObject
public:
QtLocalPeer(QObject *parent = 0, const QString &appId = QString());
~QtLocalPeer ();
bool isClient();
bool sendMessage(const QString &message, int timeout);
bool sendMessage(const QByteArray &message, int timeout);

View File

@ -50,6 +50,8 @@ class Base : public QWidget {
}
}
virtual void framerateChanged() {}
protected:
Base(QWidget*, uint scopeSize = 7);
@ -84,6 +86,4 @@ void initSin(Scope&, const uint = 6000);
} // END namespace Analyzer
using Analyzer::Scope;
#endif

View File

@ -165,6 +165,9 @@ void AnalyzerContainer::ChangeFramerate(int new_framerate) {
// Even if it is not supposed to happen, I don't want to get a dbz error
new_framerate = new_framerate == 0 ? kMediumFramerate : new_framerate;
current_analyzer_->changeTimeout(1000 / new_framerate);
// notify the current analyzer that the framerate has changed
current_analyzer_->framerateChanged();
}
SaveFramerate(new_framerate);
}

View File

@ -16,11 +16,12 @@
#include <QtDebug>
#include <QPainter>
using Analyzer::Scope;
const char* BarAnalyzer::kName =
QT_TRANSLATE_NOOP("AnalyzerContainer", "Bar analyzer");
BarAnalyzer::BarAnalyzer(QWidget* parent)
: Analyzer::Base(parent, 8) {
BarAnalyzer::BarAnalyzer(QWidget* parent) : Analyzer::Base(parent, 8) {
// roof pixmaps don't depend on size() so we do in the ctor
m_bg = parent->palette().color(QPalette::Background);

View File

@ -16,7 +16,7 @@ class BarAnalyzer : public Analyzer::Base {
Q_INVOKABLE BarAnalyzer(QWidget*);
void init();
virtual void analyze(QPainter& p, const Scope&, bool new_frame);
virtual void analyze(QPainter& p, const Analyzer::Scope&, bool new_frame);
// virtual void transform( Scope& );
/**
@ -53,7 +53,7 @@ class BarAnalyzer : public Analyzer::Base {
QPixmap m_pixBarGradient;
QPixmap m_pixCompose;
QPixmap canvas_;
Scope m_scope; // so we don't create a vector every frame
Analyzer::Scope m_scope; // so we don't create a vector every frame
QColor m_bg;
};

View File

@ -100,10 +100,16 @@ void BlockAnalyzer::determineStep() {
// boxes/blocks of pixels)
// I calculated the value 30 based on some trial and error
const double fallTime = 30 * m_rows;
// the fall time of 30 is too slow on framerates above 50fps
const double fallTime = timeout() < 20 ? 20 * m_rows : 30 * m_rows;
m_step = double(m_rows * timeout()) / fallTime;
}
void BlockAnalyzer::framerateChanged() { // virtual
determineStep();
}
void BlockAnalyzer::transform(Analyzer::Scope& s) // pure virtual
{
for (uint x = 0; x < s.size(); ++x) s[x] *= 2;

View File

@ -32,10 +32,11 @@ class BlockAnalyzer : public Analyzer::Base {
static const char* kName;
protected:
virtual void transform(Scope&);
virtual void analyze(QPainter& p, const Scope&, bool new_frame);
virtual void transform(Analyzer::Scope&);
virtual void analyze(QPainter& p, const Analyzer::Scope&, bool new_frame);
virtual void resizeEvent(QResizeEvent*);
virtual void paletteChange(const QPalette&);
virtual void framerateChanged();
void drawBackground();
void determineStep();
@ -49,7 +50,7 @@ class BlockAnalyzer : public Analyzer::Base {
QPixmap m_topBarPixmap;
QPixmap m_background;
QPixmap canvas_;
Scope m_scope; // so we don't create a vector every frame
Analyzer::Scope m_scope; // so we don't create a vector every frame
std::vector<float> m_store; // current bar heights
std::vector<float> m_yscale;

View File

@ -5,6 +5,8 @@
#include <cmath>
#include <QPainter>
using Analyzer::Scope;
const char* BoomAnalyzer::kName =
QT_TRANSLATE_NOOP("AnalyzerContainer", "Boom analyzer");

View File

@ -19,8 +19,8 @@ class BoomAnalyzer : public Analyzer::Base {
static const char* kName;
virtual void init();
virtual void transform(Scope& s);
virtual void analyze(QPainter& p, const Scope&, bool new_frame);
virtual void transform(Analyzer::Scope& s);
virtual void analyze(QPainter& p, const Analyzer::Scope&, bool new_frame);
public slots:
void changeK_barHeight(int);

View File

@ -25,6 +25,8 @@
#include "core/arraysize.h"
#include "core/logging.h"
using Analyzer::Scope;
const char* NyanCatAnalyzer::kName = "Nyanalyzer cat";
const float NyanCatAnalyzer::kPixelScale = 0.02f;

View File

@ -31,7 +31,7 @@ class NyanCatAnalyzer : public Analyzer::Base {
static const char* kName;
protected:
void transform(Scope&);
void transform(Analyzer::Scope&);
void analyze(QPainter& p, const Analyzer::Scope&, bool new_frame);
void timerEvent(QTimerEvent* e);

View File

@ -15,6 +15,8 @@
#include <QPainter>
using Analyzer::Scope;
const char* Sonogram::kName =
QT_TRANSLATE_NOOP("AnalyzerContainer", "Sonogram");

View File

@ -29,8 +29,8 @@ class Sonogram : public Analyzer::Base {
static const char* kName;
protected:
void analyze(QPainter& p, const Scope&, bool new_frame);
void transform(Scope&);
void analyze(QPainter& p, const Analyzer::Scope&, bool new_frame);
void transform(Analyzer::Scope&);
void demo(QPainter& p);
void resizeEvent(QResizeEvent*);

View File

@ -12,6 +12,8 @@
#include "turbine.h"
using Analyzer::Scope;
const char* TurbineAnalyzer::kName =
QT_TRANSLATE_NOOP("AnalyzerContainer", "Turbine");

View File

@ -16,7 +16,7 @@ class TurbineAnalyzer : public BoomAnalyzer {
public:
Q_INVOKABLE TurbineAnalyzer(QWidget* parent) : BoomAnalyzer(parent) {}
void analyze(QPainter& p, const Scope&, bool new_frame);
void analyze(QPainter& p, const Analyzer::Scope&, bool new_frame);
static const char* kName;
};

View File

@ -57,6 +57,7 @@ void CurrentArtLoader::TempArtLoaded(quint64 id, const QImage& image) {
if (!image.isNull()) {
temp_art_.reset(new QTemporaryFile(temp_file_pattern_));
temp_art_->setAutoRemove(true);
temp_art_->open();
image.save(temp_art_->fileName(), "JPEG");
@ -64,6 +65,7 @@ void CurrentArtLoader::TempArtLoaded(quint64 id, const QImage& image) {
// since it's the GUI thread, but the alternative is hard.
temp_art_thumbnail_.reset(new QTemporaryFile(temp_file_pattern_));
temp_art_thumbnail_->open();
temp_art_thumbnail_->setAutoRemove(true);
thumbnail = image.scaledToHeight(120, Qt::SmoothTransformation);
thumbnail.save(temp_art_thumbnail_->fileName(), "JPEG");

View File

@ -31,6 +31,7 @@
#include <QFrame>
#include <QLineEdit>
#include <QMessageBox>
#include <QMutexLocker>
#include <QtDebug>
#include <QtConcurrentRun>
#include <cdio/cdio.h>
@ -72,7 +73,8 @@ RipCD::RipCD(QWidget* parent)
queued_(0),
finished_success_(0),
finished_failed_(0),
ui_(new Ui_RipCD) {
ui_(new Ui_RipCD),
cancel_requested_(false) {
cdio_ = cdio_open(NULL, DRIVER_UNKNOWN);
// Init
ui_->setupUi(this);
@ -144,9 +146,7 @@ RipCD::RipCD(QWidget* parent)
ui_->progress_bar->setMaximum(100);
}
RipCD::~RipCD() {
cdio_destroy(cdio_);
}
RipCD::~RipCD() { cdio_destroy(cdio_); }
/*
* WAV Header documentation
@ -232,6 +232,13 @@ void RipCD::ThreadClickedRipButton() {
QByteArray buffered_input_bytes(CDIO_CD_FRAMESIZE_RAW, '\0');
for (lsn_t i_cursor = i_first_lsn; i_cursor <= i_last_lsn; i_cursor++) {
{
QMutexLocker l(&mutex_);
if (cancel_requested_) {
qLog(Debug) << "CD ripping canceled.";
return;
}
}
if (cdio_read_audio_sector(cdio_, buffered_input_bytes.data(),
i_cursor) == DRIVER_OP_SUCCESS) {
destination_file->write(buffered_input_bytes.data(),
@ -317,6 +324,10 @@ void RipCD::ClickedRipButton() {
return;
}
SetWorking(true);
{
QMutexLocker l(&mutex_);
cancel_requested_ = false;
}
QtConcurrent::run(this, &RipCD::ThreadClickedRipButton);
}
@ -401,6 +412,10 @@ void RipCD::AddDestinationDirectory(QString dir) {
}
void RipCD::Cancel() {
{
QMutexLocker l(&mutex_);
cancel_requested_ = true;
}
ui_->progress_bar->setValue(0);
transcoder_->Cancel();
RemoveTemporaryDirectory();

View File

@ -22,6 +22,7 @@
#include <QCheckBox>
#include <QThread>
#include <QFile>
#include <QMutex>
#include <cdio/cdio.h>
#include "ui_ripcd.h"
#include <memory>
@ -62,6 +63,8 @@ class RipCD : public QDialog {
QPushButton* close_button_;
QPushButton* rip_button_;
QString temporary_directory_;
bool cancel_requested_;
QMutex mutex_;
void WriteWAVHeader(QFile* stream, int32_t i_bytecount);
int NumTracksToRip();

View File

@ -93,6 +93,9 @@ NowPlayingWidget::NowPlayingWidget(QWidget* parent)
mode_mapper);
CreateModeAction(LargeSongDetails, tr("Large album cover"), mode_group,
mode_mapper);
CreateModeAction(LargeSongDetailsBelow,
tr("Large album cover (details below)"), mode_group,
mode_mapper);
menu_->addActions(mode_group->actions());
menu_->addSeparator();
@ -141,6 +144,16 @@ NowPlayingWidget::NowPlayingWidget(QWidget* parent)
SLOT(FadePreviousTrack(qreal)));
fade_animation_->setDirection(QTimeLine::Backward); // 1.0 -> 0.0
// add placeholder text to get the correct height
if (mode_ == LargeSongDetailsBelow) {
details_->setDefaultStyleSheet(
"p {"
" font-size: small;"
" color: white;"
"}");
details_->setHtml(QString("<p align=center><i></i><br/><br/></p>"));
}
UpdateHeight();
connect(album_cover_choice_controller_, SIGNAL(AutomaticCoverSearchDone()),
@ -189,6 +202,12 @@ void NowPlayingWidget::UpdateHeight() {
total_height_ =
kTopBorder + cover_loader_options_.desired_height_ + kBottomOffset;
break;
case LargeSongDetailsBelow:
cover_loader_options_.desired_height_ = qMin(kMaxCoverSize, width());
total_height_ = kTopBorder + cover_loader_options_.desired_height_ +
kBottomOffset + details_->size().height();
break;
}
// Update the animation settings and resize the widget now if we're visible
@ -226,6 +245,16 @@ void NowPlayingWidget::UpdateDetailsText() {
"}");
html += "<p align=center>";
break;
case LargeSongDetailsBelow:
details_->setTextWidth(cover_loader_options_.desired_height_);
details_->setDefaultStyleSheet(
"p {"
" font-size: small;"
" color: white;"
"}");
html += "<p align=center>";
break;
}
// TODO: Make this configurable
@ -235,6 +264,11 @@ void NowPlayingWidget::UpdateDetailsText() {
html += "</p>";
details_->setHtml(html);
// if something spans multiple lines the height needs to change
if (mode_ == LargeSongDetailsBelow) {
UpdateHeight();
}
}
void NowPlayingWidget::ScaleCover() {
@ -333,7 +367,7 @@ void NowPlayingWidget::DrawContents(QPainter* p) {
p->translate(-small_ideal_height_ - kPadding, 0);
break;
case LargeSongDetails:
case LargeSongDetails: {
const int total_size = qMin(kMaxCoverSize, width());
const int x_offset =
(width() - cover_loader_options_.desired_height_) / 2;
@ -372,6 +406,37 @@ void NowPlayingWidget::DrawContents(QPainter* p) {
details_->drawContents(p);
p->translate(-x_offset, -height() + text_height);
break;
}
case LargeSongDetailsBelow:
// Work out how high the text is going to be
const int text_height = details_->size().height();
const int cover_size = qMin(kMaxCoverSize, width());
const int x_offset =
(width() - cover_loader_options_.desired_height_) / 2;
// Draw the black background
p->fillRect(QRect(0, kTopBorder, width(), height() - kTopBorder),
Qt::black);
// Draw the cover
if (hypnotoad_) {
p->drawPixmap(x_offset, kTopBorder, cover_size, cover_size,
hypnotoad_->currentPixmap());
} else {
p->drawPixmap(x_offset, kTopBorder, cover_size, cover_size, cover_);
if (downloading_covers_) {
p->drawPixmap(x_offset + 45, 35, 16, 16,
spinner_animation_->currentPixmap());
}
}
// Draw the text below
p->translate(x_offset, height() - text_height);
details_->drawContents(p);
p->translate(-x_offset, -height() + text_height);
break;
}
}
@ -396,9 +461,11 @@ void NowPlayingWidget::SetMode(int mode) {
}
void NowPlayingWidget::resizeEvent(QResizeEvent* e) {
if (visible_ && mode_ == LargeSongDetails && e->oldSize() != e->size()) {
UpdateHeight();
UpdateDetailsText();
if (visible_ && e->oldSize() != e->size()) {
if (mode_ == LargeSongDetails || mode_ == LargeSongDetailsBelow) {
UpdateHeight();
UpdateDetailsText();
}
}
}

View File

@ -54,7 +54,11 @@ class NowPlayingWidget : public QWidget {
static const int kTopBorder;
// Values are saved in QSettings
enum Mode { SmallSongDetails = 0, LargeSongDetails = 1, };
enum Mode {
SmallSongDetails = 0,
LargeSongDetails = 1,
LargeSongDetailsBelow = 2,
};
void SetApplication(Application* app);