OpenShot Library | libopenshot  1.0.0
BeatSync.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2026 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_BEAT_SYNC_EFFECT_H
14 #define OPENSHOT_BEAT_SYNC_EFFECT_H
15 
16 #include "../AnimatedCurve.h"
17 #include "../Color.h"
18 #include "../EffectBase.h"
19 #include "../Frame.h"
20 #include "../Json.h"
21 #include "../KeyFrame.h"
22 
23 #include <memory>
24 #include <string>
25 
26 namespace openshot
27 {
28  class BeatSync : public EffectBase
29  {
30  private:
31  void init_effect_details();
32  float envelope_; // persistent IIR envelope state
33  int64_t last_frame_; // detects seeks so we can reset envelope
34 
35  public:
36  Color low_color; // generated color at minimum response
37  Color high_color; // generated color at maximum response
38  Keyframe intensity; // audio gain multiplier (0.0–10.0)
39  Keyframe threshold; // energy floor below which nothing happens (0.0–1.0)
40  Keyframe attack_ms; // envelope rise time in milliseconds
41  Keyframe decay_ms; // envelope fall time in milliseconds
42  Keyframe frequency_low; // normalized frequency floor (0=20Hz, 1=20kHz)
43  Keyframe frequency_high; // normalized frequency ceiling (0=20Hz, 1=20kHz)
44  bool invert; // flip: silence = max effect, loud = no effect
45  AnimatedCurve response_curve; // maps normalized audio response to color blend
46 
47  BeatSync();
49 
50  std::shared_ptr<openshot::Frame> GetFrame(int64_t frame_number) override { return GetFrame(std::make_shared<openshot::Frame>(), frame_number); }
51  std::shared_ptr<openshot::Frame> GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number) override;
52 
53  std::string Json() const override;
54  void SetJson(const std::string value) override;
55  Json::Value JsonValue() const override;
56  void SetJsonValue(const Json::Value root) override;
57  std::string PropertiesJSON(int64_t requested_frame) const override;
58  };
59 }
60 
61 #endif
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number) override
This method is required for all derived classes of ClipBase, and returns a new openshot::Frame object...
Definition: BeatSync.h:50
std::string PropertiesJSON(int64_t requested_frame) const override
Definition: BeatSync.cpp:255
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: BeatSync.cpp:240
Keyframe frequency_low
Definition: BeatSync.h:42
Keyframe frequency_high
Definition: BeatSync.h:43
Keyframe intensity
Definition: BeatSync.h:38
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: BeatSync.cpp:231
Keyframe attack_ms
Definition: BeatSync.h:40
Keyframe threshold
Definition: BeatSync.h:39
AnimatedCurve response_curve
Definition: BeatSync.h:45
std::string Json() const override
Generate JSON string of this object.
Definition: BeatSync.cpp:211
Keyframe decay_ms
Definition: BeatSync.h:41
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: BeatSync.cpp:215
This class represents a color (used on the timeline and clips)
Definition: Color.h:27
This abstract class is the base class, used by all effects in libopenshot.
Definition: EffectBase.h:57
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Definition: KeyFrame.h:53
This namespace is the default namespace for all code in the openshot library.
Definition: AnimatedCurve.h:24