NAP
sequenceplayeraudiooutput.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 // nap includes
8 #include <nap/resourceptr.h>
9 #include <nap/signalslot.h>
10 #include <sequenceplayeroutput.h>
11 #include <audio/node/outputnode.h>
12 #include <audio/resource/audiobufferresource.h>
13 #include <audio/service/audioservice.h>
14 #include <nap/signalslot.h>
15 #include <rtti/objectptr.h>
16 #include <audio/node/mixnode.h>
17 
18 // local includes
19 #include "sequenceplayeraudioadapter.h"
20 #include "multisamplebufferplayernode.h"
21 
22 namespace nap
23 {
25 
26  // forward declares
27  class SequenceService;
28 
29  // shortcut to map of created multi sample buffer player nodes
30  using BufferPlayerMap = std::unordered_map<std::string, audio::SafeOwner<audio::MultiSampleBufferPlayerNode>>;
31 
42  class NAPAPI SequencePlayerAudioOutput final : public SequencePlayerOutput
43  {
45 
46  RTTI_ENABLE(SequencePlayerOutput);
47  public:
53 
59  bool init(utility::ErrorState& errorState) override;
60 
64  void onDestroy() override;
65 
70  virtual const std::vector<rtti::ObjectPtr<audio::AudioBufferResource>>& getBuffers() const;
71 
77  void connectInputPin(audio::InputPin& inputPin, int channel);
78 
84  void disconnectInputPin(audio::InputPin& inputPin, int channel);
85 
91  audio::OutputPin* getOutputForChannel(int channel);
92 
97  int getChannelCount() const;
98 
99  // properties
100 
101  //Resource pointers to AudioBuffers
102  std::vector<ResourcePtr<audio::AudioBufferResource>> mAudioBuffers;
103 
108  bool mManualRouting = false;
109 
114  int mMaxChannels = 8;
115  protected:
120  void update(double deltaTime) override;
121 
122  private:
130  void handleAudioSegmentPlay(const SequencePlayerAudioAdapter* adapter, const std::string& id, double time,
131  float playbackSpeed);
132 
138  void handleAudioSegmentStop(const SequencePlayerAudioAdapter* adapter, const std::string& id);
139 
144  void registerAdapter(const SequencePlayerAudioAdapter* adapter);
145 
150  void unregisterAdapter(const SequencePlayerAudioAdapter* adapter);
151 
152  // pointer to audio service
153  audio::AudioService* mAudioService;
154 
155  // map of BufferPlayerMaps
156  std::unordered_map<const SequencePlayerAudioAdapter*, BufferPlayerMap> mBufferPlayers;
157 
158  // map of output nodes created and owned by SequencePlayerAudioOutput
159  std::vector<audio::SafeOwner<audio::OutputNode>> mOutputNodes;
160 
161  // mix nodes created and owned by SequencePlayerAudioOutput
162  std::vector<audio::SafeOwner<audio::MixNode>> mMixNodes;
163  };
164 
165  // shortcut to factory function
167 }
nap::SequenceService
Definition: sequenceservice.h:42
nap::SequencePlayerAudioAdapter
Definition: sequenceplayeraudioadapter.h:25
nap::rtti::ObjectCreator
Definition: factory.h:49
nap::utility::ErrorState
Definition: errorstate.h:19
nap::BufferPlayerMap
std::unordered_map< std::string, audio::SafeOwner< audio::MultiSampleBufferPlayerNode > > BufferPlayerMap
Definition: sequenceplayeraudiooutput.h:30
nap::SequencePlayerAudioOutput::mAudioBuffers
std::vector< ResourcePtr< audio::AudioBufferResource > > mAudioBuffers
Property: 'Audio Buffers' resource pointers to audio buffers.
Definition: sequenceplayeraudiooutput.h:102
nap::audio::AudioService
Definition: audioservice.h:26
nap::SequencePlayerOutput
Definition: sequenceplayeroutput.h:23
nap::audio::OutputPin
Definition: audiopin.h:204
nap::SequencePlayerAudioOutput
Definition: sequenceplayeraudiooutput.h:42
nap::audio::InputPin
Definition: audiopin.h:87
nap
Definition: templateapp.h:17