ControlGroup/Slider: Return state data by value
Makes it less error-prone to get state data from sliders (no need to pass any locals), and also allows direct assignment, letting the retrieved data be const.
This commit is contained in:
parent
4c30b9e14d
commit
918d448b5b
|
@ -115,9 +115,9 @@ void Guitar::GetState(u8* const data)
|
||||||
// slider bar
|
// slider bar
|
||||||
if (m_slider_bar->controls[0]->control_ref->BoundCount())
|
if (m_slider_bar->controls[0]->control_ref->BoundCount())
|
||||||
{
|
{
|
||||||
ControlState slider_bar;
|
const ControllerEmu::Slider::StateData slider_data = m_slider_bar->GetState();
|
||||||
m_slider_bar->GetState(&slider_bar);
|
|
||||||
guitar_data.sb = s_slider_bar_control_codes.lower_bound(slider_bar)->second;
|
guitar_data.sb = s_slider_bar_control_codes.lower_bound(slider_data.value)->second;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,26 +98,22 @@ void Turntable::GetState(u8* const data)
|
||||||
|
|
||||||
// left table
|
// left table
|
||||||
{
|
{
|
||||||
ControlState tt;
|
const ControllerEmu::Slider::StateData lt = m_left_table->GetState();
|
||||||
m_left_table->GetState(&tt);
|
const s8 tt = static_cast<s8>(lt.value * 0x1F);
|
||||||
|
|
||||||
const s8 tt_ = static_cast<s8>(tt * 0x1F);
|
tt_data.ltable1 = tt;
|
||||||
|
tt_data.ltable2 = tt >> 5;
|
||||||
tt_data.ltable1 = tt_;
|
|
||||||
tt_data.ltable2 = tt_ >> 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// right table
|
// right table
|
||||||
{
|
{
|
||||||
ControlState tt;
|
const ControllerEmu::Slider::StateData rt = m_right_table->GetState();
|
||||||
m_right_table->GetState(&tt);
|
const s8 tt = static_cast<s8>(rt.value * 0x1F);
|
||||||
|
|
||||||
const s8 tt_ = static_cast<s8>(tt * 0x1F);
|
tt_data.rtable1 = tt;
|
||||||
|
tt_data.rtable2 = tt >> 1;
|
||||||
tt_data.rtable1 = tt_;
|
tt_data.rtable3 = tt >> 3;
|
||||||
tt_data.rtable2 = tt_ >> 1;
|
tt_data.rtable4 = tt >> 5;
|
||||||
tt_data.rtable3 = tt_ >> 3;
|
|
||||||
tt_data.rtable4 = tt_ >> 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// effect dial
|
// effect dial
|
||||||
|
@ -133,10 +129,9 @@ void Turntable::GetState(u8* const data)
|
||||||
|
|
||||||
// crossfade slider
|
// crossfade slider
|
||||||
{
|
{
|
||||||
ControlState cfs;
|
const ControllerEmu::Slider::StateData cfs = m_crossfade->GetState();
|
||||||
m_crossfade->GetState(&cfs);
|
|
||||||
|
|
||||||
tt_data.slider = static_cast<u8>((cfs * 0x07) + 0x08);
|
tt_data.slider = static_cast<u8>((cfs.value * 0x07) + 0x08);
|
||||||
}
|
}
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
|
|
|
@ -30,14 +30,14 @@ Slider::Slider(const std::string& name_) : Slider(name_, name_)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slider::GetState(ControlState* const slider)
|
Slider::StateData Slider::GetState()
|
||||||
{
|
{
|
||||||
const ControlState deadzone = numeric_settings[0]->GetValue();
|
const ControlState deadzone = numeric_settings[0]->GetValue();
|
||||||
const ControlState state = controls[1]->control_ref->State() - controls[0]->control_ref->State();
|
const ControlState state = controls[1]->control_ref->State() - controls[0]->control_ref->State();
|
||||||
|
|
||||||
if (fabs(state) > deadzone)
|
if (fabs(state) > deadzone)
|
||||||
*slider = (state - (deadzone * sign(state))) / (1 - deadzone);
|
return {(state - (deadzone * sign(state))) / (1 - deadzone)};
|
||||||
else
|
|
||||||
*slider = 0;
|
return {0.0};
|
||||||
}
|
}
|
||||||
} // namespace ControllerEmu
|
} // namespace ControllerEmu
|
||||||
|
|
|
@ -13,9 +13,14 @@ namespace ControllerEmu
|
||||||
class Slider : public ControlGroup
|
class Slider : public ControlGroup
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
struct StateData
|
||||||
|
{
|
||||||
|
ControlState value{};
|
||||||
|
};
|
||||||
|
|
||||||
Slider(const std::string& name_, const std::string& ui_name_);
|
Slider(const std::string& name_, const std::string& ui_name_);
|
||||||
explicit Slider(const std::string& name_);
|
explicit Slider(const std::string& name_);
|
||||||
|
|
||||||
void GetState(ControlState* slider);
|
StateData GetState();
|
||||||
};
|
};
|
||||||
} // namespace ControllerEmu
|
} // namespace ControllerEmu
|
||||||
|
|
Loading…
Reference in New Issue