Blender  V3.3
sequencer/intern/sound.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved.
3  * 2003-2009 Blender Foundation.
4  * 2005-2006 Peter Schlaile <peter [at] schlaile [dot] de> */
5 
10 #include <math.h>
11 
12 #include "DNA_scene_types.h"
13 #include "DNA_sequence_types.h"
14 #include "DNA_sound_types.h"
15 
16 #include "BLI_listbase.h"
17 #include "BLI_utildefines.h"
18 
19 #include "BKE_main.h"
20 #include "BKE_scene.h"
21 #include "BKE_sound.h"
22 
23 #include "SEQ_sound.h"
24 #include "SEQ_time.h"
25 
26 #include "sequencer.h"
27 #include "strip_time.h"
28 
29 /* Unlike _update_sound_ funcs, these ones take info from audaspace to update sequence length! */
30 #ifdef WITH_AUDASPACE
31 static bool sequencer_refresh_sound_length_recursive(Main *bmain, Scene *scene, ListBase *seqbase)
32 {
33  Sequence *seq;
34  bool changed = false;
35 
36  for (seq = seqbase->first; seq; seq = seq->next) {
37  if (seq->type == SEQ_TYPE_META) {
38  if (sequencer_refresh_sound_length_recursive(bmain, scene, &seq->seqbase)) {
39  changed = true;
40  }
41  }
42  else if (seq->type == SEQ_TYPE_SOUND_RAM && seq->sound) {
43  SoundInfo info;
44  if (!BKE_sound_info_get(bmain, seq->sound, &info)) {
45  continue;
46  }
47 
48  int old = seq->len;
49  float fac;
50 
51  seq->len = MAX2(1, round((info.length - seq->sound->offset_time) * FPS));
52  fac = (float)seq->len / (float)old;
53  old = seq->startofs;
54  seq->startofs *= fac;
55  seq->endofs *= fac;
56  seq->start += (old - seq->startofs); /* So that visual/"real" start frame does not change! */
57 
58  changed = true;
59  }
60  }
61  return changed;
62 }
63 #endif
64 
66 {
67 #ifdef WITH_AUDASPACE
68  if (scene->ed) {
69  sequencer_refresh_sound_length_recursive(bmain, scene, &scene->ed->seqbase);
70  }
71 #else
72  UNUSED_VARS(bmain, scene);
73 #endif
74 }
75 
77 {
78  Editing *ed = scene->ed;
79 
80  if (ed) {
81  Sequence *seq;
82 
83  for (seq = ed->seqbase.first; seq; seq = seq->next) {
84  if (seq->type == SEQ_TYPE_META) {
86  }
87  else if (ELEM(seq->type, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SCENE)) {
89  }
90  }
91  }
92 }
93 
95 {
96  if (seq->type == SEQ_TYPE_SCENE) {
97  if (seq->scene && seq->scene_sound) {
98  /* We have to take into account start frame of the sequence's scene! */
99  int startofs = seq->startofs + seq->anim_startofs + seq->scene->r.sfra;
100 
102  seq->scene_sound,
105  startofs,
106  0.0);
107  }
108  }
109  else {
111  }
112  /* mute is set in seq_update_muting_recursive */
113 }
114 
115 static void seq_update_sound_recursive(Scene *scene, ListBase *seqbasep, bSound *sound)
116 {
117  Sequence *seq;
118 
119  for (seq = seqbasep->first; seq; seq = seq->next) {
120  if (seq->type == SEQ_TYPE_META) {
122  }
123  else if (seq->type == SEQ_TYPE_SOUND_RAM) {
124  if (seq->scene_sound && sound == seq->sound) {
126  }
127  }
128  }
129 }
130 
132 {
133  if (scene->ed) {
135  }
136 }
137 
138 float SEQ_sound_pitch_get(const Scene *scene, const Sequence *seq)
139 {
140  Sequence *meta_parent = seq_sequence_lookup_meta_by_seq(scene, seq);
141  if (meta_parent != NULL) {
142  return seq->speed_factor * SEQ_sound_pitch_get(scene, meta_parent);
143  }
144  return seq->speed_factor;
145 }
typedef float(TangentPoint)[2]
bool BKE_sound_info_get(struct Main *main, struct bSound *sound, SoundInfo *sound_info)
void BKE_sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence)
void BKE_sound_move_scene_sound(const struct Scene *scene, void *handle, int startframe, int endframe, int frameskip, double audio_offset)
void BKE_sound_update_scene_sound(void *handle, struct bSound *sound)
#define UNUSED_VARS(...)
#define MAX2(a, b)
#define ELEM(...)
#define FPS
@ SEQ_TYPE_SOUND_RAM
@ SEQ_TYPE_META
@ SEQ_TYPE_SCENE
Scene scene
Sequence * seq_sequence_lookup_meta_by_seq(const Scene *scene, const Sequence *key)
static void seq_update_sound_recursive(Scene *scene, ListBase *seqbasep, bSound *sound)
void SEQ_sound_update_bounds_all(Scene *scene)
void SEQ_sound_update(Scene *scene, bSound *sound)
float SEQ_sound_pitch_get(const Scene *scene, const Sequence *seq)
void SEQ_sound_update_bounds(Scene *scene, Sequence *seq)
void SEQ_sound_update_length(Main *bmain, Scene *scene)
void seq_update_sound_bounds_recursive(const Scene *scene, Sequence *metaseq)
Definition: strip_time.c:140
int SEQ_time_left_handle_frame_get(const Scene *UNUSED(scene), const Sequence *seq)
Definition: strip_time.c:506
int SEQ_time_right_handle_frame_get(const Scene *scene, const Sequence *seq)
Definition: strip_time.c:515
ListBase seqbase
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
struct Editing * ed
struct RenderData r
struct Scene * scene
void * scene_sound
ListBase seqbase
struct bSound * sound
struct Sequence * next
float length
Definition: BKE_sound.h:84
double offset_time