NAP
multisamplebufferplayernode.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Std includes
8 #include <atomic>
9 
10 // Nap includes
11 #include <audio/utility/safeptr.h>
12 
13 // Audio includes
14 #include <audio/core/audionode.h>
15 #include <audio/core/audionodemanager.h>
16 #include <audio/node/bufferplayernode.h>
17 
18 namespace nap
19 {
20  namespace audio
21  {
23 
29  class NAPAPI MultiSampleBufferPlayerNode : public Node
30  {
31  RTTI_ENABLE(Node)
32  public:
33  MultiSampleBufferPlayerNode(int channel, NodeManager& manager);
34 
38  std::vector<OutputPin*> getOutputPins();
39 
45  void play(DiscreteTimeValue position = 0, ControllerValue speed = 1.);
46 
50  void stop();
51 
56  void setSpeed(ControllerValue speed);
57 
62  void setPosition(DiscreteTimeValue position);
63 
68  void setBuffer(SafePtr<MultiSampleBuffer> buffer);
69 
74  {
75  return mSpeed;
76  }
77 
82  {
83  return mPosition;
84  }
85  private:
86  // Inherited from Node
87  void process() override;
88 
89  std::atomic<bool> mPlaying = {false}; // Indicates wether the node is currently playing.
90  std::atomic<int> mChannels = {0}; // The amount of channels
91  std::atomic<double> mPosition = {0}; // Current position of playback in samples within the source buffer.
92  std::atomic<ControllerValue> mSpeed = {1.f}; // Playback speed as a fraction of the original speed.
93  SafePtr<MultiSampleBuffer> mBuffer = nullptr; // Pointer to the buffer with audio material being played back.
94 
95  std::vector<std::unique_ptr<OutputPin>> mOwnedOutputPins;
96  };
97 
98  }
99 }
nap::audio::MultiSampleBufferPlayerNode
Definition: multisamplebufferplayernode.h:29
nap::audio::MultiSampleBufferPlayerNode::getSpeed
ControllerValue getSpeed() const
Definition: multisamplebufferplayernode.h:73
nap::audio::NodeManager
Definition: audionodemanager.h:33
nap::audio::ControllerValue
float ControllerValue
Definition: audiotypes.h:113
nap::audio::Node
Definition: audionode.h:33
nap::audio::MultiSampleBufferPlayerNode::getPosition
DiscreteTimeValue getPosition() const
Definition: multisamplebufferplayernode.h:81
nap::audio::DiscreteTimeValue
nap::uint64 DiscreteTimeValue
Definition: audiotypes.h:125
nap
Definition: templateapp.h:17
nap::audio::SafePtr
Definition: safeptr.h:28