Skip to content

Commit

Permalink
feat(ui): Added MIDI activity indicator to the Channel Node (input + …
Browse files Browse the repository at this point in the history
…output)
  • Loading branch information
mfep committed Apr 17, 2024
1 parent 2d3153a commit d31df33
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/MidiChannelNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const char* mc::MidiChannelNode::sm_combo_items[] = {

mc::MidiChannelNode::MidiChannelNode(std::function<float()> get_scale) : m_get_scale(get_scale)
{
m_midi_channel_map_node.add_observer(this);
}

mc::MidiChannelNode::~MidiChannelNode()
{
m_midi_channel_map_node.remove_observer(this);
}

void mc::MidiChannelNode::accept_serializer(nlohmann::json& j,
Expand All @@ -33,11 +39,15 @@ void mc::MidiChannelNode::render_internal()
ImGui::TextUnformatted("Channel map");
ImNodes::EndNodeTitleBar();
ImNodes::BeginInputAttribute(in_id());
m_input_indicator.render();
ImGui::SameLine();
ImGui::TextUnformatted("MIDI in");
ImNodes::EndInputAttribute();
ImGui::SameLine(100 * m_get_scale());
ImNodes::BeginOutputAttribute(out_id());
ImGui::TextUnformatted("MIDI out");
ImGui::SameLine();
m_output_indicator.render();
ImNodes::EndOutputAttribute();

std::array<int, midi::ChannelMap::num_channels> channels;
Expand Down Expand Up @@ -113,6 +123,16 @@ void mc::MidiChannelNode::render_internal()
}
}

void mc::MidiChannelNode::message_processed(std::span<const unsigned char> /*message_bytes*/)
{
m_output_indicator.trigger();
}

void mc::MidiChannelNode::message_received(std::span<const unsigned char> /*message_bytes*/)
{
m_input_indicator.trigger();
}

const char* mc::MidiChannelNode::get_label(size_t index)
{
static std::vector<std::string> labels;
Expand Down
11 changes: 9 additions & 2 deletions src/MidiChannelNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

#include <functional>

#include "ActivityIndicator.hpp"
#include "Node.hpp"
#include "midi/ChannelMapNode.hpp"

namespace mc
{

class MidiChannelNode final : public Node
class MidiChannelNode final : public Node, private midi::GraphObserver
{
public:
MidiChannelNode(std::function<float()> get_scale);
explicit MidiChannelNode(std::function<float()> get_scale);
~MidiChannelNode();

void accept_serializer(nlohmann::json& j, const NodeSerializer& serializer) const override;

Expand All @@ -20,6 +22,8 @@ class MidiChannelNode final : public Node

private:
void render_internal() override;
void message_processed(std::span<const unsigned char> message_bytes) override;
void message_received(std::span<const unsigned char> message_bytes) override;

static const char* get_label(size_t index);
static const char* get_hidden_label(size_t index);
Expand All @@ -30,6 +34,9 @@ class MidiChannelNode final : public Node
std::function<float()> m_get_scale;
midi::ChannelMapNode m_midi_channel_map_node;

ActivityIndicator m_input_indicator;
ActivityIndicator m_output_indicator;

friend class NodeSerializer;
};

Expand Down

0 comments on commit d31df33

Please sign in to comment.