Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setting the wrong default cue color. #11554

Merged
merged 5 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions src/engine/controls/cuecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,16 @@ void CueControl::quantizeChanged(double v) {
}
}

mixxx::RgbColor CueControl::colorFromConfig(const ConfigKey& configKey) {
auto hotcueColorPalette =
m_colorPaletteSettings.getHotcueColorPalette();
int colorIndex = m_pConfig->getValue(configKey, -1);
if (colorIndex < 0 || colorIndex >= hotcueColorPalette.size()) {
return hotcueColorPalette.defaultColor();
}
return hotcueColorPalette.at(colorIndex);
};

void CueControl::hotcueSet(HotcueControl* pControl, double value, HotcueSetMode mode) {
//qDebug() << "CueControl::hotcueSet" << value;

Expand Down Expand Up @@ -896,35 +906,33 @@ void CueControl::hotcueSet(HotcueControl* pControl, double value, HotcueSetMode

int hotcueIndex = pControl->getHotcueIndex();

CuePointer pCue = m_pLoadedTrack->createAndAddCue(
cueType,
hotcueIndex,
cueStartPosition,
cueEndPosition);

// TODO(XXX) deal with spurious signals
attachCue(pCue, pControl);

mixxx::RgbColor color = mixxx::PredefinedColorPalettes::kDefaultCueColor;
if (cueType == mixxx::CueType::Loop) {
ConfigKey autoLoopColorsKey("[Controls]", "auto_loop_colors");
if (getConfig()->getValue(autoLoopColorsKey, false)) {
auto hotcueColorPalette =
m_colorPaletteSettings.getHotcueColorPalette();
pCue->setColor(hotcueColorPalette.colorForHotcueIndex(hotcueIndex));
color = m_colorPaletteSettings.getHotcueColorPalette().colorForHotcueIndex(hotcueIndex);
} else {
pCue->setColor(mixxx::PredefinedColorPalettes::kDefaultLoopColor);
color = colorFromConfig(ConfigKey("[Controls]", "LoopDefaultColorIndex"));
}
} else {
ConfigKey autoHotcueColorsKey("[Controls]", "auto_hotcue_colors");
if (getConfig()->getValue(autoHotcueColorsKey, false)) {
auto hotcueColorPalette =
m_colorPaletteSettings.getHotcueColorPalette();
pCue->setColor(hotcueColorPalette.colorForHotcueIndex(hotcueIndex));
color = m_colorPaletteSettings.getHotcueColorPalette().colorForHotcueIndex(hotcueIndex);
} else {
pCue->setColor(mixxx::PredefinedColorPalettes::kDefaultCueColor);
color = colorFromConfig(ConfigKey("[Controls]", "HotcueDefaultColorIndex"));
}
}

CuePointer pCue = m_pLoadedTrack->createAndAddCue(
cueType,
hotcueIndex,
cueStartPosition,
cueEndPosition,
color);

// TODO(XXX) deal with spurious signals
attachCue(pCue, pControl);

if (cueType == mixxx::CueType::Loop) {
setCurrentSavedLoopControlAndActivate(pControl);
}
Expand Down Expand Up @@ -2631,6 +2639,7 @@ void HotcueControl::slotHotcueColorChangeRequest(double color) {
qWarning() << "slotHotcueColorChanged got invalid value:" << color;
return;
}
// qDebug() << "HotcueControl::slotHotcueColorChangeRequest" << color;
m_hotcueColor->setAndConfirm(color);
}

Expand Down Expand Up @@ -2661,6 +2670,7 @@ void HotcueControl::setCue(const CuePointer& pCue) {
Cue::StartAndEndPositions pos = pCue->getStartAndEndPosition();
setPosition(pos.startPosition);
setEndPosition(pos.endPosition);
// qDebug() << "HotcueControl::setCue";
setColor(pCue->getColor());
setStatus((pCue->getType() == mixxx::CueType::Invalid)
? HotcueControl::Status::Empty
Expand All @@ -2675,6 +2685,7 @@ mixxx::RgbColor::optional_t HotcueControl::getColor() const {
}

void HotcueControl::setColor(mixxx::RgbColor::optional_t newColor) {
// qDebug() << "HotcueControl::setColor()" << newColor;
if (newColor) {
m_hotcueColor->set(*newColor);
}
Expand Down
1 change: 1 addition & 0 deletions src/engine/controls/cuecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ class CueControl : public EngineControl {
void seekOnLoad(mixxx::audio::FramePos seekOnLoadPosition);
void setHotcueFocusIndex(int hotcueIndex);
int getHotcueFocusIndex() const;
mixxx::RgbColor colorFromConfig(const ConfigKey& configKey);

UserSettingsPointer m_pConfig;
ColorPaletteSettings m_colorPaletteSettings;
Expand Down
4 changes: 3 additions & 1 deletion src/test/cue_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "engine/engine.h"
#include "test/mixxxtest.h"
#include "util/color/color.h"
#include "util/color/predefinedcolorpalettes.h"

namespace mixxx {

Expand All @@ -13,7 +14,8 @@ TEST(CueTest, NewCueIsDirty) {
mixxx::CueType::HotCue,
1,
mixxx::audio::kStartFramePos,
mixxx::audio::kInvalidFramePos);
mixxx::audio::kInvalidFramePos,
mixxx::PredefinedColorPalettes::kDefaultCueColor);
EXPECT_TRUE(cue.isDirty());
}

Expand Down
5 changes: 3 additions & 2 deletions src/track/cue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ Cue::Cue(
mixxx::CueType type,
int hotCueIndex,
mixxx::audio::FramePos startPosition,
mixxx::audio::FramePos endPosition)
mixxx::audio::FramePos endPosition,
mixxx::RgbColor color)
: m_bDirty(true), // not yet in database, needs to be saved
m_type(type),
m_startPosition(startPosition),
m_endPosition(endPosition),
m_iHotCue(hotCueIndex),
m_color(mixxx::PredefinedColorPalettes::kDefaultCueColor) {
m_color(color) {
DEBUG_ASSERT(m_iHotCue == kNoHotCue || m_iHotCue >= mixxx::kFirstHotCueIndex);
DEBUG_ASSERT(m_startPosition.isValid() || m_endPosition.isValid());
DEBUG_ASSERT(!m_dbId.isValid());
Expand Down
3 changes: 2 additions & 1 deletion src/track/cue.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class Cue : public QObject {
mixxx::CueType type,
int hotCueIndex,
mixxx::audio::FramePos startPosition,
mixxx::audio::FramePos endPosition);
mixxx::audio::FramePos endPosition,
mixxx::RgbColor color);

~Cue() override = default;

Expand Down
9 changes: 6 additions & 3 deletions src/track/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,8 @@ void Track::setMainCuePosition(mixxx::audio::FramePos position) {
mixxx::CueType::MainCue,
Cue::kNoHotCue,
position,
mixxx::audio::kInvalidFramePos));
mixxx::audio::kInvalidFramePos,
mixxx::PredefinedColorPalettes::kDefaultCueColor));
// While this method could be called from any thread,
// associated Cue objects should always live on the
// same thread as their host, namely this->thread().
Expand Down Expand Up @@ -964,7 +965,8 @@ CuePointer Track::createAndAddCue(
mixxx::CueType type,
int hotCueIndex,
mixxx::audio::FramePos startPosition,
mixxx::audio::FramePos endPosition) {
mixxx::audio::FramePos endPosition,
mixxx::RgbColor color) {
VERIFY_OR_DEBUG_ASSERT(hotCueIndex == Cue::kNoHotCue ||
hotCueIndex >= mixxx::kFirstHotCueIndex) {
return CuePointer{};
Expand All @@ -976,7 +978,8 @@ CuePointer Track::createAndAddCue(
type,
hotCueIndex,
startPosition,
endPosition));
endPosition,
color));
// While this method could be called from any thread,
// associated Cue objects should always live on the
// same thread as their host, namely this->thread().
Expand Down
10 changes: 7 additions & 3 deletions src/track/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "track/cueinfoimporter.h"
#include "track/track_decl.h"
#include "track/trackrecord.h"
#include "util/color/predefinedcolorpalettes.h"
#include "util/compatibility/qmutex.h"
#include "util/fileaccess.h"
#include "util/memory.h"
Expand Down Expand Up @@ -298,18 +299,21 @@ class Track : public QObject {
mixxx::CueType type,
int hotCueIndex,
mixxx::audio::FramePos startPosition,
mixxx::audio::FramePos endPosition);
mixxx::audio::FramePos endPosition,
mixxx::RgbColor color = mixxx::PredefinedColorPalettes::kDefaultCueColor);
CuePointer createAndAddCue(
mixxx::CueType type,
int hotCueIndex,
double startPositionSamples,
double endPositionSamples) {
double endPositionSamples,
mixxx::RgbColor color = mixxx::PredefinedColorPalettes::kDefaultCueColor) {
return createAndAddCue(type,
hotCueIndex,
mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
startPositionSamples),
mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
endPositionSamples));
endPositionSamples),
color);
}
CuePointer findCueByType(mixxx::CueType type) const; // NOTE: Cannot be used for hotcues.
CuePointer findCueById(DbId id) const;
Expand Down
4 changes: 4 additions & 0 deletions src/util/color/colorpalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class ColorPalette final {
return m_colorList.end();
}

mixxx::RgbColor defaultColor() const {
return m_colorList.last();
}

QString getName() const {
return m_name;
}
Expand Down