Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_sequencer/sequencer_add.c
| Show First 20 Lines • Show All 631 Lines • ▼ Show 20 Lines | static void sequencer_add_movie_clamp_sound_strip_length(Scene *scene, | ||||
| Sequence *seq_movie, | Sequence *seq_movie, | ||||
| Sequence *seq_sound) | Sequence *seq_sound) | ||||
| { | { | ||||
| if (ELEM(NULL, seq_movie, seq_sound) || seq_sound->len <= seq_movie->len) { | if (ELEM(NULL, seq_movie, seq_sound) || seq_sound->len <= seq_movie->len) { | ||||
| return; | return; | ||||
| } | } | ||||
| SEQ_transform_set_right_handle_frame(seq_sound, SEQ_transform_get_right_handle_frame(seq_movie)); | SEQ_transform_set_right_handle_frame(seq_sound, SEQ_transform_get_right_handle_frame(seq_movie)); | ||||
| SEQ_transform_set_left_handle_frame(seq_sound, SEQ_transform_get_left_handle_frame(seq_movie)); | |||||
| SEQ_time_update_sequence(scene, seqbase, seq_sound); | SEQ_time_update_sequence(scene, seqbase, seq_sound); | ||||
| } | } | ||||
| static void sequencer_add_movie_multiple_strips(bContext *C, | static void sequencer_add_movie_multiple_strips(bContext *C, | ||||
| wmOperator *op, | wmOperator *op, | ||||
| SeqLoadData *load_data, | SeqLoadData *load_data, | ||||
| SeqCollection *r_movie_strips) | SeqCollection *r_movie_strips) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| const Editing *ed = SEQ_editing_ensure(scene); | const Editing *ed = SEQ_editing_ensure(scene); | ||||
| RNA_BEGIN (op->ptr, itemptr, "files") { | RNA_BEGIN (op->ptr, itemptr, "files") { | ||||
| char dir_only[FILE_MAX]; | char dir_only[FILE_MAX]; | ||||
| char file_only[FILE_MAX]; | char file_only[FILE_MAX]; | ||||
| RNA_string_get(op->ptr, "directory", dir_only); | RNA_string_get(op->ptr, "directory", dir_only); | ||||
| RNA_string_get(&itemptr, "name", file_only); | RNA_string_get(&itemptr, "name", file_only); | ||||
| BLI_join_dirfile(load_data->path, sizeof(load_data->path), dir_only, file_only); | BLI_join_dirfile(load_data->path, sizeof(load_data->path), dir_only, file_only); | ||||
| BLI_strncpy(load_data->name, file_only, sizeof(load_data->name)); | BLI_strncpy(load_data->name, file_only, sizeof(load_data->name)); | ||||
| Sequence *seq_movie = NULL; | Sequence *seq_movie = NULL; | ||||
| Sequence *seq_sound = NULL; | Sequence *seq_sound = NULL; | ||||
| double video_start_offset = -1; | |||||
| double audio_start_offset = 0; | |||||
| if (RNA_boolean_get(op->ptr, "sound")) { | |||||
| SoundStreamInfo sound_info; | |||||
| if (BKE_sound_stream_info_get(bmain, load_data->path, 0, &sound_info)) { | |||||
| audio_start_offset = video_start_offset = sound_info.start; | |||||
| } | |||||
| } | |||||
| load_data->channel++; | load_data->channel++; | ||||
| seq_movie = SEQ_add_movie_strip(bmain, scene, ed->seqbasep, load_data, &video_start_offset); | seq_movie = SEQ_add_movie_strip(bmain, scene, ed->seqbasep, load_data); | ||||
| load_data->channel--; | load_data->channel--; | ||||
| if (seq_movie == NULL) { | if (seq_movie == NULL) { | ||||
| BKE_reportf(op->reports, RPT_ERROR, "File '%s' could not be loaded", load_data->path); | BKE_reportf(op->reports, RPT_ERROR, "File '%s' could not be loaded", load_data->path); | ||||
| } | } | ||||
| else { | else { | ||||
| if (RNA_boolean_get(op->ptr, "sound")) { | if (RNA_boolean_get(op->ptr, "sound")) { | ||||
| int minimum_frame_offset = MIN2(video_start_offset, audio_start_offset) * FPS; | seq_sound = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data); | ||||
| sequencer_add_movie_clamp_sound_strip_length(scene, ed->seqbasep, seq_movie, seq_sound); | |||||
| int video_frame_offset = video_start_offset * FPS; | |||||
| int audio_frame_offset = audio_start_offset * FPS; | |||||
| double video_frame_remainder = video_start_offset * FPS - video_frame_offset; | |||||
| double audio_frame_remainder = audio_start_offset * FPS - audio_frame_offset; | |||||
| double audio_skip = (video_frame_remainder - audio_frame_remainder) / FPS; | |||||
| video_frame_offset -= minimum_frame_offset; | |||||
| audio_frame_offset -= minimum_frame_offset; | |||||
| load_data->start_frame += audio_frame_offset; | |||||
| seq_sound = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data, audio_skip); | |||||
| int min_startdisp = 0, max_enddisp = 0; | |||||
| if (seq_sound != NULL) { | |||||
| min_startdisp = MIN2(seq_movie->startdisp, seq_sound->startdisp); | |||||
| max_enddisp = MAX2(seq_movie->enddisp, seq_sound->enddisp); | |||||
| } | } | ||||
| load_data->start_frame += max_enddisp - min_startdisp - audio_frame_offset; | |||||
| } | |||||
| else { | |||||
| load_data->start_frame += seq_movie->enddisp - seq_movie->startdisp; | load_data->start_frame += seq_movie->enddisp - seq_movie->startdisp; | ||||
| } | |||||
| sequencer_add_movie_clamp_sound_strip_length(scene, ed->seqbasep, seq_movie, seq_sound); | |||||
| seq_load_apply_generic_options(C, op, seq_sound); | seq_load_apply_generic_options(C, op, seq_sound); | ||||
| seq_load_apply_generic_options(C, op, seq_movie); | seq_load_apply_generic_options(C, op, seq_movie); | ||||
| SEQ_collection_append_strip(seq_movie, r_movie_strips); | SEQ_collection_append_strip(seq_movie, r_movie_strips); | ||||
| } | } | ||||
| } | } | ||||
| RNA_END; | RNA_END; | ||||
| } | } | ||||
| static bool sequencer_add_movie_single_strip(bContext *C, | static bool sequencer_add_movie_single_strip(bContext *C, | ||||
| wmOperator *op, | wmOperator *op, | ||||
| SeqLoadData *load_data, | SeqLoadData *load_data, | ||||
| SeqCollection *r_movie_strips) | SeqCollection *r_movie_strips) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| const Editing *ed = SEQ_editing_ensure(scene); | const Editing *ed = SEQ_editing_ensure(scene); | ||||
| Sequence *seq_movie = NULL; | Sequence *seq_movie = NULL; | ||||
| Sequence *seq_sound = NULL; | Sequence *seq_sound = NULL; | ||||
| double video_start_offset = -1; | |||||
| double audio_start_offset = 0; | |||||
| if (RNA_boolean_get(op->ptr, "sound")) { | |||||
| SoundStreamInfo sound_info; | |||||
| if (BKE_sound_stream_info_get(bmain, load_data->path, 0, &sound_info)) { | |||||
| audio_start_offset = video_start_offset = sound_info.start; | |||||
| } | |||||
| } | |||||
| load_data->channel++; | load_data->channel++; | ||||
| seq_movie = SEQ_add_movie_strip(bmain, scene, ed->seqbasep, load_data, &video_start_offset); | seq_movie = SEQ_add_movie_strip(bmain, scene, ed->seqbasep, load_data); | ||||
| load_data->channel--; | load_data->channel--; | ||||
| if (seq_movie == NULL) { | if (seq_movie == NULL) { | ||||
| BKE_reportf(op->reports, RPT_ERROR, "File '%s' could not be loaded", load_data->path); | BKE_reportf(op->reports, RPT_ERROR, "File '%s' could not be loaded", load_data->path); | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (RNA_boolean_get(op->ptr, "sound")) { | if (RNA_boolean_get(op->ptr, "sound")) { | ||||
| int minimum_frame_offset = MIN2(video_start_offset, audio_start_offset) * FPS; | seq_sound = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data); | ||||
| int video_frame_offset = video_start_offset * FPS; | |||||
| int audio_frame_offset = audio_start_offset * FPS; | |||||
| double video_frame_remainder = video_start_offset * FPS - video_frame_offset; | |||||
| double audio_frame_remainder = audio_start_offset * FPS - audio_frame_offset; | |||||
| double audio_skip = (video_frame_remainder - audio_frame_remainder) / FPS; | |||||
| video_frame_offset -= minimum_frame_offset; | |||||
| audio_frame_offset -= minimum_frame_offset; | |||||
| load_data->start_frame += audio_frame_offset; | |||||
| seq_sound = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data, audio_skip); | |||||
| } | |||||
| sequencer_add_movie_clamp_sound_strip_length(scene, ed->seqbasep, seq_movie, seq_sound); | sequencer_add_movie_clamp_sound_strip_length(scene, ed->seqbasep, seq_movie, seq_sound); | ||||
| } | |||||
| seq_load_apply_generic_options(C, op, seq_sound); | seq_load_apply_generic_options(C, op, seq_sound); | ||||
| seq_load_apply_generic_options(C, op, seq_movie); | seq_load_apply_generic_options(C, op, seq_movie); | ||||
| SEQ_collection_append_strip(seq_movie, r_movie_strips); | SEQ_collection_append_strip(seq_movie, r_movie_strips); | ||||
| return true; | return true; | ||||
| } | } | ||||
| static int sequencer_add_movie_strip_exec(bContext *C, wmOperator *op) | static int sequencer_add_movie_strip_exec(bContext *C, wmOperator *op) | ||||
| ▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | static void sequencer_add_sound_multiple_strips(bContext *C, | ||||
| RNA_BEGIN (op->ptr, itemptr, "files") { | RNA_BEGIN (op->ptr, itemptr, "files") { | ||||
| char dir_only[FILE_MAX]; | char dir_only[FILE_MAX]; | ||||
| char file_only[FILE_MAX]; | char file_only[FILE_MAX]; | ||||
| RNA_string_get(op->ptr, "directory", dir_only); | RNA_string_get(op->ptr, "directory", dir_only); | ||||
| RNA_string_get(&itemptr, "name", file_only); | RNA_string_get(&itemptr, "name", file_only); | ||||
| BLI_join_dirfile(load_data->path, sizeof(load_data->path), dir_only, file_only); | BLI_join_dirfile(load_data->path, sizeof(load_data->path), dir_only, file_only); | ||||
| BLI_strncpy(load_data->name, file_only, sizeof(load_data->name)); | BLI_strncpy(load_data->name, file_only, sizeof(load_data->name)); | ||||
| Sequence *seq = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data, 0.0f); | Sequence *seq = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data); | ||||
| if (seq == NULL) { | if (seq == NULL) { | ||||
| BKE_reportf(op->reports, RPT_ERROR, "File '%s' could not be loaded", load_data->path); | BKE_reportf(op->reports, RPT_ERROR, "File '%s' could not be loaded", load_data->path); | ||||
| } | } | ||||
| else { | else { | ||||
| seq_load_apply_generic_options(C, op, seq); | seq_load_apply_generic_options(C, op, seq); | ||||
| load_data->start_frame += seq->enddisp - seq->startdisp; | load_data->start_frame += seq->enddisp - seq->startdisp; | ||||
| } | } | ||||
| } | } | ||||
| RNA_END; | RNA_END; | ||||
| } | } | ||||
| static bool sequencer_add_sound_single_strip(bContext *C, wmOperator *op, SeqLoadData *load_data) | static bool sequencer_add_sound_single_strip(bContext *C, wmOperator *op, SeqLoadData *load_data) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Editing *ed = SEQ_editing_ensure(scene); | Editing *ed = SEQ_editing_ensure(scene); | ||||
| Sequence *seq = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data, 0.0f); | Sequence *seq = SEQ_add_sound_strip(bmain, scene, ed->seqbasep, load_data); | ||||
| if (seq == NULL) { | if (seq == NULL) { | ||||
| BKE_reportf(op->reports, RPT_ERROR, "File '%s' could not be loaded", load_data->path); | BKE_reportf(op->reports, RPT_ERROR, "File '%s' could not be loaded", load_data->path); | ||||
| return false; | return false; | ||||
| } | } | ||||
| seq_load_apply_generic_options(C, op, seq); | seq_load_apply_generic_options(C, op, seq); | ||||
| return true; | return true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 448 Lines • Show Last 20 Lines | |||||