r105: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / cinelerra / pluginclient.C
blob44027158e171dc32ae3edd815c5949f750ea1a02
1 #include "edl.h"
2 #include "edlsession.h"
3 #include "pluginclient.h"
4 #include "pluginserver.h"
6 #include <string.h>
7 #include <libintl.h>
8 #define _(String) gettext(String)
9 #define gettext_noop(String) String
10 #define N_(String) gettext_noop (String)
12 PluginClient::PluginClient(PluginServer *server)
14         reset();
15         this->server = server;
18 PluginClient::~PluginClient()
22 int PluginClient::reset()
24         interactive = 0;
25         gui_messages = 0;
26         show_initially = 0;
27         message_lock = 0;
28         wr = rd = 0;
29         master_gui_on = 0;
30         client_gui_on = 0;
31         sample_rate = 0;
32         frame_rate = 0;
33         realtime_priority = 0;
34         gui_string[0] = 0;
35         total_in_buffers = 0;
36         total_out_buffers = 0;
37         source_len = 0;
38         source_position = 0;
39         total_len = 0;
42 int PluginClient::plugin_init(int argc, char *argv[])
44         if(argc < 3)
45         {
46                 printf(_("This is a plugin for Broadcast 2000a.  Grow a mane.\n"));
47                 success = 0;
48                 return 1;
49         }
51 // get the message pipes
52         messages = new Messages(MESSAGE_TO_PLUGIN, MESSAGE_FROM_PLUGIN, atol(argv[1]));
54         if(atol(argv[2]) >= 0)
55         {
56                 gui_messages = new Messages(MESSAGE_TO_PLUGIN, MESSAGE_FROM_PLUGIN, atol(argv[2]));
57                 gui_messages->write_message(GET_STRING);
58                 gui_messages->read_message(gui_string);
60                 show_initially = 1;       // flag for plugin
61                 client_gui_on = 1;
62         }
63         success = 1;
65         return 0;
70 // For realtime plugins initialize buffers
71 int PluginClient::plugin_init_realtime(int realtime_priority, 
72         int total_in_buffers,
73         int buffer_size)
75 //printf("PluginClient::plugin_init_realtime 1\n");
76 // Get parameters for all
77         master_gui_on = get_gui_status();
79 //printf("PluginClient::plugin_init_realtime 1\n");
80 // get parameters depending on video or audio
81         init_realtime_parameters();
82 //printf("PluginClient::plugin_init_realtime 1\n");
83         smp = server->edl->session->smp;
84         this->realtime_priority = realtime_priority;
85         this->total_in_buffers = this->total_out_buffers = total_in_buffers;
86         this->out_buffer_size = this->in_buffer_size = buffer_size;
87 //printf("PluginClient::plugin_init_realtime 1\n");
88         return 0;
91 int PluginClient::plugin_start_loop(int64_t start, int64_t end, int64_t buffer_size, int total_buffers)
93         this->start = start;
94         this->end = end;
95         this->in_buffer_size = this->out_buffer_size = buffer_size;
96 //printf("PluginClient::plugin_start_loop 1 %d\n", in_buffer_size);
97         this->total_in_buffers = this->total_out_buffers = total_buffers;
98         sample_rate = get_project_samplerate();
99         frame_rate = get_project_framerate();
100         start_loop();
101         return 0;
104 int PluginClient::plugin_process_loop()
106         return process_loop();
109 int PluginClient::plugin_stop_loop()
111         return stop_loop();
114 MainProgressBar* PluginClient::start_progress(char *string, int64_t length)
116         return server->start_progress(string, length);
121 int PluginClient::plugin_get_parameters()
123         sample_rate = get_project_samplerate();
124         frame_rate = get_project_framerate();
125         int result = get_parameters();
126         return result;
129 // ========================= main loop
131 int PluginClient::is_multichannel() { return 0; }
132 int PluginClient::is_synthesis() { return 0; }
133 int PluginClient::is_realtime() { return 0; }
134 int PluginClient::is_fileio() { return 0; }
135 int PluginClient::delete_buffer_ptrs() { return 0; }
136 char* PluginClient::plugin_title() { return _("Untitled"); }
137 VFrame* PluginClient::new_picon() { return 0; }
138 Theme* PluginClient::new_theme() { return 0; }
139 int PluginClient::is_audio() { return 0; }
140 int PluginClient::is_video() { return 0; }
141 int PluginClient::is_theme() { return 0; }
142 int PluginClient::uses_gui() { return 1; }
143 int PluginClient::is_transition() { return 0; }
144 int PluginClient::load_defaults() { return 0; }
145 int PluginClient::save_defaults() { return 0; }
146 //int PluginClient::start_gui() { return 0; }
147 //int PluginClient::stop_gui() { return 0; }
148 int PluginClient::show_gui() { return 0; }
149 //int PluginClient::hide_gui() { return 0; }
150 int PluginClient::set_string() { return 0; }
151 int PluginClient::get_parameters() { return 0; }
152 int PluginClient::get_samplerate() { return get_project_samplerate(); }
153 double PluginClient::get_framerate() { return get_project_framerate(); }
154 int PluginClient::init_realtime_parameters() { return 0; }
155 int PluginClient::delete_nonrealtime_parameters() { return 0; }
156 int PluginClient::start_loop() { return 0; };
157 int PluginClient::process_loop() { return 0; };
158 int PluginClient::stop_loop() { return 0; };
160 void PluginClient::set_interactive()
162         interactive = 1;
165 int64_t PluginClient::get_in_buffers(int64_t recommended_size)
167         return recommended_size;
170 int64_t PluginClient::get_out_buffers(int64_t recommended_size)
172         return recommended_size;
175 int PluginClient::get_gui_status()
177         return server->get_gui_status();
180 int PluginClient::plugin_start_plugin()
182 // Create any necessary pointers and download any parameters for the derived plugin.
183         smp = get_project_smp();
185         start_plugin();
187         delete_nonrealtime_parameters();
188         send_completed();
189         return 0;
192 int PluginClient::start_plugin()
194         printf(_("No processing defined for this plugin.\n"));
195         return 0;
198 // close event from client side
199 void PluginClient::client_side_close()
201 // Last command executed
202         server->client_side_close();
205 int PluginClient::stop_gui_client()
207         if(!client_gui_on) return 0;
208         client_gui_on = 0;
209 //      stop_gui();                      // give to plugin
210         return 0;
213 int PluginClient::get_project_samplerate()
215         return server->get_project_samplerate();
218 double PluginClient::get_project_framerate()
220         return server->get_project_framerate();
224 void PluginClient::update_display_title()
226         server->generate_display_title(gui_string);
227         set_string();
230 char* PluginClient::get_gui_string()
232         return gui_string;
236 char* PluginClient::get_path()
238         return server->path;
241 int PluginClient::set_string_client(char *string)
243         strcpy(gui_string, string);
244         set_string();
245         return 0;
248 int PluginClient::save_data_client()
250 //      save_data(messages->get_message_buffer());         // user puts data directly into buffer
251 //      messages->write_message_raw();
252         return 0;
255 int PluginClient::load_data_client()
257 //      read_data(messages->read_message_raw());         // user reads data directly from buffer
258         return 0;
261 KeyFrame* PluginClient::get_prev_keyframe(int64_t position)
263         return server->get_prev_keyframe(position);
266 KeyFrame* PluginClient::get_next_keyframe(int64_t position)
268         return server->get_next_keyframe(position);
271 int PluginClient::get_interpolation_type()
273         return server->get_interpolation_type();
277 int PluginClient::automation_used()    // If automation is used
279         return 0;
282 float PluginClient::get_automation_value(int64_t position)     // Get the automation value for the position in the current fragment
284         int i;
285         for(i = automation.total - 1; i >= 0; i--)
286         {
287                 if(automation.values[i].position <= position)
288                 {
289                         return automation.values[i].intercept + automation.values[i].slope * (position - automation.values[i].position);
290                 }
291         }
292         return 0;
295 int64_t PluginClient::get_source_len()
297         return source_len;
300 int64_t PluginClient::get_source_position()
302         return source_position;
305 int64_t PluginClient::get_source_start()
307         return server->get_source_start();
310 int64_t PluginClient::get_total_len()
312         return total_len;
316 int PluginClient::get_configure_change()
318 //      read_data(messages->read_message_raw());
319         return 0;
323 int PluginClient::get_project_smp()
325         return smp;
328 char* PluginClient::get_defaultdir()
330         return BCASTDIR;
334 int PluginClient::send_completed()
336         messages->write_message(COMPLETED);
339 int PluginClient::send_cancelled()
341         messages->write_message(CANCEL);
344 int PluginClient::send_hide_gui()
346 // Stop the GUI server and delete GUI messages
347         client_gui_on = 0;
348         return 0;
351 int PluginClient::send_configure_change()
353 // handle everything using the gui messages
354 //printf("PluginClient::send_configure_change 1 %p\n", server);
355         KeyFrame* keyframe = server->get_keyframe();
356 //printf("PluginClient::send_configure_change 1\n");
357         save_data(keyframe);
358 //printf("PluginClient::send_configure_change 1\n");
359         server->sync_parameters();
360 //printf("PluginClient::send_configure_change 2\n");
361         return 0;
364 int PluginClient::write_frames(int64_t total_frames)
366 // buffers are preloaded by client
367         messages->write_message(WRITE_FRAMES);
369         messages->write_message(total_frames);
370         int result = messages->read_message();
371         if(result == OK) return 0;
372         else return 1;
375 int PluginClient::write_samples(int64_t total_samples)
377 // buffers are preloaded by client
378         messages->write_message(WRITE_SAMPLES);
379         
380         messages->write_message(total_samples);
381         int result = messages->read_message();
382         if(result == OK) return 0;
383         else return 1;