Enabling AV-sync again. You can now choose between No sync, Frame Dropping or AV...
authorJoerg Mueller <nexyon@gmail.com>
Fri, 19 Feb 2010 12:20:29 +0000 (12:20 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Fri, 19 Feb 2010 12:20:29 +0000 (12:20 +0000)
release/scripts/ui/space_time.py
source/blender/blenkernel/BKE_sound.h
source/blender/blenkernel/intern/sound.c
source/blender/editors/include/ED_screen_types.h
source/blender/editors/screen/screen_ops.c
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_scene.c

index 4ef2c3797adfbac6124cb2380da734ced76137c6..9ec4a4446d5a090489c1f2d76d520ed59d95cf66 100644 (file)
@@ -72,7 +72,7 @@ class TIME_HT_header(bpy.types.Header):
             subsub = row.row()
             subsub.prop(tools, "record_with_nla", toggle=True)
 
-        layout.prop(scene, "sync_audio", text="AV-sync", toggle=True, icon='SPEAKER')
+        layout.prop(scene, "sync_mode", text="")
 
         layout.separator()
 
@@ -152,6 +152,7 @@ class TIME_MT_playback(bpy.types.Menu):
 
         layout.separator()
 
+        layout.prop(scene, "frame_drop", text="Frame Dropping")
         layout.prop(scene, "sync_audio", text="AV-sync", icon='SPEAKER')
         layout.prop(scene, "mute_audio")
         layout.prop(scene, "scrub_audio")
index f44ce47ebccfe8ab7aebe7389881997e012db841..97a2adb6e6b28b9fca516dc80f47d4873695df79 100644 (file)
@@ -86,6 +86,8 @@ void sound_stop_scene(struct Scene *scene);
 
 void sound_seek_scene(struct bContext *C);
 
+float sound_sync_scene(struct Scene *scene);
+
 int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length);
 
 #endif
index 35cedbd2d5337265a134e7392df5be342a2e2dab..4e08a52d992a0d3526a3ad8b1a528577e2b98a6d 100644 (file)
@@ -394,6 +394,11 @@ void sound_seek_scene(struct bContext *C)
        AUD_unlock();
 }
 
+float sound_sync_scene(struct Scene *scene)
+{
+       return AUD_getPosition(scene->sound_scene_handle);
+}
+
 int sound_read_sound_buffer(bSound* sound, float* buffer, int length)
 {
        return AUD_readSound(sound->cache, buffer, length);
index cff454d5bff0e2989cd1995c115cf05fab532947..8580dcc33c99a5267225f63744911637321941b4 100644 (file)
@@ -47,7 +47,7 @@ enum {
        ANIMPLAY_FLAG_JUMPED            = (1<<1),
                /* drop frames as needed to maintain framerate */
        ANIMPLAY_FLAG_SYNC                      = (1<<2),
-               /* don't drop frames (and ignore AUDIO_SYNC flag) */
+               /* don't drop frames (and ignore SCE_FRAME_DROP flag) */
        ANIMPLAY_FLAG_NO_SYNC           = (1<<3),
 };
 
index 728ce622d9b37b3e367365811a2fd3412fdba737..fae7e7b6c40957846d9fe6cf2e77c4382714cede 100644 (file)
@@ -2426,23 +2426,30 @@ static int screen_animation_step(bContext *C, wmOperator *op, wmEvent *event)
                /* sync, don't sync, or follow scene setting */
                if(sad->flag & ANIMPLAY_FLAG_SYNC) sync= 1;
                else if(sad->flag & ANIMPLAY_FLAG_NO_SYNC) sync= 0;
-               else sync= (scene->audio.flag & AUDIO_SYNC);
+               else sync= (scene->flag & SCE_FRAME_DROP);
                
-               if(sync) {
-                       /* skip frames */
-                       int step = floor(wt->duration * FPS);
-                       if(sad->flag & ANIMPLAY_FLAG_REVERSE) // XXX does this option work with audio?
-                               scene->r.cfra -= step;
-                       else
-                               scene->r.cfra += step;
-                       wt->duration -= ((float)step)/FPS;
+               if((scene->audio.flag & AUDIO_SYNC) && !(sad->flag & ANIMPLAY_FLAG_REVERSE))
+               {
+                       scene->r.cfra = floor(sound_sync_scene(scene) * FPS);
                }
-               else {
-                       /* one frame +/- */
-                       if(sad->flag & ANIMPLAY_FLAG_REVERSE)
-                               scene->r.cfra--;
-                       else
-                               scene->r.cfra++;
+               else
+               {
+                       if(sync) {
+                               int step = floor(wt->duration * FPS);
+                               /* skip frames */
+                               if(sad->flag & ANIMPLAY_FLAG_REVERSE)
+                                       scene->r.cfra -= step;
+                               else
+                                       scene->r.cfra += step;
+                               wt->duration -= ((float)step)/FPS;
+                       }
+                       else {
+                               /* one frame +/- */
+                               if(sad->flag & ANIMPLAY_FLAG_REVERSE)
+                                       scene->r.cfra--;
+                               else
+                                       scene->r.cfra++;
+                       }
                }
                
                /* reset 'jumped' flag before checking if we need to jump... */
index c408fd69f4fc07b5d9d6eabd38b90dbe1242e655..2bea683b392e227d463628cea5320b74949ce983 100644 (file)
@@ -1067,6 +1067,7 @@ typedef struct Scene {
 #define SCE_DS_SELECTED                        (1<<0)
 #define SCE_DS_COLLAPSED               (1<<1)
 #define SCE_NLA_EDIT_ON                        (1<<2)
+#define SCE_FRAME_DROP                 (1<<3)
 
 
        /* return flag next_object function */
index 2d5310971db58bda175a42b8b5b568e147cadb11..c947edd7d6d990f56c2754ea47788e063de07247 100644 (file)
@@ -704,6 +704,32 @@ static void rna_Scene_simplify_update(Main *bmain, Scene *scene, PointerRNA *ptr
        WM_main_add_notifier(NC_GEOM|ND_DATA, NULL);
 }
 
+static int rna_Scene_sync_mode_get(PointerRNA *ptr)
+{
+       Scene *scene= (Scene*)ptr->data;
+       if(scene->audio.flag & AUDIO_SYNC)
+               return AUDIO_SYNC;
+       return scene->flag & SCE_FRAME_DROP;
+}
+
+static void rna_Scene_sync_mode_set(PointerRNA *ptr, int value)
+{
+       Scene *scene= (Scene*)ptr->data;
+
+       if(value == AUDIO_SYNC)
+               scene->audio.flag |= AUDIO_SYNC;
+       else if(value == SCE_FRAME_DROP)
+       {
+               scene->audio.flag &= ~AUDIO_SYNC;
+               scene->flag |= SCE_FRAME_DROP;
+       }
+       else
+       {
+               scene->audio.flag &= ~AUDIO_SYNC;
+               scene->flag &= ~SCE_FRAME_DROP;
+       }
+}
+
 #else
 
 static void rna_def_transform_orientation(BlenderRNA *brna)
@@ -2600,6 +2626,12 @@ void RNA_def_scene(BlenderRNA *brna)
                {6, "EXPONENT_CLAMPED", 0, "Exponent Clamped", "Exponent distance model with clamping"},
                {0, NULL, 0, NULL, NULL}};
 
+       static EnumPropertyItem sync_mode_items[] = {
+               {0, "NONE", 0, "No Sync", "Do not sync, play every frame"},
+               {SCE_FRAME_DROP, "FRAME_DROP", 0, "Frame Dropping", "Drop frames if playback is too slow"},
+               {AUDIO_SYNC, "AUDIO_SYNC", 0, "AV-sync", "Sync to audio playback, dropping frames"},
+               {0, NULL, 0, NULL, NULL}};
+
        /* Struct definition */
        srna= RNA_def_struct(brna, "Scene", "ID");
        RNA_def_struct_ui_text(srna, "Scene", "Scene consisting objects and defining time and render related settings");
@@ -2725,7 +2757,19 @@ void RNA_def_scene(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "NLA TweakMode", "Indicates whether there is any action referenced by NLA being edited. Strictly read-only");
        RNA_def_property_update(prop, NC_SPACE|ND_SPACE_GRAPH, NULL);
        
-       
+       /* Frame dropping flag for playback and sync enum */
+       prop= RNA_def_property(srna, "frame_drop", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", SCE_FRAME_DROP);
+       RNA_def_property_ui_text(prop, "Frame Dropping", "Play back dropping frames if frame display is too slow");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
+
+       prop= RNA_def_property(srna, "sync_mode", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_funcs(prop, "rna_Scene_sync_mode_get", "rna_Scene_sync_mode_set", NULL);
+       RNA_def_property_enum_items(prop, sync_mode_items);
+       RNA_def_property_ui_text(prop, "Sync Mode", "How to sync playback");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
+
+
        /* Nodes (Compositing) */
        prop= RNA_def_property(srna, "nodetree", PROP_POINTER, PROP_NONE);
        RNA_def_property_ui_text(prop, "Node Tree", "Compositing node tree");