smallpond

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/smallpond
Log | Files | Refs | README | LICENSE

commit 528264f4597c9ef9671b80fcd399c44c2fb09503
parent d8add7f12f7fdae3c146067cfa420cbed2097a1d
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Tue, 25 Oct 2022 22:23:48 -0500

control termination of video from lua in drawframe

Diffstat:
Mmain.c | 16++++++++++++----
Msmallpond.lua | 9++++++---
2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/main.c b/main.c @@ -1,3 +1,4 @@ +#include <stdbool.h> #include <stdint.h> #include <stdio.h> @@ -148,6 +149,8 @@ main(int argc, char *argv[]) lua_setglobal(L, "draw_quad"); lua_pushcfunction(L, glyph_extents); lua_setglobal(L, "glyph_extents"); + lua_pushnumber(L, 854); + lua_setglobal(L, "framewidth"); FT_Library library; int error = FT_Init_FreeType(&library); @@ -240,15 +243,19 @@ main(int argc, char *argv[]) return 1; } - for (int i = 0; i < 30; i++) { + bool done = false; + unsigned int count = 0; + while (!done) { /* fill with white */ cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); cairo_rectangle(cr, 0, 0, 854, 480); cairo_fill(cr); // draw frame lua_getglobal(L, "drawframe"); - lua_pushnumber(L, i); - lua_call(L, 1, 0); + lua_pushnumber(L, count); + lua_call(L, 1, 1); + + done = lua_toboolean(L, -1); cairo_surface_flush(surface); uint8_t *image_data = cairo_image_surface_get_data(surface); @@ -271,8 +278,9 @@ main(int argc, char *argv[]) } fflush(stdout); - frame->pts = i; + frame->pts = count; putframe(c, frame, pkt, output); + count++; } putframe(c, NULL, pkt, output); diff --git a/smallpond.lua b/smallpond.lua @@ -713,11 +713,12 @@ for staff, item in ipairs(extra3) do end end -local height = yoff -local width = xmax - xmin - function drawframe(time) local toff = -time * 10 + print(framewidth - toff, xmax) + if -toff > xmax then + return true + end for _, staff in ipairs(stafforder) do local extent = extents[staff] for i, d in ipairs(staff3[staff]) do @@ -742,4 +743,6 @@ function drawframe(time) draw_line(1, toff + item.x, -firstymin, toff + item.x, lastymin + 4*em) end end + + return false end