Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

patch.C

Go to the documentation of this file.
00001 #include "filexml.h"
00002 #include "mwindow.h"
00003 #include "module.h"
00004 #include "modules.h"
00005 #include "mwindowgui.h"
00006 #include "patch.h"
00007 #include "patchbay.h"
00008 #include "mainsession.h"
00009 #include "theme.h"
00010 #include <string.h>
00011 
00012 Patch::Patch(MWindow *mwindow, PatchBay *patchbay, int data_type) : ListItem<Patch>()
00013 {
00014         this->mwindow = mwindow;
00015         this->patches = patchbay;
00016         this->data_type = data_type;
00017         record = play = automate = draw = 1;
00018         title[0] = 0;
00019 }
00020 
00021 Patch::~Patch()
00022 {
00023         if(mwindow->gui)
00024         {
00025                 delete recordpatch;  
00026                 delete playpatch;  
00027                 delete autopatch;  
00028                 delete drawpatch;
00029                 delete title_text;  
00030         }
00031 }
00032 
00033 int Patch::create_objects(char *text, int pixel)
00034 {
00035         int x, y;
00036         this->pixel = pixel;
00037         strcpy(title, text);
00038         
00039         if(mwindow->gui)
00040         {
00041                 if(mwindow->session->tracks_vertical)
00042                 {
00043                         //x = patches->gui->w - pixel - mwindow->zoom_track;
00044                         x = pixel + 3;
00045                         y = 0;
00046                 }
00047                 else
00048                 {
00049                         x = 3;
00050                         y = pixel;
00051                 }
00052 
00053                 patches->add_subwindow(recordpatch = new RecordPatchOld(mwindow, this, x, y));
00054                 patches->add_subwindow(playpatch = new PlayPatchOld(mwindow, this, x, y));
00055                 patches->add_subwindow(title_text = new TitlePatchOld(mwindow, this, text, x, y));
00056                 //patches->add_subwindow(autotitle = new BC_Title(x + PATCH_AUTO_TITLE, y + PATCH_ROW2, "A", SMALLFONT));
00057                 //patches->add_subwindow(autopatch = new AutoPatchOld(mwindow, this, x, y));
00058                 //patches->add_subwindow(drawtitle = new BC_Title(x + PATCH_DRAW_TITLE, y + PATCH_ROW2, "D", SMALLFONT));
00059                 patches->add_subwindow(drawpatch = new DrawPatchOld(mwindow, this, x, y));
00060         }
00061         return 0;
00062 }
00063 
00064 int Patch::save(FileXML *xml)
00065 {
00066         xml->tag.set_title("PATCH");
00067         xml->append_tag();
00068 
00069         if(play)
00070         {
00071                 xml->tag.set_title("PLAY");
00072                 xml->append_tag();
00073                 xml->tag.set_title("/PLAY");
00074                 xml->append_tag();
00075         }
00076         
00077         if(record)  
00078         {
00079                 xml->tag.set_title("RECORD");
00080                 xml->append_tag();
00081                 xml->tag.set_title("/RECORD");
00082                 xml->append_tag();
00083         }
00084         
00085         if(automate)  
00086         {
00087                 xml->tag.set_title("AUTO");
00088                 xml->append_tag();
00089                 xml->tag.set_title("/AUTO");
00090                 xml->append_tag();
00091         }
00092         
00093         if(draw)  
00094         {
00095                 xml->tag.set_title("DRAW");
00096                 xml->append_tag();
00097                 xml->tag.set_title("/DRAW");
00098                 xml->append_tag();
00099         }
00100         
00101         xml->tag.set_title("TITLE");
00102         xml->append_tag();
00103         xml->append_text(title);
00104         xml->tag.set_title("/TITLE");
00105         xml->append_tag();
00106         
00107         
00108         xml->tag.set_title("/PATCH");
00109         xml->append_tag();
00110         xml->append_newline();
00111         return 0;
00112 }
00113 
00114 int Patch::load(FileXML *xml)
00115 {
00116         int result = 0; 
00117         play = record = automate = draw = 0;    // defaults
00118         
00119         do{
00120                 result = xml->read_tag();
00121                 
00122                 if(!result)
00123                 {
00124                         if(xml->tag.title_is("/PATCH"))
00125                         {
00126                                 result = 1;
00127                         }
00128                         else
00129                         if(xml->tag.title_is("PLAY"))
00130                         {
00131                                 play = 1;
00132                         }
00133                         else
00134                         if(xml->tag.title_is("RECORD"))
00135                         {
00136                                 record = 1;
00137                         }
00138                         else
00139                         if(xml->tag.title_is("AUTO"))
00140                         {
00141                                 automate = 1;
00142                         }
00143                         else
00144                         if(xml->tag.title_is("DRAW"))
00145                         {
00146                                 draw = 1;
00147                         }
00148                         else
00149                         if(xml->tag.title_is("TITLE"))
00150                         {
00151                                 strcpy(title, xml->read_text());
00152                         }
00153                 }
00154         }while(!result);
00155         
00156         if(mwindow->gui)
00157         {
00158                 playpatch->update(play);
00159                 recordpatch->update(record);
00160                 autopatch->update(automate);
00161                 drawpatch->update(draw);
00162                 title_text->update(title);
00163         }
00164         return 0;
00165 }
00166 
00167 int Patch::set_pixel(int pixel)
00168 {         // must be top of track for track zoom
00169         this->pixel = pixel;
00170         if(mwindow->gui)
00171         {
00172                 if(mwindow->session->tracks_vertical)
00173                 {
00174                         pixel += 3;
00175                         playpatch->reposition_window(pixel + PATCH_PLAY, playpatch->get_y());
00176                         recordpatch->reposition_window(pixel + PATCH_REC, recordpatch->get_y());
00177                         autopatch->reposition_window(pixel + PATCH_AUTO, autopatch->get_y());
00178                         title_text->reposition_window(pixel, title_text->get_y());
00179                         drawpatch->reposition_window(pixel + PATCH_DRAW, drawpatch->get_y());
00180                 }
00181                 else
00182                 {
00183                         playpatch->reposition_window(playpatch->get_x(), pixel + PATCH_ROW2);
00184                         recordpatch->reposition_window(recordpatch->get_x(), pixel + PATCH_ROW2);
00185                         autopatch->reposition_window(autopatch->get_x(), pixel + PATCH_ROW2);
00186                         drawpatch->reposition_window(drawpatch->get_x(), pixel + PATCH_ROW2);
00187                         title_text->reposition_window(title_text->get_x(), pixel + 3);
00188                 }
00189         }
00190         return 0;
00191 }
00192 
00193 int Patch::set_title(char *new_title)
00194 {
00195         strcpy(title, new_title);
00196         title_text->update(new_title);
00197         return 0;
00198 }
00199 
00200 int Patch::flip_vertical()
00201 {
00202         if(mwindow->gui)
00203         {
00204                 if(mwindow->session->tracks_vertical)
00205                 {
00206                         playpatch->reposition_window(playpatch->get_x(), PATCH_ROW2);
00207                         recordpatch->reposition_window(recordpatch->get_x(), PATCH_ROW2);
00208                         autopatch->reposition_window(autopatch->get_x(), PATCH_ROW2);
00209                         drawpatch->reposition_window(drawpatch->get_x(), PATCH_ROW2);
00210                         title_text->reposition_window(title_text->get_x(), 3);
00211                 }
00212                 else
00213                 {
00214                         playpatch->reposition_window(PATCH_PLAY, playpatch->get_y());
00215                         recordpatch->reposition_window(PATCH_REC, recordpatch->get_y());
00216                         autopatch->reposition_window(PATCH_AUTO, autopatch->get_y());
00217                         drawpatch->reposition_window(PATCH_DRAW, drawpatch->get_y());
00218                         title_text->reposition_window(PATCH_TITLE, title_text->get_y());
00219                 }
00220                 set_pixel(pixel);
00221         }
00222         return 0;
00223 }
00224 
00225 
00226 int Patch::pixelmovement(int distance)
00227 {
00228         if(mwindow->gui)
00229         {
00230                 pixel -= distance;
00231                 set_pixel(pixel);
00232         }
00233         return 0;
00234 }
00235 
00236 Module* Patch::get_module()    // return corresponding module from console
00237 {
00238 //      return mwindow->console->modules->module_number(patches->number_of(this));
00239 }
00240 
00241 PlayPatchOld::PlayPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
00242  : BC_Toggle(x + PATCH_PLAY, 
00243         y + PATCH_ROW2, 
00244         mwindow->theme->playpatch_data,
00245         1,
00246         "",
00247         1,
00248         0,
00249         0)
00250 {
00251         this->patch = patch; 
00252         patches = patch->patches; 
00253 }
00254 
00255 
00256 int PlayPatchOld::handle_event()
00257 {
00258 // get the total selected before this event
00259         if(shift_down())
00260         {
00261                 int total_selected = patches->plays_selected();
00262 
00263                 if(total_selected == 0)
00264                 {
00265 // nothing previously selected
00266                         patches->select_all_play();
00267                 }
00268                 else
00269                 if(total_selected == 1)
00270                 {
00271                         if(patch->play)
00272                         {
00273 // this patch was previously the only one on
00274                                 patches->select_all_play();
00275                         }
00276                         else
00277                         {
00278 // another patch was previously the only one on
00279                                 patches->deselect_all_play();
00280                                 patch->play = 1;
00281                         }
00282                 }
00283                 else
00284                 if(total_selected > 1)
00285                 {
00286                         patches->deselect_all_play();
00287                         patch->play = 1;
00288                 }
00289                 
00290                 update(patch->play);
00291         }
00292         else
00293         {
00294                 patch->play = get_value();
00295         }
00296         patches->button_down = 1;
00297         patches->reconfigure_trigger = 1;
00298         patches->new_status = get_value();
00299         return 1;
00300 }
00301 
00302 int PlayPatchOld::button_release()
00303 {
00304         return 0;
00305 }
00306 
00307 int PlayPatchOld::cursor_moved_over()
00308 {
00309         if(patches->button_down && patches->new_status != get_value())
00310         {
00311                 update(patches->new_status);
00312                 patch->play = get_value();
00313                 return 1;
00314         }
00315         return 0;
00316 }
00317 
00318 RecordPatchOld::RecordPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
00319  : BC_Toggle(x + PATCH_REC, 
00320         y + PATCH_ROW2, 
00321         mwindow->theme->recordpatch_data,
00322         1,
00323         "",
00324         1,
00325         0,
00326         0)
00327 { 
00328         this->patch = patch; 
00329         patches = patch->patches; 
00330 }
00331 
00332 int RecordPatchOld::handle_event()
00333 {
00334 // get the total selected before this event
00335         if(shift_down())
00336         {
00337                 int total_selected = patches->records_selected();
00338 
00339                 if(total_selected == 0)
00340                 {
00341 // nothing previously selected
00342                         patches->select_all_record();
00343                 }
00344                 else
00345                 if(total_selected == 1)
00346                 {
00347                         if(patch->record)
00348                         {
00349 // this patch was previously the only one on
00350                                 patches->select_all_record();
00351                         }
00352                         else
00353                         {
00354 // another patch was previously the only one on
00355                                 patches->deselect_all_record();
00356                                 patch->record = 1;
00357                         }
00358                 }
00359                 else
00360                 if(total_selected > 1)
00361                 {
00362                         patches->deselect_all_record();
00363                         patch->record = 1;
00364                 }
00365                 
00366                 update(patch->record);
00367         }
00368         else
00369         {
00370                 patch->record = get_value();
00371         }
00372         patches->button_down = 1;
00373         patches->new_status = get_value();
00374         return 1;
00375 }
00376 
00377 int RecordPatchOld::button_release()
00378 {
00379         //if(patches->button_down)
00380         //{
00381         //      patches->button_down = 0;
00382 // restart the playback
00383                 //patches->mwindow->start_reconfigure(1);
00384                 //patches->mwindow->stop_reconfigure(1);
00385         //}
00386         return 0;
00387 }
00388 
00389 int RecordPatchOld::cursor_moved_over()
00390 {
00391         if(patches->button_down && patches->new_status != get_value()) 
00392         {
00393                 update(patches->new_status);
00394                 patch->record = get_value();
00395                 return 1;
00396         }
00397         return 0;
00398 }
00399 
00400 TitlePatchOld::TitlePatchOld(MWindow *mwindow, Patch *patch, char *text, int x, int y)
00401  : BC_TextBox(x, y + PATCH_TITLE, 124, 1, text, 0)
00402 { 
00403         this->patch = patch; 
00404         patches = patch->patches; 
00405         module = 0; 
00406 }
00407 
00408 int TitlePatchOld::handle_event()
00409 {
00410         if(!module) module = patch->get_module();
00411         module->set_title(get_text());
00412         strcpy(patch->title, get_text());
00413         return 1;
00414 }
00415 
00416 DrawPatchOld::DrawPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
00417  : BC_Toggle(x + PATCH_DRAW, 
00418         y + PATCH_ROW2, 
00419         mwindow->theme->drawpatch_data,
00420         1,
00421         "",
00422         1, 
00423         0, 
00424         0)
00425 { 
00426         this->patch = patch; 
00427         this->patches = patch->patches; 
00428 }
00429 
00430 int DrawPatchOld::handle_event()
00431 {
00432 // get the total selected before this event
00433         if(shift_down())
00434         {
00435                 int total_selected = patches->draws_selected();
00436 
00437                 if(total_selected == 0)
00438                 {
00439 // nothing previously selected
00440                         patches->select_all_draw();
00441                 }
00442                 else
00443                 if(total_selected == 1)
00444                 {
00445                         if(patch->draw)
00446                         {
00447 // this patch was previously the only one on
00448                                 patches->select_all_draw();
00449                         }
00450                         else
00451                         {
00452 // another patch was previously the only one on
00453                                 patches->deselect_all_draw();
00454                                 patch->draw = 1;
00455                         }
00456                 }
00457                 else
00458                 if(total_selected > 1)
00459                 {
00460                         patches->deselect_all_draw();
00461                         patch->draw = 1;
00462                 }
00463                 
00464                 update(patch->draw);
00465         }
00466         else
00467         {
00468                 patch->draw = get_value();
00469         }
00470         patches->button_down = 1;
00471         patches->new_status = get_value();
00472         return 1;
00473 }
00474 
00475 int DrawPatchOld::cursor_moved_over()
00476 {
00477         if(patches->button_down && patches->new_status != get_value())
00478         {
00479                 update(patches->new_status);
00480                 patch->draw = get_value();
00481         return 1;
00482         }
00483         return 0;
00484 }

Generated on Sun Jan 8 13:38:58 2006 for Cinelerra-svn by  doxygen 1.4.4