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

Add "Continuous" FloatModels (stepsize = 0) #7623

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions include/AutomatableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ class LMMS_EXPORT AutomatableModel : public Model, public JournallingObject
setValue( m_value + steps * m_step );
}

void addValue(float amount)
{
setValue(m_value + amount);
}

float range() const
{
return m_range;
Expand Down
2 changes: 1 addition & 1 deletion plugins/TripleOscillator/TripleOscillator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Plugin::Descriptor PLUGIN_EXPORT tripleoscillator_plugin_descriptor =
OscillatorObject::OscillatorObject( Model * _parent, int _idx ) :
Model( _parent ),
m_volumeModel( DefaultVolume / NUM_OF_OSCILLATORS, MinVolume,
MaxVolume, 1.0f, this, tr( "Osc %1 volume" ).arg( _idx+1 ) ),
MaxVolume, 0.0f, this, tr( "Osc %1 volume" ).arg( _idx+1 ) ),
m_panModel( DefaultPanning, PanningLeft, PanningRight, 1.0f, this,
tr( "Osc %1 panning" ).arg( _idx+1 ) ),
m_coarseModel( -_idx*KeysPerOctave,
Expand Down
3 changes: 3 additions & 0 deletions src/core/AutomatableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ void AutomatableModel::setUseControllerValue(bool b)

float FloatModel::getRoundedValue() const
{
if (step<float>() == 0.0f) { return value(); }
return std::round(value() / step<float>()) * step<float>();
}

Expand All @@ -789,6 +790,8 @@ float FloatModel::getRoundedValue() const
int FloatModel::getDigitCount() const
{
auto steptemp = step<float>();
if (steptemp == 0.0f) { return 10; }

int digits = 0;
while ( steptemp < 1 )
{
Expand Down
25 changes: 18 additions & 7 deletions src/gui/widgets/FloatModelEditorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void FloatModelEditorBase::wheelEvent(QWheelEvent * we)
else if (modKeys == Qt::AltModifier)
{
// The alt key enables even finer adjustments
numberOfStepsForFullSweep = 2000;
numberOfStepsForFullSweep = 10000;

// It seems that on some systems pressing Alt with mess with the directions,
// i.e. scrolling the mouse wheel is interpreted as pressing the mouse wheel
Expand All @@ -331,10 +331,17 @@ void FloatModelEditorBase::wheelEvent(QWheelEvent * we)
direction = -direction;
}

// Compute the number of steps but make sure that we always do at least one step
const float stepMult = std::max(range / numberOfStepsForFullSweep / step, 1.f);
const int inc = direction * stepMult;
model()->incValue(inc);
if (step != 0.0f)
{
// Compute the number of steps but make sure that we always do at least one step
const float stepMult = std::max(range / numberOfStepsForFullSweep / step, 1.f);
const int inc = direction * stepMult;
model()->incValue(inc);
}
else
{
model()->addValue(direction * range / numberOfStepsForFullSweep);
}

s_textFloat->setText(displayValue());
s_textFloat->moveGlobal(this, QPoint(width() + 2, 0));
Expand All @@ -359,7 +366,9 @@ void FloatModelEditorBase::setPosition(const QPoint & p)
float newValue = value * ratio;
if (qAbs(newValue) >= step)
{
float roundedValue = qRound((oldValue - value) / step) * step;
float roundedValue = step != 0.0f
? qRound((oldValue - value) / step) * step
: oldValue - value;
model()->setValue(roundedValue);
m_leftOver = 0.0f;
}
Expand All @@ -373,7 +382,9 @@ void FloatModelEditorBase::setPosition(const QPoint & p)
{
if (qAbs(value) >= step)
{
float roundedValue = qRound((oldValue - value) / step) * step;
float roundedValue = step != 0.0f
? qRound((oldValue - value) / step) * step
: oldValue - value;
model()->setValue(roundedValue);
m_leftOver = 0.0f;
}
Expand Down
Loading