Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / pluginclient.h
index 9ad0586ddff1a58111041894c7f48571a819fc0b..50d50608f27ab584f75520243fc72b634a28d284 100644 (file)
 
 // Base class inherited by all the different types of plugins.
 
-#define MAX_FRAME_BUFFER 1024
+#define MAX_FRAME_BUFFER 8192
 
 class PluginClient;
 
 
 #include "arraylist.h"
+#include "linklist.h"
 #include "bchash.inc"
 #include "condition.h"
 #include "edlsession.inc"
@@ -106,66 +107,142 @@ PluginClientWindow* plugin_class::new_window() \
 #define LOAD_CONFIGURATION_MACRO(plugin_class, config_class) \
 int plugin_class::load_configuration() \
 { \
-       KeyFrame *prev_keyframe, *next_keyframe; \
-       prev_keyframe = get_prev_keyframe(get_source_position()); \
-       next_keyframe = get_next_keyframe(get_source_position()); \
- \
-       int64_t next_position = edl_to_local(next_keyframe->position); \
+       KeyFrame * prev_keyframe = get_prev_keyframe(get_source_position()); \
        int64_t prev_position = edl_to_local(prev_keyframe->position); \
- \
        config_class old_config, prev_config, next_config; \
        old_config.copy_from(config); \
        read_data(prev_keyframe); \
        prev_config.copy_from(config); \
-       read_data(next_keyframe); \
-       next_config.copy_from(config); \
- \
-       config.interpolate(prev_config,  \
-               next_config,  \
-               (next_position == prev_position) ? \
-                       get_source_position() : \
-                       prev_position, \
-               (next_position == prev_position) ? \
-                       get_source_position() + 1 : \
-                       next_position, \
-               get_source_position()); \
+       KeyFrame * next_keyframe = get_next_keyframe(get_source_position()); \
+       if( next_keyframe ) { \
+               int64_t next_position = edl_to_local(next_keyframe->position); \
+               read_data(next_keyframe); \
+               next_config.copy_from(config); \
  \
-       if(!config.equivalent(old_config)) \
-               return 1; \
-       else \
-               return 0; \
+               config.interpolate(prev_config, next_config,  \
+                       (next_position == prev_position) ? \
+                               get_source_position() : prev_position, \
+                       (next_position == prev_position) ? \
+                               get_source_position() + 1 : next_position, \
+                       get_source_position()); \
+       } \
+       return !config.equivalent(old_config) ? 1 : 0; \
 }
 
 
+class PluginClientFrame : public ListItem<PluginClientFrame>
+{
+public:
+       PluginClientFrame();
+       virtual ~PluginClientFrame();
+// offset in EDL seconds for synchronizing with GUI
+       double position;
+};
+
+class PluginClientFrames : public List<PluginClientFrame>
+{
+public:
+       PluginClientFrames();
+       ~PluginClientFrames();
+
+       static int fwd_cmpr(PluginClientFrame *ap, PluginClientFrame *bp);
+       static int rev_cmpr(PluginClientFrame *ap, PluginClientFrame *bp);
+       void fwd_sort() { sort(fwd_cmpr); }
+       void rev_sort() { sort(rev_cmpr); }
+       void sort_position(int dir);
+       void reset();
+       void add_gui_frame(PluginClientFrame *frame);
+       void concatenate(PluginClientFrames *frames);
+       PluginClientFrame *get_gui_frame(double pos, int dir);
+
+       int count;
+};
 
 
 class PluginClientWindow : public BC_Window
 {
 public:
        PluginClientWindow(PluginClient *client,
-               int w,
-               int h,
-               int min_w,
-               int min_h,
-               int allow_resize);
-       PluginClientWindow(const char *title,
-               int x,
-               int y,
-               int w,
-               int h,
-               int min_w,
-               int min_h,
-               int allow_resize);
+               int w, int h, int min_w, int min_h, int allow_resize);
+       PluginClientWindow(const char *title, int x, int y,
+               int w, int h, int min_w, int min_h, int allow_resize);
        virtual ~PluginClientWindow();
 
        virtual int translation_event();
        virtual int close_event();
        virtual void done_event(int result) {}
+// A listener for PluginParam events
+       virtual void param_updated();
 
        PluginClient *client;
 };
 
+// A GUI helper
+class PluginFPot : public BC_FPot
+{
+public:
+       PluginFPot(PluginParam *param, int x, int y);
+       int handle_event();
+               PluginParam *param;
+};
 
+class PluginIPot : public BC_IPot
+{
+public:
+       PluginIPot(PluginParam *param, int x, int y);
+       int handle_event();
+               PluginParam *param;
+};
+
+class PluginQPot : public BC_QPot
+{
+public:
+       PluginQPot(PluginParam *param, int x, int y);
+       int handle_event();
+               PluginParam *param;
+};
+
+class PluginText : public BC_TextBox
+{
+public:
+       PluginText(PluginParam *param, int x, int y, int value);
+       PluginText(PluginParam *param, int x, int y, float value);
+       int handle_event();
+               PluginParam *param;
+};
+
+class PluginParam
+{
+public:
+       PluginParam(PluginClient *plugin, PluginClientWindow *gui,
+               int x1, int x2, int x3, int y, int text_w,
+               int *output_i, float *output_f, // floating point output
+               int *output_q, // frequency output
+               const char *title, float min, float max);
+       ~PluginParam();
+
+       void initialize();
+       void update(int skip_text, int skip_pot);
+// set the number of fractional digits
+       void set_precision(int digits);
+
+// possible outputs
+       float *output_f;
+       PluginFPot *fpot;
+       int *output_i;
+       PluginIPot *ipot;
+       int *output_q;
+       PluginQPot *qpot;
+
+       char *title;
+       PluginText *text;
+       PluginClientWindow *gui;
+       PluginClient *plugin;
+       int x1, x2, x3;
+       int y, text_w;
+       float min, max;
+       int precision;
+};
 
 
 class PluginClientThread : public Thread
@@ -188,22 +265,6 @@ private:
 
 
 
-// Client overrides for GUI update data
-class PluginClientFrame
-{
-public:
-// Period_d is 1 second
-       PluginClientFrame(int data_size, int period_n, int period_d);
-       virtual ~PluginClientFrame();
-       int data_size;
-       int period_n;
-       int period_d;
-// Draw immediately
-       int force;
-};
-
-
-
 class PluginClient
 {
 public:
@@ -228,11 +289,6 @@ public:
 // Get theme being used by Cinelerra currently.  Used by all plugins.
        Theme* get_theme();
 
-
-
-
-
-
 // Non realtime signal processors define these.
 // Give the samplerate of the output for a non realtime plugin.
 // For realtime plugins give the requested samplerate.
@@ -241,20 +297,17 @@ public:
 // For realtime plugins give the requested framerate.
        virtual double get_framerate();
        virtual int delete_nonrealtime_parameters();
-       virtual int get_parameters();     // get information from user before non realtime processing
+       virtual int get_parameters();    // get information from user before non realtime processing
        virtual int64_t get_in_buffers(int64_t recommended_size);  // return desired size for input buffers
-       virtual int64_t get_out_buffers(int64_t recommended_size);     // return desired size for output buffers
+       virtual int64_t get_out_buffers(int64_t recommended_size);       // return desired size for output buffers
        virtual int start_loop();
        virtual int process_loop();
        virtual int stop_loop();
 // Hash files are the defaults for rendered plugins
-       virtual int load_defaults();       // load default settings for the plugin
-       virtual int save_defaults();      // save the current settings as defaults
+       virtual int load_defaults();       // load default settings for the plugin
+       virtual int save_defaults();      // save the current settings as defaults
        BC_Hash* get_defaults();
 
-
-
-
 // Realtime commands for signal processors.
 // These must be defined by the plugin itself.
 // Set the GUI title identifying the plugin to modules and patches.
@@ -277,22 +330,14 @@ public:
        int is_defaults();
 
        virtual void update_gui();
-       virtual void save_data(KeyFrame *keyframe) {};    // write the plugin settings to text in text format
-       virtual void read_data(KeyFrame *keyframe) {};    // read the plugin settings from the text
-       int send_hide_gui();                                    // should be sent when the GUI receives a close event from the user
+       virtual void save_data(KeyFrame *keyframe) {};  // write the plugin settings to text in text format
+       virtual void read_data(KeyFrame *keyframe) {};  // read the plugin settings from the text
+       int send_hide_gui();                                                                    // should be sent when the GUI receives a close event from the user
 // Destroys the window but not the thread pointer.
        void hide_gui();
-
-       int get_configure_change();                             // get propogated configuration change from a send_configure_change
-
-// Called by plugin server to update GUI with rendered data.
-       void plugin_render_gui(void *data);
-       void plugin_render_gui(void *data, int size);
-
-       void begin_process_buffer();
-       void end_process_buffer();
-
        void plugin_update_gui();
+       virtual void begin_process_buffer() {}
+       virtual void end_process_buffer() {}
        virtual int plugin_process_loop(VFrame **buffers, int64_t &write_length) { return 1; };
        virtual int plugin_process_loop(Samples **buffers, int64_t &write_length) { return 1; };
 // get parameters depending on video or audio
@@ -313,8 +358,8 @@ public:
 // data for every frame.
 // If the result is the default keyframe, the keyframe's position is 0.
 // position - relative to EDL rate or local rate to allow simple
-//     passing of get_source_position.
-//     If -1 the tracking position in the edl is used.
+//      passing of get_source_position.
+//      If -1 the tracking position in the edl is used.
 // is_local - if 1, the position is converted to the EDL rate.
        KeyFrame* get_prev_keyframe(int64_t position, int is_local = 1);
        KeyFrame* get_next_keyframe(int64_t position, int is_local = 1);
@@ -328,7 +373,7 @@ public:
 // console.  This gets a keyframe from the EDL, with the position set to the
 // EDL tracking position.
        int send_configure_change();
-
+       virtual void span_keyframes(KeyFrame *src, int64_t start, int64_t end);
 
 // Called from process_buffer
 // Returns 1 if a GUI is open so OpenGL routines can determine if
@@ -366,9 +411,14 @@ public:
 // Get the direction of the most recent process_buffer
        int get_direction();
 
+// position and direction for plugin gui tracking draws
+       double get_tracking_position();
+       int get_tracking_direction();
+
 // Plugin must call this before performing OpenGL operations.
 // Returns 1 if the user supports opengl buffers.
        int get_use_opengl();
+       int to_ram(VFrame *vframe);
 
 // Get total tracks to process
        int get_total_buffers();
@@ -384,8 +434,6 @@ public:
        float get_green();
        float get_blue();
 
-
-
 // Operations for file handlers
        virtual int open_file() { return 0; };
        virtual int get_audio_parameters() { return 0; };
@@ -394,20 +442,12 @@ public:
        virtual int open_file(char *path, int wr, int rd) { return 1; };
        virtual int close_file() { return 0; };
 
-
-
-
-
 // All plugins define these.
        PluginClientThread* get_thread();
 
-
-
 // Non realtime operations for signal processors.
-       virtual int plugin_start_loop(int64_t start,
-               int64_t end,
-               int64_t buffer_size,
-               int total_buffers);
+       virtual int plugin_start_loop(int64_t start, int64_t end,
+               int64_t buffer_size, int total_buffers);
        int plugin_stop_loop();
        int plugin_process_loop();
        MainProgressBar* start_progress(char *string, int64_t length);
@@ -425,7 +465,7 @@ public:
        int write_frames(int64_t total_frames);  // returns 1 for failure / tells the server that all output channel buffers are ready to go
        int write_samples(int64_t total_samples);  // returns 1 for failure / tells the server that all output channel buffers are ready to go
        virtual int plugin_get_parameters();
-       const char* get_defaultdir();     // Directory defaults should be stored in
+       const char* get_defaultdir();    // Directory defaults should be stored in
        void set_interactive();
 
 // Realtime operations.
@@ -434,48 +474,39 @@ public:
        virtual int plugin_command_derived(int plugin_command) { return 0; };
        int plugin_get_range();
        int plugin_init_realtime(int realtime_priority,
-               int total_in_buffers,
-               int buffer_size);
-
+               int total_in_buffers, int buffer_size);
 
 // GUI updating wrappers for realtime plugins
 // Append frame to queue for next send_frame_buffer
        void add_gui_frame(PluginClientFrame *frame);
-
-
+       int get_gui_frames();
 
        virtual void render_gui(void *data);
        virtual void render_gui(void *data, int size);
-
-// Called by client to get the total number of frames to draw in update_gui
-       int get_gui_update_frames();
-// Get GUI frame from frame_buffer.  Client must delete it.
-       PluginClientFrame* get_gui_frame();
-
-// Called by client to cause GUI to be rendered with data.
        void send_render_gui();
        void send_render_gui(void *data);
        void send_render_gui(void *data, int size);
+       void plugin_render_gui(void *data);
+       void plugin_render_gui(void *data, int size);
 
-
-
-
-
-
-
-
-// create pointers to buffers of the plugin's type before realtime rendering
-       virtual int delete_buffer_ptrs();
-
-
-
+       void reset_gui_frames();
+       void reset_plugin_gui_frames();
+       void plugin_reset_gui_frames();
+       void plugin_render_gui_frames(PluginClientFrames *frames);
+// first frame ready
+       int pending_gui_frame();
+// Called by client to get the total number of frames to draw in update_gui
+       int pending_gui_frames();
+// pop frames until buffer passes position=pos(-1 or seconds) in direction=dir(-1,0,1)
+       PluginClientFrame *get_gui_frame(double pos, int dir);
+       PluginClientFrame* next_gui_frame();
 
 // communication convenience routines for the base class
        int stop_gui_client();
        int save_data_client();
        int load_data_client();
-       int set_string_client(char *string);                // set the string identifying the plugin
-       int send_cancelled();        // non realtime plugin sends when cancelled
+       int set_string_client(char *string);                            // set the string identifying the plugin
+       int send_cancelled();           // non realtime plugin sends when cancelled
 
 // ================================= Buffers ===============================
 
@@ -497,18 +528,18 @@ public:
        ArrayList<PluginClientAuto> automation;
 
 // ================================== Messages ===========================
-       char gui_string[BCTEXTLEN];          // string identifying module and plugin
-       int master_gui_on;              // Status of the master gui plugin
-       int client_gui_on;              // Status of this client's gui
+       char gui_string[BCTEXTLEN];               // string identifying module and plugin
+       int master_gui_on;                        // Status of the master gui plugin
+       int client_gui_on;                        // Status of this client's gui
 
-       int show_initially;             // set to show a realtime plugin initially
+       int show_initially;                      // set to show a realtime plugin initially
 // range in project for processing
        int64_t start, end;
-       int interactive;                // for the progress bar plugin
+       int interactive;                                // for the progress bar plugin
        int success;
-       int total_out_buffers;          // total send buffers allocated by the server
-       int total_in_buffers;           // total receive buffers allocated by the server
-       int wr, rd;                     // File permissions for fileio plugins.
+       int total_out_buffers;            // total send buffers allocated by the server
+       int total_in_buffers;              // total receive buffers allocated by the server
+       int wr, rd;                                      // File permissions for fileio plugins.
 
 // These give the largest fragment the plugin is expected to handle.
 // size of a send buffer to the server
@@ -541,7 +572,7 @@ public:
        PluginClientThread *thread;
 
 // Frames for updating GUI
-       ArrayList<PluginClientFrame*> frame_buffer;
+       PluginClientFrames client_frames;
 // Time of last GUI update
        Timer *update_timer;
 
@@ -551,7 +582,7 @@ private:
 // Temporaries set in new_window
        int window_x, window_y;
 // File handlers:
-//     Asset *asset;     // Point to asset structure in shared memory
+//     Asset *asset;    // Point to asset structure in shared memory
 };