Sound Bakery  v0.1.0
Open-source audio middleware for games
Loading...
Searching...
No Matches
node_instance.h
1#pragma once
2
3#include "sound_bakery/core/core_include.h"
4#include "sound_bakery/system.h"
5
6namespace SB::Engine
7{
8 class Bus;
9 class Container;
10 class Node;
11 class NodeBase;
12 class NodeInstance;
13 class Sound;
14 class SoundContainer;
15 class Voice;
16
20 struct SB_CLASS NodeGroupInstance
21 {
22 bool initNodeGroup(const NodeBase& node);
23
24 sc_dsp* lowpass = nullptr;
25 sc_dsp* highpass = nullptr;
26 std::unique_ptr<sc_node_group, SC_NODE_GROUP_DELETER> nodeGroup;
27 };
28
32 struct SB_CLASS ParentNodeOwner
33 {
34 bool createParent(const NodeBase& thisNode, Voice* owningVoice);
35
36 std::shared_ptr<NodeInstance> parent;
37 };
38
42 struct SB_CLASS ChildrenNodeOwner
43 {
44 bool createChildren(const NodeBase& thisNode,
45 Voice* owningVoice,
46 NodeInstance* thisNodeInstance,
47 unsigned int numTimesPlayed);
48
49 std::vector<std::shared_ptr<NodeInstance>> childrenNodes;
50 };
51
52 enum class NodeInstanceType
53 {
54 CHILD,
55 BUS,
56 MAIN
57 };
58
59 enum class NodeInstanceState
60 {
61 UNINIT,
62
63 STOPPED,
64 STOPPING,
65 PAUSED,
66 VIRTUAL,
67
68 PLAYING
69 };
70
71 struct SB_CLASS InitNodeInstance
72 {
77
84 NodeInstanceType type = NodeInstanceType::MAIN;
85
89 Voice* owningVoice = nullptr;
90
96 NodeInstance* parentForChildren = nullptr;
97 };
98
103 class SB_CLASS NodeInstance : public SB::Core::Object
104 {
105 public:
107
108 bool init(const InitNodeInstance& initData);
109 bool play();
110
111 void update();
112
113 bool isPlaying() const
114 {
115 return m_state == NodeInstanceState::PLAYING || m_state == NodeInstanceState::STOPPING;
116 }
117
118 std::shared_ptr<Node> getReferencingNode() const noexcept { return m_referencingNode; }
119 NodeInstance* getParent() const noexcept { return m_parent.parent.get(); }
120 sc_node_group* getBus() const noexcept { return m_nodeGroup.nodeGroup.get(); }
121
122 private:
123 void setVolume(float oldVolume, float newVolume);
124 void setPitch(float oldPitch, float newPitch);
125 void setLowpass(float oldLowpass, float newLowpass);
126 void setHighpass(float oldHighpass, float newHighpass);
127
128 std::shared_ptr<Node> m_referencingNode = nullptr;
129 Voice* m_owningVoice = nullptr;
130 NodeInstanceState m_state = NodeInstanceState::UNINIT;
131 NodeGroupInstance m_nodeGroup;
132 ParentNodeOwner m_parent;
133 ChildrenNodeOwner m_children;
134 std::unique_ptr<sc_sound_instance, SC_SOUND_INSTANCE_DELETER> m_soundInstance;
135 unsigned int m_numTimesPlayed = 0;
136
137 REGISTER_REFLECTION(NodeInstance, SB::Core::Object)
138 };
139} // namespace SB::Engine
Definition database_ptr.h:23
Simple base Object that all Sound Bakery objects should inherit from.
Definition object.h:33
Definition node.h:20
NodeInstances represent runtime versions of Nodes, either containers or busses.
Definition node_instance.h:104
A runtime graph of nodes and busses, playing a sound or many.
Definition voice.h:17
Owns a list of child node instances.
Definition node_instance.h:43
Definition node_instance.h:72
SB::Core::DatabasePtr< NodeBase > refNode
Node to reference.
Definition node_instance.h:76
Owns a node group and applies DSP effects to it.
Definition node_instance.h:21
Owns a parent node instance.
Definition node_instance.h:33
ma_node with an additional enum descriptor.
Definition sound_chef_common.h:152
Groups nodes/DSPs together into one.
Definition sound_chef_common.h:177