Exposing artboard volume
Adds ```artboard->volume(0.9f);``` to C++ and artboard.volume getter/setter to JS!
Needs to be exposed to the high level TS runtime so it can then be used by React for our community.
Diffs=
cb2ea5b2d Exposing artboard volume (#7022)
Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
diff --git a/.rive_head b/.rive_head
index 406e3a5..8d2c3c4 100644
--- a/.rive_head
+++ b/.rive_head
@@ -1 +1 @@
-8ecc99130db737d49ce0889501c421bd53b58f9e
+cb2ea5b2d31eb6888a96cb25524392087bdf47c7
diff --git a/include/rive/artboard.hpp b/include/rive/artboard.hpp
index 8338a6d..2365af9 100644
--- a/include/rive/artboard.hpp
+++ b/include/rive/artboard.hpp
@@ -260,10 +260,15 @@
StatusCode import(ImportStack& importStack) override;
+ float volume() const;
+ void volume(float value);
+
#ifdef EXTERNAL_RIVE_AUDIO_ENGINE
rcp<AudioEngine> audioEngine() const;
void audioEngine(rcp<AudioEngine> audioEngine);
#endif
+private:
+ float m_volume = 1.0f;
};
class ArtboardInstance : public Artboard
diff --git a/src/artboard.cpp b/src/artboard.cpp
index b386bf7..6021a07 100644
--- a/src/artboard.cpp
+++ b/src/artboard.cpp
@@ -796,6 +796,9 @@
return result;
}
+float Artboard::volume() const { return m_volume; }
+void Artboard::volume(float value) { m_volume = value; }
+
////////// ArtboardInstance
#include "rive/animation/linear_animation_instance.hpp"
diff --git a/src/audio_event.cpp b/src/audio_event.cpp
index d0d8098..9a9e043 100644
--- a/src/audio_event.cpp
+++ b/src/audio_event.cpp
@@ -20,6 +20,12 @@
return;
}
+ auto volume = audioAsset->volume() * artboard()->volume();
+ if (volume <= 0.0f)
+ {
+ return;
+ }
+
auto engine =
#ifdef EXTERNAL_RIVE_AUDIO_ENGINE
artboard()->audioEngine() != nullptr ? artboard()->audioEngine() :
@@ -27,9 +33,10 @@
AudioEngine::RuntimeEngine();
auto sound = engine->play(audioSource, engine->timeInFrames(), 0, 0);
- if (audioAsset->volume() != 1.0f)
+
+ if (volume != 1.0f)
{
- sound->volume(audioAsset->volume());
+ sound->volume(volume);
}
#endif
}