From a7aef3040ca756a915b3a2b38f4041abfc001330 Mon Sep 17 00:00:00 2001 From: Marco Auer Date: Thu, 19 Oct 2023 10:37:01 +0200 Subject: [PATCH] Minor refactoring and added badges on readme file --- .github/workflows/build.yml | 2 +- docs/README.md | 2 ++ src/common/config.h | 10 +++++----- src/common/data_item.h | 8 ++++---- src/common/inbound_task.h | 8 ++++---- src/common/midi_logger.cpp | 2 +- src/common/midi_message.cpp | 12 ++++++------ src/common/midi_message.h | 20 ++++++++++---------- src/common/outbound_task.h | 8 ++++---- src/common/text_log_msg.h | 8 ++++---- src/common/text_logger.cpp | 12 ++++++------ src/common/types.h | 9 ++++++++- src/plugin/plugin.h | 14 +++++++------- src/plugin/ui/settings_window.cpp | 2 ++ 14 files changed, 64 insertions(+), 53 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fed1a554..fd502f36 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build all platforms +name: build-all-platforms on: push: diff --git a/docs/README.md b/docs/README.md index d3c087da..7c7c1aac 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,5 +1,7 @@ # MIDI Controller plugin for X-Plane 11.50+ / 12 +[![build-all-platforms](https://github.com/mauer/xmidictrl/actions/workflows/build.yml/badge.svg)](https://github.com/mauer/xmidictrl/actions/workflows/build.yml) +[![pages-build-deployment](https://github.com/mauer/xmidictrl/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/mauer/xmidictrl/actions/workflows/pages/pages-build-deployment) XMidiCtrl is a plugin for X-Plane 11/12 and allows the connection of MIDI devices to commands and datarefs without the need of additional software. diff --git a/src/common/config.h b/src/common/config.h index 51fda150..9f310576 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -32,19 +32,19 @@ namespace xmidictrl { class config { public: - explicit config(environment &in_emv); + explicit config(environment& in_emv); virtual ~config() = default; protected: - [[nodiscard]] environment &env() const; + [[nodiscard]] environment& env() const; - bool load_file(text_logger &in_log, std::string_view in_filename); - void close_file(text_logger &in_log); + bool load_file(text_logger& in_log, std::string_view in_filename); + void close_file(text_logger& in_log); toml::value m_config {}; private: - environment &m_env; + environment& m_env; std::string m_filename {}; }; diff --git a/src/common/data_item.h b/src/common/data_item.h index deb1f484..c70b54e5 100644 --- a/src/common/data_item.h +++ b/src/common/data_item.h @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------------------------------------------- // XMidiCtrl - MIDI Controller plugin for X-Plane // -// Copyright (c) 2021-2022 Marco Auer +// Copyright (c) 2021-2023 Marco Auer // // XMidiCtrl is free software: you can redistribute it and/or modify it under the terms of the // GNU Affero General Public License as published by the Free Software Foundation, either version 3 @@ -15,8 +15,8 @@ // If not, see . //--------------------------------------------------------------------------------------------------------------------- -#ifndef DATA_ITEM_H -#define DATA_ITEM_H +#ifndef XMC_DATA_ITEM_H +#define XMC_DATA_ITEM_H // Standard #include @@ -36,4 +36,4 @@ struct data_item { } // Namespace xmidictrl -#endif // DATA_ITEM_H +#endif // XMC_DATA_ITEM_H diff --git a/src/common/inbound_task.h b/src/common/inbound_task.h index d83caf44..c9c97ed9 100644 --- a/src/common/inbound_task.h +++ b/src/common/inbound_task.h @@ -2,7 +2,7 @@ //--------------------------------------------------------------------------------------------------------------------- // XMidiCtrl - MIDI Controller plugin for X-Plane // -// Copyright (c) 2021-2022 Marco Auer +// Copyright (c) 2021-2023 Marco Auer // // XMidiCtrl is free software: you can redistribute it and/or modify it under the terms of the // GNU Affero General Public License as published by the Free Software Foundation, either version 3 @@ -16,8 +16,8 @@ // If not, see . //--------------------------------------------------------------------------------------------------------------------- -#ifndef INBOUND_TASK_H -#define INBOUND_TASK_H +#ifndef XMC_INBOUND_TASK_H +#define XMC_INBOUND_TASK_H // Standard #include @@ -35,4 +35,4 @@ struct inbound_task { } // Namespace xmidictrl -#endif // INBOUND_TASK_H \ No newline at end of file +#endif // XMC_INBOUND_TASK_H \ No newline at end of file diff --git a/src/common/midi_logger.cpp b/src/common/midi_logger.cpp index 38957ff7..71cbfd60 100644 --- a/src/common/midi_logger.cpp +++ b/src/common/midi_logger.cpp @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------------------------------------------- // XMidiCtrl - MIDI Controller plugin for X-Plane // -// Copyright (c) 2021-2022 Marco Auer +// Copyright (c) 2021-2023 Marco Auer // // XMidiCtrl is free software: you can redistribute it and/or modify it under the terms of the // GNU Affero General Public License as published by the Free Software Foundation, either version 3 diff --git a/src/common/midi_message.cpp b/src/common/midi_message.cpp index 2ef314cd..eef257ba 100644 --- a/src/common/midi_message.cpp +++ b/src/common/midi_message.cpp @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------------------------------------------- // XMidiCtrl - MIDI Controller plugin for X-Plane // -// Copyright (c) 2021-2022 Marco Auer +// Copyright (c) 2021-2023 Marco Auer // // XMidiCtrl is free software: you can redistribute it and/or modify it under the terms of the // GNU Affero General Public License as published by the Free Software Foundation, either version 3 @@ -29,7 +29,7 @@ namespace xmidictrl { /** * Constructor */ -midi_message::midi_message(text_logger &in_log, midi_direction in_direction) +midi_message::midi_message(text_logger& in_log, midi_direction in_direction) : m_direction(in_direction) { m_log = std::make_unique(&in_log); @@ -55,7 +55,7 @@ midi_message::~midi_message() /** * Return the message log */ -text_logger &midi_message::log() +text_logger& midi_message::log() { return *m_log; } @@ -80,7 +80,7 @@ void midi_message::clear() /** * Parse the given message */ -bool midi_message::parse_message(std::vector *in_msg) +bool midi_message::parse_message(std::vector* in_msg) { clear(); @@ -159,7 +159,7 @@ std::string midi_message::mappings_as_string() return m_mappings.at(0)->as_text().data(); std::string map_str; - for (auto &mapping: m_mappings) { + for (auto& mapping: m_mappings) { if (map_str.empty()) { map_str = mapping->as_text(); } else { @@ -175,7 +175,7 @@ std::string midi_message::mappings_as_string() /** * Add mapping to MIDI message */ -void midi_message::add_mapping(const std::shared_ptr &in_map) +void midi_message::add_mapping(const std::shared_ptr& in_map) { m_mappings.push_back(in_map); } diff --git a/src/common/midi_message.h b/src/common/midi_message.h index 225119df..79758278 100644 --- a/src/common/midi_message.h +++ b/src/common/midi_message.h @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------------------------------------------- // XMidiCtrl - MIDI Controller plugin for X-Plane // -// Copyright (c) 2021-2022 Marco Auer +// Copyright (c) 2021-2023 Marco Auer // // XMidiCtrl is free software: you can redistribute it and/or modify it under the terms of the // GNU Affero General Public License as published by the Free Software Foundation, either version 3 @@ -15,8 +15,8 @@ // If not, see . //--------------------------------------------------------------------------------------------------------------------- -#ifndef MIDI_MESSAGE_H -#define MIDI_MESSAGE_H +#ifndef XMC_MIDI_MESSAGE_H +#define XMC_MIDI_MESSAGE_H // Standard #include @@ -34,26 +34,26 @@ enum class midi_direction { out }; -const char* const sharp_note_names[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" }; -const char* const flat_note_names[] = { "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B" }; +const char* const sharp_note_names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; +const char* const flat_note_names[] = {"C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"}; class midi_message { public: - midi_message(text_logger &in_log, midi_direction in_direction); + midi_message(text_logger& in_log, midi_direction in_direction); ~midi_message(); - text_logger &log(); + text_logger& log(); void clear(); - bool parse_message(std::vector *in_msg); + bool parse_message(std::vector* in_msg); void create_cc_message(unsigned char in_channel, unsigned char in_data, unsigned char in_velocity); bool check(); [[nodiscard]] size_t mapping_count() const; std::string mappings_as_string(); - void add_mapping(const std::shared_ptr &in_map); + void add_mapping(const std::shared_ptr& in_map); void set_time(time_point in_time); [[nodiscard]] std::string time() const; @@ -98,4 +98,4 @@ class midi_message { } // Namespace xmidictrl -#endif // MIDI_MESSAGE_H \ No newline at end of file +#endif // XMC_MIDI_MESSAGE_H \ No newline at end of file diff --git a/src/common/outbound_task.h b/src/common/outbound_task.h index 1dcac828..cafcc906 100644 --- a/src/common/outbound_task.h +++ b/src/common/outbound_task.h @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------------------------------------------- // XMidiCtrl - MIDI Controller plugin for X-Plane // -// Copyright (c) 2021-2022 Marco Auer +// Copyright (c) 2021-2023 Marco Auer // // XMidiCtrl is free software: you can redistribute it and/or modify it under the terms of the // GNU Affero General Public License as published by the Free Software Foundation, either version 3 @@ -15,8 +15,8 @@ // If not, see . //--------------------------------------------------------------------------------------------------------------------- -#ifndef OUTBOUND_TASK_H -#define OUTBOUND_TASK_H +#ifndef XMC_OUTBOUND_TASK_H +#define XMC_OUTBOUND_TASK_H // Standard #include @@ -42,4 +42,4 @@ struct outbound_task { } // Namespace xmidictrl -#endif // OUTBOUND_TASK_H +#endif // XMC_OUTBOUND_TASK_H diff --git a/src/common/text_log_msg.h b/src/common/text_log_msg.h index 968c1398..c7d2f180 100644 --- a/src/common/text_log_msg.h +++ b/src/common/text_log_msg.h @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------------------------------------------- // XMidiCtrl - MIDI Controller plugin for X-Plane // -// Copyright (c) 2021-2022 Marco Auer +// Copyright (c) 2021-2023 Marco Auer // // XMidiCtrl is free software: you can redistribute it and/or modify it under the terms of the // GNU Affero General Public License as published by the Free Software Foundation, either version 3 @@ -15,8 +15,8 @@ // If not, see . //--------------------------------------------------------------------------------------------------------------------- -#ifndef TEXT_LOG_MSG_H -#define TEXT_LOG_MSG_H +#ifndef XMC_TEXT_LOG_MSG_H +#define XMC_TEXT_LOG_MSG_H // XMidiCtrl #include "types.h" @@ -52,4 +52,4 @@ struct text_log_msg { } // Namespace xmidictrl -#endif // TEXT_LOG_MSG_H \ No newline at end of file +#endif // XMC_TEXT_LOG_MSG_H \ No newline at end of file diff --git a/src/common/text_logger.cpp b/src/common/text_logger.cpp index f7d5b638..dc4e5ffd 100644 --- a/src/common/text_logger.cpp +++ b/src/common/text_logger.cpp @@ -30,7 +30,7 @@ namespace xmidictrl { /** * Constructor */ -text_logger::text_logger(text_logger *in_parent) +text_logger::text_logger(text_logger* in_parent) : m_parent(in_parent) { } @@ -131,7 +131,7 @@ size_t text_logger::count() /** * Return a specific text message */ -text_log_msg *text_logger::message(int in_index) +text_log_msg* text_logger::message(int in_index) { std::mutex mutex; std::lock_guard lock(mutex); @@ -152,7 +152,7 @@ std::string text_logger::messages_as_text() return {m_messages.at(0)->text}; std::string text; - for (auto &msg : m_messages) { + for (auto& msg: m_messages) { if (text.empty()) { text = msg->text; } else { @@ -325,10 +325,10 @@ void text_logger::add_message(log_level in_level, std::string_view in_text) std::lock_guard lock(mutex); if (in_level == log_level::warn) - m_warn_count++; - + m_warn_count++; + if (in_level == log_level::error) - m_error_count++; + m_error_count++; // get current date time stamp time_t t = std::time(nullptr); diff --git a/src/common/types.h b/src/common/types.h index e2775b51..615131d5 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -169,12 +169,19 @@ const char* const CFG_MAPTYPE_SLIDER = "sld"; //--------------------------------------------------------------------------------------------------------------------- -// ENUMERATIONS +// TYPES //--------------------------------------------------------------------------------------------------------------------- // time point using time_point = std::chrono::system_clock::time_point; + + + +//--------------------------------------------------------------------------------------------------------------------- +// ENUMERATIONS +//--------------------------------------------------------------------------------------------------------------------- + // Device type enum class device_type { virtual_device, diff --git a/src/plugin/plugin.h b/src/plugin/plugin.h index fe494a9b..8e3b854a 100644 --- a/src/plugin/plugin.h +++ b/src/plugin/plugin.h @@ -43,9 +43,9 @@ class plugin { plugin(); ~plugin(); - static plugin &instance(); + static plugin& instance(); - static float callback_flight_loop(float in_elapsed_me, float in_elapsed_sim, int in_counter, void *in_refcon); + static float callback_flight_loop(float in_elapsed_me, float in_elapsed_sim, int in_counter, void* in_refcon); void enable(); void disable(); @@ -56,7 +56,7 @@ class plugin { void show_info_message(std::string_view in_id, std::string_view in_msg, int in_seconds = -1); void add_virtual_midi_message(unsigned char in_cc, unsigned char in_velocity); - void add_inbound_task(const std::shared_ptr &in_task); + void add_inbound_task(const std::shared_ptr& in_task); void show_messages_window(); void show_devices_window(); @@ -79,11 +79,11 @@ class plugin { void create_commands(); void remove_commands(); - static int read_drf_sublayer(void *in_refcon); - static void write_drf_sublayer(void *in_refcon, int in_value); + static int read_drf_sublayer(void* in_refcon); + static void write_drf_sublayer(void* in_refcon, int in_value); - static int command_handler(XPLMCommandRef in_command, XPLMCommandPhase in_phase, void *in_refcon); - static int virtual_midi_command_handler(XPLMCommandRef in_command, XPLMCommandPhase in_phase, void *in_refcon); + static int command_handler(XPLMCommandRef in_command, XPLMCommandPhase in_phase, void* in_refcon); + static int virtual_midi_command_handler(XPLMCommandRef in_command, XPLMCommandPhase in_phase, void* in_refcon); std::shared_ptr create_window(window_type in_type); diff --git a/src/plugin/ui/settings_window.cpp b/src/plugin/ui/settings_window.cpp index 486dbcd5..f8543496 100644 --- a/src/plugin/ui/settings_window.cpp +++ b/src/plugin/ui/settings_window.cpp @@ -252,6 +252,8 @@ void settings_window::create_tab_midi() ImGui::NewLine(); ImGui::NewLine(); ImGui::NewLine(); + ImGui::NewLine(); + ImGui::NewLine(); if (ImGui::Button(" " ICON_FA_FLOPPY_DISK " Save Settings ")) save_settings();