From 6c5c58e05799f2b593cd81fcff57e6ef72ad57fb Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Sun, 9 Aug 2009 21:16:39 +0000 Subject: 2.5: Sound branch merge! See mailing list for additional information. --- source/blender/editors/space_sequencer/SConscript | 1 + .../editors/space_sequencer/sequencer_add.c | 140 ++++++++++++--------- .../editors/space_sequencer/sequencer_draw.c | 15 +-- .../editors/space_sequencer/sequencer_edit.c | 53 ++++---- .../editors/space_sequencer/sequencer_select.c | 4 +- 5 files changed, 121 insertions(+), 92 deletions(-) (limited to 'source/blender/editors/space_sequencer') diff --git a/source/blender/editors/space_sequencer/SConscript b/source/blender/editors/space_sequencer/SConscript index ab51068a529..9e7ea185c25 100644 --- a/source/blender/editors/space_sequencer/SConscript +++ b/source/blender/editors/space_sequencer/SConscript @@ -6,5 +6,6 @@ sources = env.Glob('*.c') incs = '../include ../../blenlib ../../blenkernel ../../blenfont ../../makesdna ../../imbuf' incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include' incs += ' ../../makesrna' +incs += ' #/intern/audaspace' env.BlenderLib ( 'bf_editors_space_sequencer', sources, Split(incs), [], libtype=['core'], priority=[100] ) diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index 99a13c8d9e0..5d58ea431a9 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -89,6 +89,9 @@ #include "UI_resources.h" #include "UI_view2d.h" +#include "BKE_sound.h" +#include "AUD_C-API.h" + /* own include */ #include "sequencer_intern.h" @@ -224,24 +227,80 @@ void SEQUENCER_OT_scene_strip_add(struct wmOperatorType *ot) RNA_def_string(ot->srna, "scene", "", MAX_ID_NAME-2, "Scene Name", "Scene name to add as a strip"); } +static Sequence* sequencer_add_sound_strip(bContext *C, wmOperator *op, int start_frame, int channel, char* filename) +{ + Scene *scene= CTX_data_scene(C); + Editing *ed= seq_give_editing(scene, TRUE); + + bSound *sound; + + Sequence *seq; /* generic strip vars */ + Strip *strip; + StripElem *se; + + AUD_SoundInfo info; + + sound = sound_new_file(CTX_data_main(C), filename); + + if (sound==NULL || sound->snd_sound == NULL) { + if(op) + BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); + return NULL; + } + + info = AUD_getInfo(sound->snd_sound); + + if (info.specs.format == AUD_FORMAT_INVALID) { + sound_delete(C, sound); + if(op) + BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); + return NULL; + } + + seq = alloc_sequence(ed->seqbasep, start_frame, channel); + + seq->type= SEQ_SOUND; + seq->sound= sound; + + /* basic defaults */ + seq->strip= strip= MEM_callocN(sizeof(Strip), "strip"); + strip->len = seq->len = (int) (info.length * FPS); + strip->us= 1; + + strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem"); + + BLI_split_dirfile_basic(filename, strip->dir, se->name); + + seq->sound_handle = sound_new_handle(scene, sound, start_frame, start_frame + strip->len, 0); + + calc_sequence_disp(seq); + sort_seq(scene); + + /* last active name */ + strncpy(ed->act_sounddir, strip->dir, FILE_MAXDIR-1); + + return seq; +} + /* add movie operator */ static int sequencer_add_movie_strip_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); Editing *ed= seq_give_editing(scene, TRUE); - + struct anim *an; char filename[FILE_MAX]; - Sequence *seq; /* generic strip vars */ + Sequence *seq, *soundseq; /* generic strip vars */ Strip *strip; StripElem *se; - - int start_frame, channel; /* operator props */ - + + int start_frame, channel, sound; /* operator props */ + start_frame= RNA_int_get(op->ptr, "start_frame"); channel= RNA_int_get(op->ptr, "channel"); - + sound = RNA_boolean_get(op->ptr, "sound"); + RNA_string_get(op->ptr, "filename", filename); an = openanim(filename, IB_rect); @@ -271,10 +330,19 @@ static int sequencer_add_movie_strip_exec(bContext *C, wmOperator *op) calc_sequence_disp(seq); sort_seq(scene); + if(sound) + { + soundseq = sequencer_add_sound_strip(C, NULL, start_frame, channel+1, filename); + if(soundseq != NULL) + RNA_string_get(op->ptr, "name", soundseq->name); + } + if (RNA_boolean_get(op->ptr, "replace_sel")) { deselect_all_seq(scene); set_last_seq(scene, seq); seq->flag |= SELECT; + if(soundseq) + soundseq->flag |= SELECT; } ED_area_tag_redraw(CTX_wm_area(C)); @@ -310,24 +378,15 @@ void SEQUENCER_OT_movie_strip_add(struct wmOperatorType *ot) WM_operator_properties_filesel(ot, FOLDERFILE|MOVIEFILE); sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME); - RNA_def_boolean(ot->srna, "sound", TRUE, "Sound", "Load hd sound with the movie"); // XXX need to impliment this + RNA_def_boolean(ot->srna, "sound", TRUE, "Sound", "Load sound with the movie"); } - /* add sound operator */ static int sequencer_add_sound_strip_exec(bContext *C, wmOperator *op) { - Scene *scene= CTX_data_scene(C); - Editing *ed= seq_give_editing(scene, TRUE); - - bSound *sound; - char filename[FILE_MAX]; - + Scene *scene= CTX_data_scene(C); Sequence *seq; /* generic strip vars */ - Strip *strip; - StripElem *se; - int start_frame, channel; /* operator props */ start_frame= RNA_int_get(op->ptr, "start_frame"); @@ -335,47 +394,16 @@ static int sequencer_add_sound_strip_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "filename", filename); - /* XXX if(sfile->flag & FILE_STRINGCODE) { - BLI_makestringcode(G.sce, str); - }*/ - -// XXX sound= sound_new_sound(filename); - sound= NULL; - - if (sound==NULL || sound->sample->type == SAMPLE_INVALID) { - BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); - return OPERATOR_CANCELLED; - } + seq = sequencer_add_sound_strip(C, op, start_frame, channel, filename); - if (sound==NULL || sound->sample->bits != 16) { - BKE_report(op->reports, RPT_ERROR, "Only 16 bit audio is supported"); + if(seq == NULL) return OPERATOR_CANCELLED; - } - - sound->flags |= SOUND_FLAGS_SEQUENCE; -// XXX audio_makestream(sound); - - seq = alloc_sequence(ed->seqbasep, start_frame, channel); - - seq->type= SEQ_RAM_SOUND; - seq->sound= sound; - - /* basic defaults */ - seq->strip= strip= MEM_callocN(sizeof(Strip), "strip"); - strip->len = seq->len = (int) ( ((float)(sound->streamlen-1) / ( (float)scene->r.audio.mixrate*4.0 ))* FPS); - strip->us= 1; - - strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem"); - - BLI_split_dirfile_basic(filename, strip->dir, se->name); RNA_string_get(op->ptr, "name", seq->name); - - calc_sequence_disp(seq); - sort_seq(scene); - - /* last active name */ - strncpy(ed->act_sounddir, strip->dir, FILE_MAXDIR-1); + + if (RNA_boolean_get(op->ptr, "cache")) { + sound_cache(seq->sound, 0); + } if (RNA_boolean_get(op->ptr, "replace_sel")) { deselect_all_seq(scene); @@ -416,7 +444,7 @@ void SEQUENCER_OT_sound_strip_add(struct wmOperatorType *ot) WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE); sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME); - RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Load the sound as streaming audio"); // XXX need to impliment this + RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Cache the sound in memory."); } /* add image operator */ @@ -585,7 +613,7 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op) if(seq->plugin==NULL) { BLI_remlink(ed->seqbasep, seq); - seq_free_sequence(ed, seq); + seq_free_sequence(scene, seq); BKE_reportf(op->reports, RPT_ERROR, "Sequencer plugin \"%s\" could not load.", filename); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 3b90039335e..3d0d908d3f6 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -173,8 +173,7 @@ static void get_seq_color3ubv(Scene *curscene, Sequence *seq, char *col) case SEQ_PLUGIN: UI_GetThemeColor3ubv(TH_SEQ_PLUGIN, col); break; - case SEQ_HD_SOUND: - case SEQ_RAM_SOUND: + case SEQ_SOUND: UI_GetThemeColor3ubv(TH_SEQ_AUDIO, col); blendcol[0] = blendcol[1] = blendcol[2] = 128; if(seq->flag & SEQ_MUTE) UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.5, 20); @@ -546,11 +545,8 @@ static void draw_seq_text(View2D *v2d, Sequence *seq, float x1, float x2, float else sprintf(str, "%d | %s", seq->len, give_seqname(seq)); } - else if (seq->type == SEQ_RAM_SOUND) { - sprintf(str, "%d | %s", seq->len, seq->strip->stripdata->name); - } - else if (seq->type == SEQ_HD_SOUND) { - sprintf(str, "%d | %s", seq->len, seq->strip->stripdata->name); + else if (seq->type == SEQ_SOUND) { + sprintf(str, "%d | %s", seq->len, seq->sound->name); } else if (seq->type == SEQ_MOVIE) { sprintf(str, "%d | %s%s", seq->len, seq->strip->dir, seq->strip->stripdata->name); @@ -664,8 +660,9 @@ static void draw_seq_strip(Scene *scene, ARegion *ar, SpaceSeq *sseq, Sequence * draw_shadedstrip(seq, background_col, x1, y1, x2, y2); /* draw additional info and controls */ - if (seq->type == SEQ_RAM_SOUND) - drawseqwave(scene, v2d, seq, x1, y1, x2, y2, ar->winx); +// XXX +/* if (seq->type == SEQ_SOUND) + drawseqwave(scene, v2d, seq, x1, y1, x2, y2, ar->winx);*/ if (!is_single_image) draw_seq_extensions(scene, sseq, seq); diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 036c0769c1e..1555784f470 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -65,6 +65,7 @@ #include "BKE_scene.h" #include "BKE_utildefines.h" #include "BKE_report.h" +#include "BKE_sound.h" #include "WM_api.h" #include "WM_types.h" @@ -166,7 +167,7 @@ Sequence *get_foreground_frame_seq(Scene *scene, int frame) if(seq->flag & SEQ_MUTE || seq->startdisp > frame || seq->enddisp <= frame) continue; /* only use elements you can see - not */ - if (ELEM6(seq->type, SEQ_IMAGE, SEQ_META, SEQ_SCENE, SEQ_MOVIE, SEQ_MOVIE_AND_HD_SOUND, SEQ_COLOR)) { + if (ELEM5(seq->type, SEQ_IMAGE, SEQ_META, SEQ_SCENE, SEQ_MOVIE, SEQ_COLOR)) { if (seq->machine > best_machine) { best_seq = seq; best_machine = seq->machine; @@ -563,7 +564,7 @@ static void reload_sound_strip(Scene *scene, char *name) calc_sequence(seqact); seq->strip= 0; - seq_free_sequence(ed, seq); + seq_free_sequence(scene, seq); BLI_remlink(ed->seqbasep, seq); seq= ed->seqbasep->first; @@ -603,7 +604,7 @@ static void reload_image_strip(Scene *scene, char *name) calc_sequence(seqact); seq->strip= 0; - seq_free_sequence(ed, seq); + seq_free_sequence(scene, seq); BLI_remlink(ed->seqbasep, seq); update_changed_seq_and_deps(scene, seqact, 1, 1); @@ -722,7 +723,7 @@ int seq_effect_find_selected(Scene *scene, Sequence *activeseq, int type, Sequen for(seq=ed->seqbasep->first; seq; seq=seq->next) { if(seq->flag & SELECT) { - if (seq->type == SEQ_RAM_SOUND || seq->type == SEQ_HD_SOUND) { + if (seq->type == SEQ_SOUND) { *error_str= "Can't apply effects to audio sequence strips"; return 0; } @@ -849,7 +850,6 @@ static Sequence *del_seq_find_replace_recurs(Scene *scene, Sequence *seq) static void recurs_del_seq_flag(Scene *scene, ListBase *lb, short flag, short deleteall) { - Editing *ed= seq_give_editing(scene, FALSE); Sequence *seq, *seqn; Sequence *last_seq = get_last_seq(scene); @@ -857,20 +857,20 @@ static void recurs_del_seq_flag(Scene *scene, ListBase *lb, short flag, short de while(seq) { seqn= seq->next; if((seq->flag & flag) || deleteall) { - if(seq->type==SEQ_RAM_SOUND && seq->sound) + if(seq->type==SEQ_SOUND && seq->sound) seq->sound->id.us--; BLI_remlink(lb, seq); if(seq==last_seq) set_last_seq(scene, NULL); if(seq->type==SEQ_META) recurs_del_seq_flag(scene, &seq->seqbase, flag, 1); if(seq->ipo) seq->ipo->id.us--; - seq_free_sequence(ed, seq); + seq_free_sequence(scene, seq); } seq= seqn; } } -static Sequence *dupli_seq(Sequence *seq) +static Sequence *dupli_seq(struct Scene *scene, Sequence *seq) { Sequence *seqn = MEM_dupallocN(seq); // XXX animato: ID *id; @@ -936,14 +936,13 @@ static Sequence *dupli_seq(Sequence *seq) seqn->strip->stripdata = MEM_dupallocN(seq->strip->stripdata); seqn->anim= 0; - } else if(seq->type == SEQ_RAM_SOUND) { - seqn->strip->stripdata = + } else if(seq->type == SEQ_SOUND) { + seqn->strip->stripdata = MEM_dupallocN(seq->strip->stripdata); + if(seq->sound_handle) + seqn->sound_handle = sound_new_handle(scene, seqn->sound, seq->sound_handle->startframe, seq->sound_handle->endframe, seq->sound_handle->frameskip); + seqn->sound->id.us++; - } else if(seq->type == SEQ_HD_SOUND) { - seqn->strip->stripdata = - MEM_dupallocN(seq->strip->stripdata); - seqn->hdaudio = 0; } else if(seq->type == SEQ_IMAGE) { seqn->strip->stripdata = MEM_dupallocN(seq->strip->stripdata); @@ -970,13 +969,13 @@ static Sequence *dupli_seq(Sequence *seq) return seqn; } -static Sequence * deep_dupli_seq(Sequence * seq) +static Sequence * deep_dupli_seq(struct Scene *scene, Sequence * seq) { - Sequence * seqn = dupli_seq(seq); + Sequence * seqn = dupli_seq(scene, seq); if (seq->type == SEQ_META) { Sequence * s; for(s= seq->seqbase.first; s; s = s->next) { - Sequence * n = deep_dupli_seq(s); + Sequence * n = deep_dupli_seq(scene, s); if (n) { BLI_addtail(&seqn->seqbase, n); } @@ -995,7 +994,7 @@ static void recurs_dupli_seq(Scene *scene, ListBase *old, ListBase *new) for(seq= old->first; seq; seq= seq->next) { seq->tmp= NULL; if(seq->flag & SELECT) { - seqn = dupli_seq(seq); + seqn = dupli_seq(scene, seq); if (seqn) { /*should never fail */ seq->flag &= SEQ_DESEL; seqn->flag &= ~(SEQ_LEFTSEL+SEQ_RIGHTSEL+SEQ_LOCK); @@ -1061,10 +1060,10 @@ static Sequence *cut_seq_hard(Scene *scene, Sequence * seq, int cutframe) reload_sequence_new_file(scene, seq); calc_sequence(seq); - + if (!skip_dup) { /* Duplicate AFTER the first change */ - seqn = deep_dupli_seq(seq); + seqn = deep_dupli_seq(scene, seq); } if (seqn) { @@ -1150,10 +1149,10 @@ static Sequence *cut_seq_soft(Scene *scene, Sequence * seq, int cutframe) } calc_sequence(seq); - + if (!skip_dup) { /* Duplicate AFTER the first change */ - seqn = deep_dupli_seq(seq); + seqn = deep_dupli_seq(scene, seq); } if (seqn) { @@ -1493,11 +1492,13 @@ static int sequencer_mute_exec(bContext *C, wmOperator *op) if(selected){ /* mute unselected */ if (seq->flag & SELECT) { seq->flag |= SEQ_MUTE; + seq_update_sound(seq); } } else { if ((seq->flag & SELECT)==0) { seq->flag |= SEQ_MUTE; + seq_update_sound(seq); } } } @@ -1544,11 +1545,13 @@ static int sequencer_unmute_exec(bContext *C, wmOperator *op) if(selected){ /* unmute unselected */ if (seq->flag & SELECT) { seq->flag &= ~SEQ_MUTE; + seq_update_sound(seq); } } else { if ((seq->flag & SELECT)==0) { seq->flag &= ~SEQ_MUTE; + seq_update_sound(seq); } } } @@ -2007,7 +2010,7 @@ static int sequencer_separate_images_exec(bContext *C, wmOperator *op) start_ofs += step; } - seq_free_sequence(ed, seq); + seq_free_sequence(scene, seq); seq = seq->next; } else { seq = seq->next; @@ -2130,7 +2133,7 @@ static int sequencer_meta_make_exec(bContext *C, wmOperator *op) while(seq) { if(seq->flag & SELECT) { tot++; - if (seq->type == SEQ_RAM_SOUND) { + if (seq->type == SEQ_SOUND) { BKE_report(op->reports, RPT_ERROR, "Can't make Meta Strip from audio"); return OPERATOR_CANCELLED;; } @@ -2242,7 +2245,7 @@ static int sequencer_meta_separate_exec(bContext *C, wmOperator *op) last_seq->seqbase.last= 0; BLI_remlink(ed->seqbasep, last_seq); - seq_free_sequence(ed, last_seq); + seq_free_sequence(scene, last_seq); /* emtpy meta strip, delete all effects depending on it */ for(seq=ed->seqbasep->first; seq; seq=seq->next) diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c index 335652235c6..dda5837e5f5 100644 --- a/source/blender/editors/space_sequencer/sequencer_select.c +++ b/source/blender/editors/space_sequencer/sequencer_select.c @@ -153,7 +153,7 @@ void select_single_seq(Scene *scene, Sequence *seq, int deselect_all) /* BRING B if(seq->strip) strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR-1); } - else if((seq->type==SEQ_HD_SOUND) || (seq->type==SEQ_RAM_SOUND)) { + else if(seq->type==SEQ_SOUND) { if(seq->strip) strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR-1); } @@ -336,7 +336,7 @@ static int sequencer_select_invoke(bContext *C, wmOperator *op, wmEvent *event) strncpy(ed->act_imagedir, seq->strip->dir, FILE_MAXDIR-1); } } else - if (seq->type == SEQ_HD_SOUND || seq->type == SEQ_RAM_SOUND) { + if (seq->type == SEQ_SOUND) { if(seq->strip) { strncpy(ed->act_sounddir, seq->strip->dir, FILE_MAXDIR-1); } -- cgit v1.2.3