Fix T46368: Subtitle Export: Subtitles are not sorted by time.

We need a temp list of Text effect strips here, to be able to sort it as we want...
This commit is contained in:
Bastien Montagne 2015-10-04 16:42:19 +02:00
parent c919ce3aa9
commit f2499b6015
Notes: blender-bot 2023-02-14 09:38:57 +01:00
Referenced by issue #46368, Subtitle Export: Subtitles are not sorted by time
3 changed files with 40 additions and 13 deletions

View File

@ -108,6 +108,8 @@ void BKE_sequencer_new_render_data(
int rectx, int recty, int preview_render_size,
SeqRenderData *r_context);
int BKE_sequencer_cmp_time_startdisp(const void *a, const void *b);
/* Wipe effect */
enum {
DO_SINGLE_WIPE,

View File

@ -1013,6 +1013,15 @@ void BKE_sequencer_sort(Scene *scene)
*(ed->seqbasep) = seqbase;
}
/** Comparision function suitable to be used with BLI_listbase_sort()... */
int BKE_sequencer_cmp_time_startdisp(const void *a, const void *b)
{
Sequence *seq_a = a;
Sequence *seq_b = b;
return (seq_a->startdisp > seq_b->startdisp);
}
static int clear_scene_in_allseqs_cb(Sequence *seq, void *arg_pt)
{
if (seq->scene == (Scene *)arg_pt)

View File

@ -3859,7 +3859,9 @@ static int sequencer_export_subtitles_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
Sequence *seq = BKE_sequencer_active_get(scene);
Sequence *seq_next;
Editing *ed = BKE_sequencer_editing_get(scene, false);
ListBase text_seq = {0};
int iter = 0;
FILE *file;
char filepath[FILE_MAX];
@ -3885,26 +3887,40 @@ static int sequencer_export_subtitles_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
/* time to open and write! */
file = BLI_fopen(filepath, "w");
SEQ_BEGIN(ed, seq)
{
if (seq->type == SEQ_TYPE_TEXT) {
TextVars *data = seq->effectdata;
char timecode_str_start[32];
char timecode_str_end[32];
BLI_timecode_string_from_time(timecode_str_start, sizeof(timecode_str_start),
-2, FRA2TIME(seq->startdisp), FPS, USER_TIMECODE_SUBRIP);
BLI_timecode_string_from_time(timecode_str_end, sizeof(timecode_str_end),
-2, FRA2TIME(seq->enddisp), FPS, USER_TIMECODE_SUBRIP);
fprintf(file, "%d\n%s --> %s\n%s\n\n", iter++, timecode_str_start, timecode_str_end, data->text);
BLI_addtail(&text_seq, MEM_dupallocN(seq));
}
}
SEQ_END
if (BLI_listbase_is_empty(&text_seq)) {
BKE_report(op->reports, RPT_ERROR, "No subtitles (text strips) to export");
return OPERATOR_CANCELLED;
}
BLI_listbase_sort(&text_seq, BKE_sequencer_cmp_time_startdisp);
/* time to open and write! */
file = BLI_fopen(filepath, "w");
for (seq = text_seq.first; seq; seq = seq_next) {
TextVars *data = seq->effectdata;
char timecode_str_start[32];
char timecode_str_end[32];
BLI_timecode_string_from_time(timecode_str_start, sizeof(timecode_str_start),
-2, FRA2TIME(seq->startdisp), FPS, USER_TIMECODE_SUBRIP);
BLI_timecode_string_from_time(timecode_str_end, sizeof(timecode_str_end),
-2, FRA2TIME(seq->enddisp), FPS, USER_TIMECODE_SUBRIP);
fprintf(file, "%d\n%s --> %s\n%s\n\n", iter++, timecode_str_start, timecode_str_end, data->text);
seq_next = seq->next;
MEM_freeN(seq);
}
fclose(file);
return OPERATOR_FINISHED;