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 int 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));
85 int Patch::save(FileXML *xml)
87 xml->tag.set_title("PATCH");
92 xml->tag.set_title("PLAY");
98 xml->tag.set_title("RECORD");
104 xml->tag.set_title("AUTO");
110 xml->tag.set_title("DRAW");
114 xml->tag.set_title("TITLE");
116 xml->append_text(title);
117 xml->tag.set_title("/TITLE");
121 xml->tag.set_title("/PATCH");
123 xml->append_newline();
127 int Patch::load(FileXML *xml)
130 play = record = automate = draw = 0; // defaults
133 result = xml->read_tag();
137 if(xml->tag.title_is("/PATCH"))
142 if(xml->tag.title_is("PLAY"))
147 if(xml->tag.title_is("RECORD"))
152 if(xml->tag.title_is("AUTO"))
157 if(xml->tag.title_is("DRAW"))
162 if(xml->tag.title_is("TITLE"))
164 strcpy(title, xml->read_text());
171 playpatch->update(play);
172 recordpatch->update(record);
173 autopatch->update(automate);
174 drawpatch->update(draw);
175 title_text->update(title);
180 int Patch::set_pixel(int pixel)
181 { // must be top of track for track zoom
185 if(mwindow->session->tracks_vertical)
188 playpatch->reposition_window(pixel + PATCH_PLAY, playpatch->get_y());
189 recordpatch->reposition_window(pixel + PATCH_REC, recordpatch->get_y());
190 autopatch->reposition_window(pixel + PATCH_AUTO, autopatch->get_y());
191 title_text->reposition_window(pixel, title_text->get_y());
192 drawpatch->reposition_window(pixel + PATCH_DRAW, drawpatch->get_y());
196 playpatch->reposition_window(playpatch->get_x(), pixel + PATCH_ROW2);
197 recordpatch->reposition_window(recordpatch->get_x(), pixel + PATCH_ROW2);
198 autopatch->reposition_window(autopatch->get_x(), pixel + PATCH_ROW2);
199 drawpatch->reposition_window(drawpatch->get_x(), pixel + PATCH_ROW2);
200 title_text->reposition_window(title_text->get_x(), pixel + 3);
206 int Patch::set_title(char *new_title)
208 strcpy(title, new_title);
209 title_text->update(new_title);
213 int Patch::flip_vertical()
217 if(mwindow->session->tracks_vertical)
219 playpatch->reposition_window(playpatch->get_x(), PATCH_ROW2);
220 recordpatch->reposition_window(recordpatch->get_x(), PATCH_ROW2);
221 autopatch->reposition_window(autopatch->get_x(), PATCH_ROW2);
222 drawpatch->reposition_window(drawpatch->get_x(), PATCH_ROW2);
223 title_text->reposition_window(title_text->get_x(), 3);
227 playpatch->reposition_window(PATCH_PLAY, playpatch->get_y());
228 recordpatch->reposition_window(PATCH_REC, recordpatch->get_y());
229 autopatch->reposition_window(PATCH_AUTO, autopatch->get_y());
230 drawpatch->reposition_window(PATCH_DRAW, drawpatch->get_y());
231 title_text->reposition_window(PATCH_TITLE, title_text->get_y());
239 int Patch::pixelmovement(int distance)
249 Module* Patch::get_module() // return corresponding module from console
251 // return mwindow->console->modules->module_number(patches->number_of(this));
254 PlayPatchOld::PlayPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
255 : BC_Toggle(x + PATCH_PLAY,
257 mwindow->theme->playpatch_data,
265 patches = patch->patches;
269 int PlayPatchOld::handle_event()
271 // get the total selected before this event
274 int total_selected = patches->plays_selected();
276 if(total_selected == 0)
278 // nothing previously selected
279 patches->select_all_play();
282 if(total_selected == 1)
286 // this patch was previously the only one on
287 patches->select_all_play();
291 // another patch was previously the only one on
292 patches->deselect_all_play();
297 if(total_selected > 1)
299 patches->deselect_all_play();
307 patch->play = get_value();
309 patches->button_down = 1;
310 patches->reconfigure_trigger = 1;
311 patches->new_status = get_value();
315 int PlayPatchOld::button_release()
320 int PlayPatchOld::cursor_moved_over()
322 if(patches->button_down && patches->new_status != get_value())
324 update(patches->new_status);
325 patch->play = get_value();
331 RecordPatchOld::RecordPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
332 : BC_Toggle(x + PATCH_REC,
334 mwindow->theme->recordpatch_data,
342 patches = patch->patches;
345 int RecordPatchOld::handle_event()
347 // get the total selected before this event
350 int total_selected = patches->records_selected();
352 if(total_selected == 0)
354 // nothing previously selected
355 patches->select_all_record();
358 if(total_selected == 1)
362 // this patch was previously the only one on
363 patches->select_all_record();
367 // another patch was previously the only one on
368 patches->deselect_all_record();
373 if(total_selected > 1)
375 patches->deselect_all_record();
379 update(patch->record);
383 patch->record = get_value();
385 patches->button_down = 1;
386 patches->new_status = get_value();
390 int RecordPatchOld::button_release()
392 //if(patches->button_down)
394 // patches->button_down = 0;
395 // restart the playback
396 //patches->mwindow->start_reconfigure(1);
397 //patches->mwindow->stop_reconfigure(1);
402 int RecordPatchOld::cursor_moved_over()
404 if(patches->button_down && patches->new_status != get_value())
406 update(patches->new_status);
407 patch->record = get_value();
413 TitlePatchOld::TitlePatchOld(MWindow *mwindow, Patch *patch, char *text, int x, int y)
414 : BC_TextBox(x, y + PATCH_TITLE, 124, 1, text, 0)
417 patches = patch->patches;
421 int TitlePatchOld::handle_event()
423 if(!module) module = patch->get_module();
424 module->set_title(get_text());
425 strcpy(patch->title, get_text());
429 DrawPatchOld::DrawPatchOld(MWindow *mwindow, Patch *patch, int x, int y)
430 : BC_Toggle(x + PATCH_DRAW,
432 mwindow->theme->drawpatch_data,
440 this->patches = patch->patches;
443 int DrawPatchOld::handle_event()
445 // get the total selected before this event
448 int total_selected = patches->draws_selected();
450 if(total_selected == 0)
452 // nothing previously selected
453 patches->select_all_draw();
456 if(total_selected == 1)
460 // this patch was previously the only one on
461 patches->select_all_draw();
465 // another patch was previously the only one on
466 patches->deselect_all_draw();
471 if(total_selected > 1)
473 patches->deselect_all_draw();
481 patch->draw = get_value();
483 patches->button_down = 1;
484 patches->new_status = get_value();
488 int DrawPatchOld::cursor_moved_over()
490 if(patches->button_down && patches->new_status != get_value())
492 update(patches->new_status);
493 patch->draw = get_value();