4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "mwindowgui.h"
29 #include "mainsession.h"
33 Patch::Patch(MWindow *mwindow, PatchBay *patchbay, int data_type) : ListItem<Patch>()
35 this->mwindow = mwindow;
36 this->patches = patchbay;
37 this->data_type = data_type;
38 record = play = automate = draw = 1;
54 void Patch::create_objects(char *text, int pixel)
62 if(mwindow->session->tracks_vertical)
64 //x = patches->gui->w - pixel - mwindow->zoom_track;
74 patches->add_subwindow(recordpatch = new RecordPatchOld(mwindow, this, x, y));
75 patches->add_subwindow(playpatch = new PlayPatchOld(mwindow, this, x, y));
76 patches->add_subwindow(title_text = new TitlePatchOld(mwindow, this, text, x, y));
77 //patches->add_subwindow(autotitle = new BC_Title(x + PATCH_AUTO_TITLE, y + PATCH_ROW2, "A", SMALLFONT));
78 //patches->add_subwindow(autopatch = new AutoPatchOld(mwindow, this, x, y));
79 //patches->add_subwindow(drawtitle = new BC_Title(x + PATCH_DRAW_TITLE, y + PATCH_ROW2, "D", SMALLFONT));
80 patches->add_subwindow(drawpatch = new DrawPatchOld(mwindow, this, x, y));
84 int Patch::save(FileXML *xml)
86 xml->tag.set_title("PATCH");
91 xml->tag.set_title("PLAY");
93 xml->tag.set_title("/PLAY");
99 xml->tag.set_title("RECORD");
101 xml->tag.set_title("/RECORD");
107 xml->tag.set_title("AUTO");
109 xml->tag.set_title("/AUTO");
115 xml->tag.set_title("DRAW");
117 xml->tag.set_title("/DRAW");
121 xml->tag.set_title("TITLE");
123 xml->append_text(title);
124 xml->tag.set_title("/TITLE");
128 xml->tag.set_title("/PATCH");
130 xml->append_newline();
134 int Patch::load(FileXML *xml)
137 play = record = automate = draw = 0; // defaults
140 result = xml->read_tag();
144 if(xml->tag.title_is("/PATCH"))
149 if(xml->tag.title_is("PLAY"))
154 if(xml->tag.title_is("RECORD"))
159 if(xml->tag.title_is("AUTO"))
164 if(xml->tag.title_is("DRAW"))
169 if(xml->tag.title_is("TITLE"))
171 strcpy(title, xml->read_text());
178 playpatch->update(play);
179 recordpatch->update(record);
180 autopatch->update(automate);
181 drawpatch->update(draw);
182 title_text->update(title);
187 int Patch::set_pixel(int pixel)
188 { // must be top of track for track zoom
192 if(mwindow->session->tracks_vertical)
195 playpatch->reposition_window(pixel + PATCH_PLAY, playpatch->get_y());
196 recordpatch->reposition_window(pixel + PATCH_REC, recordpatch->get_y());
197 autopatch->reposition_window(pixel + PATCH_AUTO, autopatch->get_y());
198 title_text->reposition_window(pixel, title_text->get_y());
199 drawpatch->reposition_window(pixel + PATCH_DRAW, drawpatch->get_y());
203 playpatch->reposition_window(playpatch->get_x(), pixel + PATCH_ROW2);
204 recordpatch->reposition_window(recordpatch->get_x(), pixel + PATCH_ROW2);
205 autopatch->reposition_window(autopatch->get_x(), pixel + PATCH_ROW2);
206 drawpatch->reposition_window(drawpatch->get_x(), pixel + PATCH_ROW2);
207 title_text->reposition_window(title_text->get_x(), pixel + 3);
213 int Patch::set_title(char *new_title)
215 strcpy(title, new_title);
216 title_text->update(new_title);
220 int Patch::flip_vertical()
224 if(mwindow->session->tracks_vertical)
226 playpatch->reposition_window(playpatch->get_x(), PATCH_ROW2);
227 recordpatch->reposition_window(recordpatch->get_x(), PATCH_ROW2);
228 autopatch->reposition_window(autopatch->get_x(), PATCH_ROW2);
229 drawpatch->reposition_window(drawpatch->get_x(), PATCH_ROW2);
230 title_text->reposition_window(title_text->get_x(), 3);
234 playpatch->reposition_window(PATCH_PLAY, playpatch->get_y());
235 recordpatch->reposition_window(PATCH_REC, recordpatch->get_y());
236 autopatch->reposition_window(PATCH_AUTO, autopatch->get_y());
237 drawpatch->reposition_window(PATCH_DRAW, drawpatch->get_y());
238 title_text->reposition_window(PATCH_TITLE, title_text->get_y());
246 int Patch::pixelmovement(int distance)
256 Module* Patch::get_module() // return corresponding module from console
258 // return mwindow->console->modules->module_number(patches->number_of(this));
261 PlayPatchOld::PlayPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
262 : BC_Toggle(x + PATCH_PLAY,
264 mwindow->theme->playpatch_data,
272 patches = patch->patches;
276 int PlayPatchOld::handle_event()
278 // get the total selected before this event
281 int total_selected = patches->plays_selected();
283 if(total_selected == 0)
285 // nothing previously selected
286 patches->select_all_play();
289 if(total_selected == 1)
293 // this patch was previously the only one on
294 patches->select_all_play();
298 // another patch was previously the only one on
299 patches->deselect_all_play();
304 if(total_selected > 1)
306 patches->deselect_all_play();
314 patch->play = get_value();
316 patches->button_down = 1;
317 patches->reconfigure_trigger = 1;
318 patches->new_status = get_value();
322 int PlayPatchOld::button_release()
327 int PlayPatchOld::cursor_moved_over()
329 if(patches->button_down && patches->new_status != get_value())
331 update(patches->new_status);
332 patch->play = get_value();
338 RecordPatchOld::RecordPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
339 : BC_Toggle(x + PATCH_REC,
341 mwindow->theme->recordpatch_data,
349 patches = patch->patches;
352 int RecordPatchOld::handle_event()
354 // get the total selected before this event
357 int total_selected = patches->records_selected();
359 if(total_selected == 0)
361 // nothing previously selected
362 patches->select_all_record();
365 if(total_selected == 1)
369 // this patch was previously the only one on
370 patches->select_all_record();
374 // another patch was previously the only one on
375 patches->deselect_all_record();
380 if(total_selected > 1)
382 patches->deselect_all_record();
386 update(patch->record);
390 patch->record = get_value();
392 patches->button_down = 1;
393 patches->new_status = get_value();
397 int RecordPatchOld::button_release()
399 //if(patches->button_down)
401 // patches->button_down = 0;
402 // restart the playback
403 //patches->mwindow->start_reconfigure(1);
404 //patches->mwindow->stop_reconfigure(1);
409 int RecordPatchOld::cursor_moved_over()
411 if(patches->button_down && patches->new_status != get_value())
413 update(patches->new_status);
414 patch->record = get_value();
420 TitlePatchOld::TitlePatchOld(MWindow *mwindow, Patch *patch, char *text, int x, int y)
421 : BC_TextBox(x, y + PATCH_TITLE, 124, 1, text, 0)
424 patches = patch->patches;
428 int TitlePatchOld::handle_event()
430 if(!module) module = patch->get_module();
431 module->set_title(get_text());
432 strcpy(patch->title, get_text());
436 DrawPatchOld::DrawPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
437 : BC_Toggle(x + PATCH_DRAW,
439 mwindow->theme->drawpatch_data,
447 this->patches = patch->patches;
450 int DrawPatchOld::handle_event()
452 // get the total selected before this event
455 int total_selected = patches->draws_selected();
457 if(total_selected == 0)
459 // nothing previously selected
460 patches->select_all_draw();
463 if(total_selected == 1)
467 // this patch was previously the only one on
468 patches->select_all_draw();
472 // another patch was previously the only one on
473 patches->deselect_all_draw();
478 if(total_selected > 1)
480 patches->deselect_all_draw();
488 patch->draw = get_value();
490 patches->button_down = 1;
491 patches->new_status = get_value();
495 int DrawPatchOld::cursor_moved_over()
497 if(patches->button_down && patches->new_status != get_value())
499 update(patches->new_status);
500 patch->draw = get_value();