aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2020-01-14 23:11:26 +0100
committerThomas White <taw@bitwiz.me.uk>2020-01-14 23:11:26 +0100
commitb2660879dc21df26ad12526072a75726091225e5 (patch)
treeb1ee1de845ef1042e451b9dc23302c40957a6a02
parent588d51ef1e462eefc3761e55dc9ae87f75a3115c (diff)
Track time taken for each narrative item
-rw-r--r--libstorycode/narrative.c52
-rw-r--r--libstorycode/narrative_priv.h4
2 files changed, 56 insertions, 0 deletions
diff --git a/libstorycode/narrative.c b/libstorycode/narrative.c
index 25c01c5..c9c94d6 100644
--- a/libstorycode/narrative.c
+++ b/libstorycode/narrative.c
@@ -236,6 +236,7 @@ static void init_item(struct narrative_item *item)
item->n_runs = 0;
item->slide = NULL;
item->slide_thumbnail = NULL;
+ item->estd_duration = 0.0;
}
@@ -278,6 +279,8 @@ extern void add_text_item(Narrative *n, struct text_run *runs, int n_runs,
item->runs = runs;
item->n_runs = n_runs;
+
+ update_timing(item);
}
@@ -323,6 +326,7 @@ void narrative_add_slide(Narrative *n, Slide *slide)
item->type = NARRATIVE_ITEM_SLIDE;
item->slide = slide;
item->slide_thumbnail = NULL;
+ update_timing(item);
}
@@ -403,6 +407,8 @@ static void delete_text(struct narrative_item *item, size_t o1, ssize_t o2)
memmove(item->runs[r2].text, &item->runs[r2].text[roffs2],
strlen(&item->runs[r2].text[roffs2])+1);
}
+
+ update_timing(item);
}
@@ -424,6 +430,7 @@ void narrative_delete_block(Narrative *n, int i1, size_t o1, int i2, size_t o2)
} else {
if ( i1 == i2 ) {
delete_text(&n->items[i1], o1, o2);
+ update_timing(&n->items[i1]);
return; /* easy case */
} else {
/* Truncate i1 at o1 */
@@ -476,6 +483,7 @@ void narrative_delete_block(Narrative *n, int i1, size_t o1, int i2, size_t o2)
item1->n_runs += item2->n_runs;
delete_item(n, i2);
+ update_timing(item1);
}
}
@@ -533,6 +541,9 @@ void narrative_split_item(Narrative *n, int i1, size_t o1)
item2->runs[0].type = TEXT_RUN_NORMAL;;
}
+
+ update_timing(item1);
+ update_timing(item2);
}
@@ -737,6 +748,47 @@ char *narrative_range_as_text(Narrative *n, int p1, size_t o1, int p2, size_t o2
}
+static double timing_from_wordcount(struct narrative_item *item)
+{
+ int i;
+ int words = 0;
+
+ for ( i=0; i<item->n_runs; i++ ) {
+ char *text = item->runs[i].text;
+ int j;
+ size_t len = strlen(text);
+ for ( j=0; j<len; j++ ) {
+ if ( text[j] == ' ' ) words++;
+ }
+ }
+
+ return words / 100.0;
+}
+
+
+void update_timing(struct narrative_item *item)
+{
+ switch ( item->type ) {
+
+ case NARRATIVE_ITEM_TEXT :
+ case NARRATIVE_ITEM_BP :
+ item->estd_duration = timing_from_wordcount(item);
+ break;
+
+ case NARRATIVE_ITEM_PRESTITLE :
+ case NARRATIVE_ITEM_EOP :
+ case NARRATIVE_ITEM_SEGSTART :
+ case NARRATIVE_ITEM_SEGEND :
+ item->estd_duration = 0.0;
+ break;
+
+ case NARRATIVE_ITEM_SLIDE :
+ item->estd_duration = 1.0;
+ break;
+ }
+}
+
+
static void debug_runs(struct narrative_item *item)
{
int j;
diff --git a/libstorycode/narrative_priv.h b/libstorycode/narrative_priv.h
index 1f2c16a..b9d8eae 100644
--- a/libstorycode/narrative_priv.h
+++ b/libstorycode/narrative_priv.h
@@ -79,6 +79,8 @@ struct narrative_item
void *slide_thumbnail;
#endif
int selected; /* Whether or not this item should be given a "selected" highlight */
+
+ double estd_duration; /* Estimated duration in minutes, based on word count */
};
@@ -101,5 +103,7 @@ struct _narrative
extern int narrative_which_run(struct narrative_item *item, size_t item_offs, size_t *run_offs);
+extern void update_timing(struct narrative_item *item);
+
#endif /* NARRATIVE_PRIV_H */