1 // main.h
2 // LiVES
3 // (c) G. Finch (salsaman+lives@gmail.com) 2003 - 2020
4 // see file ../COPYING for full licensing details
5 
6 /*  This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License version 3 or higher as
8     published by the Free Software Foundation.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 */
19 
20 // begin legal warning
21 /*
22     NO WARRANTY
23 
24     BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
25       FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
26   OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
27       PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
28       OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
29   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
30   TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
31       PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
32   REPAIR OR CORRECTION.
33 
34       IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
35       WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
36       REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
37       INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
38       OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
39   TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
40   YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
41       PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
42   POSSIBILITY OF SUCH DAMAGES.
43 */
44 // end legal warning
45 
46 // Have fun, and let's fight for Free Speech, Open Media and True Creativity !
47 // - Salsaman
48 
49 // note: preferred formatting style is: astyle --style=java -H -Y -s2 -U -k3 -W3 -xC128 -xL -p -o -O -Q -xp
50 
51 #ifndef HAS_LIVES_MAIN_H
52 #define HAS_LIVES_MAIN_H
53 
54 #ifdef __cplusplus
55 #undef HAVE_UNICAP
56 #endif
57 
58 //#define WEED_STARTUP_TESTS
59 #define STD_STRINGFUNCS
60 
61 #ifdef __GNUC__
62 #  define WARN_UNUSED  __attribute__((warn_unused_result))
63 #  define GNU_PURE  __attribute__((pure))
64 #  define GNU_DEPRECATED(msg)  __attribute__((deprecated(msg)))
65 #  define GNU_CONST  __attribute__((const))
66 #  define GNU_MALLOC  __attribute__((malloc))
67 #  define GNU_MALLOC_SIZE(argx) __attribute__((alloc_size(argx)))
68 #  define GNU_MALLOC_SIZE2(argx, argy) __attribute__((alloc_size(argx, argy)))
69 #  define GNU_ALIGN(argx) __attribute__((alloc_align(argx)))
70 #  define GNU_ALIGNED(sizex) __attribute__((assume_aligned(sizex)))
71 #  define GNU_NORETURN __attribute__((noreturn))
72 #  define GNU_FLATTEN  __attribute__((flatten)) // inline all function calls
73 #  define GNU_HOT  __attribute__((hot))
74 #  define GNU_SENTINEL  __attribute__((__sentinel__(0)))
75 #  define GNU_RETURNS_TWICE  __attribute__((returns_twice))
76 #else
77 #  define WARN_UNUSED
78 #  define GNU_PURE
79 #  define GNU_CONST
80 #  define GNU_MALLOC
81 #  define GNU_MALLOC_SIZE(x)
82 #  define GNU_MALLOC_SIZE2(x, y)
83 #  define GNU_DEPRECATED(msg)
84 #  define GNU_ALIGN(x)
85 #  define GNU_ALIGNED(x)
86 #  define GNU_NORETURN
87 #  define GNU_FLATTEN
88 #  define GNU_HOT
89 #  define GNU_SENTINEL
90 #  define GNU_RETURNS_TWICE
91 #endif
92 
93 #include <sys/types.h>
94 #include <inttypes.h>
95 #include <string.h>
96 
97 typedef int64_t ticks_t;
98 
99 typedef int frames_t; // nb. will chenge to int64_t at some future point
100 typedef int64_t frames64_t; // will become the new standard
101 
102 #define ENABLE_OSC2
103 
104 #ifndef GUI_QT
105 #define GUI_GTK
106 #define LIVES_PAINTER_IS_CAIRO
107 #define LIVES_LINGO_IS_PANGO
108 #else
109 #define PAINTER_QPAINTER
110 #define NO_PROG_LOAD
111 #undef ENABLE_GIW
112 #endif
113 
114 #include <sys/file.h>
115 #include <unistd.h>
116 
117 typedef pid_t lives_pid_t;
118 typedef int lives_pgid_t;
119 
120 #ifdef GUI_GTK
121 #ifndef GDK_WINDOWING_X11
122 #define GDK_WINDOWING_X11
123 #endif
124 #endif // GUI_GTK
125 
126 #ifdef GUI_GTK
127 
128 #define USE_GLIB
129 
130 #define LIVES_OS_UNIX G_OS_UNIX
131 
132 #include <gtk/gtk.h>
133 #include <gdk/gdkkeysyms.h>
134 
135 #if GTK_CHECK_VERSION(3, 0, 0)
136 #ifdef ENABLE_GIW
137 #define ENABLE_GIW_3
138 #endif
139 #else
140 #undef ENABLE_GIW_3
141 #endif
142 
143 #endif
144 
145 #if !GTK_CHECK_VERSION(3, 0, 0)
146 // borked in < 3.0
147 #undef HAVE_WAYLAND
148 #endif
149 
150 #ifdef HAVE_WAYLAND
151 #include <gdk/gdkwayland.h>
152 #endif
153 
154 #ifdef GDK_WINDOWING_WAYLAND
155 #ifndef GDK_IS_WAYLAND_DISPLAY
156 #define GDK_IS_WAYLAND_DISPLAY(a) FALSE
157 #endif
158 #endif
159 
160 #include <sys/stat.h>
161 #include <stdlib.h>
162 #include <stdio.h>
163 #include <signal.h>
164 #include <assert.h>
165 #include <errno.h>
166 
167 #ifdef __cplusplus
168 #define __STDC_CONSTANT_MACROS
169 #ifdef _STDINT_H
170 #undef _STDINT_H
171 #endif
172 #endif
173 
174 #include <stdint.h>
175 #include <stdarg.h>
176 
177 #ifndef ulong
178 #define ulong unsigned long
179 #endif
180 
181 #define QUOTEME(x) #x
182 
183 /// max files is actually 1 more than this, since file 0 is the clipboard
184 #define MAX_FILES 65535
185 
186 /// this must match AC_PREFIX_DEFAULT in configure.in
187 /// TODO - when lives-plugins is a separate package, use pkg-config to get PREFIX and remove PREFIX_DEFAULT
188 #ifndef PREFIX_DEFAULT
189 #define PREFIX_DEFAULT "/usr"
190 #endif
191 
192 /// if --prefix= was not set, this is set to "NONE"
193 #ifndef PREFIX
194 #define PREFIX PREFIX_DEFAULT
195 #endif
196 
197 #define LIVES_DIR_SEP "/"
198 #define LIVES_COPYRIGHT_YEARS "2002 - 2020"
199 
200 #if defined (IS_DARWIN) || defined (IS_FREEBSD) || defined(__DragonFly__)
201 #ifndef off64_t
202 #define off64_t off_t
203 #endif
204 #ifndef lseek64
205 #define lseek64 lseek
206 #endif
207 #endif
208 
209 #define DEF_FILE_PERMS (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) ///< non-executable, is modified by the umask
210 
211 #define ALLOW_NONFREE_CODECS
212 
213 /// LiVES will show a warning if this (MBytes) is exceeded on load
214 /// (can be overridden in prefs)
215 #define WARN_FILE_SIZE 500
216 
217 /// maximum fps we will allow (double)
218 #define FPS_MAX 200.
219 
220 #define MAX_FRAME_WIDTH 100000.
221 #define MAX_FRAME_HEIGHT 100000.
222 
223 #define ENABLE_DVD_GRAB
224 
225 #ifdef HAVE_MJPEGTOOLS
226 #define HAVE_YUV4MPEG
227 #endif
228 
229 #ifdef ENABLE_ORC
230 #include <orc/orc.h>
231 #endif
232 
233 #ifdef ENABLE_OIL
234 #include <liboil/liboil.h>
235 #endif
236 
237 #ifndef IS_SOLARIS
238 #define LIVES_INLINE static inline
239 #define LIVES_GLOBAL_INLINE inline
240 #else
241 #define LIVES_INLINE static
242 #define LIVES_GLOBAL_INLINE
243 #define LIVES_LOCAL_INLINE
244 #endif
245 
246 #define LIVES_LOCAL_INLINE LIVES_INLINE
247 
248 #include <limits.h>
249 #include <float.h>
250 
251 #ifndef PATH_MAX
252 #ifdef MAX_PATH
253 #define PATH_MAX MAX_PATH
254 #else
255 #define PATH_MAX 4096
256 #endif
257 #endif
258 
259 #define URL_MAX 2048
260 
261 #define strip_ext(fname) lives_strdup((char *)(fname ? strrchr(fname, '.') ? lives_memset(strrchr(fname, '.'), 0, 1) \
262 					       ? fname : fname : fname : NULL))
263 
264 // math macros / functions
265 
266 #define squared(a) ((a) * (a))
267 
268 #define sig(a) ((a) < 0. ? -1.0 : 1.0)
269 
270 // round to nearest integer
271 #define ROUND_I(a) ((int)((double)(a) + .5))
272 
273 // clamp a between 0 and b; both values rounded to nearest int
274 #define NORMAL_CLAMP(a, b) (ROUND_I((a))  < 0 ? 0 : ROUND_I((a)) > ROUND_I((b)) ? ROUND_I((b)) : ROUND_I((a)))
275 
276 // clamp a between 1 and b; both values rounded to nearest int; if rounded value of a is <= 0, return rounded b
277 #define UTIL_CLAMP(a, b) (NORMAL_CLAMP((a), (b)) <= 0 ? ROUND_I((b)) : ROUND_I((a)))
278 
279 // normal integer clamp
280 #define INT_CLAMP(i, min, max) ((i) < (min) ? (min) : (i) > (max) ? (max) : (i))
281 
282 // round a up double / float a to  next multiple of int b
283 #define CEIL(a, b) ((int)(((double)(a) + (double)(b) - .000000001) / ((double)(b))) * (b))
284 
285 // round int a up to next multiple of int b, unless a is already a multiple of b
286 #define ALIGN_CEIL(a, b) (((int)(((a) + (b) - 1.) / (b))) * (b))
287 
288 // round int a up to next multiple of int b, unless a is already a multiple of b
289 #define ALIGN_CEIL64(a, b) ((((int64_t)(a) + (int64_t)(b) - 1) / (int64_t)(b)) * (int64_t)(b))
290 
291 // round float / double a down to nearest multiple of int b
292 #define FLOOR(a, b) ((int)(((double)(a) - .000000001) / ((double)(b))) * (b))
293 
294 // floating point division, maintains the sign of the dividend, regardless of the sign of the divisor
295 #define SIGNED_DIVIDE(a, b) ((a) < 0. ? -fabs((a) / (b)) : fabs((a) / (b)))
296 
297 // using signed ints, the first part will be 1 iff -a < b, the second iff a > b, equivalent to abs(a) > b
298 #define ABS_THRESH(a, b) (((a) + (b)) >> 31) | (((b) - (a)) >> 31)
299 
300 #define myround(n) ((n) >= 0. ? (int)((n) + 0.5) : (int)((n) - 0.5))
301 
302 #ifdef NEED_ENDIAN_TEST
303 #undef NEED_ENDIAN_TEST
304 static const int32_t testint = 0x12345678;
305 #define IS_BIG_ENDIAN (((char *)&testint)[0] == 0x12)  // runtime test only !
306 #endif
307 
308 // utils.c math functions
309 float LEFloat_to_BEFloat(float f) GNU_CONST;
310 uint64_t lives_10pow(int pow) GNU_CONST;
311 double lives_fix(double val, int decimals) GNU_CONST;
312 uint32_t get_approx_ln(uint32_t val) GNU_CONST;
313 uint64_t get_approx_ln64(uint64_t x)GNU_CONST;
314 uint64_t get_near2pow(uint64_t val) GNU_CONST;
315 
316 typedef struct {
317   uint16_t red;
318   uint16_t green;
319   uint16_t blue;
320 } lives_colRGB48_t;
321 
322 typedef struct {
323   uint16_t red;
324   uint16_t green;
325   uint16_t blue;
326   uint16_t alpha;
327 } lives_colRGBA64_t;
328 
329 #define WEED_ADVANCED_PALETTES
330 
331 #if NEED_LOCAL_WEED
332 #include "../libweed/weed-host.h"
333 #include "../libweed/weed.h"
334 #include "../libweed/weed-events.h"
335 #include "../libweed/weed-palettes.h"
336 #include "../libweed/weed-effects.h"
337 #else
338 #include <weed/weed-host.h>
339 #include <weed/weed.h>
340 #include <weed/weed-events.h>
341 #include <weed/weed-palettes.h>
342 #include <weed/weed-effects.h>
343 #endif
344 
345 #if NEED_LOCAL_WEED_UTILS
346 #include "../libweed/weed-utils.h"
347 #else
348 #include <weed/weed-utils.h>
349 #endif
350 
351 #ifdef USE_SWSCALE
352 // for weed-compat.h
353 #define HAVE_AVCODEC
354 #define HAVE_AVUTIL
355 #endif
356 
357 #define NEED_FOURCC_COMPAT
358 
359 #ifdef NEED_LOCAL_WEED_COMPAT
360 #include "../libweed/weed-compat.h"
361 #else
362 #include <weed/weed-compat.h>
363 #endif
364 
365 weed_leaf_get_f _weed_leaf_get;
366 weed_leaf_set_f _weed_leaf_set;
367 weed_plant_new_f _weed_plant_new;
368 weed_plant_list_leaves_f _weed_plant_list_leaves;
369 weed_leaf_num_elements_f _weed_leaf_num_elements;
370 weed_leaf_element_size_f _weed_leaf_element_size;
371 weed_leaf_seed_type_f _weed_leaf_seed_type;
372 weed_leaf_get_flags_f _weed_leaf_get_flags;
373 weed_plant_free_f _weed_plant_free;
374 weed_leaf_set_flags_f _weed_leaf_set_flags;
375 weed_leaf_delete_f _weed_leaf_delete;
376 
377 #ifndef IGN_RET
378 #define IGN_RET(a) ((void)((a) + 1))
379 #endif
380 
381 #define EXPECTED(x) __builtin_expect((x), 1)
382 #define UNEXPECTED(x) __builtin_expect((x), 0)
383 
384 #include "weed-effects-utils.h"
385 #include "support.h"
386 #include "widget-helper.h"
387 
388 /// install guidance flags
389 #define INSTALL_CANLOCAL (1ul << 0)
390 
391 typedef enum {
392   MISSING = -1, ///< not yet implemented (TODO)
393   UNCHECKED = 0,
394   PRESENT,
395   LOCAL
396 } lives_presence_t;
397 
398 #ifdef NEW_CHECKSTATUS
399 typedef enum {
400   CONFLICTING = -1,
401   MANDATORY, ///< mandatory for application
402   RECOMMENDED,
403   OPTIONAL,
404   NECESSARY ///< necessary for the funtion in question
405 } lives_importance_t;
406 
407 typedef struct {
408   lives_presence_t present;
409   lives_importance_t import;
410   uint64_t flags;
411 } lives_checkstatus_t;
412 
413 #define XCAPABLE(foo, EXE_FOO) ((capable->has_##foo->present == UNCHECKED \
414 				 ? ((capable->has_##foo->present =	\
415 							 (has_executable(EXE_FOO) ? PRESENT : MISSING))) : \
416 				 capable->has_##foo->present) == PRESENT)
417 #define GET_EXE(foo) QUOTEME(foo)
418 #define PRESENT(foo) (XCAPABLE(foo, GET_EXE(foo)) == PRESENT)
419 #define MISSING(foo) (XCAPABLE(foo, GET_EXE(foo)) == MISSING)
420 //TODO:
421 // #define GET_EXE(mplayer) EXEC_MPLAYER
422 // etc.
423 // then: if (capable->has_mplayer) => if (PRESENT(mplayer)) etc.
424 // and even:
425 
426 //#define IS_SHOW_STOPPER(foo) ((MISSING(foo) && MANDATORY(foo)))
427 
428 #else
429 typedef lives_presence_t lives_checkstatus_t;
430 #endif
431 
432 typedef struct {
433   char wm_name[64];
434   uint64_t ver_major;
435   uint64_t ver_minor;
436   uint64_t ver_micro;
437 
438   LiVESXWindow *root_window;
439   boolean is_composited;
440 
441 #define ANNOY_DISPLAY      	(1ul << 0)
442 #define ANNOY_DISK		(1ul << 1)
443 #define ANNOY_PROC		(1ul << 2)
444 #define ANNOY_NETWORK		(1ul << 3)
445 #define ANNOY_SOUNDS		(1ul << 4)
446 #define ANNOY_DEV		(1ul << 5)
447 #define ANNOY_OTHER		(1ul << 6)
448 
449 #define ANNOY_FS		(1ul << 32)
450 #define ANNOY_CONT		(1ul << 33)
451 #define ANNOY_PERIOD		(1ul << 34)
452 #define ANNOY_SPONT		(1ul << 35)
453 #define ANNOY_TIMED		(1ul << 36)
454 #define ANNOY_LOCK		(1ul << 37)
455 
456 #define RES_HIDE		(1ul << 0)
457 #define RES_SUSPEND		(1ul << 1)
458 #define RES_STOP		(1ul << 2)
459 #define RES_BLOCK		(1ul << 3)
460 #define RES_MUTE		(1ul << 4)
461 
462 #define RESTYPE_ACTION		(1ul << 16)
463 #define RESTYPE_CONFIG		(1ul << 17)
464 #define RESTYPE_SIGNAL		(1ul << 18)
465 #define RESTYPE_CMD		(1ul << 19)
466 #define RESTYPE_LOCKOUT		(1ul << 20)
467 #define RESTYPE_TIMED		(1ul << 21)
468 #define RESTYPE_MONITOR		(1ul << 22)
469 
470   char panel[64];
471   uint64_t pan_annoy;
472   uint64_t pan_res;
473   char ssave[64];
474   uint64_t ssave_annoy;
475   uint64_t ssave_res;
476   char other[64];
477   uint64_t oth_annoy;
478   uint64_t oth_res;
479 
480   char color_settings[64];
481   char display_settings[64];
482   char ssv_settings[64];
483   char pow_settings[64];
484   char settings[64];
485   char term[64];
486   char taskmgr[64];
487   char sshot[64];
488 } wm_caps_t;
489 
490 
491 typedef struct {
492   // the following can be assumed TRUE / PRESENT, they are checked on startup
493   boolean smog_version_correct;
494   boolean can_read_from_config;
495 
496   boolean can_write_to_config;
497   boolean can_write_to_config_new;
498 
499   boolean can_write_to_config_backup;
500   boolean can_write_to_workdir;
501 
502   lives_checkstatus_t has_smogrify;
503 
504   // the following may need checking before use
505   lives_checkstatus_t has_perl;
506   lives_checkstatus_t has_file;
507   lives_checkstatus_t has_dvgrab;
508   lives_checkstatus_t has_sox_play;
509   lives_checkstatus_t has_sox_sox;
510   lives_checkstatus_t has_autolives;
511   lives_checkstatus_t has_mplayer;
512   lives_checkstatus_t has_mplayer2;
513   lives_checkstatus_t has_mpv;
514   lives_checkstatus_t has_convert;
515   lives_checkstatus_t has_composite;
516   lives_checkstatus_t has_identify;
517   lives_checkstatus_t has_ffprobe;
518   lives_checkstatus_t has_ffmpeg;
519   lives_checkstatus_t has_cdda2wav;
520   lives_checkstatus_t has_icedax;
521   lives_checkstatus_t has_midistartstop;
522   lives_checkstatus_t has_jackd;
523   lives_checkstatus_t has_pulse_audio;
524   lives_checkstatus_t has_xwininfo;
525   lives_checkstatus_t has_gdb;
526   lives_checkstatus_t has_gzip;
527   lives_checkstatus_t has_gconftool_2;
528   lives_checkstatus_t has_xdg_screensaver;
529   //lives_checkstatus_t has_xdg_open;
530   lives_checkstatus_t has_wmctrl;
531   lives_checkstatus_t has_xdotool;
532   lives_checkstatus_t has_youtube_dl;
533   lives_checkstatus_t has_youtube_dlc;
534   lives_checkstatus_t has_pip;
535   lives_checkstatus_t has_du;
536   lives_checkstatus_t has_md5sum;
537   lives_checkstatus_t has_gio;
538   lives_checkstatus_t has_wget;
539   lives_checkstatus_t has_curl;
540   lives_checkstatus_t has_mktemp;
541   lives_checkstatus_t has_snap;
542 
543   /// home directory - default location for config file - locale encoding
544   char home_dir[PATH_MAX];
545 
546   char backend_path[PATH_MAX];
547 
548   char *xdg_data_home; // e.g $HOME/.local/share
549   char *xdg_session_desktop; // e.g ubuntustudio
550   char *xdg_current_desktop; // e.g XFCE
551   char *xdg_runtime_dir; // e.g /run/user/$uid
552 
553   char touch_cmd[PATH_MAX];
554   char rm_cmd[PATH_MAX];
555   char mv_cmd[PATH_MAX];
556   char cp_cmd[PATH_MAX];
557   char ln_cmd[PATH_MAX];
558   char chmod_cmd[PATH_MAX];
559   char cat_cmd[PATH_MAX];
560   char grep_cmd[PATH_MAX];
561   char sed_cmd[PATH_MAX];
562   char wc_cmd[PATH_MAX];
563   char echo_cmd[PATH_MAX];
564   char eject_cmd[PATH_MAX];
565   char rmdir_cmd[PATH_MAX];
566 
567   /// used for returning startup messages from the backend
568   char startup_msg[1024];
569 
570   // plugins
571   lives_checkstatus_t has_encoder_plugins;
572 
573   lives_checkstatus_t has_python;
574   uint64_t python_version;
575 
576   int ncpus;
577   int byte_order;
578 
579   char *myname_full;
580   char *myname;
581 
582   char *cpu_name;
583   short cpu_bits;
584   int cacheline_size;
585 
586   int64_t boot_time;
587   int xstdout;
588   int nmonitors;
589   int primary_monitor;
590 
591   pid_t mainpid;
592   pthread_t main_thread;
593   pthread_t gui_thread;
594 
595   char *username;
596 
597   mode_t umask;
598 
599   char *gui_theme_name;
600   char *icon_theme_name;
601   char *extra_icon_path;
602   LiVESList *all_icons;
603 
604   char *wm_type; ///< window manager type, e.g. x11
605   char *wm_name; ///< window manager name, may be different from wm_caps.wwm_name
606   boolean has_wm_caps;
607   wm_caps_t wm_caps;
608 
609   int64_t ds_used, ds_free, ds_tot;
610   char *mountpoint;  ///< utf-8
611 
612   char *os_name;
613   char *os_release;
614   char *os_hardware;
615 
616   char *distro_name;
617   char *distro_ver;
618   char *distro_codename;
619 
620   char *mach_name;
621 
622   int dclick_time;
623   int dclick_dist;
624   char *sysbindir;
625 } capability;
626 
627 capability *capable;
628 
629 #define DEF_ALIGN (sizeof(void *) * 8)
630 
631 #include "machinestate.h"
632 #include "lsd-tab.h"
633 
634 boolean weed_threadsafe;
635 int weed_abi_version;
636 
637 #define ALLOW_PNG24
638 
639 /// this struct is used only when physically resampling frames on the disk
640 /// we create an array of these and write them to the disk
641 typedef struct {
642   int value;
643   int64_t reltime;
644 } resample_event;
645 
646 typedef struct {
647   int afile;
648   double seek;
649   double vel;
650 } lives_audio_track_state_t;
651 
652 #ifdef IS_LIBLIVES
653 #include "liblives.hpp"
654 #include "lbindings.h"
655 #endif
656 
657 #define N_RECENT_FILES 16
658 
659 typedef enum {
660   UNDO_NONE = 0,
661   UNDO_EFFECT,
662   UNDO_RESIZABLE,
663   UNDO_MERGE,
664   UNDO_RESAMPLE,
665   UNDO_TRIM_AUDIO,
666   UNDO_CHANGE_SPEED,
667   UNDO_AUDIO_RESAMPLE,
668   UNDO_APPEND_AUDIO,
669   UNDO_INSERT,
670   UNDO_CUT,
671   UNDO_DELETE,
672   UNDO_DELETE_AUDIO,
673   UNDO_INSERT_SILENCE,
674   UNDO_NEW_AUDIO,
675 
676   /// resample/resize and resample audio for encoding
677   UNDO_ATOMIC_RESAMPLE_RESIZE,
678 
679   /// resample/reorder/resize/apply effects
680   UNDO_RENDER,
681 
682   UNDO_FADE_AUDIO,
683   UNDO_AUDIO_VOL,
684 
685   /// record audio to selection
686   UNDO_REC_AUDIO,
687 
688   UNDO_INSERT_WITH_AUDIO
689 } lives_undo_t;
690 
691 /// which stream end should cause playback to finish ?
692 typedef enum {
693   NEVER_STOP = 0,
694   STOP_ON_VID_END,
695   STOP_ON_AUD_END
696 } lives_whentostop_t;
697 
698 /// cancel reason
699 typedef enum {
700   /// no cancel
701   CANCEL_NONE = FALSE,
702 
703   /// user pressed stop
704   CANCEL_USER,
705 
706   /// cancel but keep opening
707   CANCEL_NO_PROPOGATE,
708 
709   /// effect processing finished during preview
710   CANCEL_PREVIEW_FINISHED,
711 
712   /// application quit
713   CANCEL_APP_QUIT,
714 
715   /// ran out of preview frames
716   CANCEL_NO_MORE_PREVIEW,
717 
718   /// image could not be captured
719   CANCEL_CAPTURE_ERROR,
720 
721   /// event_list completed
722   CANCEL_EVENT_LIST_END,
723 
724   /// video playback completed
725   CANCEL_VID_END,
726 
727   /// generator was stopped
728   CANCEL_GENERATOR_END,
729 
730   /// external process ended (e.g. autolives uncheck)
731   CANCEL_EXTERNAL_ENDED,
732 
733   /// user pressed 'Keep'
734   CANCEL_KEEP,
735 
736   /// video playback completed
737   CANCEL_AUD_END,
738 
739   /// cancelled because of error
740   CANCEL_ERROR,
741 
742   /// cancelled because of soundcard error
743   CANCEL_AUDIO_ERROR,
744 
745   /// cancelled and paused
746   CANCEL_USER_PAUSED,
747 
748   /// an error occurred, retry the operation
749   CANCEL_RETRY,
750 
751   /// software error: e.g set mainw->current_file directly during pb instead of mainw->new_clip
752   CANCEL_INTERNAL_ERROR,
753 
754   /// special cancel for TV toy
755   CANCEL_KEEP_LOOPING = CANCEL_NONE + 100
756 } lives_cancel_t;
757 
758 typedef enum {
759   CANCEL_KILL = 0, ///< normal - kill background processes working on current clip
760   CANCEL_SOFT     ///< just cancel in GUI (for keep, etc)
761 } lives_cancel_type_t;
762 
763 typedef enum {
764   CLIP_TYPE_DISK, ///< imported video, broken into frames
765   CLIP_TYPE_FILE, ///< unimported video, not or partially broken in frames
766   CLIP_TYPE_GENERATOR, ///< frames from generator plugin
767   CLIP_TYPE_NULL_VIDEO, ///< generates blank video frames
768   CLIP_TYPE_TEMP, ///< temp type, for internal use only
769   CLIP_TYPE_YUV4MPEG, ///< yuv4mpeg stream
770   CLIP_TYPE_LIVES2LIVES, ///< type for LiVES to LiVES streaming
771   CLIP_TYPE_VIDEODEV,  ///< frames from video device
772 } lives_clip_type_t;
773 
774 typedef enum {
775   IMG_TYPE_UNKNOWN = 0,
776   IMG_TYPE_JPEG,
777   IMG_TYPE_PNG,
778   N_IMG_TYPES
779 } lives_img_type_t;
780 
781 #define IMG_TYPE_BEST IMG_TYPE_PNG
782 
783 #define AFORM_SIGNED 0
784 #define AFORM_LITTLE_ENDIAN 0
785 
786 #define AFORM_UNSIGNED 1
787 #define AFORM_BIG_ENDIAN (1<<1)
788 #define AFORM_UNKNOWN 65536
789 
790 typedef enum {
791   LIVES_INTERLACE_NONE = 0,
792   LIVES_INTERLACE_BOTTOM_FIRST = 1,
793   LIVES_INTERLACE_TOP_FIRST = 2
794 } lives_interlace_t;
795 
796 #include "colourspace.h"
797 #include "pangotext.h"
798 
799 #define WEED_LEAF_HOST_DEINTERLACE "host_deint" // frame needs deinterlacing
800 #define WEED_LEAF_HOST_TC "host_tc" // timecode for deinterlace
801 #define WEED_LEAF_HOST_DECODER "host_decoder" // pointer to decoder for a layer
802 #define WEED_LEAF_HOST_PTHREAD "host_pthread" // thread for a layer
803 
804 #define CLIP_NAME_MAXLEN 256
805 
806 #define AV_TRACK_MIN_DIFF 0.001 ///< ignore track time differences < this (seconds)
807 
808 #define IS_VALID_CLIP(clip) (clip >= 0 && clip <= MAX_FILES && mainw->files[clip])
809 #define CURRENT_CLIP_IS_VALID IS_VALID_CLIP(mainw->current_file)
810 
811 #define IS_TEMP_CLIP(clip) (IS_VALID_CLIP(clip) && mainw->files[clip]->clip_type == CLIP_TYPE_TEMP)
812 #define CURRENT_CLIP_IS_TEMP IS_TEMP_CLIP(mainw->current_file)
813 
814 #define CLIP_HAS_VIDEO(clip) (IS_VALID_CLIP(clip) ? mainw->files[clip]->frames > 0 : FALSE)
815 #define CURRENT_CLIP_HAS_VIDEO CLIP_HAS_VIDEO(mainw->current_file)
816 
817 #define CLIP_HAS_AUDIO(clip) (IS_VALID_CLIP(clip) ? (mainw->files[clip]->achans > 0 && mainw->files[clip]->asampsize > 0) : FALSE)
818 #define CURRENT_CLIP_HAS_AUDIO CLIP_HAS_AUDIO(mainw->current_file)
819 
820 #define CLIP_VIDEO_TIME(clip) ((double)(IS_VALID_CLIP(clip) ? mainw->files[clip]->video_time : 0.))
821 
822 #define CLIP_LEFT_AUDIO_TIME(clip) ((double)(IS_VALID_CLIP(clip) ? mainw->files[clip]->laudio_time : 0.))
823 
824 #define CLIP_RIGHT_AUDIO_TIME(clip) ((double)(IS_VALID_CLIP(clip) ? (mainw->files[clip]->achans > 1 ? \
825 								     mainw->files[clip]->raudio_time : 0.) : 0.))
826 
827 #define CLIP_AUDIO_TIME(clip) ((double)(CLIP_LEFT_AUDIO_TIME(clip) >= CLIP_RIGHT_AUDIO_TIME(clip) \
828 					? CLIP_LEFT_AUDIO_TIME(clip) : CLIP_RIGHT_AUDIO_TIME(clip)))
829 
830 #define CLIP_TOTAL_TIME(clip) ((double)(CLIP_VIDEO_TIME(clip) > CLIP_AUDIO_TIME(clip) ? CLIP_VIDEO_TIME(clip) : \
831 					CLIP_AUDIO_TIME(clip)))
832 
833 #define IS_NORMAL_CLIP(clip) (IS_VALID_CLIP(clip)			\
834 			      ? (mainw->files[clip]->clip_type == CLIP_TYPE_DISK \
835 				 || mainw->files[clip]->clip_type == CLIP_TYPE_FILE \
836 				 || mainw->files[clip]->clip_type == CLIP_TYPE_NULL_VIDEO) : FALSE)
837 
838 #define CURRENT_CLIP_IS_NORMAL IS_NORMAL_CLIP(mainw->current_file)
839 
840 #define LIVES_IS_PLAYING (mainw && mainw->playing_file > -1)
841 
842 #define LIVES_IS_RENDERING (mainw && ((!mainw->multitrack && mainw->is_rendering) \
843 					      || (mainw->multitrack && mainw->multitrack->is_rendering)) \
844 			    && !mainw->preview_rendering)
845 
846 #define CURRENT_CLIP_TOTAL_TIME CLIP_TOTAL_TIME(mainw->current_file)
847 
848 #define CURRENT_CLIP_IS_CLIPBOARD (mainw->current_file == 0)
849 
850 /// use REVERSE / FORWARD when a sign is used, BACKWARD / FORWARD when a parity is used
851 typedef enum {
852   LIVES_DIRECTION_REVERSE = -1,
853   LIVES_DIRECTION_BACKWARD,
854   LIVES_DIRECTION_FORWARD,
855   LIVES_DIRECTION_LEFT,
856   LIVES_DIRECTION_RIGHT,
857   LIVES_DIRECTION_UP,
858   LIVES_DIRECTION_DOWN,
859   LIVES_DIRECTION_IN,
860   LIVES_DIRECTION_OUT,
861 } lives_direction_t;
862 
863 #define LIVES_DIRECTION_FWD_OR_REV(dir) ((dir) == LIVES_DIRECTION_BACKWARD ? LIVES_DIRECTION_REVERSE : (dir))
864 #define LIVES_DIRECTION_SIG(dir) ((lives_direction_t)sig(dir))  /// LIVES_DIRECTION_REVERSE or LIVES_DIRECTION_FORWARD
865 #define LIVES_DIRECTION_PAR(dir) ((lives_direction_t)((dir) & 1)) /// LIVES_DIRECTION_BACKWARD or LIVES_DIRECTION_FORWARD
866 #define LIVES_DIRECTION_OPPOSITE(dir1, dir2) (((dir1) == LIVES_DIR_BACKWARD || (dir1) == LIVES_DIR_REVERSED) \
867 					      ? (dir2) == LIVES_DIR_FORWARD : \
868 					      ((dir2) == LIVES_DIR_BACKWARD || (dir2) == LIVES_DIR_REVERSED) \
869 					      ? (dir1) == LIVES_DIR_FORWARD : sig(dir1) != sig(dir2))
870 typedef union _binval {
871   uint64_t num;
872   const char chars[8];
873   size_t size;
874 } binval;
875 
876 /// corresponds to one clip in the GUI
877 typedef struct _lives_clip_t {
878   binval binfmt_check, binfmt_version, binfmt_bytes;
879 
880   uint64_t unique_id;    ///< this and the handle can be used to uniquely id a file
881   char handle[256];
882 
883   char md5sum[64];
884   char type[64];
885 
886   lives_clip_type_t clip_type;
887   lives_img_type_t img_type;
888 
889   // basic info (saved during backup)
890   frames_t frames;  ///< number of video frames
891   frames_t start, end;
892 
893   double fps;  /// framerate of the clip
894   boolean ratio_fps; ///< if the fps was set by a ratio
895 
896   int hsize; ///< frame width (horizontal) in pixels (NOT macropixels !)
897   int vsize; ///< frame height (vertical) in pixels
898 
899   lives_interlace_t interlace; ///< interlace type (if known - none, topfirst, bottomfirst or : see plugins.h)
900 
901   int bpp; ///< bits per pixel of the image frames, 24 or 32
902 
903   int gamma_type;
904 
905   int arps; ///< audio physical sample rate (i.e the "normal" sample rate of the clip when played at 1,0 X velocity)
906   int arate; ///< current audio playback rate (varies if the clip rate is changed)
907   int achans; ///< number of audio channels (0, 1 or 2)
908   int asampsize; ///< audio sample size in bits (8 or 16)
909   uint32_t signed_endian; ///< bitfield
910   float vol; ///< relative volume level / gain; sizeof array will be equal to achans
911 
912   size_t afilesize;
913   size_t f_size;
914 
915   boolean changed;
916   boolean was_in_set;
917 
918   /////////////////
919   char title[1024], author[1024], comment[1024], keywords[1024];
920   ////////////////
921 
922   char name[CLIP_NAME_MAXLEN];  ///< the display name
923   char file_name[PATH_MAX]; ///< input file
924   char save_file_name[PATH_MAX];
925 
926   boolean is_untitled, orig_file_name, was_renamed;
927 
928   // various times; total time is calculated as the longest of video, laudio and raudio
929   double video_time, laudio_time, raudio_time;
930 
931   double pointer_time;  ///< pointer time in timeline, + the playback start posn for clipeditor (unless playing the selection)
932   double real_pointer_time;  ///< pointer time in timeline, can extend beyond video, for audio
933 
934   frames_t frameno, last_frameno;
935 
936   char mime_type[256]; ///< not important
937 
938   boolean deinterlace; ///< auto deinterlace
939 
940   int header_version;
941 #define LIVES_CLIP_HEADER_VERSION 102
942 
943   // extended info (not saved)
944 
945   //opening/restoring status
946   boolean opening, opening_audio, opening_only_audio, opening_loc;
947   frames_t opening_frames;
948   boolean restoring;
949   boolean is_loaded;  ///< should we continue loading if we come back to this clip
950 
951   frames_t progress_start, progress_end;
952 
953   ///undo
954   lives_undo_t undo_action;
955 
956   frames_t undo_start, undo_end;
957   frames_t insert_start, insert_end;
958 
959   char undo_text[32], redo_text[32];
960 
961   boolean undoable, redoable;
962 
963   // used for storing undo values
964   int undo1_int, undo2_int, undo3_int, undo4_int;
965   uint32_t undo1_uint;
966   double undo1_dbl, undo2_dbl;
967   boolean undo1_boolean, undo2_boolean, undo3_boolean;
968 
969   int undo_arate; ///< audio playback rate
970   int undo_achans;
971   int undo_asampsize;
972   int undo_arps;
973   uint32_t undo_signed_endian;
974 
975   int ohsize, ovsize;
976 
977   frames_t old_frames; ///< for deordering, etc.
978 
979   // used only for insert_silence, holds pre-padding length for undo
980   double old_laudio_time, old_raudio_time;
981 
982   /////
983   // binfmt fields may be added here:
984   ///
985 
986 
987   ////
988   //// end add section ^^^^^^^
989 
990   /// binfmt is just a file dump of the struct up to the end of binfmt_end
991   char binfmt_rsvd[4096];
992   uint64_t binfmt_end; ///< marks the end of anything "interesring" we may want to save via binfmt extension
993 
994   /// DO NOT remove or alter any fields before this ^^^^^
995   ///////////////////////////////////////////////////////////////////////////
996   // fields after here can be removed or changed or added to
997 
998   boolean has_binfmt;
999 
1000   /// index of frames for CLIP_TYPE_FILE
1001   /// >0 means corresponding frame within original clip
1002   /// -1 means corresponding image file (equivalent to CLIP_TYPE_DISK)
1003   /// size must be >= frames, MUST be contiguous in memory
1004   frames_t *frame_index;
1005   frames_t *frame_index_back; ///< for undo
1006 
1007   double pb_fps;  ///< current playback rate, may vary from fps, can be 0. or negative
1008 
1009   char info_file[PATH_MAX]; ///< used for asynch communication with externals
1010 
1011   LiVESWidget *menuentry;
1012   ulong menuentry_func;
1013   double freeze_fps; ///< pb_fps for paused / frozen clips
1014   boolean play_paused;
1015 
1016   lives_direction_t adirection; ///< audio play direction during playback, FORWARD or REVERSE.
1017 
1018   /// don't show preview/pause buttons on processing
1019   boolean nopreview;
1020 
1021   /// don't show the 'keep' button - e.g. for operations which resize frames
1022   boolean nokeep;
1023 
1024   // current and last played index frames for internal player
1025   frames_t saved_frameno;
1026 
1027   /////////////////////////////////////////////////////////////
1028   // see resample.c for new events system
1029 
1030   // events
1031   resample_event *resample_events;  ///<for block resampler
1032 
1033   weed_plant_t *event_list;
1034   weed_plant_t *event_list_back;
1035   weed_plant_t *next_event;
1036 
1037   LiVESList *layout_map;
1038   ////////////////////////////////////////////////////////////////////////////////////////
1039 
1040   void *ext_src; ///< points to opaque source for non-disk types
1041 
1042 #define LIVES_EXT_SRC_UNKNOWN -1
1043 #define LIVES_EXT_SRC_NONE 0
1044 #define LIVES_EXT_SRC_DECODER 1
1045 #define LIVES_EXT_SRC_FILTER 2
1046 #define LIVES_EXT_SRC_FIFO 3
1047 #define LIVES_EXT_SRC_STREAM 4
1048 #define LIVES_EXT_SRC_DEVICE 5
1049 #define LIVES_EXT_SRC_FILE_BUFF 6
1050 
1051   int ext_src_type;
1052 
1053   int n_altsrcs;
1054   void **alt_srcs;
1055   int *alt_src_types;
1056 
1057   uint64_t *cache_objects; ///< for future use
1058 
1059   lives_proc_thread_t pumper;
1060   frames_t fx_frame_pump; ///< rfx frame pump for virtual clips (CLIP_TYPE_FILE)
1061 
1062 #define IMG_BUFF_SIZE 262144  ///< 256 * 1024 < chunk size for reading images
1063 
1064   volatile off64_t aseek_pos; ///< audio seek posn. (bytes) for when we switch clips
1065 
1066   // decoder data
1067 
1068   frames_t last_vframe_played; /// experimental for player
1069 
1070   /// layout map for the current layout
1071   frames_t stored_layout_frame; ///M highest value used
1072   int stored_layout_idx;
1073   double stored_layout_audio;
1074   double stored_layout_fps;
1075 
1076   lives_subtitles_t *subt;
1077 
1078   boolean no_proc_sys_errors; ///< skip system error dialogs in processing
1079   boolean no_proc_read_errors; ///< skip read error dialogs in processing
1080   boolean no_proc_write_errors; ///< skip write error dialogs in processing
1081 
1082   boolean keep_without_preview; ///< allow keep, even when nopreview is set - TODO use only nopreview and nokeep
1083 
1084   lives_painter_surface_t *laudio_drawable, *raudio_drawable;
1085 
1086   int cb_src; ///< source clip for clipboard; for other clips, may be used to hold some temporary linkage
1087 
1088   boolean needs_update; ///< loaded values were incorrect, update header
1089   boolean needs_silent_update; ///< needs internal update, we shouldn't concern the user
1090 
1091   boolean checked_for_old_header, has_old_header;
1092 
1093   float **audio_waveform; ///< values for drawing the audio wave
1094   size_t *aw_sizes; ///< size of each audio_waveform in units of floats (i.e 4 bytes)
1095 
1096   int last_play_sequence;  ///< updated only when FINISHING playing a clip (either by switching or ending playback, better for a/vsync)
1097 
1098   int tcache_height; /// height for thumbnail cache (width is fixed, but if this changes, invalidate)
1099   frames_t tcache_dubious_from; /// set by clip alterations, frames from here onwards should be freed
1100   LiVESList *tcache; /// thumbnail cache, list of lives_tcache_entry_t
1101   boolean checked; /// clip integrity checked on load - to avoid duplicating it
1102 } lives_clip_t;
1103 
1104 typedef struct {
1105   /// list of entries in clip thumbnail cache (for multitrack timeline)
1106   frames_t frame;
1107   LiVESPixbuf *pixbuf;
1108 } lives_tcache_entry_t;
1109 
1110 /// some shared structures
1111 
1112 #define USE_MPV (!capable->has_mplayer && !capable->has_mplayer2 && capable->has_mpv)
1113 #define HAS_EXTERNAL_PLAYER (capable->has_mplayer || capable->has_mplayer2 || capable->has_mpv)
1114 
1115 #ifdef ENABLE_JACK
1116 #include "jack.h"
1117 #endif
1118 
1119 #define USE_16BIT_PCONV
1120 
1121 // common defs for mainwindow (retain this order)
1122 #include "plugins.h"
1123 #include "paramspecial.h"
1124 #include "multitrack.h"
1125 #include "events.h"
1126 #include "mainwindow.h"
1127 #include "keyboard.h"
1128 #include "preferences.h"
1129 
1130 extern mainwindow *mainw;
1131 
1132 #define BACKEND_NAME EXEC_SMOGRIFY
1133 
1134 // internal player clock
1135 #include <sys/time.h>
1136 struct timeval tv;
1137 
1138 /// type sizes
1139 extern ssize_t sizint, sizdbl, sizshrt;
1140 
1141 typedef enum {
1142   CLIP_DETAILS_BPP,
1143   CLIP_DETAILS_FPS,
1144   CLIP_DETAILS_PB_FPS,
1145   CLIP_DETAILS_WIDTH,
1146   CLIP_DETAILS_HEIGHT,
1147   CLIP_DETAILS_UNIQUE_ID,
1148   CLIP_DETAILS_ARATE,
1149   CLIP_DETAILS_PB_ARATE,
1150   CLIP_DETAILS_ACHANS,
1151   CLIP_DETAILS_ASIGNED,
1152   CLIP_DETAILS_AENDIAN,
1153   CLIP_DETAILS_ASAMPS,
1154   CLIP_DETAILS_FRAMES,
1155   CLIP_DETAILS_TITLE,
1156   CLIP_DETAILS_AUTHOR,
1157   CLIP_DETAILS_COMMENT,
1158   CLIP_DETAILS_PB_FRAMENO,
1159   CLIP_DETAILS_FILENAME,
1160   CLIP_DETAILS_CLIPNAME,
1161   CLIP_DETAILS_HEADER_VERSION,
1162   CLIP_DETAILS_KEYWORDS,
1163   CLIP_DETAILS_INTERLACE,
1164   CLIP_DETAILS_DECODER_NAME,
1165   CLIP_DETAILS_GAMMA_TYPE,
1166   CLIP_DETAILS_MD5SUM, // for future use
1167   CLIP_DETAILS_CACHE_OBJECTS, // for future use
1168   CLIP_DETAILS_RESERVED30,
1169   CLIP_DETAILS_RESERVED29,
1170   CLIP_DETAILS_RESERVED28,
1171   CLIP_DETAILS_RESERVED27,
1172   CLIP_DETAILS_RESERVED26,
1173   CLIP_DETAILS_RESERVED25,
1174   CLIP_DETAILS_RESERVED24,
1175   CLIP_DETAILS_RESERVED23,
1176   CLIP_DETAILS_RESERVED22,
1177   CLIP_DETAILS_RESERVED21,
1178   CLIP_DETAILS_RESERVED20,
1179   CLIP_DETAILS_RESERVED19,
1180   CLIP_DETAILS_RESERVED18,
1181   CLIP_DETAILS_RESERVED17,
1182   CLIP_DETAILS_RESERVED16,
1183   CLIP_DETAILS_RESERVED15,
1184   CLIP_DETAILS_RESERVED14,
1185   CLIP_DETAILS_RESERVED13,
1186   CLIP_DETAILS_RESERVED12,
1187   CLIP_DETAILS_RESERVED11,
1188   CLIP_DETAILS_RESERVED10,
1189   CLIP_DETAILS_RESERVED9,
1190   CLIP_DETAILS_RESERVED8,
1191   CLIP_DETAILS_RESERVED7,
1192   CLIP_DETAILS_RESERVED6,
1193   CLIP_DETAILS_RESERVED5,
1194   CLIP_DETAILS_RESERVED4,
1195   CLIP_DETAILS_RESERVED3,
1196   CLIP_DETAILS_RESERVED2,
1197   CLIP_DETAILS_RESERVED1,
1198   CLIP_DETAILS_RESERVED0
1199 } lives_clip_details_t;
1200 
1201 // some useful functions
1202 
1203 // callbacks.c
1204 boolean all_config(LiVESWidget *, LiVESXEventConfigure *, livespointer ppsurf);
1205 boolean all_expose(LiVESWidget *, lives_painter_t *, livespointer psurf);
1206 
1207 // dialogs.c
1208 boolean do_progress_dialog(boolean visible, boolean cancellable, const char *text);
1209 
1210 boolean do_warning_dialog(const char *text);
1211 boolean do_warning_dialogf(const char *fmt, ...);
1212 boolean do_warning_dialog_with_check(const char *text, uint64_t warn_mask_number);
1213 
1214 boolean do_yesno_dialog(const char *text);
1215 boolean do_yesno_dialogf(const char *fmt, ...);
1216 boolean do_yesno_dialog_with_check(const char *text, uint64_t warn_mask_number);
1217 
1218 void do_abort_dialog(const char *text);
1219 LiVESResponseType do_abort_ok_dialog(const char *text);
1220 LiVESResponseType do_abort_retry_dialog(const char *text);
1221 LiVESResponseType do_abort_cancel_retry_dialog(const char *text) WARN_UNUSED;
1222 
1223 LiVESResponseType do_retry_cancel_dialog(const char *text);
1224 
1225 LiVESResponseType do_error_dialog(const char *text);
1226 LiVESResponseType do_error_dialogf(const char *fmt, ...);
1227 LiVESResponseType do_error_dialog_with_check(const char *text, uint64_t warn_mask_number);
1228 
1229 LiVESResponseType do_info_dialog(const char *text);
1230 LiVESResponseType do_info_dialogf(const char *fmt, ...);
1231 LiVESResponseType do_info_dialog_with_expander(const char *text, const char *exp_text, LiVESList *);
1232 
1233 LiVESWidget *create_message_dialog(lives_dialog_t diat, const char *text, int warn_mask_number);
1234 LiVESWidget *create_question_dialog(const char *title, const char *text);
1235 
1236 LiVESWindow *get_transient_full();
1237 
1238 void do_abortblank_error(const char *what);
1239 void do_optarg_blank_err(const char *what);
1240 void do_clip_divergence_error(int fileno);
1241 LiVESResponseType do_system_failed_error(const char *com, int retval, const char *addinfo, boolean can_retry,
1242     boolean try_sudo);
1243 LiVESResponseType do_write_failed_error_s_with_retry(const char *fname, const char *errtext) WARN_UNUSED;
1244 void do_write_failed_error_s(const char *filename, const char *addinfo);
1245 LiVESResponseType do_read_failed_error_s_with_retry(const char *fname, const char *errtext) WARN_UNUSED;
1246 void do_read_failed_error_s(const char *filename, const char *addinfo);
1247 boolean do_header_write_error(int clip);
1248 LiVESResponseType do_header_read_error_with_retry(int clip) WARN_UNUSED;
1249 LiVESResponseType do_header_missing_detail_error(int clip, lives_clip_details_t detail) WARN_UNUSED;
1250 void do_chdir_failed_error(const char *dir);
1251 LiVESResponseType handle_backend_errors(boolean can_retry);
1252 boolean check_backend_return(lives_clip_t *sfile);
1253 const char *get_cache_stats(void);
1254 
1255 /** warn about disk space */
1256 char *ds_critical_msg(const char *dir, char **mountpoint, uint64_t dsval);
1257 char *ds_warning_msg(const char *dir, char **mountpoint, uint64_t dsval, uint64_t cwarn, uint64_t nwarn);
1258 boolean check_storage_space(int clipno, boolean is_processing);
1259 
1260 char *get_upd_msg(void);
1261 
1262 boolean ask_permission_dialog(int what);
1263 boolean ask_permission_dialog_complex(int what, char **argv, int argc, int offs, const char *sudocom);
1264 boolean do_abort_check(void);
1265 void add_warn_check(LiVESBox *box, int warn_mask_number);
1266 LiVESResponseType do_memory_error_dialog(char *op, size_t bytes);
1267 void too_many_files(void);
1268 void workdir_warning(void);
1269 void do_audio_import_error(void);
1270 void do_mt_backup_space_error(lives_mt *, int memreq_mb);
1271 
1272 LiVESResponseType do_resize_dlg(int cwidth, int cheight, int fwidth, int fheight);
1273 LiVESResponseType do_imgfmts_error(lives_img_type_t imgtype);
1274 
1275 char *workdir_ch_warning(void);
1276 void do_shutdown_msg(void);
1277 
1278 boolean do_close_changed_warn(void);
1279 boolean do_save_clipset_warn(void);
1280 boolean do_clipboard_fps_warning(void);
1281 void perf_mem_warning(void);
1282 void do_dvgrab_error(void);
1283 boolean do_comments_dialog(int fileno, char *filename);
1284 boolean do_auto_dialog(const char *text, int type);
1285 void do_encoder_acodec_error(void);
1286 void do_encoder_sox_error(void);
1287 boolean rdet_suggest_values(int width, int height, double fps, int fps_num, int fps_denom, int arate,
1288                             int asigned, boolean swap_endian, boolean anr, boolean ignore_fps);
1289 boolean do_encoder_restrict_dialog(int width, int height, double fps, int fps_num, int fps_denom,
1290                                    int arate, int asigned, boolean swap_endian, boolean anr, boolean save_all);
1291 void do_messages_window(boolean is_startup);
1292 void do_firstever_dialog(void);
1293 void do_upgrade_error_dialog(void);
1294 void do_no_mplayer_sox_error(void);
1295 void do_need_mplayer_dialog(void);
1296 void do_need_mplayer_mpv_dialog(void);
1297 void do_aud_during_play_error(void);
1298 void do_rendered_fx_dialog(void);
1299 void do_layout_scrap_file_error(void);
1300 void do_layout_ascrap_file_error(void);
1301 void do_program_not_found_error(const char *progname);
1302 void do_lb_composite_error(void);
1303 void do_lb_convert_error(void);
1304 void do_set_load_lmap_error(void);
1305 boolean do_set_duplicate_warning(const char *new_set);
1306 boolean do_set_rename_old_layouts_warning(const char *new_set);
1307 boolean do_layout_alter_frames_warning(void);
1308 boolean do_layout_alter_audio_warning(void);
1309 boolean do_reload_set_query(void);
1310 boolean findex_bk_dialog(const char *fname_back);
1311 boolean paste_enough_dlg(int lframe);
1312 boolean do_yuv4m_open_warning(void);
1313 void do_mt_undo_mem_error(void);
1314 void do_mt_undo_buf_error(void);
1315 void do_mt_set_mem_error(boolean has_mt);
1316 void do_mt_audchan_error(int warn_mask);
1317 void do_mt_no_audchan_error(void);
1318 void do_mt_no_jack_error(int warn_mask);
1319 boolean do_mt_rect_prompt(void);
1320 void do_audrate_error_dialog(void);
1321 boolean do_event_list_warning(void);
1322 void do_nojack_rec_error(void);
1323 void do_vpp_palette_error(void);
1324 void do_vpp_fps_error(void);
1325 void do_decoder_palette_error(void);
1326 void do_rmem_max_error(int size);
1327 boolean do_gamma_import_warn(uint64_t fv, int gamma_type);
1328 boolean do_mt_lb_warn(boolean lb);
1329 LiVESResponseType do_file_notfound_dialog(const char *detail, const char *dirname);
1330 LiVESResponseType do_dir_notfound_dialog(const char *detail, const char *dirname);
1331 void do_no_decoder_error(const char *fname);
1332 void do_no_loadfile_error(const char *fname);
1333 void do_jack_noopen_warn(void);
1334 void do_jack_noopen_warn2(void);
1335 void do_jack_noopen_warn3(void);
1336 void do_jack_noopen_warn4(void);
1337 LiVESResponseType do_file_perm_error(const char *file_name, boolean allow_cancel);
1338 LiVESResponseType do_dir_perm_error(const char *dir_name, boolean allow_cancel);
1339 void do_dir_perm_access_error(const char *dir_name);
1340 void do_encoder_img_fmt_error(render_details *rdet);
1341 void do_after_crash_warning(void);
1342 void do_after_invalid_warning(void);
1343 void do_bad_layout_error(void);
1344 void do_card_in_use_error(void);
1345 void do_dev_busy_error(const char *devstr);
1346 boolean do_existing_subs_warning(void);
1347 void do_invalid_subs_error(void);
1348 boolean do_erase_subs_warning(void);
1349 boolean do_sub_type_warning(const char *ext, const char *type_ext);
1350 boolean do_move_workdir_dialog(void);
1351 boolean do_set_locked_warning(const char *setname);
1352 void do_no_in_vdevs_error(void);
1353 void do_locked_in_vdevs_error(void);
1354 void do_do_not_close_d(void);
1355 void do_set_noclips_error(const char *setname);
1356 boolean do_foundclips_query(void);
1357 void do_no_autolives_error(void);
1358 void do_autolives_needs_clips_error(void);
1359 void do_pulse_lost_conn_error(void);
1360 void do_jack_lost_conn_error(void);
1361 void do_cd_error_dialog(void);
1362 void do_bad_theme_error(const char *themefile);
1363 void do_bad_theme_import_error(const char *theme_file);
1364 boolean do_theme_exists_warn(const char *themename);
1365 boolean do_layout_recover_dialog(void);
1366 void do_no_sets_dialog(const char *dir);
1367 void add_resnn_label(LiVESDialog *dialog);
1368 
1369 int process_one(boolean visible);
1370 void update_progress(boolean visible);
1371 void do_threaded_dialog(const char *translated_text, boolean has_cancel);
1372 void end_threaded_dialog(void);
1373 void threaded_dialog_spin(double fraction);
1374 void threaded_dialog_push(void);
1375 void threaded_dialog_pop(void);
1376 
1377 void response_ok(LiVESButton *button, livespointer user_data);
1378 void pump_io_chan(LiVESIOChannel *iochan);
1379 
1380 void do_splash_progress(void);
1381 
1382 // message collection
1383 void d_print(const char *fmt, ...);
1384 char *dump_messages(int start, int end); // utils.c
1385 weed_plant_t *get_nth_info_message(int n); // utils.c
1386 int add_messages_to_list(const char *text);
1387 int free_n_msgs(int frval);
1388 
1389 // d_print shortcuts
1390 void d_print_cancelled(void);
1391 void d_print_failed(void);
1392 void d_print_done(void);
1393 void d_print_enough(int frames);
1394 void d_print_file_error_failed(void);
1395 
1396 boolean d_print_urgency(double timeout_seconds, const char *fmt, ...);
1397 boolean d_print_overlay(double timeout_seconds, const char *fmt, ...);
1398 
1399 // general
1400 void do_text_window(const char *title, const char *text);
1401 
1402 // saveplay.c
1403 boolean read_file_details(const char *file_name, boolean only_check_for_audio, boolean open_image);
1404 boolean add_file_info(const char *check_handle, boolean aud_only);
1405 boolean save_file_comments(int fileno);
1406 void set_default_comment(lives_clip_t *sfile, const char *extrat);
1407 boolean restore_clip_binfmt(int clipno);
1408 lives_clip_t *clip_forensic(int clipno);
1409 boolean reload_clip(int fileno, int maxframe);
1410 void wait_for_bg_audio_sync(int fileno);
1411 ulong deduce_file(const char *filename, double start_time, int end);
1412 ulong open_file(const char *filename);
1413 ulong open_file_sel(const char *file_name, double start_time, int frames);
1414 void pad_init_silence(void);
1415 void open_fw_device(void);
1416 char *get_untitled_name(int number);
1417 boolean get_new_handle(int index, const char *name);
1418 boolean get_temp_handle(int index);
1419 int close_temp_handle(int new_clip);
1420 boolean get_handle_from_info_file(int index);
1421 lives_clip_t *create_cfile(int new_file, const char *handle, boolean is_loaded);
1422 int create_nullvideo_clip(const char *handle);
1423 void save_file(int clip, int start, int end, const char *filename);
1424 void play_file(void);
1425 void start_playback_async(int type);
1426 boolean start_playback(int type);
1427 void play_start_timer(int type);
1428 void save_frame(LiVESMenuItem *menuitem, livespointer user_data);
1429 boolean save_frame_inner(int clip, int frame, const char *file_name, int width, int height, boolean from_osc);
1430 void wait_for_stop(const char *stop_command);
1431 boolean save_clip_values(int which_file);
1432 void add_to_recovery_file(const char *handle);
1433 boolean rewrite_recovery_file(void);
1434 boolean check_for_recovery_files(boolean auto_recover);
1435 boolean recover_files(char *recovery_file, boolean auto_recover);
1436 void recover_layout_map(int numclips);
1437 const char *get_deinterlace_string(void);
1438 void reload_subs(int fileno);
1439 
1440 // saveplay.c backup
1441 void backup_file(int clip, int start, int end, const char *filename);
1442 int save_event_frames(void);
1443 boolean write_headers(lives_clip_t *file);
1444 
1445 // saveplay.c restore
1446 ulong restore_file(const char *filename);
1447 boolean read_headers(int clipno, const char *dir, const char *file_name);
1448 
1449 // saveplay.c sets
1450 void open_set_file(int clipnum);
1451 
1452 // saveplay.c scrap file
1453 boolean open_scrap_file(void);
1454 boolean open_ascrap_file(void);
1455 int save_to_scrap_file(weed_layer_t *layer);
1456 boolean load_from_scrap_file(weed_layer_t *layer, int frame);
1457 void close_ascrap_file(boolean remove);
1458 void close_scrap_file(boolean remove);
1459 void add_to_ascrap_mb(uint64_t bytes);
1460 
1461 boolean check_for_disk_space(boolean fullcheck);
1462 
1463 // main.c
1464 typedef void (*SignalHandlerPointer)(int);
1465 
1466 void set_signal_handlers(SignalHandlerPointer sigfunc);
1467 void catch_sigint(int signum);
1468 void defer_sigint(int signum);
1469 void startup_message_fatal(char *msg) GNU_NORETURN;
1470 boolean startup_message_choice(const char *msg, int msgtype);
1471 boolean startup_message_nonfatal(const char *msg);
1472 boolean startup_message_info(const char *msg);
1473 boolean startup_message_nonfatal_dismissable(const char *msg, uint64_t warning_mask);
1474 capability *get_capabilities(void);
1475 void get_monitors(boolean reset);
1476 void replace_with_delegates(void);
1477 void set_drawing_area_from_pixbuf(LiVESWidget *darea, LiVESPixbuf *pixbuf, lives_painter_surface_t *);
1478 void load_start_image(int frame);
1479 void load_end_image(int frame);
1480 void showclipimgs(void);
1481 void load_preview_image(boolean update_always);
1482 boolean resize_message_area(livespointer data);
1483 boolean lazy_startup_checks(void *data);
1484 
1485 #define is_layer_ready(layer) (weed_get_boolean_value((layer), WEED_LEAF_THREAD_PROCESSING, NULL) == WEED_FALSE \
1486 			       && weed_get_voidptr_value(layer, WEED_LEAF_RESIZE_THREAD, NULL) == NULL)
1487 
1488 boolean pull_frame(weed_layer_t *layer, const char *image_ext, ticks_t tc);
1489 void pull_frame_threaded(weed_layer_t *layer, const char *img_ext, ticks_t tc, int width, int height);
1490 boolean check_layer_ready(weed_layer_t *layer);
1491 boolean pull_frame_at_size(weed_layer_t *layer, const char *image_ext, ticks_t tc,
1492                            int width, int height, int target_palette);
1493 LiVESPixbuf *pull_lives_pixbuf_at_size(int clip, int frame, const char *image_ext, ticks_t tc,
1494                                        int width, int height, LiVESInterpType interp, boolean fordisp);
1495 LiVESPixbuf *pull_lives_pixbuf(int clip, int frame, const char *image_ext, ticks_t tc);
1496 
1497 boolean weed_layer_create_from_file_progressive(weed_layer_t *layer, const char *fname, int width,
1498     int height, int tpalette, const char *img_ext);
1499 
1500 boolean lives_pixbuf_save(LiVESPixbuf *pixbuf, char *fname, lives_img_type_t imgtype, int quality,
1501                           int width, int height, LiVESError **gerrorptr);
1502 
1503 typedef struct {
1504   LiVESPixbuf *pixbuf;
1505   LiVESError *error;
1506   char *fname;
1507   lives_img_type_t img_type;
1508   int compression;
1509   int width, height;
1510 } savethread_priv_t;
1511 
1512 void *lives_pixbuf_save_threaded(void *saveargs);
1513 
1514 void init_track_decoders(void);
1515 void free_track_decoders(void);
1516 
1517 #ifdef USE_LIBPNG
1518 boolean layer_from_png(int fd, weed_layer_t *layer, int width, int height, int tpalette, boolean prog);
1519 //boolean save_to_png(FILE *fp, weed_layer_t *layer, int comp);
1520 #endif
1521 
1522 void wait_for_cleaner(void);
1523 void load_frame_image(int frame);
1524 void sensitize(void);
1525 void sensitize_rfx(void);
1526 void desensitize(void);
1527 void procw_desensitize(void);
1528 void close_current_file(int file_to_switch_to);   ///< close current file, and try to switch to file_to_switch_to
1529 void switch_to_file(int old_file, int new_file);
1530 void do_quick_switch(int new_file);
1531 boolean switch_audio_clip(int new_file, boolean activate);
1532 void resize(double scale);
1533 boolean set_palette_colours(boolean force_reload);
1534 void set_main_title(const char *filename, int or_untitled_number);
1535 void set_record(void);
1536 void get_player_size(int *opwidth, int *opheight);
1537 
1538 //gui.c
1539 void  create_LiVES(void);
1540 void show_lives(void);
1541 void set_colours(LiVESWidgetColor *colf, LiVESWidgetColor *colb, LiVESWidgetColor *colf2,
1542                  LiVESWidgetColor *colb2, LiVESWidgetColor *coli, LiVESWidgetColor *colt);
1543 void set_preview_box_colours(void);
1544 void load_theme_images(void);
1545 void set_interactive(boolean interactive);
1546 char *get_menu_name(lives_clip_t *sfile, boolean add_set);
1547 int get_vspace(void);
1548 void enable_record(void);
1549 void toggle_record(void);
1550 void disable_record(void);
1551 void make_custom_submenus(void);
1552 void fade_background(void);
1553 void unfade_background(void);
1554 void fullscreen_internal(void);
1555 void block_expose(void);
1556 void unblock_expose(void);
1557 void frame_size_update(void);
1558 void splash_init(void);
1559 void splash_end(void);
1560 void splash_msg(const char *msg, double pct);
1561 void resize_widgets_for_monitor(boolean get_play_times);
1562 void reset_message_area(void);
1563 void get_letterbox_sizes(int *pwidth, int *pheight, int *lb_width, int *lb_height, boolean player_can_upscale);
1564 
1565 #if GTK_CHECK_VERSION(3, 0, 0)
1566 void calibrate_sepwin_size(void);
1567 boolean expose_pim(LiVESWidget *, lives_painter_t *, livespointer);
1568 boolean expose_sim(LiVESWidget *, lives_painter_t *, livespointer);
1569 boolean expose_eim(LiVESWidget *, lives_painter_t *, livespointer);
1570 #endif
1571 
1572 // system calls in utils.c
1573 int lives_system(const char *com, boolean allow_error);
1574 ssize_t lives_popen(const char *com, boolean allow_error, char *buff, ssize_t buflen);
1575 lives_pid_t lives_fork(const char *com);
1576 int lives_open3(const char *pathname, int flags, mode_t mode);
1577 int lives_open2(const char *pathname, int flags);
1578 ssize_t lives_write(int fd, livesconstpointer buf, ssize_t count, boolean allow_fail);
1579 ssize_t lives_write_le(int fd, livesconstpointer buf, ssize_t count, boolean allow_fail);
1580 ssize_t lives_read(int fd, void *buf, ssize_t count, boolean allow_less);
1581 ssize_t lives_read_le(int fd, void *buf, ssize_t count, boolean allow_less);
1582 
1583 // buffered io
1584 
1585 /// fixed values only for write buffers (must be multiples of 16)
1586 #define BUFFER_FILL_BYTES_SMALL 64   /// 1 -> 16 bytes
1587 #define BUFFER_FILL_BYTES_SMALLMED 1024 /// 17 - 256 bytes
1588 #define BUFFER_FILL_BYTES_MED 4096  /// 257 -> 2048 bytes
1589 #define BUFFER_FILL_BYTES_BIGMED 16386  /// 2049 - 8192 bytes
1590 #define BUFFER_FILL_BYTES_LARGE 65536
1591 
1592 #define BUFF_SIZE_READ_SMALL 0
1593 #define BUFF_SIZE_READ_SMALLMED 1
1594 #define BUFF_SIZE_READ_MED 2
1595 #define BUFF_SIZE_READ_LARGE 3
1596 #define BUFF_SIZE_READ_CUSTOM -1
1597 
1598 #define BUFF_SIZE_WRITE_SMALL 0
1599 #define BUFF_SIZE_WRITE_SMALLMED 1
1600 #define BUFF_SIZE_WRITE_MED 2
1601 #define BUFF_SIZE_WRITE_BIGMED 3
1602 #define BUFF_SIZE_WRITE_LARGE 4
1603 
1604 typedef struct {
1605   ssize_t bytes;  /// buffer size for write, bytes left to read in case of read
1606   uint8_t *ptr;   /// read point in buffer
1607   uint8_t *buffer;   /// ptr to data  (ptr - buffer + bytes) gives the read size
1608   off_t offset; // file offs (of END of block)
1609   int fd;
1610   int bufsztype;
1611   boolean eof;
1612   boolean read;
1613   boolean reversed;
1614   boolean slurping;
1615   int nseqreads;
1616   int totops;
1617   int64_t totbytes;
1618   boolean allow_fail;
1619   volatile boolean invalid;
1620   size_t orig_size;
1621   char *pathname;
1622 } lives_file_buffer_t;
1623 
1624 lives_file_buffer_t *find_in_file_buffers(int fd);
1625 lives_file_buffer_t *find_in_file_buffers_by_pathname(const char *pathname);
1626 
1627 size_t get_read_buff_size(int sztype);
1628 
1629 int lives_open_buffered_rdonly(const char *pathname);
1630 int lives_open_buffered_writer(const char *pathname, int mode, boolean append);
1631 int lives_create_buffered(const char *pathname, int mode);
1632 int lives_create_buffered_nosync(const char *pathname, int mode);
1633 int lives_close_buffered(int fd);
1634 off_t lives_lseek_buffered_writer(int fd, off_t offset);
1635 off_t lives_lseek_buffered_rdonly(int fd, off_t offset);
1636 off_t lives_lseek_buffered_rdonly_absolute(int fd, off_t offset);
1637 off_t lives_buffered_offset(int fd);
1638 size_t lives_buffered_orig_size(int fd);
1639 boolean lives_buffered_rdonly_set_reversed(int fd, boolean val);
1640 ssize_t lives_write_buffered(int fd, const char *buf, ssize_t count, boolean allow_fail);
1641 ssize_t lives_buffered_write_printf(int fd, boolean allow_fail, const char *fmt, ...);
1642 ssize_t lives_write_le_buffered(int fd, livesconstpointer buf, ssize_t count, boolean allow_fail);
1643 ssize_t lives_read_buffered(int fd, void *buf, ssize_t count, boolean allow_less);
1644 ssize_t lives_read_le_buffered(int fd, void *buf, ssize_t count, boolean allow_less);
1645 boolean lives_read_buffered_eof(int fd);
1646 lives_file_buffer_t *get_file_buffer(int fd);
1647 void lives_buffered_rdonly_slurp(int fd, off_t skip);
1648 
1649 int lives_chdir(const char *path, boolean no_error_dlg);
1650 int lives_fputs(const char *s, FILE *stream);
1651 char *lives_fgets(char *s, int size, FILE *stream);
1652 size_t lives_fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
1653 size_t lives_fread_string(char *buff, size_t stlen, const char *fname);
1654 pid_t lives_getpid(void);
1655 int lives_getgid(void);
1656 int lives_getuid(void);
1657 boolean lives_freep(void **ptr);
1658 void lives_kill_subprocesses(const char *dirname, boolean kill_parent);
1659 void lives_suspend_resume_process(const char *dirname, boolean suspend);
1660 int lives_kill(lives_pid_t pid, int sig);
1661 int lives_killpg(lives_pgid_t pgrp, int sig);
1662 ssize_t lives_readlink(const char *path, char *buf, size_t bufsiz);
1663 boolean lives_setenv(const char *name, const char *value);
1664 boolean lives_unsetenv(const char *name);
1665 boolean lives_fsync(int fd);
1666 void lives_sync(int times);
1667 int lives_rmdir(const char *dir, boolean force);
1668 int lives_rmdir_with_parents(const char *dir);
1669 int lives_rm(const char *file);
1670 int lives_rmglob(const char *files);
1671 int lives_cp(const char *from, const char *to);
1672 int lives_cp_recursive(const char *from, const char *to, boolean incl_dir);
1673 int lives_cp_keep_perms(const char *from, const char *to);
1674 int lives_mv(const char *from, const char *to);
1675 int lives_touch(const char *tfile);
1676 int lives_chmod(const char *target, const char *mode);
1677 int lives_cat(const char *from, const char *to, boolean append);
1678 int lives_echo(const char *text, const char *to, boolean append);
1679 int lives_ln(const char *from, const char *to);
1680 
1681 int lives_utf8_strcasecmp(const char *s1, const char *s2);
1682 int lives_utf8_strcmp(const char *s1, const char *s2);
1683 LiVESList *lives_list_sort_alpha(LiVESList *list, boolean fwd);
1684 
1685 boolean lives_string_ends_with(const char *string, const char *fmt, ...);
1686 
1687 char *filename_from_fd(char *val, int fd);
1688 
1689 void reset_playback_clock(void);
1690 ticks_t lives_get_current_playback_ticks(ticks_t origsecs, ticks_t origusecs, lives_time_source_t *time_source);
1691 
1692 lives_alarm_t lives_alarm_set(ticks_t ticks);
1693 ticks_t lives_alarm_check(lives_alarm_t alarm_handle);
1694 boolean lives_alarm_clear(lives_alarm_t alarm_handle);
1695 
1696 void get_dirname(char *filename);
1697 char *get_dir(const char *filename);
1698 void get_basename(char *filename);
1699 void get_filename(char *filename, boolean strip_dir);
1700 char *get_extension(const char *filename);
1701 
1702 uint64_t get_version_hash(const char *exe, const char *sep, int piece);
1703 uint64_t make_version_hash(const char *ver);
1704 char *unhash_version(uint64_t version);
1705 
1706 void init_clipboard(void);
1707 
1708 void print_cache(LiVESList *cache);
1709 
1710 LiVESList *cache_file_contents(const char *filename);
1711 char *get_val_from_cached_list(const char *key, size_t maxlen, LiVESList *cache);
1712 void cached_list_free(LiVESList **list);
1713 
1714 void get_location(const char *exe, char *val, int maxlen);
1715 boolean check_for_executable(lives_checkstatus_t *cap, const char *exec);
1716 boolean do_please_install(const char *exec, uint64_t guidance_flags);
1717 boolean do_please_install_either(const char *exec, const char *exec2);
1718 
1719 /// lives_image_type can be a string, lives_img_type_t is an enumeration
1720 char *make_image_file_name(lives_clip_t *clip, frames_t frame, const char *img_ext);
1721 const char *get_image_ext_for_type(lives_img_type_t imgtype);
1722 lives_img_type_t lives_image_ext_to_img_type(const char *img_ext);
1723 lives_img_type_t lives_image_type_to_img_type(const char *lives_image_type);
1724 const char *image_ext_to_lives_image_type(const char *img_ext);
1725 
1726 void reset_clipmenu(void);
1727 
1728 void get_total_time(lives_clip_t
1729                     *file); ///< calculate laudio, raudio and video time (may be deprecated and replaced with macros)
1730 void get_play_times(void); ///< recalculate video / audio lengths and draw the timer bars
1731 void update_play_times(void); ///< like get_play_times, but will force redraw of audio waveforms
1732 
1733 uint32_t get_signed_endian(boolean is_signed, boolean little_endian); ///< produce bitmapped value
1734 
1735 void switch_aud_to_none(boolean set_pref);
1736 boolean switch_aud_to_sox(boolean set_pref);
1737 boolean switch_aud_to_jack(boolean set_pref);
1738 boolean switch_aud_to_pulse(boolean set_pref);
1739 
1740 boolean prepare_to_play_foreign(void);
1741 boolean after_foreign_play(void);
1742 boolean check_file(const char *file_name, boolean check_exists);  ///< check if file exists
1743 boolean check_dir_access(const char *dir, boolean leaveit);
1744 boolean lives_make_writeable_dir(const char *newdir);
1745 boolean is_writeable_dir(const char *dir);
1746 boolean ensure_isdir(char *fname);
1747 boolean dirs_equal(const char *dira, const char *dirb);
1748 char *ensure_extension(const char *fname, const char *ext) WARN_UNUSED;
1749 char *lives_ellipsize(char *, size_t maxlen, LiVESEllipsizeMode mode);
1750 char *lives_pad(char *, size_t minlen, int align);
1751 char *lives_pad_ellipsize(char *, size_t fixlen, int padlen, LiVESEllipsizeMode mode);
1752 void activate_url_inner(const char *link);
1753 void activate_url(LiVESAboutDialog *about, const char *link, livespointer data);
1754 void show_manual_section(const char *lang, const char *section);
1755 void maybe_add_mt_idlefunc(void);
1756 boolean render_choice_idle(livespointer data);
1757 
1758 double calc_time_from_frame(int clip, int frame);
1759 int calc_frame_from_time(int filenum, double time);   ///< nearest frame [1, frames]
1760 int calc_frame_from_time2(int filenum, double time);  ///< nearest frame [1, frames+1]
1761 int calc_frame_from_time3(int filenum, double time);  ///< nearest frame rounded down, [1, frames+1]
1762 int calc_frame_from_time4(int filenum, double time);  ///<  nearest frame, no maximum
1763 
1764 boolean check_for_ratio_fps(double fps);
1765 double get_ratio_fps(const char *string);
1766 void calc_maxspect(int rwidth, int rheight, int *cwidth, int *cheight);
1767 void calc_midspect(int rwidth, int rheight, int *cwidth, int *cheight);
1768 void calc_minspect(int rwidth, int rheight, int *cwidth, int *cheight);
1769 
1770 char *remove_trailing_zeroes(double val);
1771 
1772 void remove_layout_files(LiVESList *lmap);
1773 boolean add_lmap_error(lives_lmap_error_t lerror, const char *name, livespointer user_data,
1774                        int clipno, int frameno, double atime, boolean affects_current);
1775 void buffer_lmap_error(lives_lmap_error_t lerror, const char *name, livespointer user_data, int clipno,
1776                        int frameno, double atime, boolean affects_current);
1777 void unbuffer_lmap_errors(boolean add);
1778 
1779 void clear_lmap_errors(void);
1780 boolean prompt_remove_layout_files(void);
1781 boolean do_std_checks(const char *type_name, const char *type, size_t maxlen, const char *nreject);
1782 boolean is_legal_set_name(const char *set_name, boolean allow_dupes, boolean leeway);
1783 char *repl_workdir(const char *entry, boolean fwd);
1784 char *clip_detail_to_string(lives_clip_details_t what, size_t *maxlenp);
1785 boolean get_clip_value(int which, lives_clip_details_t, void *retval, size_t maxlen);
1786 boolean save_clip_value(int which, lives_clip_details_t, void *val);
1787 boolean check_frame_count(int idx, boolean last_chkd);
1788 int get_frame_count(int idx, int xsize);
1789 boolean get_frames_sizes(int fileno, int frame_to_test, int *hsize, int *vsize);
1790 int count_resampled_frames(int in_frames, double orig_fps, double resampled_fps);
1791 boolean int_array_contains_value(int *array, int num_elems, int value);
1792 boolean check_for_lock_file(const char *set_name, int type);
1793 void lives_list_free_strings(LiVESList *);
1794 void lives_list_free_all(LiVESList **);
1795 void lives_slist_free_all(LiVESSList **);
1796 
1797 boolean create_event_space(int length_in_eventsb);
1798 void add_to_recent(const char *filename, double start, int frames, const char *file_open_params);
1799 int verhash(char *version);
1800 void set_undoable(const char *what, boolean sensitive);
1801 void set_redoable(const char *what, boolean sensitive);
1802 void zero_spinbuttons(void);
1803 void set_sel_label(LiVESWidget *label);
1804 void clear_mainw_msg(void);
1805 size_t get_token_count(const char *string, int delim);
1806 LiVESPixbuf *lives_pixbuf_new_blank(int width, int height, int palette);
1807 void find_when_to_stop(void);
1808 frames_t calc_new_playback_position(int fileno, ticks_t otc, ticks_t *ntc);
1809 void calc_aframeno(int fileno);
1810 void minimise_aspect_delta(double allowed_aspect, int hblock, int vblock, int hsize, int vsize, int *width, int *height);
1811 LiVESInterpType get_interp_value(short quality, boolean low_for_mt);
1812 
1813 LiVESList *lives_list_move_to_first(LiVESList *list, LiVESList *item) WARN_UNUSED;
1814 LiVESList *lives_list_delete_string(LiVESList *, const char *string) WARN_UNUSED;
1815 LiVESList *lives_list_copy_strings(LiVESList *list);
1816 boolean string_lists_differ(LiVESList *, LiVESList *);
1817 LiVESList *lives_list_append_unique(LiVESList *xlist, const char *add);
1818 LiVESList *buff_to_list(const char *buffer, const char *delim, boolean allow_blanks, boolean strip);
1819 int lives_list_strcmp_index(LiVESList *list, livesconstpointer data, boolean case_sensitive);
1820 
1821 LiVESList *get_set_list(const char *dir, boolean utf8);
1822 
1823 char *subst(const char *string, const char *from, const char *to);
1824 char *insert_newlines(const char *text, int maxwidth);
1825 
1826 int hextodec(const char *string);
1827 
1828 boolean get_screen_usable_size(int *w, int *h);
1829 
1830 #include "osc_notify.h"
1831 
1832 // inlines
1833 #define cfile mainw->files[mainw->current_file]
1834 #define CLIPBOARD_FILE 0
1835 #define clipboard mainw->files[CLIPBOARD_FILE]
1836 
1837 #define LIVES_TV_CHANNEL1 "http://www.serverwillprovide.com/sorteal/livestvclips/livestv.ogm"
1838 
1839 const char *dummychar;
1840 
1841 void break_me(const char *dtl);
1842 
1843 #define LIVES_NO_DEBUG
1844 #ifndef LIVES_DEBUG
1845 #ifndef LIVES_NO_DEBUG
1846 #define LIVES_DEBUG(x)      fprintf(stderr, "LiVES debug: %s\n", x)
1847 #else // LIVES_NO_DEBUG
1848 #define LIVES_DEBUG(x)      dummychar = x
1849 #endif // LIVES_NO_DEBUG
1850 #endif // LIVES_DEBUG
1851 
1852 #ifndef LIVES_INFO
1853 #ifndef LIVES_NO_INFO
1854 #define LIVES_INFO(x)      fprintf(stderr, "LiVES info: %s\n", x)
1855 #else // LIVES_NO_INFO
1856 #define LIVES_INFO(x)      dummychar = x
1857 #endif // LIVES_NO_INFO
1858 #endif // LIVES_INFO
1859 
1860 #ifndef LIVES_WARN
1861 #ifndef LIVES_NO_WARN
1862 #define LIVES_WARN(x)      fprintf(stderr, "LiVES warning: %s\n", x)
1863 #else // LIVES_NO_WARN
1864 #define LIVES_WARN(x)      dummychar = x
1865 #endif // LIVES_NO_WARN
1866 #endif // LIVES_WARN
1867 
1868 #ifndef LIVES_ERROR
1869 #ifndef LIVES_NO_ERROR
1870 #define LIVES_ERROR(x)      {fprintf(stderr, "LiVES ERROR: %s\n", x); break_me(x);}
1871 #else // LIVES_NO_ERROR
1872 #define LIVES_ERROR(x)      dummychar = x
1873 #endif // LIVES_NO_ERROR
1874 #endif // LIVES_ERROR
1875 
1876 #ifndef LIVES_CRITICAL
1877 #ifndef LIVES_NO_CRITICAL
1878 #define LIVES_CRITICAL(x)      {fprintf(stderr, "LiVES CRITICAL: %s\n", x); break_me(x); raise (LIVES_SIGSEGV);}
1879 #else // LIVES_NO_CRITICAL
1880 #define LIVES_CRITICAL(x)      dummychar = x
1881 #endif // LIVES_NO_CRITICAL
1882 #endif // LIVES_CRITICAL
1883 
1884 #ifndef LIVES_FATAL
1885 #ifndef LIVES_NO_FATAL
1886 #define LIVES_FATAL(x)      {fprintf(stderr, "LiVES FATAL: %s\n", x); lives_notify(LIVES_OSC_NOTIFY_QUIT, x), \
1887 									break_me(x); _exit (1);}
1888 #else // LIVES_NO_FATAL
1889 #define LIVES_FATAL(x)      dummychar = x
1890 #endif // LIVES_NO_FATAL
1891 #endif // LIVES_FATAL
1892 
1893 #ifndef USE_STD_MEMFUNCS
1894 
1895 #ifdef _lives_malloc
1896 #undef  lives_malloc
1897 #define lives_malloc _lives_malloc
1898 #endif
1899 #ifdef _lives_realloc
1900 #undef  lives_realloc
1901 #define lives_realloc _lives_realloc
1902 #endif
1903 #ifdef _lives_free
1904 #undef  lives_free
1905 #define lives_free _lives_free
1906 #endif
1907 #ifdef _lives_memcpy
1908 #undef  lives_memcpy
1909 #define lives_memcpy _lives_memcpy
1910 #endif
1911 #ifdef _lives_memcmp
1912 #undef  lives_memcmp
1913 #define lives_memcmp _lives_memcmp
1914 #endif
1915 #ifdef _lives_memset
1916 #undef  lives_memset
1917 #define lives_memset _lives_memset
1918 #endif
1919 #ifdef _lives_memmove
1920 #undef  lives_memmove
1921 #define lives_memmove _lives_memmove
1922 #endif
1923 #ifdef _lives_calloc
1924 #undef  lives_calloc
1925 #define lives_calloc _lives_calloc
1926 #endif
1927 
1928 #endif
1929 //#define VALGRIND_ON  ///< define this to ease debugging with valgrind
1930 #ifdef VALGRIND_ON
1931 #define QUICK_EXIT
1932 #else
1933 #define USE_REC_RS
1934 #define RESEEK_ENABLE
1935 #endif
1936 
1937 #endif // #ifndef HAS_LIVES_MAIN_H
1938 
1939