r956: README.BUILD - add more library recommendations
[cinelerra_cv/ct.git] / cinelerra / patch.C
blob0ed788fcd8c3f1f907ce980ce8d038e9f2f26f59
1 #include "filexml.h"
2 #include "mwindow.h"
3 #include "module.h"
4 #include "modules.h"
5 #include "mwindowgui.h"
6 #include "patch.h"
7 #include "patchbay.h"
8 #include "mainsession.h"
9 #include "theme.h"
10 #include <string.h>
12 Patch::Patch(MWindow *mwindow, PatchBay *patchbay, int data_type) : ListItem<Patch>()
14         this->mwindow = mwindow;
15         this->patches = patchbay;
16         this->data_type = data_type;
17         record = play = automate = draw = 1;
18         title[0] = 0;
21 Patch::~Patch()
23         if(mwindow->gui)
24         {
25                 delete recordpatch;  
26                 delete playpatch;  
27                 delete autopatch;  
28                 delete drawpatch;
29                 delete title_text;  
30         }
33 int Patch::create_objects(char *text, int pixel)
35         int x, y;
36         this->pixel = pixel;
37         strcpy(title, text);
38         
39         if(mwindow->gui)
40         {
41                 if(mwindow->session->tracks_vertical)
42                 {
43                         //x = patches->gui->w - pixel - mwindow->zoom_track;
44                         x = pixel + 3;
45                         y = 0;
46                 }
47                 else
48                 {
49                         x = 3;
50                         y = pixel;
51                 }
53                 patches->add_subwindow(recordpatch = new RecordPatchOld(mwindow, this, x, y));
54                 patches->add_subwindow(playpatch = new PlayPatchOld(mwindow, this, x, y));
55                 patches->add_subwindow(title_text = new TitlePatchOld(mwindow, this, text, x, y));
56                 //patches->add_subwindow(autotitle = new BC_Title(x + PATCH_AUTO_TITLE, y + PATCH_ROW2, "A", SMALLFONT));
57                 //patches->add_subwindow(autopatch = new AutoPatchOld(mwindow, this, x, y));
58                 //patches->add_subwindow(drawtitle = new BC_Title(x + PATCH_DRAW_TITLE, y + PATCH_ROW2, "D", SMALLFONT));
59                 patches->add_subwindow(drawpatch = new DrawPatchOld(mwindow, this, x, y));
60         }
61         return 0;
64 int Patch::save(FileXML *xml)
66         xml->tag.set_title("PATCH");
67         xml->append_tag();
69         if(play)
70         {
71                 xml->tag.set_title("PLAY");
72                 xml->append_tag();
73                 xml->tag.set_title("/PLAY");
74                 xml->append_tag();
75         }
76         
77         if(record)  
78         {
79                 xml->tag.set_title("RECORD");
80                 xml->append_tag();
81                 xml->tag.set_title("/RECORD");
82                 xml->append_tag();
83         }
84         
85         if(automate)  
86         {
87                 xml->tag.set_title("AUTO");
88                 xml->append_tag();
89                 xml->tag.set_title("/AUTO");
90                 xml->append_tag();
91         }
92         
93         if(draw)  
94         {
95                 xml->tag.set_title("DRAW");
96                 xml->append_tag();
97                 xml->tag.set_title("/DRAW");
98                 xml->append_tag();
99         }
100         
101         xml->tag.set_title("TITLE");
102         xml->append_tag();
103         xml->append_text(title);
104         xml->tag.set_title("/TITLE");
105         xml->append_tag();
106         
107         
108         xml->tag.set_title("/PATCH");
109         xml->append_tag();
110         xml->append_newline();
111         return 0;
114 int Patch::load(FileXML *xml)
116         int result = 0; 
117         play = record = automate = draw = 0;    // defaults
118         
119         do{
120                 result = xml->read_tag();
121                 
122                 if(!result)
123                 {
124                         if(xml->tag.title_is("/PATCH"))
125                         {
126                                 result = 1;
127                         }
128                         else
129                         if(xml->tag.title_is("PLAY"))
130                         {
131                                 play = 1;
132                         }
133                         else
134                         if(xml->tag.title_is("RECORD"))
135                         {
136                                 record = 1;
137                         }
138                         else
139                         if(xml->tag.title_is("AUTO"))
140                         {
141                                 automate = 1;
142                         }
143                         else
144                         if(xml->tag.title_is("DRAW"))
145                         {
146                                 draw = 1;
147                         }
148                         else
149                         if(xml->tag.title_is("TITLE"))
150                         {
151                                 strcpy(title, xml->read_text());
152                         }
153                 }
154         }while(!result);
155         
156         if(mwindow->gui)
157         {
158                 playpatch->update(play);
159                 recordpatch->update(record);
160                 autopatch->update(automate);
161                 drawpatch->update(draw);
162                 title_text->update(title);
163         }
164         return 0;
167 int Patch::set_pixel(int pixel)
168 {         // must be top of track for track zoom
169         this->pixel = pixel;
170         if(mwindow->gui)
171         {
172                 if(mwindow->session->tracks_vertical)
173                 {
174                         pixel += 3;
175                         playpatch->reposition_window(pixel + PATCH_PLAY, playpatch->get_y());
176                         recordpatch->reposition_window(pixel + PATCH_REC, recordpatch->get_y());
177                         autopatch->reposition_window(pixel + PATCH_AUTO, autopatch->get_y());
178                         title_text->reposition_window(pixel, title_text->get_y());
179                         drawpatch->reposition_window(pixel + PATCH_DRAW, drawpatch->get_y());
180                 }
181                 else
182                 {
183                         playpatch->reposition_window(playpatch->get_x(), pixel + PATCH_ROW2);
184                         recordpatch->reposition_window(recordpatch->get_x(), pixel + PATCH_ROW2);
185                         autopatch->reposition_window(autopatch->get_x(), pixel + PATCH_ROW2);
186                         drawpatch->reposition_window(drawpatch->get_x(), pixel + PATCH_ROW2);
187                         title_text->reposition_window(title_text->get_x(), pixel + 3);
188                 }
189         }
190         return 0;
193 int Patch::set_title(char *new_title)
195         strcpy(title, new_title);
196         title_text->update(new_title);
197         return 0;
200 int Patch::flip_vertical()
202         if(mwindow->gui)
203         {
204                 if(mwindow->session->tracks_vertical)
205                 {
206                         playpatch->reposition_window(playpatch->get_x(), PATCH_ROW2);
207                         recordpatch->reposition_window(recordpatch->get_x(), PATCH_ROW2);
208                         autopatch->reposition_window(autopatch->get_x(), PATCH_ROW2);
209                         drawpatch->reposition_window(drawpatch->get_x(), PATCH_ROW2);
210                         title_text->reposition_window(title_text->get_x(), 3);
211                 }
212                 else
213                 {
214                         playpatch->reposition_window(PATCH_PLAY, playpatch->get_y());
215                         recordpatch->reposition_window(PATCH_REC, recordpatch->get_y());
216                         autopatch->reposition_window(PATCH_AUTO, autopatch->get_y());
217                         drawpatch->reposition_window(PATCH_DRAW, drawpatch->get_y());
218                         title_text->reposition_window(PATCH_TITLE, title_text->get_y());
219                 }
220                 set_pixel(pixel);
221         }
222         return 0;
226 int Patch::pixelmovement(int distance)
228         if(mwindow->gui)
229         {
230                 pixel -= distance;
231                 set_pixel(pixel);
232         }
233         return 0;
236 Module* Patch::get_module()    // return corresponding module from console
238 //      return mwindow->console->modules->module_number(patches->number_of(this));
241 PlayPatchOld::PlayPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
242  : BC_Toggle(x + PATCH_PLAY, 
243         y + PATCH_ROW2, 
244         mwindow->theme->playpatch_data,
245         1,
246         "",
247         1,
248         0,
249         0)
251         this->patch = patch; 
252         patches = patch->patches; 
256 int PlayPatchOld::handle_event()
258 // get the total selected before this event
259         if(shift_down())
260         {
261                 int total_selected = patches->plays_selected();
263                 if(total_selected == 0)
264                 {
265 // nothing previously selected
266                         patches->select_all_play();
267                 }
268                 else
269                 if(total_selected == 1)
270                 {
271                         if(patch->play)
272                         {
273 // this patch was previously the only one on
274                                 patches->select_all_play();
275                         }
276                         else
277                         {
278 // another patch was previously the only one on
279                                 patches->deselect_all_play();
280                                 patch->play = 1;
281                         }
282                 }
283                 else
284                 if(total_selected > 1)
285                 {
286                         patches->deselect_all_play();
287                         patch->play = 1;
288                 }
289                 
290                 update(patch->play);
291         }
292         else
293         {
294                 patch->play = get_value();
295         }
296         patches->button_down = 1;
297         patches->reconfigure_trigger = 1;
298         patches->new_status = get_value();
299         return 1;
302 int PlayPatchOld::button_release()
304         return 0;
307 int PlayPatchOld::cursor_moved_over()
309         if(patches->button_down && patches->new_status != get_value())
310         {
311                 update(patches->new_status);
312                 patch->play = get_value();
313                 return 1;
314         }
315         return 0;
318 RecordPatchOld::RecordPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
319  : BC_Toggle(x + PATCH_REC, 
320         y + PATCH_ROW2, 
321         mwindow->theme->recordpatch_data,
322         1,
323         "",
324         1,
325         0,
326         0)
328         this->patch = patch; 
329         patches = patch->patches; 
332 int RecordPatchOld::handle_event()
334 // get the total selected before this event
335         if(shift_down())
336         {
337                 int total_selected = patches->records_selected();
339                 if(total_selected == 0)
340                 {
341 // nothing previously selected
342                         patches->select_all_record();
343                 }
344                 else
345                 if(total_selected == 1)
346                 {
347                         if(patch->record)
348                         {
349 // this patch was previously the only one on
350                                 patches->select_all_record();
351                         }
352                         else
353                         {
354 // another patch was previously the only one on
355                                 patches->deselect_all_record();
356                                 patch->record = 1;
357                         }
358                 }
359                 else
360                 if(total_selected > 1)
361                 {
362                         patches->deselect_all_record();
363                         patch->record = 1;
364                 }
365                 
366                 update(patch->record);
367         }
368         else
369         {
370                 patch->record = get_value();
371         }
372         patches->button_down = 1;
373         patches->new_status = get_value();
374         return 1;
377 int RecordPatchOld::button_release()
379         //if(patches->button_down)
380         //{
381         //      patches->button_down = 0;
382 // restart the playback
383                 //patches->mwindow->start_reconfigure(1);
384                 //patches->mwindow->stop_reconfigure(1);
385         //}
386         return 0;
389 int RecordPatchOld::cursor_moved_over()
391         if(patches->button_down && patches->new_status != get_value()) 
392         {
393                 update(patches->new_status);
394                 patch->record = get_value();
395                 return 1;
396         }
397         return 0;
400 TitlePatchOld::TitlePatchOld(MWindow *mwindow, Patch *patch, char *text, int x, int y)
401  : BC_TextBox(x, y + PATCH_TITLE, 124, 1, text, 0)
403         this->patch = patch; 
404         patches = patch->patches; 
405         module = 0; 
408 int TitlePatchOld::handle_event()
410         if(!module) module = patch->get_module();
411         module->set_title(get_text());
412         strcpy(patch->title, get_text());
413         return 1;
416 DrawPatchOld::DrawPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
417  : BC_Toggle(x + PATCH_DRAW, 
418         y + PATCH_ROW2, 
419         mwindow->theme->drawpatch_data,
420         1,
421         "",
422         1, 
423         0, 
424         0)
426         this->patch = patch; 
427         this->patches = patch->patches; 
430 int DrawPatchOld::handle_event()
432 // get the total selected before this event
433         if(shift_down())
434         {
435                 int total_selected = patches->draws_selected();
437                 if(total_selected == 0)
438                 {
439 // nothing previously selected
440                         patches->select_all_draw();
441                 }
442                 else
443                 if(total_selected == 1)
444                 {
445                         if(patch->draw)
446                         {
447 // this patch was previously the only one on
448                                 patches->select_all_draw();
449                         }
450                         else
451                         {
452 // another patch was previously the only one on
453                                 patches->deselect_all_draw();
454                                 patch->draw = 1;
455                         }
456                 }
457                 else
458                 if(total_selected > 1)
459                 {
460                         patches->deselect_all_draw();
461                         patch->draw = 1;
462                 }
463                 
464                 update(patch->draw);
465         }
466         else
467         {
468                 patch->draw = get_value();
469         }
470         patches->button_down = 1;
471         patches->new_status = get_value();
472         return 1;
475 int DrawPatchOld::cursor_moved_over()
477         if(patches->button_down && patches->new_status != get_value())
478         {
479                 update(patches->new_status);
480                 patch->draw = get_value();
481         return 1;
482         }
483         return 0;