File audaspace-animated-sequence.patch of Package audaspace
From db2ff5807765ddc6bd0e5e9345ba23444018a36a Mon Sep 17 00:00:00 2001
From: Richard Antalik <richardantalik@gmail.com>
Date: Thu, 6 Apr 2023 22:47:47 +0200
Subject: [PATCH 1/4] Improve seeking for animated sequences
---
bindings/C/AUD_Sequence.cpp | 6 +++++
bindings/C/AUD_Sequence.h | 10 +++++++
include/sequence/AnimateableProperty.h | 8 ++++++
include/sequence/SequenceData.h | 3 ++-
include/sequence/SequenceEntry.h | 7 ++++-
src/sequence/AnimateableProperty.cpp | 13 ++++++++++
src/sequence/Sequence.cpp | 2 +-
src/sequence/SequenceData.cpp | 4 +--
src/sequence/SequenceEntry.cpp | 3 ++-
src/sequence/SequenceHandle.cpp | 36 +++++++++++++++++++++++---
10 files changed, 82 insertions(+), 10 deletions(-)
diff --git a/bindings/C/AUD_Sequence.cpp b/bindings/C/AUD_Sequence.cpp
index e3f8862..4e60a29 100644
--- a/bindings/C/AUD_Sequence.cpp
+++ b/bindings/C/AUD_Sequence.cpp
@@ -165,6 +165,12 @@ AUD_API void AUD_SequenceEntry_move(AUD_SequenceEntry* entry, double begin, doub
(*entry)->move(begin, end, skip);
}
+AUD_API void AUD_SequenceEntry_setConstantRangeAnimationData(AUD_SequenceEntry* entry, AUD_AnimateablePropertyType type, int frame_start, int frame_end, float* data)
+{
+ AnimateableProperty* prop = (*entry)->getAnimProperty(static_cast<AnimateablePropertyType>(type));
+ prop->writeConstantRange(data, frame_start, frame_end);
+}
+
AUD_API void AUD_SequenceEntry_setAnimationData(AUD_SequenceEntry* entry, AUD_AnimateablePropertyType type, int frame, float* data, char animated)
{
AnimateableProperty* prop = (*entry)->getAnimProperty(static_cast<AnimateablePropertyType>(type));
diff --git a/bindings/C/AUD_Sequence.h b/bindings/C/AUD_Sequence.h
index bdf1a61..57075f3 100644
--- a/bindings/C/AUD_Sequence.h
+++ b/bindings/C/AUD_Sequence.h
@@ -68,6 +68,16 @@ extern AUD_API void AUD_Sequence_remove(AUD_Sound* sequence, AUD_SequenceEntry*
* Writes animation data to a sequence.
* \param sequence The sound scene.
* \param type The type of animation data.
+ * \param frame_start Start of the frame range.
+ * \param frame_end End of the frame range.
+ * \param data The data to write.
+ */
+AUD_API void AUD_SequenceEntry_setConstantRangeAnimationData(AUD_SequenceEntry* entry, AUD_AnimateablePropertyType type, int frame_start, int frame_end, float* data);
+
+/**
+ * Writes animation data to a sequenced entry.
+ * \param entry The sequenced entry.
+ * \param type The type of animation data.
* \param frame The frame this data is for.
* \param data The data to write.
* \param animated Whether the attribute is animated.
diff --git a/include/sequence/AnimateableProperty.h b/include/sequence/AnimateableProperty.h
index 2c3fcf2..d14990b 100644
--- a/include/sequence/AnimateableProperty.h
+++ b/include/sequence/AnimateableProperty.h
@@ -112,6 +112,14 @@ public:
*/
void write(const float* data, int position, int count);
+ /**
+ * Fills the properties frame range with constant value and marks it animated.
+ * \param data The new value.
+ * \param position_start The start position in the animation in frames.
+ * \param position_end The end position in the animation in frames.
+ */
+ void writeConstantRange(const float* data, int position_start, int position_end);
+
/**
* Reads the properties value.
* \param position The position in the animation in frames.
diff --git a/include/sequence/SequenceData.h b/include/sequence/SequenceData.h
index c3380e6..c19c82c 100644
--- a/include/sequence/SequenceData.h
+++ b/include/sequence/SequenceData.h
@@ -198,12 +198,13 @@ public:
/**
* Adds a new entry to the scene.
* \param sound The sound this entry should play.
+ * \param sequence_data Reference to sequence_data. Mainly needed to get the FPS of the scene.
* \param begin The start time.
* \param end The end time or a negative value if determined by the sound.
* \param skip How much seconds should be skipped at the beginning.
* \return The entry added.
*/
- std::shared_ptr<SequenceEntry> add(std::shared_ptr<ISound> sound, double begin, double end, double skip);
+ std::shared_ptr<SequenceEntry> add(std::shared_ptr<ISound> sound, std::shared_ptr<SequenceData> sequence_data, double begin, double end, double skip);
/**
* Removes an entry from the scene.
diff --git a/include/sequence/SequenceEntry.h b/include/sequence/SequenceEntry.h
index b8e9f11..47b9004 100644
--- a/include/sequence/SequenceEntry.h
+++ b/include/sequence/SequenceEntry.h
@@ -23,6 +23,7 @@
*/
#include "sequence/AnimateableProperty.h"
+#include "sequence/SequenceData.h"
#include "util/ILockable.h"
#include <mutex>
@@ -63,6 +64,9 @@ private:
/// How many seconds are skipped at the beginning.
double m_skip;
+ /// reference to sequence_data. Mainly needed to get the FPS of the scene.
+ std::shared_ptr<SequenceData> m_sequence_data;
+
/// Whether the entry is muted.
bool m_muted;
@@ -122,9 +126,10 @@ public:
* \param begin The start time.
* \param end The end time or a negative value if determined by the sound.
* \param skip How much seconds should be skipped at the beginning.
+ * \param sequence_data Reference to sequence_data. Mainly needed to get the FPS of the scene.
* \param id The ID of the entry.
*/
- SequenceEntry(std::shared_ptr<ISound> sound, double begin, double end, double skip, int id);
+ SequenceEntry(std::shared_ptr<ISound> sound, double begin, double end, double skip, std::shared_ptr<SequenceData> sequence_data, int id);
virtual ~SequenceEntry();
/**
diff --git a/src/sequence/AnimateableProperty.cpp b/src/sequence/AnimateableProperty.cpp
index 306ba8e..c9c2a35 100644
--- a/src/sequence/AnimateableProperty.cpp
+++ b/src/sequence/AnimateableProperty.cpp
@@ -65,6 +65,19 @@ void AnimateableProperty::write(const float* data)
std::memcpy(getBuffer(), data, m_count * sizeof(float));
}
+void AnimateableProperty::writeConstantRange(const float* data, int position_start, int position_end)
+{
+ assureSize(position_end * m_count * sizeof(float), true);
+ float* buffer = getBuffer();
+
+ for(int i = position_start; i < position_end; i++)
+ {
+ std::memcpy(buffer + i * m_count, data, m_count * sizeof(float));
+ }
+
+ m_isAnimated = true;
+}
+
void AnimateableProperty::write(const float* data, int position, int count)
{
std::lock_guard<std::recursive_mutex> lock(m_mutex);
diff --git a/src/sequence/Sequence.cpp b/src/sequence/Sequence.cpp
index ab7e6e7..3beb225 100644
--- a/src/sequence/Sequence.cpp
+++ b/src/sequence/Sequence.cpp
@@ -92,7 +92,7 @@ AnimateableProperty* Sequence::getAnimProperty(AnimateablePropertyType type)
std::shared_ptr<SequenceEntry> Sequence::add(std::shared_ptr<ISound> sound, double begin, double end, double skip)
{
- return m_sequence->add(sound, begin, end, skip);
+ return m_sequence->add(sound, m_sequence, begin, end, skip);
}
void Sequence::remove(std::shared_ptr<SequenceEntry> entry)
diff --git a/src/sequence/SequenceData.cpp b/src/sequence/SequenceData.cpp
index 288f0bd..47d57da 100644
--- a/src/sequence/SequenceData.cpp
+++ b/src/sequence/SequenceData.cpp
@@ -149,11 +149,11 @@ AnimateableProperty* SequenceData::getAnimProperty(AnimateablePropertyType type)
}
}
-std::shared_ptr<SequenceEntry> SequenceData::add(std::shared_ptr<ISound> sound, double begin, double end, double skip)
+std::shared_ptr<SequenceEntry> SequenceData::add(std::shared_ptr<ISound> sound, std::shared_ptr<SequenceData> sequence_data, double begin, double end, double skip)
{
std::lock_guard<std::recursive_mutex> lock(m_mutex);
- std::shared_ptr<SequenceEntry> entry = std::shared_ptr<SequenceEntry>(new SequenceEntry(sound, begin, end, skip, m_id++));
+ std::shared_ptr<SequenceEntry> entry = std::shared_ptr<SequenceEntry>(new SequenceEntry(sound, begin, end, skip, sequence_data, m_id++));
m_entries.push_back(entry);
m_entry_status++;
diff --git a/src/sequence/SequenceEntry.cpp b/src/sequence/SequenceEntry.cpp
index b63bdd2..0fbab21 100644
--- a/src/sequence/SequenceEntry.cpp
+++ b/src/sequence/SequenceEntry.cpp
@@ -22,7 +22,7 @@
AUD_NAMESPACE_BEGIN
-SequenceEntry::SequenceEntry(std::shared_ptr<ISound> sound, double begin, double end, double skip, int id) :
+SequenceEntry::SequenceEntry(std::shared_ptr<ISound> sound, double begin, double end, double skip, std::shared_ptr<SequenceData> sequence_data, int id) :
m_status(0),
m_pos_status(1),
m_sound_status(0),
@@ -31,6 +31,7 @@ SequenceEntry::SequenceEntry(std::shared_ptr<ISound> sound, double begin, double
m_begin(begin),
m_end(end),
m_skip(skip),
+ m_sequence_data(sequence_data),
m_muted(false),
m_relative(true),
m_volume_max(1.0f),
diff --git a/src/sequence/SequenceHandle.cpp b/src/sequence/SequenceHandle.cpp
index fca4e80..55384ba 100644
--- a/src/sequence/SequenceHandle.cpp
+++ b/src/sequence/SequenceHandle.cpp
@@ -241,10 +241,38 @@ bool SequenceHandle::seek(double position)
return false;
std::lock_guard<ILockable> lock(*m_entry);
- double seekpos = position - m_entry->m_begin;
- if(seekpos < 0)
- seekpos = 0;
- seekpos += m_entry->m_skip;
+
+ double seek_frame = (position - m_entry->m_begin) * m_entry->m_sequence_data->getFPS();
+
+ if(seek_frame < 0)
+ seek_frame = 0;
+
+ seek_frame += m_entry->m_skip * m_entry->m_sequence_data->getFPS();
+
+ AnimateableProperty* pitch_property = m_entry->getAnimProperty(AP_PITCH);
+
+ double target_frame = 0;
+
+ if(pitch_property != nullptr)
+ {
+ int frame_start = (m_entry->m_begin - m_entry->m_skip) * m_entry->m_sequence_data->getFPS();
+
+ for(int i = 0; seek_frame > 0; i++)
+ {
+ float pitch;
+ pitch_property->read(frame_start + i, &pitch);
+ const double factor = seek_frame > 1.0 ? 1.0 : seek_frame;
+ target_frame += pitch * factor;
+ seek_frame--;
+ }
+ }
+ else
+ {
+ target_frame = seek_frame;
+ }
+
+ double seekpos = target_frame / m_entry->m_sequence_data->getFPS();
+
m_handle->setPitch(1.0f);
m_handle->seek(seekpos);
--
2.42.1
--
From 5f745ff3707552b090ea19c3839c70ca68b5429d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20M=C3=BCller?= <nexyon@gmail.com>
Date: Mon, 24 Jul 2023 16:18:02 +0200
Subject: [PATCH 4/4] Bugfix for reading an animated property with a negative
time value.
This can now happen in SequenceHandle::seek.
---
src/sequence/AnimateableProperty.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/sequence/AnimateableProperty.cpp b/src/sequence/AnimateableProperty.cpp
index c9c2a35..b38827f 100644
--- a/src/sequence/AnimateableProperty.cpp
+++ b/src/sequence/AnimateableProperty.cpp
@@ -184,6 +184,12 @@ void AnimateableProperty::read(float position, float* out)
t = 0;
}
+ if(position < 0)
+ {
+ position = 0;
+ t = 0;
+ }
+
if(t == 0)
{
std::memcpy(out, getBuffer() + int(std::floor(position)) * m_count, m_count * sizeof(float));
--
2.42.1