Skip to content

Commit

Permalink
General fixes, especially around sublayering
Browse files Browse the repository at this point in the history
  • Loading branch information
mauer committed Jan 8, 2024
1 parent 541b12f commit 8c46174
Show file tree
Hide file tree
Showing 36 changed files with 266 additions and 109 deletions.
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
Expand Down Expand Up @@ -46,6 +46,7 @@ MaxEmptyLinesToKeep: 4
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: false
SeparateDefinitionBlocks : Leave
Expand Down
6 changes: 4 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
+ Allow selection of different ports when loading an aircraft
+ Label push/pull
+ Check all mapping texts, especially pnp
+ SubLayer for each device
+ SubLayer for outbound devices
+ SubLayer for each device (done)
+ SubLayer for outbound devices (done)
+ Dataref-Array for SubLayer e.g. general array dataref for XMidiCtrl
+ Add filter for log types in windows
+ Check für Sublayer Dataref if parameter SL is defined (done)
+ Controlling button LEDs using a bitwise and on a dataref such as for sim/cockpit/autopilot/autopilot_state which is a bitfield.
31 changes: 27 additions & 4 deletions docs/inbound_mapping_slider.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,33 @@

## Description

The mapping for a slider can use X-Plane commands or a dataref. If you define commands and a dataref, the
dataref will be used.
The mapping for a slider can work with X-Plane commands or a dataref.

## Commands Mapping

The mapping with commands allow you to define command which will be executed when the slider is right at the top, the
bottom and/or in the middle. That's perfect to map three-way switches or even the landing gear.
The command mapping allows you to define three commands in total. One command when the slider is all the way up,
another one when the slider is all the way down and optionally a command when the slider is right in the middle.

For advanced mappings you can define the data 2 minimum and maximum value as well as a margin which should be used. The
margin sets the range when the commands get executed.

#### Example

| Parameter | Value |
|---------------|-------|
| Data 2 Min | 0 |
| Data 2 Max | 127 |
| Data 2 Margin | 10 |

The commands will be executed when Data 2 has these values:

| Command | Data 2 Range | Formula |
|----------------|--------------|--------------------------------------------------------|
| Command Up | 117 .. 127 | `Data 2 Max` - `Data 2 Margin` |
| Command Middle | 53 .. 73 | (`Data 2 Max` - `Data 2 Min`) / `2` -+ `Data 2 Margin` |
| Command Down | 00 .. 10 | `Data 2 Min` + `Data 2 Margin` |

Each command will be executed on time until the slider leaves the range area and returns.

### Required Parameters

Expand All @@ -22,6 +42,9 @@ bottom and/or in the middle. That's perfect to map three-way switches or even th
| Parameter | Description |
|----------------|-----------------------------------------------------------------|
| command_middle | Command which will be executed when the slider is in the middle |
| data_2_min | Minimum value of Data 2 |
| data_2_max | Maximum value of Data 2 |
| data_2_margin | Margin to be used (value has to be between 0 and 25) |

### Examples

Expand Down
11 changes: 9 additions & 2 deletions lib/common/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ unsigned char map::data_1() const
*/
std::string map::data_1_as_string()
{
std::string str = fmt::format("{} {}", data_1_type_as_string(), m_data_1);
std::string str = fmt::format("{} {}", data_1_type_as_string(), std::to_string(m_data_1));
return str;
}

Expand Down Expand Up @@ -152,8 +152,15 @@ std::string map::get_key()
/**
* Check the mapping
*/
bool map::check(text_logger&)
bool map::check(text_logger& in_log, const device_settings& in_dev_settings)
{
// check if a sublayer was defined
if (!m_sl.empty() && in_dev_settings.sl_dataref.empty()) {
in_log.error(source_line());
in_log.error(" --> Sublayer is defined for mapping, but no sublayer dataref was defined in the device");
return false;
}

if (m_channel != MIDI_NONE && m_data_1 != MIDI_NONE && m_data_1_type != map_data_1_type::none)
return true;
else
Expand Down
5 changes: 3 additions & 2 deletions lib/common/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "toml.hpp"

// XMidiCtrl
#include "device_settings.h"
#include "midi_message.h"
#include "text_logger.h"
#include "types.h"
Expand Down Expand Up @@ -58,7 +59,7 @@ class map {
virtual ~map() = default;

void set_no(unsigned int in_no);
unsigned int no() const;
[[nodiscard]] unsigned int no() const;

void set_include_name(std::string_view in_name);
[[nodiscard]] std::string_view include_name() const;
Expand All @@ -77,7 +78,7 @@ class map {

std::string get_key();

virtual bool check(text_logger& in_log);
virtual bool check(text_logger& in_log, const device_settings& in_dev_settings);

static std::string build_map_key(unsigned char in_ch, std::string_view in_type_code, unsigned char in_data);

Expand Down
2 changes: 2 additions & 0 deletions lib/common/text_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace xmidictrl {
text_logger::text_logger(text_logger* in_parent)
: m_parent(in_parent)
{
if (in_parent != nullptr)
set_debug_mode(in_parent->debug_mode());
}


Expand Down
1 change: 0 additions & 1 deletion lib/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const char* const COMMAND_TOGGLE_SUBLAYER = "TOGGLE_SUBLAYER";
const char* const CFG_KEY_COMMAND_DOWN = "command_down";
const char* const CFG_KEY_COMMAND_FAST_DOWN = "command_fast_down";
const char* const CFG_KEY_COMMAND_FAST_UP = "command_fast_up";
const char* const CFG_KEY_COMMAND_MIDDLE = "command_middle";
const char* const CFG_KEY_COMMAND_UP = "command_up";
const char* const CFG_KEY_COMMON_PROFILE = "common_profile";
const char* const CFG_KEY_DATAREF = "dataref";
Expand Down
10 changes: 5 additions & 5 deletions lib/map/map_in/map_in_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ void map_in_cmd::read_config(text_logger& in_log, toml::value& in_data, toml::va
/**
* Check the mapping
*/
bool map_in_cmd::check(text_logger& in_log)
bool map_in_cmd::check(text_logger& in_log, const device_settings& in_dev_settings)
{
if (!map::check(in_log))
if (!map::check(in_log, in_dev_settings))
return false;

if (m_command.empty()) {
Expand Down Expand Up @@ -127,14 +127,14 @@ bool map_in_cmd::execute(midi_message& in_msg, std::string_view in_sl_value)
if (!check_sublayer(in_sl_value))
return true;

in_msg.log().debug(" --> Execute command '" + m_command + "'");

if (in_msg.data_2() == m_data_2_on) {
in_msg.log().debug(" --> Begin execution of command '" + m_command + "'");
env().cmd().begin(in_msg.log(), m_command);
} else if (in_msg.data_2() == m_data_2_off) {
in_msg.log().debug(" --> End execution of command '" + m_command + "'");
env().cmd().end(in_msg.log(), m_command);
} else {
in_msg.log().error("Invalid MIDI velocity '" + std::to_string(in_msg.data_2()) + "'");
in_msg.log().error("Invalid MIDI Data 2 value '" + std::to_string(in_msg.data_2()) + "'");
in_msg.log().error(
" --> Supported values for the current mapping are '" + std::to_string(m_data_2_on) + "' and '"
+ std::to_string(m_data_2_off) + "'");
Expand Down
2 changes: 1 addition & 1 deletion lib/map/map_in/map_in_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class map_in_cmd : public map_in_label {
[[nodiscard]] unsigned char data_2_off() const;

void read_config(text_logger& in_log, toml::value& in_data, toml::value& in_config) override;
bool check(text_logger& in_log) override;
bool check(text_logger& in_log, const device_settings& in_dev_settings) override;

bool execute(midi_message &in_msg, std::string_view in_sl_value) override;

Expand Down
4 changes: 2 additions & 2 deletions lib/map/map_in/map_in_drf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ void map_in_drf::read_config(text_logger& in_log, toml::value& in_data, toml::va
/**
* Check the mapping
*/
bool map_in_drf::check(text_logger& in_log)
bool map_in_drf::check(text_logger& in_log, const device_settings& in_dev_settings)
{
bool result = true;

if (!map::check(in_log))
if (!map::check(in_log, in_dev_settings))
result = false;

if (m_dataref.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/map/map_in/map_in_drf.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class map_in_drf : public map_in_label {
map_in_type type() override;

void read_config(text_logger &in_log, toml::value &in_data, toml::value &in_config) override;
bool check(text_logger &in_log) override;
bool check(text_logger &in_log, const device_settings& in_dev_settings) override;

bool execute(midi_message& in_msg, std::string_view in_sl_value) override;

Expand Down
4 changes: 2 additions & 2 deletions lib/map/map_in/map_in_enc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ void map_in_enc::read_config(text_logger& in_log, toml::value& in_data, toml::va
/**
* Check the mapping
*/
bool map_in_enc::check(text_logger& in_log)
bool map_in_enc::check(text_logger& in_log, const device_settings& in_dev_settings)
{
bool result = true;

if (!map::check(in_log))
if (!map::check(in_log, in_dev_settings))
result = false;

switch (m_enc_map_type) {
Expand Down
4 changes: 2 additions & 2 deletions lib/map/map_in/map_in_enc.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class map_in_enc : public map_in_label {
map_in_type type() override;

void read_config(text_logger& in_log, toml::value& in_data, toml::value& in_config) override;
bool check(text_logger& in_log) override;
bool check(text_logger& in_log, const device_settings& in_dev_settings) override;

bool execute(midi_message& in_msg, std::string_view in_sl_value) override;

Expand Down Expand Up @@ -79,7 +79,7 @@ class map_in_enc : public map_in_label {
void modify_up(midi_message& in_msg, bool in_fast);
void modify_down(midi_message& in_msg, bool in_fast);

float check_value_min_max(float in_value, float in_modifier) const;
[[nodiscard]] float check_value_min_max(float in_value, float in_modifier) const;

// members
encoder_mode m_enc_mode {encoder_mode::relative};
Expand Down
2 changes: 1 addition & 1 deletion lib/map/map_in/map_in_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void map_in_list::create_mappings(text_logger& in_log,
mapping->read_config(in_log, in_profile[map_no], in_config);
mapping->set_include_name(in_inc_name);

if (mapping->check(in_log)) {
if (mapping->check(in_log, in_dev_settings)) {
add(mapping);
in_log.debug_line(in_profile[map_no].location().line(), "Mapping added");
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/map/map_in/map_in_pnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ void map_in_pnp::read_config(text_logger& in_log, toml::value& in_data, toml::va
/**
* Check the mapping
*/
bool map_in_pnp::check(text_logger& in_log)
bool map_in_pnp::check(text_logger& in_log, const device_settings& in_dev_settings)
{
bool result = true;

if (!map::check(in_log))
if (!map::check(in_log, in_dev_settings))
result = false;

// pull
Expand Down
2 changes: 1 addition & 1 deletion lib/map/map_in/map_in_pnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class map_in_pnp : public map_in {
void set_time_released();

void read_config(text_logger& in_log, toml::value& in_data, toml::value& in_config) override;
bool check(text_logger& in_log) override;
bool check(text_logger& in_log, const device_settings& in_dev_settings) override;

bool execute(midi_message& in_msg, std::string_view in_sl_value) override;

Expand Down
Loading

0 comments on commit 8c46174

Please sign in to comment.