4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "mwindowgui.h"
30 #include "mainsession.h"
34 Patch::Patch(MWindow *mwindow, PatchBay *patchbay, int data_type) : ListItem<Patch>()
36 this->mwindow = mwindow;
37 this->patches = patchbay;
38 this->data_type = data_type;
39 record = play = automate = draw = 1;
55 void Patch::create_objects(char *text, int pixel)
63 if(mwindow->session->tracks_vertical)
65 //x = patches->gui->w - pixel - mwindow->zoom_track;
75 patches->add_subwindow(recordpatch = new RecordPatchOld(mwindow, this, x, y));
76 patches->add_subwindow(playpatch = new PlayPatchOld(mwindow, this, x, y));
77 patches->add_subwindow(title_text = new TitlePatchOld(mwindow, this, text, x, y));
78 //patches->add_subwindow(autotitle = new BC_Title(x + PATCH_AUTO_TITLE, y + PATCH_ROW2, "A", SMALLFONT));
79 //patches->add_subwindow(autopatch = new AutoPatchOld(mwindow, this, x, y));
80 //patches->add_subwindow(drawtitle = new BC_Title(x + PATCH_DRAW_TITLE, y + PATCH_ROW2, "D", SMALLFONT));
81 patches->add_subwindow(drawpatch = new DrawPatchOld(mwindow, this, x, y));
85 int Patch::save(FileXML *xml)
87 xml->tag.set_title("PATCH");
92 xml->tag.set_title("PLAY");
94 xml->tag.set_title("/PLAY");
100 xml->tag.set_title("RECORD");
102 xml->tag.set_title("/RECORD");
108 xml->tag.set_title("AUTO");
110 xml->tag.set_title("/AUTO");
116 xml->tag.set_title("DRAW");
118 xml->tag.set_title("/DRAW");
122 xml->tag.set_title("TITLE");
124 xml->append_text(title);
125 xml->tag.set_title("/TITLE");
129 xml->tag.set_title("/PATCH");
131 xml->append_newline();
135 int Patch::load(FileXML *xml)
138 play = record = automate = draw = 0; // defaults
141 result = xml->read_tag();
145 if(xml->tag.title_is("/PATCH"))
150 if(xml->tag.title_is("PLAY"))
155 if(xml->tag.title_is("RECORD"))
160 if(xml->tag.title_is("AUTO"))
165 if(xml->tag.title_is("DRAW"))
170 if(xml->tag.title_is("TITLE"))
172 strcpy(title, xml->read_text());
179 playpatch->update(play);
180 recordpatch->update(record);
181 autopatch->update(automate);
182 drawpatch->update(draw);
183 title_text->update(title);
188 int Patch::set_pixel(int pixel)
189 { // must be top of track for track zoom
193 if(mwindow->session->tracks_vertical)
196 playpatch->reposition_window(pixel + PATCH_PLAY, playpatch->get_y());
197 recordpatch->reposition_window(pixel + PATCH_REC, recordpatch->get_y());
198 autopatch->reposition_window(pixel + PATCH_AUTO, autopatch->get_y());
199 title_text->reposition_window(pixel, title_text->get_y());
200 drawpatch->reposition_window(pixel + PATCH_DRAW, drawpatch->get_y());
204 playpatch->reposition_window(playpatch->get_x(), pixel + PATCH_ROW2);
205 recordpatch->reposition_window(recordpatch->get_x(), pixel + PATCH_ROW2);
206 autopatch->reposition_window(autopatch->get_x(), pixel + PATCH_ROW2);
207 drawpatch->reposition_window(drawpatch->get_x(), pixel + PATCH_ROW2);
208 title_text->reposition_window(title_text->get_x(), pixel + 3);
214 int Patch::set_title(char *new_title)
216 strcpy(title, new_title);
217 title_text->update(new_title);
221 int Patch::flip_vertical()
225 if(mwindow->session->tracks_vertical)
227 playpatch->reposition_window(playpatch->get_x(), PATCH_ROW2);
228 recordpatch->reposition_window(recordpatch->get_x(), PATCH_ROW2);
229 autopatch->reposition_window(autopatch->get_x(), PATCH_ROW2);
230 drawpatch->reposition_window(drawpatch->get_x(), PATCH_ROW2);
231 title_text->reposition_window(title_text->get_x(), 3);
235 playpatch->reposition_window(PATCH_PLAY, playpatch->get_y());
236 recordpatch->reposition_window(PATCH_REC, recordpatch->get_y());
237 autopatch->reposition_window(PATCH_AUTO, autopatch->get_y());
238 drawpatch->reposition_window(PATCH_DRAW, drawpatch->get_y());
239 title_text->reposition_window(PATCH_TITLE, title_text->get_y());
247 int Patch::pixelmovement(int distance)
257 Module* Patch::get_module() // return corresponding module from console
259 // return mwindow->console->modules->module_number(patches->number_of(this));
262 PlayPatchOld::PlayPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
263 : BC_Toggle(x + PATCH_PLAY,
265 mwindow->theme->playpatch_data,
273 patches = patch->patches;
277 int PlayPatchOld::handle_event()
279 // get the total selected before this event
282 int total_selected = patches->plays_selected();
284 if(total_selected == 0)
286 // nothing previously selected
287 patches->select_all_play();
290 if(total_selected == 1)
294 // this patch was previously the only one on
295 patches->select_all_play();
299 // another patch was previously the only one on
300 patches->deselect_all_play();
305 if(total_selected > 1)
307 patches->deselect_all_play();
315 patch->play = get_value();
317 patches->button_down = 1;
318 patches->reconfigure_trigger = 1;
319 patches->new_status = get_value();
323 int PlayPatchOld::button_release()
328 int PlayPatchOld::cursor_moved_over()
330 if(patches->button_down && patches->new_status != get_value())
332 update(patches->new_status);
333 patch->play = get_value();
339 RecordPatchOld::RecordPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
340 : BC_Toggle(x + PATCH_REC,
342 mwindow->theme->recordpatch_data,
350 patches = patch->patches;
353 int RecordPatchOld::handle_event()
355 // get the total selected before this event
358 int total_selected = patches->records_selected();
360 if(total_selected == 0)
362 // nothing previously selected
363 patches->select_all_record();
366 if(total_selected == 1)
370 // this patch was previously the only one on
371 patches->select_all_record();
375 // another patch was previously the only one on
376 patches->deselect_all_record();
381 if(total_selected > 1)
383 patches->deselect_all_record();
387 update(patch->record);
391 patch->record = get_value();
393 patches->button_down = 1;
394 patches->new_status = get_value();
398 int RecordPatchOld::button_release()
400 //if(patches->button_down)
402 // patches->button_down = 0;
403 // restart the playback
404 //patches->mwindow->start_reconfigure(1);
405 //patches->mwindow->stop_reconfigure(1);
410 int RecordPatchOld::cursor_moved_over()
412 if(patches->button_down && patches->new_status != get_value())
414 update(patches->new_status);
415 patch->record = get_value();
421 TitlePatchOld::TitlePatchOld(MWindow *mwindow, Patch *patch, char *text, int x, int y)
422 : BC_TextBox(x, y + PATCH_TITLE, 124, 1, text, 0)
425 patches = patch->patches;
429 int TitlePatchOld::handle_event()
431 if(!module) module = patch->get_module();
432 module->set_title(get_text());
433 strcpy(patch->title, get_text());
437 DrawPatchOld::DrawPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
438 : BC_Toggle(x + PATCH_DRAW,
440 mwindow->theme->drawpatch_data,
448 this->patches = patch->patches;
451 int DrawPatchOld::handle_event()
453 // get the total selected before this event
456 int total_selected = patches->draws_selected();
458 if(total_selected == 0)
460 // nothing previously selected
461 patches->select_all_draw();
464 if(total_selected == 1)
468 // this patch was previously the only one on
469 patches->select_all_draw();
473 // another patch was previously the only one on
474 patches->deselect_all_draw();
479 if(total_selected > 1)
481 patches->deselect_all_draw();
489 patch->draw = get_value();
491 patches->button_down = 1;
492 patches->new_status = get_value();
496 int DrawPatchOld::cursor_moved_over()
498 if(patches->button_down && patches->new_status != get_value())
500 update(patches->new_status);
501 patch->draw = get_value();