VolumePlugin.cpp 2.27 KB
Newer Older
1
#include <base/PluginBases.hpp>
2
#include <base/Ports.hpp>
Benjamin Heisch's avatar
Benjamin Heisch committed
3
#include <tools/PortHandling.hpp>
4
using namespace APAL;
5
6
7
8
/**
 * @brief VolumePlguin class, which forwards audiodata and just changes the
 * Volume. For an easy start its derived from LazyPlugin, to start easily.
 */
9
10
class VolumePlugin : public LazyPlugin
{
11
protected:
12
13
  // Define an Input and an Outputport. (To optimize accesstime, not like in
  // MidiForwarder)
14
15
16
17
  std::shared_ptr<IAudioPort> in0 =
    std::make_shared<MonoPort>("In0", PortDirection::Input);
  std::shared_ptr<IAudioPort> out0 =
    std::make_shared<MonoPort>("Out0", PortDirection::Output);
18

19
public:
20
21
22
23
  /**
   * @brief Constructor, which adding the local defined Ports, to the
   * PortComponent. Its also changed the needed Plugininformation.
   */
24
25
  VolumePlugin()
  {
26
27
    // Adding  the local ports to the portcomponent, so the plugininfrastructure
    // can process it.
28
29
    this->portComponent->addPort(in0);
    this->portComponent->addPort(out0);
30
31
    // Changing the Information about the Plugin, because the default Values
    // are... not enough ;)
32
33
34
    this->infoComponent->pluginName = "VolumePlugin";
    this->infoComponent->creatorName = "Benjamin Heisch";
    this->infoComponent->pluginUri =
35
      "http://APAL_plug.in/examples/VolumePlugin";
36
  }
Benjamin Heisch's avatar
Benjamin Heisch committed
37

38
39
40
  // Geerbt über IPlugin
  virtual void processAudio() override
  {
41
42
43
    // Simple loop over the Dat and process.
    // Currently no Volumechanging is used, but it will be added later, when the
    // Framework supports Parameter, so the Volume can be adjustet.
44
    for (size_t i = 0; i < in0->size(); i++) {
45
      for (size_t s = 0; s < in0->getSampleCount(); s++) {
46
47
48
49
        if (in0->at(i)->getData() != nullptr &&
            out0->at(i)->getData() != nullptr)
          out0->at(i)->getData()[s] = in0->at(i)->getData()[s];
      }
Benjamin Heisch's avatar
Benjamin Heisch committed
50
    }
51
52
53
54
55
  }
  virtual void init() override {}
  virtual void deinit() override {}
  virtual void activate() override {}
  virtual void deactivate() override {}
Benjamin Heisch's avatar
Benjamin Heisch committed
56
};
57
58
59
60
61
// Its very important to Register a Plugin in the GlobalData object, which is
// accessed through the GlobalData() Function.
// The easiest way ist to just use this REGISTER_PLUGIN macro. But use it in
// your sourcefile, because a static variable will be declared. And that just
// works in Sourcefiles.
Benjamin Heisch's avatar
Benjamin Heisch committed
62
REGISTER_PLUGIN(VolumePlugin);