MidiForwarder.cpp 2.08 KB
Newer Older
1
2
3
/**
 * @file Exampleplugin, to show the use of an easy Start with LazyPlugin. Easy Midi Messaging Concepts are explained here.
 */
4
#include <base/PluginBases.hpp>
Benjamin Heisch's avatar
Benjamin Heisch committed
5
6
#include <base/Ports.hpp>
#include <tools/PortHandling.hpp>
7
using namespace APAL;
8
9
10
11
/**
 * @brief MidiForwarder Example class, which has 1 Midi  Input and 2 Midi
 * Outputs. The Midi in signal is forwarded to the 2 Midi Outputs
 */
12
13
class MidiForwarder : public LazyPlugin
{
Benjamin Heisch's avatar
Benjamin Heisch committed
14
public:
15
16
17
18
  /**
   * @brief Standard constructor, which creates on instantiation the needed
   * Ports and Informations.
   */
19
20
  MidiForwarder()
  {
21
    // Adding the needed in and output ports in our portcomponent
22
23
24
25
26
27
    this->portComponent->addPort(
      std::make_shared<QueueMidiPort>("MidiIn", PortDirection::Input));
    this->portComponent->addPort(
      std::make_shared<QueueMidiPort>("MidiOut", PortDirection::Output));
    this->portComponent->addPort(
      std::make_shared<QueueMidiPort>("MidiOut2", PortDirection::Output));
28
29

    // Detect the needed Features for this Plugin(exspecially MIDI support)
30
    this->featureComponent->detectFeatures(this->getPortComponent());
31
32

    // Overwrite some default information
33
34
35
    this->infoComponent->pluginName = "MidiForwarder";
    this->infoComponent->creatorName = "Benjamin Heisch";
    this->infoComponent->pluginUri =
36
      "http://APAL_plug.in/examples/MidiForwarder";
37
38
39
40
  }
  // Geerbt über IPlugin
  virtual void processAudio() override
  {
41
    // Get the needed ports, to operate on from the portcomponent.
42
43
44
    auto in0 = getPortAt<IMidiPort>(this, 0, PortDirection::Input);
    auto out0 = getPortAt<IMidiPort>(this, 0, PortDirection::Output);
    auto out1 = getPortAt<IMidiPort>(this, 1, PortDirection::Output);
45
    // Forward all Messages from the Inputs to the output.
46
47
48
49
50
51
52
53
54
55
56
    while (!in0->empty()) {
      auto midiMsg = in0->get();
      auto midiMsg2 = midiMsg;
      out0->feed(std::move(midiMsg));
      out1->feed(std::move(midiMsg2));
    }
  }
  virtual void init() override {}
  virtual void deinit() override {}
  virtual void activate() override {}
  virtual void deactivate() override {}
Benjamin Heisch's avatar
Benjamin Heisch committed
57
};
Benjamin's avatar
Benjamin committed
58
REGISTER_PLUGIN(MidiForwarder);