vidi/Timeline.py: support setting the canvas size
[vidi-player.git] / vidi-timeline.py
index 17165fc..07639e6 100755 (executable)
@@ -22,15 +22,30 @@ import sys
 import mido
 import vidi
 
-# TODO: turn that into a command line option
+# TODO: turn these into command line options
 ADD_REST_BACKGROUND = True
+ADD_TITLE = True
+TITLE_TEXT = None
+TITLE_DURATION = 5
+TITLE_CREDITS = "Created with vidi-timeline\nhttps://git.ao2.it/vidi-player.git"
 
 
 def timeline_from_midi(midi_file, video_font_path):
     timeline = vidi.Timeline()
 
-    elapsed_time = 0
-    start_time = 0
+    if ADD_TITLE:
+        title = TITLE_TEXT
+        if not title:
+            title = os.path.splitext(os.path.basename(midi_file.filename))[0]
+            title += "\n\n"
+            title += TITLE_CREDITS
+
+        timeline.add_title_clip(title, 0, TITLE_DURATION)
+
+        elapsed_time = start_time = TITLE_DURATION
+    else:
+        elapsed_time = start_time = 0
+
     for msg in midi_file:
         elapsed_time += msg.time
         if vidi.is_note_on(msg) and msg.channel == 0: