Skip to content

Commit

Permalink
controllers: add helper to control "waveform_zoom" with potmeters
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Nov 26, 2023
1 parent 3fc28e8 commit 1b26be1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
15 changes: 14 additions & 1 deletion res/controllers/common-controller-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ String.prototype.toInt = function() {

/**
* Prints a message to the terminal and the log file.
*
* @param {string} message - The log message.
* @deprecated Use console.log()/console.warn()/console.debug() instead.
*/
Expand Down Expand Up @@ -380,6 +379,20 @@ script.crossfaderCurve = function(value, min, max) {
}
};

/* -------- ------------------------------------------------------
script.waveformZoom
Purpose: Adjusts the wavform zoom level with a pot (0 <= value <= 127)
"waveform_zoom" behaves like a ControlPotmeter but is actually
a ControlObject (no min, max or default), so we need to calculate
the scaled with script.absoluteLin().
Input: Deck group, current value of the hardware control
Output: none
-------- ------------------------------------------------------ */
script.waveformZoom = function(group, value) {
const scaledValue = script.absoluteLin(value, 0, 10, 0, 127);
engine.setValue(group, "waveform_zoom", scaledValue);
};

/* -------- ------------------------------------------------------
script.posMod
Purpose: Computes the euclidean modulo of m % n. The result is always
Expand Down
9 changes: 6 additions & 3 deletions src/mixer/basetrackplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ BaseTrackPlayerImpl::BaseTrackPlayerImpl(
this,
&BaseTrackPlayerImpl::slotLoadTrackFromSampler);

// Waveform controls
// This acts somewhat like a ControlPotmeter, but the normal _up/_down methods
// do not work properly with this CO.
// Waveform zoom controls
// This acts somewhat like a ControlPotmeter, but the normal ControlPotmeter's
// _up/_down methods would not work properly with this CO. Instead, _up/_down,
// scroll wheel ticks sent to the waveform widget and the default zoom level
// combobox in the waveform preferences page set discrete zoom levels
// (integer values of "waveform_zoom").
m_pWaveformZoom =
std::make_unique<ControlObject>(ConfigKey(getGroup(), "waveform_zoom"));
m_pWaveformZoom->connectValueChangeRequest(this,
Expand Down
2 changes: 2 additions & 0 deletions src/waveform/renderers/waveformwidgetrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "waveform/visualplayposition.h"
#include "waveform/waveform.h"

// When changing these zoom values remember to also adjust the range in
// script.waveformZoom in /res/controllers/common-controller-scripts.js
const double WaveformWidgetRenderer::s_waveformMinZoom = 1.0;
const double WaveformWidgetRenderer::s_waveformMaxZoom = 10.0;
const double WaveformWidgetRenderer::s_waveformDefaultZoom = 3.0;
Expand Down

0 comments on commit 1b26be1

Please sign in to comment.