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 sbk::engine
7{
8 class bus;
9 class container;
10 class node;
11 class node_base;
12 class node_instance;
13 class sound;
14 class sound_container;
15 class voice;
16
20 struct SB_CLASS NodeGroupInstance
21 {
22 bool initNodeGroup(const node_base& 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 node_base& thisNode, voice* owningVoice);
35
36 std::shared_ptr<node_instance> parent;
37 };
38
42 struct SB_CLASS ChildrenNodeOwner
43 {
44 bool createChildren(const node_base& thisNode,
45 voice* owningVoice,
46 node_instance* thisNodeInstance,
47 unsigned int numTimesPlayed);
48
49 std::vector<std::shared_ptr<node_instance>> 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 node_instance* parentForChildren = nullptr;
97 };
98
103 class SB_CLASS node_instance : public sbk::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 node_instance* get_parent() 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(node_instance, sbk::core::object)
138 };
139} // namespace sbk::engine
Definition database_ptr.h:23
Base object that all sound Bakery objects should inherit from.
Definition object.h:21
Generic node that can have a get_parent and own children.
Definition node.h:23
NodeInstances represent runtime versions of Nodes, either containers or busses.
Definition node_instance.h:104
Root node that builds the core graph of sounds and busses.
Definition node.h:64
A runtime graph of nodes and busses, playing a sound or many.
Definition voice.h:16
Owns a list of child node instances.
Definition node_instance.h:43
Definition node_instance.h:72
sbk::core::database_ptr< node_base > 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 get_parent node instance.
Definition node_instance.h:33
ma_node with an additional enum descriptor.
Definition sound_chef_common.h:179
Groups nodes/DSPs together into one.
Definition sound_chef_common.h:205