Skip to content

Commit

Permalink
Merge pull request #2384 from Holzhaus/color-cycle-support
Browse files Browse the repository at this point in the history
Add support for cycling through available hotcue colors
  • Loading branch information
Holzhaus authored Jan 9, 2020
2 parents 1473440 + 985068b commit 1a186a7
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 6 deletions.
48 changes: 42 additions & 6 deletions res/controllers/Roland_DJ-505-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1117,12 +1117,36 @@ DJ505.PadSection.prototype.padModeButtonPressed = function (channel, control, va
};

DJ505.PadSection.prototype.paramButtonPressed = function (channel, control, value, status, group) {
if (this.currentMode && this.currentMode.paramPlusButton && this.currentMode.paramMinusButton) {
if (control & 1) {
this.currentMode.paramPlusButton.input(channel, control, value, status, group);
} else {
this.currentMode.paramMinusButton.input(channel, control, value, status, group);
}
if (!this.currentMode) {
return;
}
var button;
switch(control) {
case 0x2A: // PARAMETER 2 -
if (this.currentMode.param2MinusButton) {
print('param2-');
button = this.currentMode.param2MinusButton;
break;
}
/* falls through */
case 0x28: // PARAMETER -
print('param-');
button = this.currentMode.paramMinusButton;
break;
case 0x2B: // PARAMETER 2 +
if (this.currentMode.param2PlusButton) {
print('param2+');
button = this.currentMode.param2PlusButton;
break;
}
/* falls through */
case 0x29: // PARAMETER +
print('param+');
button = this.currentMode.paramPlusButton;
break;
}
if (button) {
button.input(channel, control, value, status, group);
}
};

Expand Down Expand Up @@ -1218,6 +1242,18 @@ DJ505.HotcueMode = function (deck, offset) {
outKey: "beats_translate_later",
inKey: "beats_translate_later",
});
this.param2MinusButton = new components.Button({
midi: [0x94 + offset, 0x2A],
mode: this,
outKey: "hotcue_focus_color_prev",
inKey: "hotcue_focus_color_prev",
});
this.param2PlusButton = new components.Button({
midi: [0x94 + offset, 0x2B],
mode: this,
outKey: "hotcue_focus_color_next",
inKey: "hotcue_focus_color_next",
});
};
DJ505.HotcueMode.prototype = Object.create(components.ComponentContainer.prototype);

Expand Down
86 changes: 86 additions & 0 deletions src/engine/controls/cuecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,23 @@ CueControl::CueControl(QString group,

m_pVinylControlEnabled = new ControlProxy(group, "vinylcontrol_enabled");
m_pVinylControlMode = new ControlProxy(group, "vinylcontrol_mode");

m_pHotcueFocus = new ControlObject(ConfigKey(group, "hotcue_focus"));
m_pHotcueFocus->set(Cue::kNoHotCue);

m_pHotcueFocusColorPrev = new ControlObject(ConfigKey(group, "hotcue_focus_color_prev"));
connect(m_pHotcueFocusColorPrev,
&ControlObject::valueChanged,
this,
&CueControl::hotcueFocusColorPrev,
Qt::DirectConnection);

m_pHotcueFocusColorNext = new ControlObject(ConfigKey(group, "hotcue_focus_color_next"));
connect(m_pHotcueFocusColorNext,
&ControlObject::valueChanged,
this,
&CueControl::hotcueFocusColorNext,
Qt::DirectConnection);
}

CueControl::~CueControl() {
Expand Down Expand Up @@ -236,6 +253,9 @@ CueControl::~CueControl() {
delete m_pOutroEndActivate;
delete m_pVinylControlEnabled;
delete m_pVinylControlMode;
delete m_pHotcueFocus;
delete m_pHotcueFocusColorPrev;
delete m_pHotcueFocusColorNext;
qDeleteAll(m_hotcueControls);
}

Expand Down Expand Up @@ -314,6 +334,7 @@ void CueControl::trackLoaded(TrackPointer pNewTrack) {
m_pOutroStartEnabled->forceSet(0.0);
m_pOutroEndPosition->set(Cue::kNoPosition);
m_pOutroEndEnabled->forceSet(0.0);
m_pHotcueFocus->set(Cue::kNoHotCue);
m_pLoadedTrack.reset();
}

Expand Down Expand Up @@ -709,6 +730,8 @@ void CueControl::hotcueActivate(HotcueControl* pControl, double v) {
hotcueActivatePreview(pControl, v);
}
}

m_pHotcueFocus->set(pControl->getHotcueNumber());
}

void CueControl::hotcueActivatePreview(HotcueControl* pControl, double v) {
Expand Down Expand Up @@ -767,6 +790,7 @@ void CueControl::hotcueClear(HotcueControl* pControl, double v) {
}
detachCue(pControl);
m_pLoadedTrack->removeCue(pCue);
m_pHotcueFocus->set(Cue::kNoHotCue);
}

void CueControl::hotcuePositionChanged(HotcueControl* pControl, double newPosition) {
Expand Down Expand Up @@ -1645,6 +1669,68 @@ SeekOnLoadMode CueControl::getSeekOnLoadPreference() {
return static_cast<SeekOnLoadMode>(configValue);
}

void CueControl::hotcueFocusColorPrev(double v) {
if (!v) {
return;
}

int hotcueNumber = static_cast<int>(m_pHotcueFocus->get());
if (hotcueNumber < 0 || hotcueNumber >= m_hotcueControls.size()) {
return;
}

HotcueControl* pControl = m_hotcueControls.at(hotcueNumber);
if (!pControl) {
return;
}

PredefinedColorPointer pColor = pControl->getColor();
if (!pColor) {
return;
}

// Get previous color in color set
int iColorIndex = Color::kPredefinedColorsSet.predefinedColorIndex(pColor) - 1;
if (iColorIndex <= 0) {
iColorIndex = Color::kPredefinedColorsSet.allColors.size() - 1;
}
pColor = Color::kPredefinedColorsSet.allColors.at(iColorIndex);
DEBUG_ASSERT(pColor != nullptr);

pControl->setColor(pColor);
}

void CueControl::hotcueFocusColorNext(double v) {
if (!v) {
return;
}

int hotcueNumber = static_cast<int>(m_pHotcueFocus->get());
if (hotcueNumber < 0 || hotcueNumber >= m_hotcueControls.size()) {
return;
}

HotcueControl* pControl = m_hotcueControls.at(hotcueNumber);
if (!pControl) {
return;
}

PredefinedColorPointer pColor = pControl->getColor();
if (!pColor) {
return;
}

// Get next color in color set
int iColorIndex = Color::kPredefinedColorsSet.predefinedColorIndex(pColor) + 1;
if (iColorIndex >= Color::kPredefinedColorsSet.allColors.size()) {
iColorIndex = 0;
}
pColor = Color::kPredefinedColorsSet.allColors.at(iColorIndex);
DEBUG_ASSERT(pColor != nullptr);

pControl->setColor(pColor);
}


ConfigKey HotcueControl::keyForControl(int hotcue, const char* name) {
ConfigKey key;
Expand Down
7 changes: 7 additions & 0 deletions src/engine/controls/cuecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ class CueControl : public EngineControl {
void hotcueClear(HotcueControl* pControl, double v);
void hotcuePositionChanged(HotcueControl* pControl, double newPosition);

void hotcueFocusColorNext(double v);
void hotcueFocusColorPrev(double v);

void cueSet(double v);
void cueClear(double v);
void cueGoto(double v);
Expand Down Expand Up @@ -244,6 +247,10 @@ class CueControl : public EngineControl {
ControlProxy* m_pVinylControlEnabled;
ControlProxy* m_pVinylControlMode;

ControlObject* m_pHotcueFocus;
ControlObject* m_pHotcueFocusColorNext;
ControlObject* m_pHotcueFocusColorPrev;

TrackPointer m_pLoadedTrack; // is written from an engine worker thread

// Tells us which controls map to which hotcue
Expand Down

0 comments on commit 1a186a7

Please sign in to comment.