Skip to content

Commit

Permalink
Minor refactoring and added badges on readme file
Browse files Browse the repository at this point in the history
  • Loading branch information
mauer committed Oct 19, 2023
1 parent 014df14 commit a7aef30
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build all platforms
name: build-all-platforms

on:
push:
Expand Down
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
10 changes: 5 additions & 5 deletions src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
};
Expand Down
8 changes: 4 additions & 4 deletions src/common/data_item.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,8 +15,8 @@
// If not, see <https://www.gnu.org/licenses/>.
//---------------------------------------------------------------------------------------------------------------------

#ifndef DATA_ITEM_H
#define DATA_ITEM_H
#ifndef XMC_DATA_ITEM_H
#define XMC_DATA_ITEM_H

// Standard
#include <memory>
Expand All @@ -36,4 +36,4 @@ struct data_item {

} // Namespace xmidictrl

#endif // DATA_ITEM_H
#endif // XMC_DATA_ITEM_H
8 changes: 4 additions & 4 deletions src/common/inbound_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,8 +16,8 @@
// If not, see <https://www.gnu.org/licenses/>.
//---------------------------------------------------------------------------------------------------------------------

#ifndef INBOUND_TASK_H
#define INBOUND_TASK_H
#ifndef XMC_INBOUND_TASK_H
#define XMC_INBOUND_TASK_H

// Standard
#include <memory>
Expand All @@ -35,4 +35,4 @@ struct inbound_task {

} // Namespace xmidictrl

#endif // INBOUND_TASK_H
#endif // XMC_INBOUND_TASK_H
2 changes: 1 addition & 1 deletion src/common/midi_logger.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/common/midi_message.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<text_logger>(&in_log);
Expand All @@ -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;
}
Expand All @@ -80,7 +80,7 @@ void midi_message::clear()
/**
* Parse the given message
*/
bool midi_message::parse_message(std::vector<unsigned char> *in_msg)
bool midi_message::parse_message(std::vector<unsigned char>* in_msg)
{
clear();

Expand Down Expand Up @@ -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 {
Expand All @@ -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<map> &in_map)
void midi_message::add_mapping(const std::shared_ptr<map>& in_map)
{
m_mappings.push_back(in_map);
}
Expand Down
20 changes: 10 additions & 10 deletions src/common/midi_message.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,8 +15,8 @@
// If not, see <https://www.gnu.org/licenses/>.
//---------------------------------------------------------------------------------------------------------------------

#ifndef MIDI_MESSAGE_H
#define MIDI_MESSAGE_H
#ifndef XMC_MIDI_MESSAGE_H
#define XMC_MIDI_MESSAGE_H

// Standard
#include <chrono>
Expand All @@ -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<unsigned char> *in_msg);
bool parse_message(std::vector<unsigned char>* 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<map> &in_map);
void add_mapping(const std::shared_ptr<map>& in_map);

void set_time(time_point in_time);
[[nodiscard]] std::string time() const;
Expand Down Expand Up @@ -98,4 +98,4 @@ class midi_message {

} // Namespace xmidictrl

#endif // MIDI_MESSAGE_H
#endif // XMC_MIDI_MESSAGE_H
8 changes: 4 additions & 4 deletions src/common/outbound_task.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,8 +15,8 @@
// If not, see <https://www.gnu.org/licenses/>.
//---------------------------------------------------------------------------------------------------------------------

#ifndef OUTBOUND_TASK_H
#define OUTBOUND_TASK_H
#ifndef XMC_OUTBOUND_TASK_H
#define XMC_OUTBOUND_TASK_H

// Standard
#include <memory>
Expand All @@ -42,4 +42,4 @@ struct outbound_task {

} // Namespace xmidictrl

#endif // OUTBOUND_TASK_H
#endif // XMC_OUTBOUND_TASK_H
8 changes: 4 additions & 4 deletions src/common/text_log_msg.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,8 +15,8 @@
// If not, see <https://www.gnu.org/licenses/>.
//---------------------------------------------------------------------------------------------------------------------

#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"
Expand Down Expand Up @@ -52,4 +52,4 @@ struct text_log_msg {

} // Namespace xmidictrl

#endif // TEXT_LOG_MSG_H
#endif // XMC_TEXT_LOG_MSG_H
12 changes: 6 additions & 6 deletions src/common/text_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down Expand Up @@ -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<std::mutex> lock(mutex);
Expand All @@ -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 {
Expand Down Expand Up @@ -325,10 +325,10 @@ void text_logger::add_message(log_level in_level, std::string_view in_text)
std::lock_guard<std::mutex> 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);
Expand Down
9 changes: 8 additions & 1 deletion src/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions src/plugin/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<inbound_task> &in_task);
void add_inbound_task(const std::shared_ptr<inbound_task>& in_task);

void show_messages_window();
void show_devices_window();
Expand All @@ -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<xplane_window> create_window(window_type in_type);

Expand Down
2 changes: 2 additions & 0 deletions src/plugin/ui/settings_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a7aef30

Please sign in to comment.