Connection syntax migration (#637)

This commit is contained in:
Jonas Kvinge
2021-01-26 16:48:04 +01:00
committed by GitHub
parent d57f6303f4
commit bf7c8df353
362 changed files with 2452 additions and 2434 deletions

View File

@@ -60,7 +60,7 @@ void MoodbarBuilder::Init(int bands, int rate_hz) {
}
void MoodbarBuilder::AddFrame(const double* magnitudes, int size) {
void MoodbarBuilder::AddFrame(const double *magnitudes, int size) {
if (size > barkband_table_.length()) {
return;
@@ -86,7 +86,7 @@ void MoodbarBuilder::AddFrame(const double* magnitudes, int size) {
}
void MoodbarBuilder::Normalize(QList<Rgb>* vals, double Rgb::*member) {
void MoodbarBuilder::Normalize(QList<Rgb> *vals, double Rgb::*member) {
double mini = vals->at(0).*member;
double maxi = vals->at(0).*member;
@@ -101,7 +101,7 @@ void MoodbarBuilder::Normalize(QList<Rgb>* vals, double Rgb::*member) {
}
double avg = 0;
for (const Rgb& rgb : *vals) {
for (const Rgb &rgb : *vals) {
const double value = rgb.*member;
if (value != mini && value != maxi) {
avg += value / vals->count();
@@ -132,7 +132,7 @@ void MoodbarBuilder::Normalize(QList<Rgb>* vals, double Rgb::*member) {
tb = 0;
double avguu = 0;
double avgbb = 0;
for (const Rgb& rgb : *vals) {
for (const Rgb &rgb : *vals) {
const double value = rgb.*member;
if (value != mini && value != maxi) {
if (value > avgu) {
@@ -156,7 +156,7 @@ void MoodbarBuilder::Normalize(QList<Rgb>* vals, double Rgb::*member) {
}
for (auto it = vals->begin(); it != vals->end(); ++it) {
double* value = &((*it).*member);
double *value = &((*it).*member);
*value = std::isfinite(*value) ? qBound(0.0, (*value - mini) / delta, 1.0) : 0;
}
@@ -166,7 +166,7 @@ QByteArray MoodbarBuilder::Finish(int width) {
QByteArray ret;
ret.resize(width * 3);
char* data = ret.data();
char *data = ret.data();
if (frames_.count() == 0) return ret;
Normalize(&frames_, &Rgb::r);

View File

@@ -27,7 +27,7 @@ class MoodbarBuilder {
explicit MoodbarBuilder();
void Init(int bands, int rate_hz);
void AddFrame(const double* magnitudes, int size);
void AddFrame(const double *magnitudes, int size);
QByteArray Finish(int width);
private:
@@ -39,7 +39,7 @@ class MoodbarBuilder {
};
int BandFrequency(int band) const;
static void Normalize(QList<Rgb>* vals, double Rgb::*member);
static void Normalize(QList<Rgb> *vals, double Rgb::*member);
QList<uint> barkband_table_;
int bands_;

View File

@@ -22,7 +22,6 @@
#include <QUrl>
#include "core/application.h"
#include "core/closure.h"
#include "core/player.h"
#include "core/song.h"
#include "engine/engine_fwd.h"
@@ -33,13 +32,13 @@
#include "moodbarloader.h"
#include "moodbarpipeline.h"
MoodbarController::MoodbarController(Application* app, QObject* parent)
MoodbarController::MoodbarController(Application *app, QObject *parent)
: QObject(parent),
app_(app),
enabled_(false) {
connect(app_->playlist_manager(), SIGNAL(CurrentSongChanged(Song)), SLOT(CurrentSongChanged(Song)));
connect(app_->player(), SIGNAL(Stopped()), SLOT(PlaybackStopped()));
QObject::connect(app_->playlist_manager(), &PlaylistManager::CurrentSongChanged, this, &MoodbarController::CurrentSongChanged);
QObject::connect(app_->player(), &Player::Stopped, this, &MoodbarController::PlaybackStopped);
ReloadSettings();
@@ -59,7 +58,7 @@ void MoodbarController::CurrentSongChanged(const Song &song) {
if (!enabled_) return;
QByteArray data;
MoodbarPipeline* pipeline = nullptr;
MoodbarPipeline *pipeline = nullptr;
const MoodbarLoader::Result result = app_->moodbar_loader()->Load(song.url(), &data, &pipeline);
switch (result) {
@@ -76,7 +75,7 @@ void MoodbarController::CurrentSongChanged(const Song &song) {
// bar. Our slot will be called when the data is actually loaded.
emit CurrentMoodbarDataChanged(QByteArray());
NewClosure(pipeline, SIGNAL(Finished(bool)), this, SLOT(AsyncLoadComplete(MoodbarPipeline*, QUrl)), pipeline, song.url());
QObject::connect(pipeline, &MoodbarPipeline::Finished, [this, pipeline, song]() { AsyncLoadComplete(pipeline, song.url()); });
break;
}
@@ -88,7 +87,7 @@ void MoodbarController::PlaybackStopped() {
}
}
void MoodbarController::AsyncLoadComplete(MoodbarPipeline* pipeline, const QUrl& url) {
void MoodbarController::AsyncLoadComplete(MoodbarPipeline *pipeline, const QUrl &url) {
// Is this song still playing?
PlaylistItemPtr current_item = app_->player()->GetCurrentItem();

View File

@@ -31,20 +31,20 @@ class MoodbarController : public QObject {
Q_OBJECT
public:
explicit MoodbarController(Application* app, QObject* parent = nullptr);
explicit MoodbarController(Application *app, QObject *parent = nullptr);
void ReloadSettings();
signals:
void CurrentMoodbarDataChanged(const QByteArray& data);
void CurrentMoodbarDataChanged(QByteArray data);
private slots:
void CurrentSongChanged(const Song& song);
void CurrentSongChanged(const Song &song);
void PlaybackStopped();
void AsyncLoadComplete(MoodbarPipeline* pipeline, const QUrl& url);
void AsyncLoadComplete(MoodbarPipeline *pipeline, const QUrl &url);
private:
Application* app_;
Application *app_;
bool enabled_;
};

View File

@@ -47,13 +47,13 @@
MoodbarItemDelegate::Data::Data() : state_(State_None) {}
MoodbarItemDelegate::MoodbarItemDelegate(Application* app, PlaylistView* view, QObject* parent)
MoodbarItemDelegate::MoodbarItemDelegate(Application *app, PlaylistView *view, QObject *parent)
: QItemDelegate(parent),
app_(app),
view_(view),
style_(MoodbarRenderer::Style_Normal) {
connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings()));
QObject::connect(app_, &Application::SettingsChanged, this, &MoodbarItemDelegate::ReloadSettings);
ReloadSettings();
}
@@ -72,11 +72,11 @@ void MoodbarItemDelegate::ReloadSettings() {
}
void MoodbarItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
void MoodbarItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const {
QPixmap pixmap = const_cast<MoodbarItemDelegate*>(this)->PixmapForIndex(index, option.rect.size());
QPixmap pixmap = const_cast<MoodbarItemDelegate*>(this)->PixmapForIndex(idx, option.rect.size());
drawBackground(painter, option, index);
drawBackground(painter, option, idx);
if (!pixmap.isNull()) {
// Make a little border for the moodbar
@@ -86,18 +86,18 @@ void MoodbarItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& o
}
QPixmap MoodbarItemDelegate::PixmapForIndex(const QModelIndex& index, const QSize& size) {
QPixmap MoodbarItemDelegate::PixmapForIndex(const QModelIndex &idx, const QSize &size) {
// Pixmaps are keyed off URL.
const QUrl url(index.sibling(index.row(), Playlist::Column_Filename).data().toUrl());
const QUrl url(idx.sibling(idx.row(), Playlist::Column_Filename).data().toUrl());
Data* data = data_[url];
Data *data = data_[url];
if (!data) {
data = new Data;
data_.insert(url, data);
}
data->indexes_.insert(index);
data->indexes_.insert(idx);
data->desired_size_ = size;
switch (data->state_) {
@@ -126,13 +126,13 @@ QPixmap MoodbarItemDelegate::PixmapForIndex(const QModelIndex& index, const QSiz
}
void MoodbarItemDelegate::StartLoadingData(const QUrl& url, Data* data) {
void MoodbarItemDelegate::StartLoadingData(const QUrl &url, Data *data) {
data->state_ = Data::State_LoadingData;
// Load a mood file for this song and generate some colors from it
QByteArray bytes;
MoodbarPipeline* pipeline = nullptr;
MoodbarPipeline *pipeline = nullptr;
switch (app_->moodbar_loader()->Load(url, &bytes, &pipeline)) {
case MoodbarLoader::CannotLoad:
data->state_ = Data::State_CannotLoad;
@@ -145,16 +145,16 @@ void MoodbarItemDelegate::StartLoadingData(const QUrl& url, Data* data) {
case MoodbarLoader::WillLoadAsync:
// Maybe in a little while.
NewClosure(pipeline, SIGNAL(Finished(bool)), this, SLOT(DataLoaded(QUrl, MoodbarPipeline*)), url, pipeline);
QObject::connect(pipeline, &MoodbarPipeline::Finished, [this, url, pipeline]() { DataLoaded(url, pipeline); });
break;
}
}
bool MoodbarItemDelegate::RemoveFromCacheIfIndexesInvalid(const QUrl& url, Data* data) {
bool MoodbarItemDelegate::RemoveFromCacheIfIndexesInvalid(const QUrl &url, Data *data) {
for (const QPersistentModelIndex& index : data->indexes_) {
if (index.isValid()) {
for (const QPersistentModelIndex &idx : data->indexes_) {
if (idx.isValid()) {
return false;
}
}
@@ -166,8 +166,8 @@ bool MoodbarItemDelegate::RemoveFromCacheIfIndexesInvalid(const QUrl& url, Data*
void MoodbarItemDelegate::ReloadAllColors() {
for (const QUrl& url : data_.keys()) {
Data* data = data_[url];
for (const QUrl &url : data_.keys()) {
Data *data = data_[url];
if (data->state_ == Data::State_Loaded) {
StartLoadingData(url, data);
@@ -176,9 +176,9 @@ void MoodbarItemDelegate::ReloadAllColors() {
}
void MoodbarItemDelegate::DataLoaded(const QUrl& url, MoodbarPipeline* pipeline) {
void MoodbarItemDelegate::DataLoaded(const QUrl &url, MoodbarPipeline *pipeline) {
Data* data = data_[url];
Data *data = data_[url];
if (!data) {
return;
}
@@ -197,7 +197,7 @@ void MoodbarItemDelegate::DataLoaded(const QUrl& url, MoodbarPipeline* pipeline)
}
void MoodbarItemDelegate::StartLoadingColors(const QUrl& url, const QByteArray& bytes, Data* data) {
void MoodbarItemDelegate::StartLoadingColors(const QUrl &url, const QByteArray &bytes, Data *data) {
data->state_ = Data::State_LoadingColors;
@@ -206,9 +206,9 @@ void MoodbarItemDelegate::StartLoadingColors(const QUrl& url, const QByteArray&
}
void MoodbarItemDelegate::ColorsLoaded(const QUrl& url, QFuture<ColorVector> future) {
void MoodbarItemDelegate::ColorsLoaded(const QUrl &url, QFuture<ColorVector> future) {
Data* data = data_[url];
Data *data = data_[url];
if (!data) {
return;
}
@@ -224,7 +224,7 @@ void MoodbarItemDelegate::ColorsLoaded(const QUrl& url, QFuture<ColorVector> fut
}
void MoodbarItemDelegate::StartLoadingImage(const QUrl& url, Data* data) {
void MoodbarItemDelegate::StartLoadingImage(const QUrl &url, Data *data) {
data->state_ = Data::State_LoadingImage;
@@ -233,9 +233,9 @@ void MoodbarItemDelegate::StartLoadingImage(const QUrl& url, Data* data) {
}
void MoodbarItemDelegate::ImageLoaded(const QUrl& url, QFuture<QImage> future) {
void MoodbarItemDelegate::ImageLoaded(const QUrl &url, QFuture<QImage> future) {
Data* data = data_[url];
Data *data = data_[url];
if (!data) {
return;
}
@@ -256,14 +256,14 @@ void MoodbarItemDelegate::ImageLoaded(const QUrl& url, QFuture<QImage> future) {
data->pixmap_ = QPixmap::fromImage(image);
data->state_ = Data::State_Loaded;
Playlist* playlist = view_->playlist();
const QSortFilterProxyModel* filter = playlist->proxy();
Playlist *playlist = view_->playlist();
const QSortFilterProxyModel *filter = playlist->proxy();
// Update all the indices with the new pixmap.
for (const QPersistentModelIndex& index : data->indexes_) {
if (index.isValid() && index.sibling(index.row(), Playlist::Column_Filename).data().toUrl() == url) {
QModelIndex source_index = index;
if (index.model() == filter) {
for (const QPersistentModelIndex &idx : data->indexes_) {
if (idx.isValid() && idx.sibling(idx.row(), Playlist::Column_Filename).data().toUrl() == url) {
QModelIndex source_index = idx;
if (idx.model() == filter) {
source_index = filter->mapToSource(source_index);
}

View File

@@ -44,16 +44,16 @@ class MoodbarItemDelegate : public QItemDelegate {
Q_OBJECT
public:
explicit MoodbarItemDelegate(Application* app, PlaylistView* view, QObject* parent = nullptr);
explicit MoodbarItemDelegate(Application *app, PlaylistView *view, QObject *parent = nullptr);
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
private slots:
void ReloadSettings();
void DataLoaded(const QUrl& url, MoodbarPipeline* pipeline);
void ColorsLoaded(const QUrl& url, QFuture<ColorVector> future);
void ImageLoaded(const QUrl& url, QFuture<QImage> future);
void DataLoaded(const QUrl &url, MoodbarPipeline *pipeline);
void ColorsLoaded(const QUrl &url, QFuture<ColorVector> future);
void ImageLoaded(const QUrl &url, QFuture<QImage> future);
private:
struct Data {
@@ -77,18 +77,18 @@ class MoodbarItemDelegate : public QItemDelegate {
};
private:
QPixmap PixmapForIndex(const QModelIndex& index, const QSize& size);
void StartLoadingData(const QUrl& url, Data* data);
void StartLoadingColors(const QUrl& url, const QByteArray& bytes, Data* data);
void StartLoadingImage(const QUrl& url, Data* data);
QPixmap PixmapForIndex(const QModelIndex &idx, const QSize &size);
void StartLoadingData(const QUrl &url, Data *data);
void StartLoadingColors(const QUrl &url, const QByteArray &bytes, Data *data);
void StartLoadingImage(const QUrl &url, Data *data);
bool RemoveFromCacheIfIndexesInvalid(const QUrl& url, Data* data);
bool RemoveFromCacheIfIndexesInvalid(const QUrl &url, Data *data);
void ReloadAllColors();
private:
Application* app_;
PlaylistView* view_;
Application *app_;
PlaylistView *view_;
QCache<QUrl, Data> data_;
MoodbarRenderer::MoodbarStyle style_;

View File

@@ -39,7 +39,6 @@
#include <QtDebug>
#include "core/application.h"
#include "core/closure.h"
#include "core/logging.h"
#include "moodbarpipeline.h"
@@ -50,18 +49,17 @@
# include <windows.h>
#endif
MoodbarLoader::MoodbarLoader(Application* app, QObject* parent)
MoodbarLoader::MoodbarLoader(Application *app, QObject *parent)
: QObject(parent),
cache_(new QNetworkDiskCache(this)),
thread_(new QThread(this)),
kMaxActiveRequests(qMax(1, QThread::idealThreadCount() / 2)),
enabled_(false),
save_(false) {
cache_->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/moodbar");
cache_->setMaximumCacheSize(60 * 1024 * 1024); // 60MB - enough for 20,000 moodbars
connect(app, SIGNAL(SettingsChanged()), SLOT(ReloadSettings()));
QObject::connect(app, &Application::SettingsChanged, this, &MoodbarLoader::ReloadSettings);
ReloadSettings();
}
@@ -82,7 +80,7 @@ void MoodbarLoader::ReloadSettings() {
}
QStringList MoodbarLoader::MoodFilenames(const QString& song_filename) {
QStringList MoodbarLoader::MoodFilenames(const QString &song_filename) {
const QFileInfo file_info(song_filename);
const QString dir_path(file_info.dir().path());
@@ -92,7 +90,7 @@ QStringList MoodbarLoader::MoodFilenames(const QString& song_filename) {
}
MoodbarLoader::Result MoodbarLoader::Load(const QUrl& url, QByteArray* data, MoodbarPipeline** async_pipeline) {
MoodbarLoader::Result MoodbarLoader::Load(const QUrl &url, QByteArray *data, MoodbarPipeline **async_pipeline) {
if (url.scheme() != "file") {
return CannotLoad;
@@ -107,7 +105,7 @@ MoodbarLoader::Result MoodbarLoader::Load(const QUrl& url, QByteArray* data, Moo
// Check if a mood file exists for this file already
const QString filename(url.toLocalFile());
for (const QString& possible_mood_file : MoodFilenames(filename)) {
for (const QString &possible_mood_file : MoodFilenames(filename)) {
QFile f(possible_mood_file);
if (f.open(QIODevice::ReadOnly)) {
qLog(Info) << "Loading moodbar data from" << possible_mood_file;
@@ -129,9 +127,9 @@ MoodbarLoader::Result MoodbarLoader::Load(const QUrl& url, QByteArray* data, Moo
if (!thread_->isRunning()) thread_->start(QThread::IdlePriority);
// There was no existing file, analyze the audio file and create one.
MoodbarPipeline* pipeline = new MoodbarPipeline(url);
MoodbarPipeline *pipeline = new MoodbarPipeline(url);
pipeline->moveToThread(thread_);
NewClosure(pipeline, SIGNAL(Finished(bool)), this, SLOT(RequestFinished(MoodbarPipeline*, QUrl)), pipeline, url);
QObject::connect(pipeline, &MoodbarPipeline::Finished, [this, pipeline, url]() { RequestFinished(pipeline, url); });
requests_[url] = pipeline;
queued_requests_ << url;
@@ -170,7 +168,7 @@ void MoodbarLoader::RequestFinished(MoodbarPipeline *request, const QUrl &url) {
QNetworkCacheMetaData metadata;
metadata.setUrl(url);
QIODevice* cache_file = cache_->prepare(metadata);
QIODevice *cache_file = cache_->prepare(metadata);
if (cache_file) {
cache_file->write(request->data());
cache_->insert(cache_file);
@@ -200,7 +198,7 @@ void MoodbarLoader::RequestFinished(MoodbarPipeline *request, const QUrl &url) {
requests_.remove(url);
active_requests_.remove(url);
QTimer::singleShot(1000, request, SLOT(deleteLater()));
QTimer::singleShot(1000, request, &MoodbarLoader::deleteLater);
MaybeTakeNextRequest();

View File

@@ -36,7 +36,7 @@ class MoodbarLoader : public QObject {
Q_OBJECT
public:
explicit MoodbarLoader(Application* app, QObject* parent = nullptr);
explicit MoodbarLoader(Application *app, QObject *parent = nullptr);
~MoodbarLoader() override;
enum Result {
@@ -52,7 +52,7 @@ class MoodbarLoader : public QObject {
WillLoadAsync
};
Result Load(const QUrl& url, QByteArray* data, MoodbarPipeline** async_pipeline);
Result Load(const QUrl &url, QByteArray *data, MoodbarPipeline **async_pipeline);
private slots:
void ReloadSettings();
@@ -61,11 +61,11 @@ class MoodbarLoader : public QObject {
void MaybeTakeNextRequest();
private:
static QStringList MoodFilenames(const QString& song_filename);
static QStringList MoodFilenames(const QString &song_filename);
private:
QNetworkDiskCache* cache_;
QThread* thread_;
QNetworkDiskCache *cache_;
QThread *thread_;
const int kMaxActiveRequests;
@@ -73,7 +73,6 @@ class MoodbarLoader : public QObject {
QList<QUrl> queued_requests_;
QSet<QUrl> active_requests_;
bool enabled_;
bool save_;
};

View File

@@ -37,7 +37,7 @@
bool MoodbarPipeline::sIsAvailable = false;
const int MoodbarPipeline::kBands = 128;
MoodbarPipeline::MoodbarPipeline(const QUrl& local_filename)
MoodbarPipeline::MoodbarPipeline(const QUrl &local_filename)
: QObject(nullptr),
local_filename_(local_filename),
pipeline_(nullptr),
@@ -50,7 +50,7 @@ MoodbarPipeline::~MoodbarPipeline() { Cleanup(); }
bool MoodbarPipeline::IsAvailable() {
if (!sIsAvailable) {
GstElementFactory* factory = gst_element_factory_find("fftwspectrum");
GstElementFactory *factory = gst_element_factory_find("fftwspectrum");
if (!factory) {
return false;
}
@@ -63,9 +63,9 @@ bool MoodbarPipeline::IsAvailable() {
}
GstElement* MoodbarPipeline::CreateElement(const QString& factory_name) {
GstElement *MoodbarPipeline::CreateElement(const QString &factory_name) {
GstElement* ret = gst_element_factory_make(factory_name.toLatin1().constData(), nullptr);
GstElement *ret = gst_element_factory_make(factory_name.toLatin1().constData(), nullptr);
if (ret) {
gst_bin_add(GST_BIN(pipeline_), ret);
@@ -90,10 +90,10 @@ void MoodbarPipeline::Start() {
pipeline_ = gst_pipeline_new("moodbar-pipeline");
GstElement* decodebin = CreateElement("uridecodebin");
GstElement *decodebin = CreateElement("uridecodebin");
convert_element_ = CreateElement("audioconvert");
GstElement* spectrum = CreateElement("fastspectrum");
GstElement* fakesink = CreateElement("fakesink");
GstElement *spectrum = CreateElement("fastspectrum");
GstElement *fakesink = CreateElement("fakesink");
if (!decodebin || !convert_element_ || !spectrum || !fakesink) {
gst_object_unref(GST_OBJECT(pipeline_));
@@ -117,12 +117,12 @@ void MoodbarPipeline::Start() {
g_object_set(decodebin, "uri", local_filename_.toEncoded().constData(), nullptr);
g_object_set(spectrum, "bands", kBands, nullptr);
GstFastSpectrum* fast_spectrum = reinterpret_cast<GstFastSpectrum*>(spectrum);
fast_spectrum->output_callback = [this](double* magnitudes, int size) { builder_->AddFrame(magnitudes, size); };
GstFastSpectrum *fast_spectrum = reinterpret_cast<GstFastSpectrum*>(spectrum);
fast_spectrum->output_callback = [this](double *magnitudes, int size) { builder_->AddFrame(magnitudes, size); };
// Connect signals
CHECKED_GCONNECT(decodebin, "pad-added", &NewPadCallback, this);
GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline_));
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline_));
gst_bus_set_sync_handler(bus, BusCallbackSync, this, nullptr);
gst_object_unref(bus);
@@ -134,8 +134,8 @@ void MoodbarPipeline::Start() {
void MoodbarPipeline::ReportError(GstMessage *msg) {
GError* error;
gchar* debugs;
GError *error;
gchar *debugs;
gst_message_parse_error(msg, &error, &debugs);
QString message = QString::fromLocal8Bit(error->message);
@@ -147,16 +147,16 @@ void MoodbarPipeline::ReportError(GstMessage *msg) {
}
void MoodbarPipeline::NewPadCallback(GstElement*, GstPad* pad, gpointer data) {
void MoodbarPipeline::NewPadCallback(GstElement*, GstPad *pad, gpointer data) {
MoodbarPipeline* self = reinterpret_cast<MoodbarPipeline*>(data);
MoodbarPipeline *self = reinterpret_cast<MoodbarPipeline*>(data);
if (!self->running_) {
qLog(Warning) << "Received gstreamer callback after pipeline has stopped.";
return;
}
GstPad* const audiopad = gst_element_get_static_pad(self->convert_element_, "sink");
GstPad *const audiopad = gst_element_get_static_pad(self->convert_element_, "sink");
if (GST_PAD_IS_LINKED(audiopad)) {
qLog(Warning) << "audiopad is already linked, unlinking old pad";
@@ -167,8 +167,8 @@ void MoodbarPipeline::NewPadCallback(GstElement*, GstPad* pad, gpointer data) {
gst_object_unref(audiopad);
int rate = 0;
GstCaps* caps = gst_pad_get_current_caps(pad);
GstStructure* structure = gst_caps_get_structure(caps, 0);
GstCaps *caps = gst_pad_get_current_caps(pad);
GstStructure *structure = gst_caps_get_structure(caps, 0);
gst_structure_get_int(structure, "rate", &rate);
gst_caps_unref(caps);
@@ -179,9 +179,9 @@ void MoodbarPipeline::NewPadCallback(GstElement*, GstPad* pad, gpointer data) {
}
GstBusSyncReply MoodbarPipeline::BusCallbackSync(GstBus*, GstMessage* msg, gpointer data) {
GstBusSyncReply MoodbarPipeline::BusCallbackSync(GstBus*, GstMessage *msg, gpointer data) {
MoodbarPipeline* self = reinterpret_cast<MoodbarPipeline*>(data);
MoodbarPipeline *self = reinterpret_cast<MoodbarPipeline*>(data);
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
@@ -200,7 +200,7 @@ GstBusSyncReply MoodbarPipeline::BusCallbackSync(GstBus*, GstMessage* msg, gpoin
}
void MoodbarPipeline::Stop(bool success) {
void MoodbarPipeline::Stop(const bool success) {
success_ = success;
running_ = false;
@@ -220,7 +220,7 @@ void MoodbarPipeline::Cleanup() {
running_ = false;
if (pipeline_) {
GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline_));
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline_));
gst_bus_set_sync_handler(bus, nullptr, nullptr, nullptr);
gst_object_unref(bus);

View File

@@ -36,13 +36,13 @@ class MoodbarPipeline : public QObject {
Q_OBJECT
public:
explicit MoodbarPipeline(const QUrl& local_filename);
explicit MoodbarPipeline(const QUrl &local_filename);
~MoodbarPipeline() override;
static bool IsAvailable();
bool success() const { return success_; }
const QByteArray& data() const { return data_; }
const QByteArray &data() const { return data_; }
public slots:
void Start();
@@ -51,24 +51,24 @@ class MoodbarPipeline : public QObject {
void Finished(bool success);
private:
GstElement* CreateElement(const QString& factory_name);
GstElement *CreateElement(const QString &factory_name);
void ReportError(GstMessage *msg);
void Stop(bool success);
void Stop(const bool success);
void Cleanup();
static void NewPadCallback(GstElement*, GstPad* pad, gpointer data);
static GstFlowReturn NewBufferCallback(GstAppSink* app_sink, gpointer self);
static gboolean BusCallback(GstBus*, GstMessage* msg, gpointer data);
static GstBusSyncReply BusCallbackSync(GstBus*, GstMessage* msg, gpointer data);
static void NewPadCallback(GstElement*, GstPad *pad, gpointer data);
static GstFlowReturn NewBufferCallback(GstAppSink *app_sink, gpointer self);
static gboolean BusCallback(GstBus*, GstMessage *msg, gpointer data);
static GstBusSyncReply BusCallbackSync(GstBus*, GstMessage *msg, gpointer data);
private:
static bool sIsAvailable;
static const int kBands;
QUrl local_filename_;
GstElement* pipeline_;
GstElement* convert_element_;
GstElement *pipeline_;
GstElement *convert_element_;
std::unique_ptr<MoodbarBuilder> builder_;

View File

@@ -67,9 +67,10 @@ MoodbarProxyStyle::MoodbarProxyStyle(Application* app, QSlider* slider)
slider->setStyle(this);
slider->installEventFilter(this);
connect(fade_timeline_, SIGNAL(valueChanged(qreal)), SLOT(FaderValueChanged(qreal)));
QObject::connect(fade_timeline_, &QTimeLine::valueChanged, this, &MoodbarProxyStyle::FaderValueChanged);
QObject::connect(app, &Application::SettingsChanged, this, &MoodbarProxyStyle::ReloadSettings);
connect(app, SIGNAL(SettingsChanged()), SLOT(ReloadSettings()));
ReloadSettings();
}
@@ -96,7 +97,7 @@ void MoodbarProxyStyle::ReloadSettings() {
}
void MoodbarProxyStyle::SetMoodbarData(const QByteArray& data) {
void MoodbarProxyStyle::SetMoodbarData(const QByteArray &data) {
data_ = data;
moodbar_colors_dirty_ = true; // Redraw next time
@@ -104,7 +105,7 @@ void MoodbarProxyStyle::SetMoodbarData(const QByteArray& data) {
}
void MoodbarProxyStyle::SetMoodbarEnabled(bool enabled) {
void MoodbarProxyStyle::SetMoodbarEnabled(const bool enabled) {
enabled_ = enabled;
@@ -157,12 +158,12 @@ void MoodbarProxyStyle::NextState() {
}
void MoodbarProxyStyle::FaderValueChanged(qreal value) {
void MoodbarProxyStyle::FaderValueChanged(const qreal value) {
Q_UNUSED(value);
slider_->update();
}
bool MoodbarProxyStyle::eventFilter(QObject* object, QEvent* event) {
bool MoodbarProxyStyle::eventFilter(QObject *object, QEvent *event) {
if (object == slider_) {
switch (event->type()) {
@@ -184,7 +185,7 @@ bool MoodbarProxyStyle::eventFilter(QObject* object, QEvent* event) {
}
void MoodbarProxyStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget) const {
void MoodbarProxyStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const {
if (control != CC_Slider || widget != slider_) {
QProxyStyle::drawComplexControl(control, option, painter, widget);
@@ -195,7 +196,7 @@ void MoodbarProxyStyle::drawComplexControl(ComplexControl control, const QStyleO
}
void MoodbarProxyStyle::Render(ComplexControl control, const QStyleOptionSlider* option, QPainter* painter, const QWidget* widget) {
void MoodbarProxyStyle::Render(ComplexControl control, const QStyleOptionSlider *option, QPainter *painter, const QWidget *widget) {
const qreal fade_value = fade_timeline_->currentValue();
@@ -256,7 +257,7 @@ void MoodbarProxyStyle::Render(ComplexControl control, const QStyleOptionSlider*
}
void MoodbarProxyStyle::EnsureMoodbarRendered(const QStyleOptionSlider* opt) {
void MoodbarProxyStyle::EnsureMoodbarRendered(const QStyleOptionSlider *opt) {
if (moodbar_colors_dirty_) {
moodbar_colors_ = MoodbarRenderer::Colors(data_, moodbar_style_, slider_->palette());
@@ -271,7 +272,7 @@ void MoodbarProxyStyle::EnsureMoodbarRendered(const QStyleOptionSlider* opt) {
}
QRect MoodbarProxyStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex* opt, SubControl sc, const QWidget* widget) const {
QRect MoodbarProxyStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const {
if (cc != QStyle::CC_Slider || widget != slider_) {
return QProxyStyle::subControlRect(cc, opt, sc, widget);
@@ -289,7 +290,7 @@ QRect MoodbarProxyStyle::subControlRect(ComplexControl cc, const QStyleOptionCom
return opt->rect.adjusted(kMarginSize, kMarginSize, -kMarginSize, -kMarginSize);
case SC_SliderHandle: {
const QStyleOptionSlider* slider_opt = qstyleoption_cast<const QStyleOptionSlider*>(opt);
const QStyleOptionSlider *slider_opt = qstyleoption_cast<const QStyleOptionSlider*>(opt);
int x_offset = 0;
/* slider_opt->{maximum,minimum} can have the value 0 (their default
@@ -314,7 +315,7 @@ QRect MoodbarProxyStyle::subControlRect(ComplexControl cc, const QStyleOptionCom
return QProxyStyle::subControlRect(cc, opt, sc, widget);
}
void MoodbarProxyStyle::DrawArrow(const QStyleOptionSlider* option, QPainter* painter) const {
void MoodbarProxyStyle::DrawArrow(const QStyleOptionSlider *option, QPainter *painter) const {
// Get the dimensions of the arrow
const QRect rect = subControlRect(CC_Slider, option, SC_SliderHandle, slider_);
@@ -334,7 +335,7 @@ void MoodbarProxyStyle::DrawArrow(const QStyleOptionSlider* option, QPainter* pa
}
QPixmap MoodbarProxyStyle::MoodbarPixmap(const ColorVector& colors, const QSize& size, const QPalette& palette, const QStyleOptionSlider* opt) {
QPixmap MoodbarProxyStyle::MoodbarPixmap(const ColorVector &colors, const QSize &size, const QPalette &palette, const QStyleOptionSlider *opt) {
Q_UNUSED(opt);
@@ -366,33 +367,33 @@ QPixmap MoodbarProxyStyle::MoodbarPixmap(const ColorVector& colors, const QSize&
}
void MoodbarProxyStyle::ShowContextMenu(const QPoint& pos) {
void MoodbarProxyStyle::ShowContextMenu(const QPoint &pos) {
if (!context_menu_) {
context_menu_ = new QMenu(slider_);
show_moodbar_action_ = context_menu_->addAction(tr("Show moodbar"), this, SLOT(SetMoodbarEnabled(bool)));
show_moodbar_action_ = context_menu_->addAction(tr("Show moodbar"), this, &MoodbarProxyStyle::SetMoodbarEnabled);
show_moodbar_action_->setCheckable(true);
show_moodbar_action_->setChecked(enabled_);
QMenu* styles_menu = context_menu_->addMenu(tr("Moodbar style"));
QMenu *styles_menu = context_menu_->addMenu(tr("Moodbar style"));
style_action_group_ = new QActionGroup(styles_menu);
for (int i = 0; i < MoodbarRenderer::StyleCount; ++i) {
const MoodbarRenderer::MoodbarStyle style = MoodbarRenderer::MoodbarStyle(i);
QAction* action = style_action_group_->addAction(MoodbarRenderer::StyleName(style));
QAction *action = style_action_group_->addAction(MoodbarRenderer::StyleName(style));
action->setCheckable(true);
action->setData(i);
}
styles_menu->addActions(style_action_group_->actions());
connect(styles_menu, SIGNAL(triggered(QAction*)), SLOT(ChangeStyle(QAction*)));
QObject::connect(styles_menu, &QMenu::triggered, this, &MoodbarProxyStyle::ChangeStyle);
}
// Update the currently selected style
for (QAction* action : style_action_group_->actions()) {
for (QAction *action : style_action_group_->actions()) {
if (MoodbarRenderer::MoodbarStyle(action->data().toInt()) == moodbar_style_) {
action->setChecked(true);
break;
@@ -403,7 +404,7 @@ void MoodbarProxyStyle::ShowContextMenu(const QPoint& pos) {
}
void MoodbarProxyStyle::ChangeStyle(QAction* action) {
void MoodbarProxyStyle::ChangeStyle(QAction *action) {
QSettings s;
s.beginGroup(MoodbarSettingsPage::kSettingsGroup);

View File

@@ -48,21 +48,21 @@ class MoodbarProxyStyle : public QProxyStyle {
Q_OBJECT
public:
explicit MoodbarProxyStyle(Application* app, QSlider* slider);
explicit MoodbarProxyStyle(Application *app, QSlider *slider);
// QProxyStyle
void drawComplexControl(ComplexControl control, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget) const override;
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex* opt, SubControl sc, const QWidget* widget) const override;
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const override;
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const override;
// QObject
bool eventFilter(QObject* object, QEvent* event) override;
bool eventFilter(QObject *object, QEvent *event) override;
public slots:
// An empty byte array means there's no moodbar, so just show a normal slider.
void SetMoodbarData(const QByteArray& data);
void SetMoodbarData(const QByteArray &data);
// If the moodbar is disabled then a normal slider will always be shown.
void SetMoodbarEnabled(bool enabled);
void SetMoodbarEnabled(const bool enabled);
private:
static const int kMarginSize;
@@ -75,28 +75,28 @@ class MoodbarProxyStyle : public QProxyStyle {
private:
void NextState();
void Render(ComplexControl control, const QStyleOptionSlider* option, QPainter* painter, const QWidget* widget);
void EnsureMoodbarRendered(const QStyleOptionSlider* opt);
void DrawArrow(const QStyleOptionSlider* option, QPainter* painter) const;
void ShowContextMenu(const QPoint& pos);
void Render(ComplexControl control, const QStyleOptionSlider *option, QPainter *painter, const QWidget *widget);
void EnsureMoodbarRendered(const QStyleOptionSlider *opt);
void DrawArrow(const QStyleOptionSlider *option, QPainter *painter) const;
void ShowContextMenu(const QPoint &pos);
QPixmap MoodbarPixmap(const ColorVector& colors, const QSize& size, const QPalette& palette, const QStyleOptionSlider* opt);
QPixmap MoodbarPixmap(const ColorVector &colors, const QSize &size, const QPalette &palette, const QStyleOptionSlider *opt);
private slots:
void ReloadSettings();
void FaderValueChanged(qreal value);
void ChangeStyle(QAction* action);
void ChangeStyle(QAction *action);
private:
Application* app_;
QSlider* slider_;
Application *app_;
QSlider *slider_;
bool enabled_;
QByteArray data_;
MoodbarRenderer::MoodbarStyle moodbar_style_;
State state_;
QTimeLine* fade_timeline_;
QTimeLine *fade_timeline_;
QPixmap fade_source_;
QPixmap fade_target_;
@@ -106,9 +106,9 @@ class MoodbarProxyStyle : public QProxyStyle {
ColorVector moodbar_colors_;
QPixmap moodbar_pixmap_;
QMenu* context_menu_;
QAction* show_moodbar_action_;
QActionGroup* style_action_group_;
QMenu *context_menu_;
QAction *show_moodbar_action_;
QActionGroup *style_action_group_;
};
#endif // MOODBARPROXYSTYLE_H

View File

@@ -34,7 +34,7 @@
const int MoodbarRenderer::kNumHues = 12;
ColorVector MoodbarRenderer::Colors(const QByteArray& data, MoodbarStyle style, const QPalette& palette) {
ColorVector MoodbarRenderer::Colors(const QByteArray &data, const MoodbarStyle style, const QPalette &palette) {
const int samples = data.size() / 3;
@@ -65,7 +65,7 @@ ColorVector MoodbarRenderer::Colors(const QByteArray& data, MoodbarStyle style,
}
}
const unsigned char* data_p = reinterpret_cast<const unsigned char*>(data.constData());
const unsigned char *data_p = reinterpret_cast<const unsigned char*>(data.constData());
int hue_distribution[360];
int total = 0;
@@ -110,7 +110,7 @@ ColorVector MoodbarRenderer::Colors(const QByteArray& data, MoodbarStyle style,
return colors;
}
void MoodbarRenderer::Render(const ColorVector& colors, QPainter* p, const QRect& rect) {
void MoodbarRenderer::Render(const ColorVector &colors, QPainter *p, const QRect &rect) {
// Sample the colors and map them to screen pixels.
ColorVector screen_colors;
@@ -153,7 +153,7 @@ void MoodbarRenderer::Render(const ColorVector& colors, QPainter* p, const QRect
}
}
QImage MoodbarRenderer::RenderToImage(const ColorVector& colors, const QSize& size) {
QImage MoodbarRenderer::RenderToImage(const ColorVector &colors, const QSize &size) {
QImage image(size, QImage::Format_ARGB32_Premultiplied);
QPainter p(&image);
@@ -163,7 +163,7 @@ QImage MoodbarRenderer::RenderToImage(const ColorVector& colors, const QSize& si
}
QString MoodbarRenderer::StyleName(MoodbarStyle style) {
QString MoodbarRenderer::StyleName(const MoodbarStyle style) {
switch (style) {
case Style_Normal:

View File

@@ -47,17 +47,17 @@ class MoodbarRenderer {
static const int kNumHues;
static QString StyleName(MoodbarStyle style);
static QString StyleName(const MoodbarStyle style);
static ColorVector Colors(const QByteArray& data, MoodbarStyle style, const QPalette& palette);
static void Render(const ColorVector& colors, QPainter* p, const QRect& rect);
static QImage RenderToImage(const ColorVector& colors, const QSize& size);
static ColorVector Colors(const QByteArray &data, const MoodbarStyle style, const QPalette &palette);
static void Render(const ColorVector &colors, QPainter *p, const QRect &rect);
static QImage RenderToImage(const ColorVector &colors, const QSize &size);
private:
explicit MoodbarRenderer();
struct StyleProperties {
explicit StyleProperties(int threshold = 0, int range_start = 0, int range_delta = 0, int sat = 0, int val = 0)
explicit StyleProperties(const int threshold = 0, const int range_start = 0, const int range_delta = 0, const int sat = 0, const int val = 0)
: threshold_(threshold),
range_start_(range_start),
range_delta_(range_delta),