Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Be-ing committed Jan 18, 2020
1 parent ada3c85 commit 8bce62f
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 171 deletions.
6 changes: 3 additions & 3 deletions src/engine/controls/cuecontrol.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// cuecontrol.h
// cuecontrol.h
// Created 11/5/2009 by RJ Ryan (rryan@mit.edu)

#ifndef CUECONTROL_H
Expand All @@ -9,7 +9,7 @@

#include "control/controlproxy.h"
#include "engine/controls/enginecontrol.h"
#include "preferences/hotcuecolorpalettesettings.h"
#include "preferences/colorpalettesettings.h"
#include "preferences/usersettings.h"
#include "track/track.h"

Expand Down Expand Up @@ -198,7 +198,7 @@ class CueControl : public EngineControl {
double quantizeCurrentPosition(QuantizeMode mode);
TrackAt getTrackAt() const;

HotcueColorPaletteSettings m_colorPaletteSettings;
ColorPaletteSettings m_colorPaletteSettings;
bool m_bPreviewing;
ControlObject* m_pPlay;
ControlObject* m_pStopButton;
Expand Down
38 changes: 38 additions & 0 deletions src/library/dao/cuedao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,44 @@ bool CueDAO::deleteCue(Cue* cue) {
return false;
}

bool CueDAO::replaceSingleColor(const QColor& oldColor, const QColor& newColor) {
QSqlQuery query(m_database);
query.prepare("UPDATE " CUE_TABLE "SET color = :newColor WHERE color = :oldColor");
query.bindValue(":newColor", newColor.rgba());
query.bindValue(":oldColor", oldColor.rgba());
if (!query.exec()) {
LOG_FAILED_QUERY(query);
return false;
}
return true;
}

bool CueDAO::replaceColorPalette(const ColorPalette& oldPalette, const ColorPalette& newPalette) {
// TODO: repeat loop until reaching max hotcue number?
for (int i = 0; i < newPalette.size(); ++i) {
if (i == oldPalette.size()) {
return true;
}

const QColor& newColor = newPalette.at(i);
const QColor& oldColor = oldPalette.at(i);
if (newColor == oldColor) {
continue;
}

QSqlQuery query(m_database);
query.prepare("UPDATE " CUE_TABLE "SET color = :newColor WHERE (color = :oldColor AND hotcue = :hotcue)");
query.bindValue(":newColor", newColor.rgba());
query.bindValue(":oldColor", oldColor.rgba());
query.bindValue(":hotcue", i);
if (!query.exec()) {
LOG_FAILED_QUERY(query);
return false;
}
}
return true;
}

void CueDAO::saveTrackCues(TrackId trackId, const QList<CuePointer>& cueList) {
//qDebug() << "CueDAO::saveTrackCues" << QThread::currentThread() << m_database.connectionName();
// TODO(XXX) transaction, but people who are already in a transaction call
Expand Down
4 changes: 4 additions & 0 deletions src/library/dao/cuedao.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "track/track.h"
#include "library/dao/dao.h"
#include "util/color/colorpalette.h"

#define CUE_TABLE "cues"

Expand All @@ -29,6 +30,9 @@ class CueDAO : public DAO {
bool deleteCuesForTracks(const QList<TrackId>& trackIds);
bool saveCue(Cue* cue);
bool deleteCue(Cue* cue);

bool replaceSingleColor(const QColor& oldColor, const QColor& newColor);
bool replaceColorPalette(const ColorPalette& oldPalette, const ColorPalette& newPalette);
// TODO(XXX) once we refer to all tracks by their id and TIO has a getId()
// method the first parameter here won't be necessary.
void saveTrackCues(TrackId trackId, const QList<CuePointer>& cueList);
Expand Down
35 changes: 35 additions & 0 deletions src/preferences/colorpalettesettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "preferences/colorpalettesettings.h"

ColorPaletteSettings::ColorPaletteSettings(QString group, UserSettingsPointer pConfig)
: m_configGroup(group),
m_palette(ColorPalette::mixxxPalette),
m_pConfig(pConfig) {
loadFromConfig();
}

ColorPaletteSettings::~ColorPaletteSettings() {
save();
}

void ColorPaletteSettings::loadFromConfig() {
VERIFY_OR_DEBUG_ASSERT(!m_configGroup.isEmpty()) {
return;
}

QList<QColor> colorList;
for (const ConfigKey& key : m_pConfig->getKeysWithGroup(m_configGroup)) {
QColor color = m_pConfig->getValue<QColor>(key);
if (color.isValid()) {
colorList.append(color);
}
}

m_palette = ColorPalette(colorList);
}

void ColorPaletteSettings::save() {
for (int index = 0; index < m_palette.m_colorList.count(); ++index) {
QColor color = m_palette.m_colorList[index];
m_pConfig->setValue<QColor>(keyForIndex(index), color);
}
}
31 changes: 31 additions & 0 deletions src/preferences/colorpalettesettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "preferences/usersettings.h"
#include "util/color/colorpalette.h"

class ColorPaletteSettings {
public:
explicit ColorPaletteSettings(QString group, UserSettingsPointer pConfig);
~ColorPaletteSettings();

ColorPalette getPalette() const {
return m_palette;
}

void setPalette(const ColorPalette& newPalette) {
m_palette = newPalette;
save();
}

private:
void loadFromConfig();
void save();

ConfigKey keyForIndex(int index) {
return ConfigKey(m_configGroup, QString::number(index));
}

QString m_configGroup;
ColorPalette m_palette;
UserSettingsPointer m_pConfig;
};
Loading

0 comments on commit 8bce62f

Please sign in to comment.