1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-17 12:02:48 +01:00
This commit is contained in:
Mark Furneaux 2014-12-07 11:48:25 -05:00
commit de934e4cc7
4 changed files with 52 additions and 1 deletions

View File

@ -19,6 +19,8 @@
* Boston, MA 02110-1301, USA.
*/
#include <QMutex>
#include <cstring>
#include <cmath>
#include "gstfastspectrum.h"
@ -48,6 +50,8 @@ enum {
PROP_BANDS
};
static QMutex fftw_mutex;
#define gst_fastspectrum_parent_class parent_class
G_DEFINE_TYPE (GstFastSpectrum, gst_fastspectrum, GST_TYPE_AUDIO_FILTER);
@ -123,6 +127,8 @@ gst_fastspectrum_init (GstFastSpectrum * spectrum)
static void
gst_fastspectrum_alloc_channel_data (GstFastSpectrum * spectrum)
{
fftw_mutex.lock();
guint bands = spectrum->bands;
guint nfft = 2 * bands - 2;
@ -139,12 +145,16 @@ gst_fastspectrum_alloc_channel_data (GstFastSpectrum * spectrum)
spectrum->fft_output,
FFTW_ESTIMATE);
spectrum->channel_data_initialised = true;
fftw_mutex.unlock();
}
static void
gst_fastspectrum_free_channel_data (GstFastSpectrum * spectrum)
{
if (spectrum->channel_data_initialised) {
fftw_mutex.lock();
fftw_destroy_plan(spectrum->plan);
fftw_free(spectrum->fft_input);
fftw_free(spectrum->fft_output);
@ -152,6 +162,8 @@ gst_fastspectrum_free_channel_data (GstFastSpectrum * spectrum)
delete[] spectrum->spect_magnitude;
spectrum->channel_data_initialised = false;
fftw_mutex.unlock();
}
}
@ -373,6 +385,8 @@ gst_fastspectrum_run_fft (GstFastSpectrum * spectrum, guint input_pos)
guint bands = spectrum->bands;
guint nfft = 2 * bands - 2;
fftw_mutex.lock();
for (i = 0; i < nfft; i++)
spectrum->fft_input[i] =
spectrum->input_ring_buffer[(input_pos + i) % nfft];
@ -387,6 +401,8 @@ gst_fastspectrum_run_fft (GstFastSpectrum * spectrum, guint input_pos)
val /= nfft * nfft;
spectrum->spect_magnitude[i] += val;
}
fftw_mutex.unlock();
}
static GstFlowReturn

View File

@ -295,6 +295,7 @@ MusicBrainzClient::ResultList MusicBrainzClient::ParseTrack(
if (releases.isEmpty()) {
ret << result;
} else {
qStableSort(releases);
for (const Release& release : releases) {
ret << release.CopyAndMergeInto(result);
}
@ -336,6 +337,8 @@ MusicBrainzClient::Release MusicBrainzClient::ParseRelease(
QStringRef name = reader->name();
if (name == "title") {
ret.album_ = reader->readElementText();
} else if (name == "status") {
ret.SetStatusFromString(reader->readElementText());
} else if (name == "date") {
QRegExp regex(kDateRegex);
if (regex.indexIn(reader->readElementText()) == 0) {

View File

@ -110,7 +110,16 @@ signals:
};
struct Release {
Release() : track_(0), year_(0) {}
enum Status {
Status_Unknown = 0,
Status_PseudoRelease,
Status_Bootleg,
Status_Promotional,
Status_Official
};
Release() : track_(0), year_(0), status_(Status_Unknown) {}
Result CopyAndMergeInto(const Result& orig) const {
Result ret(orig);
@ -120,9 +129,30 @@ signals:
return ret;
}
void SetStatusFromString(const QString& s) {
if (s.compare("Official", Qt::CaseInsensitive) == 0) {
status_ = Status_Official;
} else if (s.compare("Promotion", Qt::CaseInsensitive) == 0) {
status_ = Status_Promotional;
} else if (s.compare("Bootleg", Qt::CaseInsensitive) == 0) {
status_ = Status_Bootleg;
} else if (s.compare("Pseudo-release", Qt::CaseInsensitive) == 0) {
status_ = Status_PseudoRelease;
} else {
status_ = Status_Unknown;
}
}
bool operator<(const Release& other) const {
// Compare status so that "best" status (e.g. Official) will be first
// when sorting a list of releases.
return status_ > other.status_;
}
QString album_;
int track_;
int year_;
Status status_;
};
struct PendingResults {

View File

@ -54,6 +54,8 @@ RemoteClient::~RemoteClient() {
client_->close();
if (client_->state() == QAbstractSocket::ConnectedState)
client_->waitForDisconnected(2000);
song_sender_->deleteLater();
}
void RemoteClient::setDownloader(bool downloader) { downloader_ = downloader; }