diff options
author | Joerg Mueller <nexyon@gmail.com> | 2010-02-21 21:01:41 +0300 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2010-02-21 21:01:41 +0300 |
commit | 38ef2df8f72fe3289beb42284b1f2f3162636519 (patch) | |
tree | 6109eccb897749f050d78de1e8e581c3dd360aa1 /source | |
parent | ee12a5368a0018467bb34292f3e4f063592dc830 (diff) |
2.5 Audio:
* Jack Transport support!
* Minor sequencer audio corrections.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_sound.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/sequencer.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/sound.c | 77 | ||||
-rw-r--r-- | source/blender/editors/include/ED_screen.h | 1 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 45 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_userdef.c | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 23 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 8 |
8 files changed, 128 insertions, 36 deletions
diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h index 97a2adb6e6b..fa035d62d62 100644 --- a/source/blender/blenkernel/BKE_sound.h +++ b/source/blender/blenkernel/BKE_sound.h @@ -38,7 +38,7 @@ struct ListBase; struct Main; struct Sequence; -void sound_init(); +void sound_init(struct Main *main); void sound_exit(); @@ -88,6 +88,8 @@ void sound_seek_scene(struct bContext *C); float sound_sync_scene(struct Scene *scene); +int sound_scene_playing(struct Scene *scene); + int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length); #endif diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 2ee913a6b6b..98dbf83f032 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -614,7 +614,7 @@ void reload_sequence_new_file(Scene *scene, Sequence * seq) } seq->strip->len = seq->len; } else if (seq->type == SEQ_SOUND) { - seq->len = AUD_getInfo(seq->sound->playback_handle).length * FPS; + seq->len = ceil(AUD_getInfo(seq->sound->playback_handle).length * FPS); seq->len -= seq->anim_startofs; seq->len -= seq->anim_endofs; if (seq->len < 0) { @@ -3848,7 +3848,7 @@ Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo /* basic defaults */ seq->strip= strip= MEM_callocN(sizeof(Strip), "strip"); - strip->len = seq->len = (int) (info.length * FPS); + strip->len = seq->len = ceil(info.length * FPS); strip->us= 1; strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem"); diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 4e08a52d992..a1a6880569b 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -39,6 +39,26 @@ static int force_device = -1; +static void sound_sync_callback(void* data, int mode, float time) +{ + struct Main* main = (struct Main*)data; + struct Scene* scene; + + scene = main->scene.first; + while(scene) + { + if(scene->audio.flag & AUDIO_SYNC) + { + if(mode) + sound_play_scene(scene); + else + sound_stop_scene(scene); + AUD_seek(scene->sound_scene_handle, time); + } + scene = scene->id.next; + } +} + int sound_define_from_str(char *str) { if (BLI_strcaseeq(str, "NULL")) @@ -58,7 +78,7 @@ void sound_force_device(int device) force_device = device; } -void sound_init() +void sound_init(struct Main *main) { AUD_DeviceSpecs specs; int device, buffersize; @@ -86,6 +106,7 @@ void sound_init() if(!AUD_init(device, specs, buffersize)) AUD_init(AUD_NULL_DEVICE, specs, buffersize); + AUD_setSyncCallback(sound_sync_callback, main); } void sound_exit() @@ -353,14 +374,24 @@ void sound_start_play_scene(struct Scene *scene) void sound_play_scene(struct Scene *scene) { + AUD_Status status; AUD_lock(); - if(!scene->sound_scene_handle || AUD_getStatus(scene->sound_scene_handle) == AUD_STATUS_INVALID) + status = AUD_getStatus(scene->sound_scene_handle); + + if(status == AUD_STATUS_INVALID) sound_start_play_scene(scene); - AUD_seek(scene->sound_scene_handle, CFRA / FPS); AUD_setLoop(scene->sound_scene_handle, -1, -1); - AUD_resume(scene->sound_scene_handle); + + if(status != AUD_STATUS_PLAYING) + { + AUD_seek(scene->sound_scene_handle, CFRA / FPS); + AUD_resume(scene->sound_scene_handle); + } + + if(scene->audio.flag & AUDIO_SYNC) + AUD_startPlayback(); AUD_unlock(); } @@ -368,15 +399,21 @@ void sound_play_scene(struct Scene *scene) void sound_stop_scene(struct Scene *scene) { AUD_pause(scene->sound_scene_handle); + + if(scene->audio.flag & AUDIO_SYNC) + AUD_stopPlayback(); } void sound_seek_scene(struct bContext *C) { struct Scene *scene = CTX_data_scene(C); + AUD_Status status; AUD_lock(); - if(!scene->sound_scene_handle || AUD_getStatus(scene->sound_scene_handle) == AUD_STATUS_INVALID) + status = AUD_getStatus(scene->sound_scene_handle); + + if(status == AUD_STATUS_INVALID) { sound_start_play_scene(scene); AUD_pause(scene->sound_scene_handle); @@ -385,21 +422,43 @@ void sound_seek_scene(struct bContext *C) if(scene->audio.flag & AUDIO_SCRUB && !CTX_wm_screen(C)->animtimer) { AUD_setLoop(scene->sound_scene_handle, -1, 1 / FPS); - AUD_seek(scene->sound_scene_handle, CFRA / FPS); + if(scene->audio.flag & AUDIO_SYNC) + AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS); + else + AUD_seek(scene->sound_scene_handle, CFRA / FPS); AUD_resume(scene->sound_scene_handle); } else - AUD_seek(scene->sound_scene_handle, CFRA / FPS); + { + if(scene->audio.flag & AUDIO_SYNC) + AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS); + else + { + if(status == AUD_STATUS_PLAYING) + AUD_seek(scene->sound_scene_handle, CFRA / FPS); + } + } AUD_unlock(); } float sound_sync_scene(struct Scene *scene) { - return AUD_getPosition(scene->sound_scene_handle); + if(scene->audio.flag & AUDIO_SYNC) + return AUD_getSequencerPosition(scene->sound_scene_handle); + else + return AUD_getPosition(scene->sound_scene_handle); +} + +int sound_scene_playing(struct Scene *scene) +{ + if(scene->audio.flag & AUDIO_SYNC) + return AUD_doesPlayback(); + else + return -1; } -int sound_read_sound_buffer(bSound* sound, float* buffer, int length) +int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length) { return AUD_readSound(sound->cache, buffer, length); } diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 5121308c745..aae354b79fa 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -108,6 +108,7 @@ void ED_screen_new_window(struct bContext *C, struct rcti *position, int type); /* anim */ void ED_update_for_newframe(const struct bContext *C, int mute); void ED_refresh_viewport_fps(struct bContext *C); +int ED_screen_animation_play(struct bContext *C, int sync, int mode); /* screen keymaps */ void ED_operatortypes_screen(void); diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index fae7e7b6c40..0c958654722 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -2537,11 +2537,11 @@ static void SCREEN_OT_animation_step(wmOperatorType *ot) /* ****************** anim player, starts or ends timer ***************** */ /* toggle operator */ -static int screen_animation_play(bContext *C, wmOperator *op, wmEvent *event) +int ED_screen_animation_play(bContext *C, int sync, int mode) { bScreen *screen= CTX_wm_screen(C); struct Scene* scene = CTX_data_scene(C); - + if(screen->animtimer) { /* stop playback now */ ED_screen_animation_timer(C, 0, 0, 0); @@ -2549,45 +2549,52 @@ static int screen_animation_play(bContext *C, wmOperator *op, wmEvent *event) } else { ScrArea *sa= CTX_wm_area(C); - int mode= (RNA_boolean_get(op->ptr, "reverse")) ? -1 : 1; - int sync= -1; + if(mode == 1) // XXX only play audio forwards!? sound_play_scene(scene); - - if(RNA_property_is_set(op->ptr, "sync")) - sync= (RNA_boolean_get(op->ptr, "sync")); - + /* timeline gets special treatment since it has it's own menu for determining redraws */ if ((sa) && (sa->spacetype == SPACE_TIME)) { SpaceTime *stime= (SpaceTime *)sa->spacedata.first; - + ED_screen_animation_timer(C, stime->redraws, sync, mode); - + /* update region if TIME_REGION was set, to leftmost 3d window */ ED_screen_animation_timer_update(screen, stime->redraws); } else { int redraws = TIME_REGION|TIME_ALL_3D_WIN; - + /* XXX - would like a better way to deal with this situation - Campbell */ - if((sa) && (sa->spacetype == SPACE_SEQ)) { + if((!sa) || (sa->spacetype == SPACE_SEQ)) { redraws |= TIME_SEQ; } - + ED_screen_animation_timer(C, redraws, sync, mode); - + if(screen->animtimer) { wmTimer *wt= screen->animtimer; ScreenAnimData *sad= wt->customdata; - + sad->ar= CTX_wm_region(C); } } } - + return OPERATOR_FINISHED; } +static int screen_animation_play_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + int mode= (RNA_boolean_get(op->ptr, "reverse")) ? -1 : 1; + int sync= -1; + + if(RNA_property_is_set(op->ptr, "sync")) + sync= (RNA_boolean_get(op->ptr, "sync")); + + return ED_screen_animation_play(C, sync, mode); +} + static void SCREEN_OT_animation_play(wmOperatorType *ot) { /* identifiers */ @@ -2596,12 +2603,12 @@ static void SCREEN_OT_animation_play(wmOperatorType *ot) ot->idname= "SCREEN_OT_animation_play"; /* api callbacks */ - ot->invoke= screen_animation_play; + ot->invoke= screen_animation_play_invoke; ot->poll= ED_operator_screenactive; RNA_def_boolean(ot->srna, "reverse", 0, "Play in Reverse", "Animation is played backwards"); - RNA_def_boolean(ot->srna, "sync", 0, "Sync", "Drop frames to maintain framerate and stay in sync with audio."); + RNA_def_boolean(ot->srna, "sync", 0, "Sync", "Drop frames to maintain framerate"); } static int screen_animation_cancel(bContext *C, wmOperator *op, wmEvent *event) @@ -2619,7 +2626,7 @@ static int screen_animation_cancel(bContext *C, wmOperator *op, wmEvent *event) WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene); /* call the other "toggling" operator to clean up now */ - return screen_animation_play(C, op, event); + return screen_animation_play_invoke(C, op, event); } return OPERATOR_PASS_THROUGH; diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 7cb7e69f047..ee2c96bcbd2 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -176,7 +176,7 @@ static PointerRNA rna_UserDef_system_get(PointerRNA *ptr) static void rna_UserDef_audio_update(Main *bmain, Scene *scene, PointerRNA *ptr) { - sound_init(); + sound_init(bmain); } static void rna_UserDef_weight_color_update(Main *bmain, Scene *scene, PointerRNA *ptr) diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 4b07aa82239..74679ce89a6 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -50,6 +50,7 @@ #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_utildefines.h" +#include "BKE_sound.h" #include "ED_fileselect.h" #include "ED_info.h" @@ -1530,6 +1531,28 @@ void wm_event_do_handlers(bContext *C) if( win->screen==NULL ) wm_event_free_all(win); + else + { + if(win->screen->scene) + { + int playing = sound_scene_playing(win->screen->scene); + if(playing != -1) + { + if(((playing == 1) && (!win->screen->animtimer)) || ((playing == 0) && (win->screen->animtimer))) + { + CTX_wm_window_set(C, win); + CTX_wm_screen_set(C, win->screen); + CTX_data_scene_set(C, win->screen->scene); + + ED_screen_animation_play(C, -1, 1); + + CTX_data_scene_set(C, NULL); + CTX_wm_screen_set(C, NULL); + CTX_wm_window_set(C, NULL); + } + } + } + } while( (event= win->queue.first) ) { int action = WM_HANDLER_CONTINUE; diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index efa8aa7e819..16776517e40 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -236,11 +236,11 @@ static void wm_window_match_do(bContext *C, ListBase *oldwmlist) } /* in case UserDef was read, we re-initialize all, and do versioning */ -static void wm_init_userdef() +static void wm_init_userdef(bContext *C) { UI_init_userdef(); MEM_CacheLimiter_set_maximum(U.memcachelimit * 1024 * 1024); - sound_init(); + sound_init(CTX_data_main(C)); } void WM_read_file(bContext *C, char *name, ReportList *reports) @@ -269,7 +269,7 @@ void WM_read_file(bContext *C, char *name, ReportList *reports) // XXX mainwindow_set_filename_to_title(G.main->name); - if(retval==2) wm_init_userdef(); // in case a userdef is read from regular .blend + if(retval==2) wm_init_userdef(C); // in case a userdef is read from regular .blend if (retval!=0) { G.relbase_valid = 1; @@ -338,7 +338,7 @@ int WM_read_homefile(bContext *C, wmOperator *op) strcpy(G.sce, scestr); /* restore */ - wm_init_userdef(); + wm_init_userdef(C); /* When loading factory settings, the reset solid OpenGL lights need to be applied. */ if (!G.background) GPU_default_lights(); |