2019-01-26 18:17:30 +00:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-11-22 19:41:10 +00:00
|
|
|
#include "InputCommon/ControlReference/FunctionExpression.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2019-01-26 18:17:30 +00:00
|
|
|
#include <chrono>
|
|
|
|
#include <cmath>
|
|
|
|
|
2019-11-22 19:44:33 +00:00
|
|
|
namespace ciface::ExpressionParser
|
2019-01-26 18:17:30 +00:00
|
|
|
{
|
|
|
|
constexpr ControlState CONDITION_THRESHOLD = 0.5;
|
|
|
|
|
2019-01-27 15:13:12 +00:00
|
|
|
using Clock = std::chrono::steady_clock;
|
|
|
|
using FSec = std::chrono::duration<ControlState>;
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
// usage: toggle(toggle_state_input, [clear_state_input])
|
2019-01-26 18:17:30 +00:00
|
|
|
class ToggleExpression : public FunctionExpression
|
|
|
|
{
|
|
|
|
private:
|
2019-10-12 00:38:18 +00:00
|
|
|
ArgumentValidation
|
|
|
|
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
|
2019-01-26 18:17:30 +00:00
|
|
|
{
|
2019-01-26 19:18:20 +00:00
|
|
|
// Optional 2nd argument for clearing state:
|
2019-10-12 00:38:18 +00:00
|
|
|
if (1 == args.size() || 2 == args.size())
|
|
|
|
return ArgumentsAreValid{};
|
|
|
|
else
|
|
|
|
return ExpectedArguments{"toggle_state_input, [clear_state_input]"};
|
2019-01-26 18:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState GetValue() const override
|
|
|
|
{
|
|
|
|
const ControlState inner_value = GetArg(0).GetValue();
|
|
|
|
|
|
|
|
if (inner_value < CONDITION_THRESHOLD)
|
|
|
|
{
|
|
|
|
m_released = true;
|
|
|
|
}
|
|
|
|
else if (m_released && inner_value > CONDITION_THRESHOLD)
|
|
|
|
{
|
|
|
|
m_released = false;
|
|
|
|
m_state ^= true;
|
|
|
|
}
|
|
|
|
|
2019-01-26 19:18:20 +00:00
|
|
|
if (2 == GetArgCount() && GetArg(1).GetValue() > CONDITION_THRESHOLD)
|
|
|
|
{
|
|
|
|
m_state = false;
|
|
|
|
}
|
|
|
|
|
2019-01-26 18:17:30 +00:00
|
|
|
return m_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutable bool m_released{};
|
|
|
|
mutable bool m_state{};
|
|
|
|
};
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
// usage: not(expression)
|
2019-01-26 18:17:30 +00:00
|
|
|
class NotExpression : public FunctionExpression
|
|
|
|
{
|
|
|
|
private:
|
2019-10-12 00:38:18 +00:00
|
|
|
ArgumentValidation
|
|
|
|
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
|
2019-01-26 18:17:30 +00:00
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
if (1 == args.size())
|
|
|
|
return ArgumentsAreValid{};
|
|
|
|
else
|
|
|
|
return ExpectedArguments{"expression"};
|
2019-01-26 18:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState GetValue() const override { return 1.0 - GetArg(0).GetValue(); }
|
|
|
|
void SetValue(ControlState value) override { GetArg(0).SetValue(1.0 - value); }
|
|
|
|
};
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
// usage: sin(expression)
|
2019-01-26 18:17:30 +00:00
|
|
|
class SinExpression : public FunctionExpression
|
|
|
|
{
|
|
|
|
private:
|
2019-10-12 00:38:18 +00:00
|
|
|
ArgumentValidation
|
|
|
|
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
|
2019-01-26 18:17:30 +00:00
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
if (1 == args.size())
|
|
|
|
return ArgumentsAreValid{};
|
|
|
|
else
|
|
|
|
return ExpectedArguments{"expression"};
|
2019-01-26 18:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState GetValue() const override { return std::sin(GetArg(0).GetValue()); }
|
|
|
|
};
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
// usage: timer(seconds)
|
2019-01-26 18:17:30 +00:00
|
|
|
class TimerExpression : public FunctionExpression
|
|
|
|
{
|
|
|
|
private:
|
2019-10-12 00:38:18 +00:00
|
|
|
ArgumentValidation
|
|
|
|
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
|
2019-01-26 18:17:30 +00:00
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
if (1 == args.size())
|
|
|
|
return ArgumentsAreValid{};
|
|
|
|
else
|
|
|
|
return ExpectedArguments{"seconds"};
|
2019-01-26 18:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState GetValue() const override
|
|
|
|
{
|
|
|
|
const auto now = Clock::now();
|
|
|
|
const auto elapsed = now - m_start_time;
|
|
|
|
|
|
|
|
const ControlState val = GetArg(0).GetValue();
|
|
|
|
|
|
|
|
ControlState progress = std::chrono::duration_cast<FSec>(elapsed).count() / val;
|
|
|
|
|
2019-01-26 20:48:26 +00:00
|
|
|
if (std::isinf(progress) || progress < 0.0)
|
2019-01-26 18:17:30 +00:00
|
|
|
{
|
2019-01-26 20:48:26 +00:00
|
|
|
// User configured a non-positive timer. Reset the timer and return 0.0.
|
2019-01-26 18:17:30 +00:00
|
|
|
progress = 0.0;
|
|
|
|
m_start_time = now;
|
|
|
|
}
|
|
|
|
else if (progress >= 1.0)
|
|
|
|
{
|
|
|
|
const ControlState reset_count = std::floor(progress);
|
|
|
|
|
|
|
|
m_start_time += std::chrono::duration_cast<Clock::duration>(FSec(val * reset_count));
|
|
|
|
progress -= reset_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable Clock::time_point m_start_time = Clock::now();
|
|
|
|
};
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
// usage: if(condition, true_expression, false_expression)
|
2019-01-26 18:17:30 +00:00
|
|
|
class IfExpression : public FunctionExpression
|
|
|
|
{
|
|
|
|
private:
|
2019-10-12 00:38:18 +00:00
|
|
|
ArgumentValidation
|
|
|
|
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
|
2019-01-26 18:17:30 +00:00
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
if (3 == args.size())
|
|
|
|
return ArgumentsAreValid{};
|
|
|
|
else
|
|
|
|
return ExpectedArguments{"condition, true_expression, false_expression"};
|
2019-01-26 18:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState GetValue() const override
|
|
|
|
{
|
|
|
|
return (GetArg(0).GetValue() > CONDITION_THRESHOLD) ? GetArg(1).GetValue() :
|
|
|
|
GetArg(2).GetValue();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
// usage: minus(expression)
|
2019-01-26 18:17:30 +00:00
|
|
|
class UnaryMinusExpression : public FunctionExpression
|
|
|
|
{
|
|
|
|
private:
|
2019-10-12 00:38:18 +00:00
|
|
|
ArgumentValidation
|
|
|
|
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
|
2019-01-26 18:17:30 +00:00
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
if (1 == args.size())
|
|
|
|
return ArgumentsAreValid{};
|
|
|
|
else
|
|
|
|
return ExpectedArguments{"expression"};
|
2019-01-26 18:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState GetValue() const override
|
|
|
|
{
|
|
|
|
// Subtraction for clarity:
|
|
|
|
return 0.0 - GetArg(0).GetValue();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
// usage: deadzone(input, amount)
|
2019-01-26 19:35:58 +00:00
|
|
|
class DeadzoneExpression : public FunctionExpression
|
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
ArgumentValidation
|
|
|
|
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
|
2019-01-26 19:35:58 +00:00
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
if (2 == args.size())
|
|
|
|
return ArgumentsAreValid{};
|
|
|
|
else
|
|
|
|
return ExpectedArguments{"input, amount"};
|
2019-01-26 19:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState GetValue() const override
|
|
|
|
{
|
|
|
|
const ControlState val = GetArg(0).GetValue();
|
|
|
|
const ControlState deadzone = GetArg(1).GetValue();
|
|
|
|
return std::copysign(std::max(0.0, std::abs(val) - deadzone) / (1.0 - deadzone), val);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
// usage: smooth(input, seconds_up, seconds_down = seconds_up)
|
2019-01-26 20:04:14 +00:00
|
|
|
// seconds is seconds to change from 0.0 to 1.0
|
|
|
|
class SmoothExpression : public FunctionExpression
|
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
ArgumentValidation
|
|
|
|
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
|
2019-01-26 20:04:14 +00:00
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
if (2 == args.size() || 3 == args.size())
|
|
|
|
return ArgumentsAreValid{};
|
|
|
|
else
|
|
|
|
return ExpectedArguments{"input, seconds_up, seconds_down = seconds_up"};
|
2019-01-26 20:04:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState GetValue() const override
|
|
|
|
{
|
|
|
|
const auto now = Clock::now();
|
|
|
|
const auto elapsed = now - m_last_update;
|
|
|
|
m_last_update = now;
|
|
|
|
|
|
|
|
const ControlState desired_value = GetArg(0).GetValue();
|
|
|
|
|
2019-04-04 00:45:09 +00:00
|
|
|
const ControlState smooth_up = GetArg(1).GetValue();
|
|
|
|
const ControlState smooth_down = (3 == GetArgCount() ? GetArg(2).GetValue() : smooth_up);
|
|
|
|
|
|
|
|
const ControlState smooth = (desired_value < m_value) ? smooth_down : smooth_up;
|
2019-01-26 20:04:14 +00:00
|
|
|
const ControlState max_move = std::chrono::duration_cast<FSec>(elapsed).count() / smooth;
|
|
|
|
|
|
|
|
if (std::isinf(max_move))
|
|
|
|
{
|
|
|
|
m_value = desired_value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const ControlState diff = desired_value - m_value;
|
|
|
|
m_value += std::copysign(std::min(max_move, std::abs(diff)), diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable ControlState m_value = 0.0;
|
|
|
|
mutable Clock::time_point m_last_update = Clock::now();
|
|
|
|
};
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
// usage: hold(input, seconds)
|
2019-01-26 20:15:36 +00:00
|
|
|
class HoldExpression : public FunctionExpression
|
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
ArgumentValidation
|
|
|
|
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
|
2019-01-26 20:15:36 +00:00
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
if (2 == args.size())
|
|
|
|
return ArgumentsAreValid{};
|
|
|
|
else
|
|
|
|
return ExpectedArguments{"input, seconds"};
|
2019-01-26 20:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState GetValue() const override
|
|
|
|
{
|
|
|
|
const auto now = Clock::now();
|
|
|
|
|
|
|
|
const ControlState input = GetArg(0).GetValue();
|
|
|
|
|
|
|
|
if (input < CONDITION_THRESHOLD)
|
|
|
|
{
|
|
|
|
m_state = false;
|
|
|
|
m_start_time = Clock::now();
|
|
|
|
}
|
|
|
|
else if (!m_state)
|
|
|
|
{
|
|
|
|
const auto hold_time = now - m_start_time;
|
|
|
|
|
|
|
|
if (std::chrono::duration_cast<FSec>(hold_time).count() >= GetArg(1).GetValue())
|
|
|
|
m_state = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable bool m_state = false;
|
|
|
|
mutable Clock::time_point m_start_time = Clock::now();
|
|
|
|
};
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
// usage: tap(input, seconds, taps=2)
|
2019-01-26 20:40:47 +00:00
|
|
|
class TapExpression : public FunctionExpression
|
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
ArgumentValidation
|
|
|
|
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
|
2019-01-26 20:40:47 +00:00
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
if (2 == args.size() || 3 == args.size())
|
|
|
|
return ArgumentsAreValid{};
|
|
|
|
else
|
|
|
|
return ExpectedArguments{"input, seconds, taps = 2"};
|
2019-01-26 20:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState GetValue() const override
|
|
|
|
{
|
|
|
|
const auto now = Clock::now();
|
|
|
|
|
|
|
|
const auto elapsed = std::chrono::duration_cast<FSec>(now - m_start_time).count();
|
|
|
|
|
|
|
|
const ControlState input = GetArg(0).GetValue();
|
|
|
|
const ControlState seconds = GetArg(1).GetValue();
|
|
|
|
|
|
|
|
const bool is_time_up = elapsed > seconds;
|
|
|
|
|
|
|
|
const u32 desired_taps = (3 == GetArgCount()) ? u32(GetArg(2).GetValue() + 0.5) : 2;
|
|
|
|
|
|
|
|
if (input < CONDITION_THRESHOLD)
|
|
|
|
{
|
|
|
|
m_released = true;
|
|
|
|
|
|
|
|
if (m_taps > 0 && is_time_up)
|
|
|
|
{
|
|
|
|
m_taps = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_released)
|
|
|
|
{
|
|
|
|
if (!m_taps)
|
|
|
|
{
|
|
|
|
m_start_time = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
++m_taps;
|
|
|
|
m_released = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return desired_taps == m_taps;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable bool m_released = true;
|
|
|
|
mutable u32 m_taps = 0;
|
|
|
|
mutable Clock::time_point m_start_time = Clock::now();
|
|
|
|
};
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
// usage: relative(input, speed, [max_abs_value, [shared_state]])
|
2019-01-26 21:30:21 +00:00
|
|
|
// speed is max movement per second
|
|
|
|
class RelativeExpression : public FunctionExpression
|
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
ArgumentValidation
|
|
|
|
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
|
2019-01-26 21:30:21 +00:00
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
if (args.size() >= 2 && args.size() <= 4)
|
|
|
|
return ArgumentsAreValid{};
|
|
|
|
else
|
|
|
|
return ExpectedArguments{"input, speed, [max_abs_value, [shared_state]]"};
|
2019-01-26 21:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState GetValue() const override
|
|
|
|
{
|
|
|
|
// There is a lot of funky math in this function but it allows for a variety of uses:
|
|
|
|
//
|
|
|
|
// e.g. A single mapping with a relatively adjusted value between 0.0 and 1.0
|
|
|
|
// Potentially useful for a trigger input
|
2019-04-04 22:35:49 +00:00
|
|
|
// relative(`Up` - `Down`, 2.0)
|
2019-01-26 21:30:21 +00:00
|
|
|
//
|
|
|
|
// e.g. A value with two mappings (such as analog stick Up/Down)
|
|
|
|
// The shared state allows the two mappings to work together.
|
|
|
|
// This mapping (for up) returns a value clamped between 0.0 and 1.0
|
2019-04-04 22:35:49 +00:00
|
|
|
// relative(`Up`, 2.0, 1.0, $y)
|
2019-01-26 21:30:21 +00:00
|
|
|
// This mapping (for down) returns the negative value clamped between 0.0 and 1.0
|
|
|
|
// (Adjustments created by `Down` are applied negatively to the shared state)
|
2019-04-04 22:35:49 +00:00
|
|
|
// relative(`Down`, 2.0, -1.0, $y)
|
2019-01-26 21:30:21 +00:00
|
|
|
|
|
|
|
const auto now = Clock::now();
|
|
|
|
|
|
|
|
if (GetArgCount() >= 4)
|
|
|
|
m_state = GetArg(3).GetValue();
|
|
|
|
|
|
|
|
const auto elapsed = std::chrono::duration_cast<FSec>(now - m_last_update).count();
|
|
|
|
m_last_update = now;
|
|
|
|
|
|
|
|
const ControlState input = GetArg(0).GetValue();
|
|
|
|
const ControlState speed = GetArg(1).GetValue();
|
|
|
|
|
|
|
|
const ControlState max_abs_value = (GetArgCount() >= 3) ? GetArg(2).GetValue() : 1.0;
|
|
|
|
|
|
|
|
const ControlState max_move = input * elapsed * speed;
|
|
|
|
const ControlState diff_from_zero = std::abs(0.0 - m_state);
|
|
|
|
const ControlState diff_from_max = std::abs(max_abs_value - m_state);
|
|
|
|
|
|
|
|
m_state += std::min(std::max(max_move, -diff_from_zero), diff_from_max) *
|
|
|
|
std::copysign(1.0, max_abs_value);
|
|
|
|
|
|
|
|
if (GetArgCount() >= 4)
|
|
|
|
const_cast<Expression&>(GetArg(3)).SetValue(m_state);
|
|
|
|
|
|
|
|
return std::max(0.0, m_state * std::copysign(1.0, max_abs_value));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable ControlState m_state = 0.0;
|
|
|
|
mutable Clock::time_point m_last_update = Clock::now();
|
|
|
|
};
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
// usage: pulse(input, seconds)
|
2019-01-26 22:34:28 +00:00
|
|
|
class PulseExpression : public FunctionExpression
|
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
ArgumentValidation
|
|
|
|
ValidateArguments(const std::vector<std::unique_ptr<Expression>>& args) override
|
2019-01-26 22:34:28 +00:00
|
|
|
{
|
2019-10-12 00:38:18 +00:00
|
|
|
if (2 == args.size())
|
|
|
|
return ArgumentsAreValid{};
|
|
|
|
else
|
|
|
|
return ExpectedArguments{"input, seconds"};
|
2019-01-26 22:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControlState GetValue() const override
|
|
|
|
{
|
|
|
|
const auto now = Clock::now();
|
|
|
|
|
|
|
|
const ControlState input = GetArg(0).GetValue();
|
|
|
|
|
|
|
|
if (input < CONDITION_THRESHOLD)
|
|
|
|
{
|
|
|
|
m_released = true;
|
|
|
|
}
|
|
|
|
else if (m_released)
|
|
|
|
{
|
|
|
|
m_released = false;
|
|
|
|
|
|
|
|
const auto seconds = std::chrono::duration_cast<Clock::duration>(FSec(GetArg(1).GetValue()));
|
|
|
|
|
|
|
|
if (m_state)
|
|
|
|
{
|
|
|
|
m_release_time += seconds;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_state = true;
|
|
|
|
m_release_time = now + seconds;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_state && now >= m_release_time)
|
|
|
|
{
|
|
|
|
m_state = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable bool m_released = false;
|
|
|
|
mutable bool m_state = false;
|
|
|
|
mutable Clock::time_point m_release_time = Clock::now();
|
|
|
|
};
|
|
|
|
|
2019-11-22 19:51:57 +00:00
|
|
|
std::unique_ptr<FunctionExpression> MakeFunctionExpression(std::string_view name)
|
2019-01-26 18:17:30 +00:00
|
|
|
{
|
2019-04-04 22:35:49 +00:00
|
|
|
if ("not" == name)
|
2019-01-26 18:17:30 +00:00
|
|
|
return std::make_unique<NotExpression>();
|
2019-11-22 19:55:33 +00:00
|
|
|
if ("if" == name)
|
2019-01-26 18:17:30 +00:00
|
|
|
return std::make_unique<IfExpression>();
|
2019-11-22 19:55:33 +00:00
|
|
|
if ("sin" == name)
|
2019-01-26 18:17:30 +00:00
|
|
|
return std::make_unique<SinExpression>();
|
2019-11-22 19:55:33 +00:00
|
|
|
if ("timer" == name)
|
2019-01-26 18:17:30 +00:00
|
|
|
return std::make_unique<TimerExpression>();
|
2019-11-22 19:55:33 +00:00
|
|
|
if ("toggle" == name)
|
2019-01-26 18:17:30 +00:00
|
|
|
return std::make_unique<ToggleExpression>();
|
2019-11-22 19:55:33 +00:00
|
|
|
if ("minus" == name)
|
2019-01-26 18:17:30 +00:00
|
|
|
return std::make_unique<UnaryMinusExpression>();
|
2019-11-22 19:55:33 +00:00
|
|
|
if ("deadzone" == name)
|
2019-01-26 19:35:58 +00:00
|
|
|
return std::make_unique<DeadzoneExpression>();
|
2019-11-22 19:55:33 +00:00
|
|
|
if ("smooth" == name)
|
2019-01-26 20:04:14 +00:00
|
|
|
return std::make_unique<SmoothExpression>();
|
2019-11-22 19:55:33 +00:00
|
|
|
if ("hold" == name)
|
2019-01-26 20:15:36 +00:00
|
|
|
return std::make_unique<HoldExpression>();
|
2019-11-22 19:55:33 +00:00
|
|
|
if ("tap" == name)
|
2019-01-26 20:40:47 +00:00
|
|
|
return std::make_unique<TapExpression>();
|
2019-11-22 19:55:33 +00:00
|
|
|
if ("relative" == name)
|
2019-01-26 21:30:21 +00:00
|
|
|
return std::make_unique<RelativeExpression>();
|
2019-11-22 19:55:33 +00:00
|
|
|
if ("pulse" == name)
|
2019-01-26 22:34:28 +00:00
|
|
|
return std::make_unique<PulseExpression>();
|
2019-11-22 19:55:33 +00:00
|
|
|
|
|
|
|
return nullptr;
|
2019-01-26 18:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FunctionExpression::CountNumControls() const
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
for (auto& arg : m_args)
|
|
|
|
result += arg->CountNumControls();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FunctionExpression::UpdateReferences(ControlEnvironment& env)
|
|
|
|
{
|
|
|
|
for (auto& arg : m_args)
|
|
|
|
arg->UpdateReferences(env);
|
|
|
|
}
|
|
|
|
|
2019-10-12 00:38:18 +00:00
|
|
|
FunctionExpression::ArgumentValidation
|
|
|
|
FunctionExpression::SetArguments(std::vector<std::unique_ptr<Expression>>&& args)
|
2019-01-26 18:17:30 +00:00
|
|
|
{
|
|
|
|
m_args = std::move(args);
|
|
|
|
|
|
|
|
return ValidateArguments(m_args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Expression& FunctionExpression::GetArg(u32 number)
|
|
|
|
{
|
|
|
|
return *m_args[number];
|
|
|
|
}
|
|
|
|
|
|
|
|
const Expression& FunctionExpression::GetArg(u32 number) const
|
|
|
|
{
|
|
|
|
return *m_args[number];
|
|
|
|
}
|
|
|
|
|
2019-01-26 19:18:20 +00:00
|
|
|
u32 FunctionExpression::GetArgCount() const
|
|
|
|
{
|
|
|
|
return u32(m_args.size());
|
|
|
|
}
|
|
|
|
|
2019-04-04 22:35:49 +00:00
|
|
|
void FunctionExpression::SetValue(ControlState)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-11-22 19:44:33 +00:00
|
|
|
} // namespace ciface::ExpressionParser
|