Guitarix
rack.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Hermann Meyer, James Warden
3  * Copyright (C) 2011 Pete Shorthose
4  * Copyright (C) 2012 Andreas Degert
5  *
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.
10  *
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.
15  *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  * ---------------------------------------------------------------------------
20  *
21  * ----------------------------------------------------------------------------
22  */
23 
24 #include <guitarix.h>
25 
26 /****************************************************************
27  ** class PluginUI
28  **
29  ** This class represents a rack unit. It refers to an engine
30  ** plugin. The user interface in the rack is loaded on demand.
31  **
32  ** It is responsible for reflecting any changes done to display
33  ** parameter variables (box_visible, flat/expanded format, ordering).
34  **
35  ** Registering with an GxUI is done in PluginDict.
36  **
37  ** When a preset load is in progress re-ordering is blocked.
38  ** MainWindow connects RackContainer::check_order() to
39  ** GxSettings::signal_selection_changed so that ordering will be done
40  ** when the load is finished.
41  **
42  */
43 
44 PluginUI::PluginUI(MainWindow& main_, const char *name,
45  const Glib::ustring& tooltip_)
46  : merge_id(0),
47  action(),
48  plugin(main_.get_machine().pluginlist_lookup_plugin(name)),
49  tooltip(tooltip_),
50  shortname(),
51  icon(),
52  group(),
53  toolitem(),
54  main(main_),
55  rackbox(),
56  hidden(false),
57  hidden_by_move(false) {
58  if (plugin->get_pdef()->description && tooltip.empty()) {
60  }
62 }
63 
65  delete rackbox;
66  if (toolitem) {
67  if (group) {
68  group->remove(*toolitem);
69  }
70  delete toolitem;
71  }
73 }
74 
75 void PluginUI::unset_ui_merge_id(Glib::RefPtr<Gtk::UIManager> uimanager) {
76  if (merge_id) {
77  uimanager->remove_ui(merge_id);
78  merge_id = 0;
79  }
80 }
81 
84 }
85 
88 }
89 
90 void PluginUI::compress(bool state) {
91  plugin->set_plug_visible(state);
92  if (rackbox) {
93  if (rackbox->can_compress()) {
94  rackbox->swtch(state);
95  }
96  }
97 }
98 
99 void PluginUI::set_action(Glib::RefPtr<Gtk::ToggleAction>& act)
100 {
101  action = act;
102  action->signal_toggled().connect(sigc::mem_fun(*this, &PluginUI::on_action_toggled));
103 }
104 
105 void PluginUI::on_action_toggled() {
106  if (rackbox && action->get_active() == rackbox->get_box_visible()) {
107  return;
108  }
109  if (action->get_active()) {
110  display_new();
111  } else {
112  display(false, true);
113  }
114 }
115 
116 void PluginUI::hide(bool animate) {
117  plugin->set_on_off(false);
118  if (rackbox) {
119  rackbox->display(false, animate);
120  main.add_icon(get_id());
121  }
122 }
123 
124 void PluginUI::show(bool animate) {
125  if (!rackbox) {
126  rackbox = main.add_rackbox(*this, plugin->get_plug_visible(), -1, animate);
127  set_active(true);
128  } else {
129  rackbox->display(true, animate);
130  }
131  if (hidden) {
132  rackbox->hide();
133  }
135 }
136 
137 void PluginUI::display(bool v, bool animate) {
138  // this function hides the rackbox. It could also destroy it (or
139  // some other function could do it, e.g. when unloading a module),
140  // but currently there are too many memory leaks in the stack based
141  // builder.
143  if (v) {
145  hidden = false;
146  show(animate);
147  } else {
149  hide(animate);
150  }
151 }
152 
153 void PluginUI::display_new(bool unordered) {
154  plugin->set_plug_visible(false);
155  if (rackbox) {
156  rackbox->swtch(false);
157  }
158  display(true, true);
159  if (!unordered) {
160  rackbox->get_parent()->reorder(get_id(), -1);
161  }
162 }
163 
165  if (!rackbox) {
166  return;
167  }
168  if (plugin->get_box_visible()) {
170  int n = 0;
171  for (RackContainer::rackbox_list::iterator i = l.begin(); i != l.end(); ++i, ++n)
172  if (*i == rackbox) {
173  break;
174  }
175  display(false,false);
176  delete rackbox;
177  rackbox = 0;
178  display(true,false);
179  //rackbox = main.add_rackbox(*this, plugin->get_plug_visible(), n, false);
180  } else {
181  delete rackbox;
182  rackbox = 0;
183  }
184 }
185 
187  int res = a->get_type() - b->get_type();
188  if (res == 0) {
189  gchar *an = g_utf8_casefold(a->get_shortname(), 1);
190  gchar *bn = g_utf8_casefold(b->get_shortname(), 1);
191  res = g_utf8_collate(an, bn);
192  g_free(an);
193  g_free(bn);
194  }
195  return res < 0;
196 }
197 
198 
199 /****************************************************************
200  ** class PluginDict
201  */
202 
204  insert(pair<std::string, PluginUI*>(p->get_id(), p));
205 }
206 
208  std::map<std::string, PluginUI*>::iterator i = find(p->get_id());
209  assert(i != end());
210  erase(i);
211 }
212 
214  for (std::map<std::string, PluginUI*>::iterator i = begin(); i != end(); ++i) {
215  delete i->second;
216  }
217  clear();
218 }
219 
221  cleanup();
222 }
223 
224 void PluginDict::compress(bool state) {
225  for (std::map<std::string, PluginUI*>::iterator i = begin(); i != end(); ++i) {
226  i->second->compress(state);
227  }
228 }
229 
230 
231 /****************************************************************
232  ** class DragIcon
233  */
234 
235 inline guint8 convert_color_channel (guint8 src, guint8 alpha) {
236  return alpha ? ((guint (src) << 8) - src) / alpha : 0;
237 }
238 
239 void convert_bgra_to_rgba (guint8 const* src, guint8* dst, int width, int height) {
240  guint8 const* src_pixel = src;
241  guint8* dst_pixel = dst;
242 
243  for (int i = 0; i < height*width; ++i) {
244  dst_pixel[0] = convert_color_channel(src_pixel[2], src_pixel[3]);
245  dst_pixel[1] = convert_color_channel(src_pixel[1], src_pixel[3]);
246  dst_pixel[2] = convert_color_channel(src_pixel[0], src_pixel[3]);
247  dst_pixel[3] = src_pixel[3];
248 
249  dst_pixel += 4;
250  src_pixel += 4;
251  }
252 }
253 
254 DragIcon::DragIcon(const PluginUI& plugin, Glib::RefPtr<Gdk::DragContext> context, gx_system::CmdlineOptions& options, int xoff)
255  : window(), drag_icon_pixbuf() {
256  Glib::RefPtr<Gdk::Screen> screen = context->get_source_window()->get_screen();
257  Glib::RefPtr<Gdk::Colormap> rgba = screen->get_rgba_colormap();
258  if (screen->is_composited()) {
259  window = new Gtk::Window(Gtk::WINDOW_POPUP);
260  if (rgba) { // else will look ugly..
261  window->set_colormap(rgba);
262  }
263  }
264  create_drag_icon_pixbuf(plugin, rgba, options);
265  int w = drag_icon_pixbuf->get_width();
266  int h = drag_icon_pixbuf->get_height();
267  int h2 = (h/2)-2;
268  int w2 = std::min(std::max(0, xoff), w-gradient_length/2) - 4;
269  if (window) {
270  window->set_size_request(w, h);
271  window->signal_expose_event().connect(sigc::mem_fun(*this, &DragIcon::icon_expose_event));
272  //context->set_icon_widget(window, w2, h2);
273  gtk_drag_set_icon_widget(context->gobj(), GTK_WIDGET(window->gobj()), w2, h2);
274  } else {
275  context->set_icon(drag_icon_pixbuf, w2, h2);
276  }
277 }
278 
280  delete window;
281 }
282 
283 bool DragIcon::icon_expose_event(GdkEventExpose *ev) {
284  Cairo::RefPtr<Cairo::Context> cr = Glib::wrap(ev->window, true)->create_cairo_context();
285  gdk_cairo_region(cr->cobj(), ev->region);
286  cr->set_operator(Cairo::OPERATOR_SOURCE);
287  cr->clip();
288  Gdk::Cairo::set_source_pixbuf(cr, drag_icon_pixbuf, 0, 0);
289  cr->paint();
290  return true;
291 }
292 
293 void DragIcon::create_drag_icon_pixbuf(const PluginUI& plugin, Glib::RefPtr<Gdk::Colormap> rgba, gx_system::CmdlineOptions& options) {
294  Gtk::OffscreenWindow w;
295  w.signal_expose_event().connect(sigc::bind(sigc::mem_fun(*this, &DragIcon::window_expose_event), sigc::ref(w)));
296  if (rgba) {
297  w.set_colormap(rgba);
298  }
299  Gtk::Widget *r = RackBox::create_drag_widget(plugin, options);
300  w.add(*r);
301  w.show_all();
302  w.get_window()->process_updates(true);
303 }
304 
305 static void destroy_data(const guint8 *data) {
306  delete[] data;
307 }
308 
309 bool DragIcon::window_expose_event(GdkEventExpose *event, Gtk::OffscreenWindow& widget) {
310  Cairo::RefPtr<Cairo::Context> cr = widget.get_window()->create_cairo_context();
311  cr->set_operator(Cairo::OPERATOR_SOURCE);
312  cr->set_source_rgba(0,0,0,0);
313  cr->paint();
314  Gtk::Widget *child = widget.get_child();
315  if (child) {
316  widget.propagate_expose(*child, event);
317  }
318  Cairo::RefPtr<Cairo::Surface> x_surf = cr->get_target();
319  //int w = gdk_window_get_width(event->window); gtk 2.24
320  //int h = gdk_window_get_height(event->window);
321  int w, h;
322  gdk_drawable_get_size(event->window, &w, &h);
323  Cairo::RefPtr<Cairo::LinearGradient> grad = Cairo::LinearGradient::create(w, 0, w-gradient_length, 0);
324  grad->add_color_stop_rgba(0, 1, 1, 1, 1);
325  grad->add_color_stop_rgba(1, 1, 1, 1, 0);
326  cr->rectangle(w-gradient_length, 0, gradient_length, h);
327  cr->mask(grad);
328  Cairo::RefPtr<Cairo::ImageSurface> i_surf = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, w, h);
329  Cairo::RefPtr<Cairo::Context> crt = Cairo::Context::create(i_surf);
330  crt->set_operator(Cairo::OPERATOR_SOURCE);
331  crt->set_source(x_surf, 0, 0);
332  crt->paint();
333  guint8 *data = new guint8[w*h*4];
334  convert_bgra_to_rgba(i_surf->get_data(), data, w, h);
335  drag_icon_pixbuf = Gdk::Pixbuf::create_from_data(data, Gdk::COLORSPACE_RGB, true, 8, w, h, i_surf->get_stride(), sigc::ptr_fun(destroy_data));
336  return true;
337 }
338 
339 
340 /****************************************************************
341  ** class MiniRackBox
342  */
343 
344 Glib::RefPtr<Gtk::SizeGroup> MiniRackBox::szg_label;
345 
346 Gtk::Widget *MiniRackBox::make_delete_button(RackBox& rb) {
347  Gtk::Widget *w;
348  if (rb.has_delete()) {
349  Gtk::Label *l = new Gtk::Label("\u2a2f");
350  l->show();
351  Gtk::Button *b = new Gtk::Button();
352  b->set_focus_on_click(false);
353  b->add(*manage(l));
354  b->signal_clicked().connect(sigc::bind(sigc::mem_fun(rb.plugin, &PluginUI::display), false, true));
355  w = b;
356  } else {
357  w = new Gtk::Alignment();
358  }
359  w->set_size_request(20, 15);
360  return w;
361 }
362 
363 bool MiniRackBox::on_my_leave_out(GdkEventCrossing *focus) {
364  if (!mconbox.get_visible()) {
365  Glib::RefPtr<Gdk::Window> window = this->get_window();
366  window->set_cursor();
367  }
368  return true;
369 }
370 
371 bool MiniRackBox::on_my_enter_in(GdkEventCrossing *focus) {
372  if (!mconbox.get_visible()) {
373  Glib::RefPtr<Gdk::Window> window = this->get_window();
374  Gdk::Cursor cursor(Gdk::HAND1);
375  window->set_cursor(cursor);
376  }
377  return true;
378 }
379 
381  : Gtk::HBox(),
382  evbox(),
383  mconbox(false, 4),
384  mb_expand_button(),
385  mb_delete_button(),
386  preset_button(),
387  on_off_switch("switchit"),
388  toggle_on_off(rb.main.get_machine(), &on_off_switch, rb.plugin.plugin->id_on_off()) {
389  if (strcmp(rb.plugin.get_id(), "ampstack") != 0) { // FIXME
390  gx_gui::connect_midi_controller(&on_off_switch, rb.plugin.plugin->id_on_off().c_str(), rb.main.get_machine());
391 
392  if (!szg_label) {
393  szg_label = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_HORIZONTAL);
394  }
395  evbox.set_visible_window(false);
396  evbox.signal_leave_notify_event().connect(sigc::mem_fun(*this, &MiniRackBox::on_my_leave_out));
397  evbox.signal_enter_notify_event().connect(sigc::mem_fun(*this, &MiniRackBox::on_my_enter_in));
398  add(evbox);
399 
400  Gtk::Alignment *al = new Gtk::Alignment();
401  al->set_padding(0, 4, 0, 0);
402  al->set_border_width(0);
403 
404  evbox.add(*manage(al));
405 
406  Gtk::HBox *box = new Gtk::HBox();
407  Gtk::HBox *top = new Gtk::HBox();
408  al->add(*manage(box));
409 
410  this->set_spacing(0);
411  this->set_border_width(0);
412 
413  box->set_spacing(0);
414  box->set_border_width(0);
415 
416  top->set_spacing(4);
417  top->set_border_width(0);
418  top->set_name("rack_unit_title_bar");
419 
420  box->pack_start(*manage(rb.wrap_bar()), Gtk::PACK_SHRINK);
421  box->pack_start(*manage(top));
422  box->pack_start(*manage(rb.wrap_bar()), Gtk::PACK_SHRINK);
423 
424  top->pack_start(on_off_switch, Gtk::PACK_SHRINK);
425  on_off_switch.set_name("effect_on_off");
426  Gtk::Widget *effect_label = RackBox::make_label(rb.plugin, options);
427  szg_label->add_widget(*manage(effect_label));
428  top->pack_start(*manage(effect_label), Gtk::PACK_SHRINK);
429 
430  top->pack_start(mconbox, Gtk::PACK_EXPAND_WIDGET);
431 
432  mb_expand_button = rb.make_expand_button(true);
433  top->pack_end(*manage(mb_expand_button), Gtk::PACK_SHRINK);
434  if (!(rb.plugin.plugin->get_pdef()->flags & PGN_NO_PRESETS)) {
435  preset_button = rb.make_preset_button();
436  top->pack_end(*manage(preset_button), Gtk::PACK_SHRINK);
437  }
438  mb_delete_button = make_delete_button(rb);
439  mb_delete_button->set_no_show_all(true);
440  top->pack_end(*manage(mb_delete_button), Gtk::PACK_SHRINK);
441 #ifdef USE_SZG
442  RackBox::szg->add_widget(*al);
443 #else
444  al->set_size_request(32, -1);
445 #endif
446  } else { // special minibox for main amp in config mode
447  if (!szg_label) {
448  szg_label = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_HORIZONTAL);
449  }
450  evbox.set_visible_window(false);
451  evbox.signal_leave_notify_event().connect(sigc::mem_fun(*this, &MiniRackBox::on_my_leave_out));
452  evbox.signal_enter_notify_event().connect(sigc::mem_fun(*this, &MiniRackBox::on_my_enter_in));
453  add(evbox);
454 
455  Gtk::Alignment *al = new Gtk::Alignment();
456  al->set_padding(0, 4, 0, 0);
457  al->set_border_width(0);
458 
459  Gtk::HBox *box = new Gtk::HBox();
460  Gtk::HBox *top = new Gtk::HBox();
461  evbox.add(*manage(box));
462 
463  top->set_name("rack_unit_title_bar");
464  Gtk::Widget *effect_label = RackBox::make_label(rb.plugin, options);
465  szg_label->add_widget(*manage(effect_label));
466  top->pack_start(*manage(effect_label), Gtk::PACK_SHRINK);
467  top->pack_start(mconbox, Gtk::PACK_EXPAND_WIDGET);
468  box->pack_start(*manage(al), Gtk::PACK_SHRINK);
469  box->pack_start(*manage(top));
470 #ifdef USE_SZG
471  RackBox::szg->add_widget(*al);
472 #else
473  al->set_size_request(64, 32);
474 #endif
475  }
476  show_all();
477 }
478 
479 void MiniRackBox::pack(Gtk::Widget *w) {
480  if (w) {
481  mconbox.pack_start(*manage(w), Gtk::PACK_SHRINK, 4);
482  }
483 }
484 
486  evbox.set_above_child(mode);
487  if (mode) {
488  mconbox.hide();
489  if (preset_button) {
490  preset_button->hide();
491  }
492  if (mb_expand_button) {
493  mb_expand_button->hide();
494  }
495  if (mb_delete_button) {
496  mb_delete_button->show();
497  }
498  } else {
499  mconbox.show();
500  if (preset_button) {
501  preset_button->show();
502  }
503  if (mb_expand_button) {
504  mb_expand_button->show();
505  }
506  if (mb_delete_button) {
507  mb_delete_button->hide();
508  }
509  }
510 }
511 
512 
513 /****************************************************************
514  ** class PluginPresetPopup
515  */
516 
517 /*
518 ** InputWindow
519 */
520 
521 class InputWindow: public Gtk::Window {
522 private:
523  Glib::ustring name;
524  void on_cancel();
525  void on_ok(Gtk::Entry *e);
526  virtual bool on_key_press_event(GdkEventKey *event);
527  static InputWindow* create_from_builder(
528  BaseObjectType* cobject, Glib::RefPtr<gx_gui::GxBuilder> bld, const Glib::ustring& save_name_default);
529  InputWindow(BaseObjectType* cobject, Glib::RefPtr<gx_gui::GxBuilder> bld, const Glib::ustring& save_name_default);
530 public:
531  ~InputWindow();
532  static InputWindow *create(const gx_system::CmdlineOptions& options, const Glib::ustring& save_name_default);
533  void run();
534  Glib::ustring& get_name() { return name; }
535 };
536 
537 InputWindow *InputWindow::create_from_builder(BaseObjectType* cobject, Glib::RefPtr<gx_gui::GxBuilder> bld,
538  const Glib::ustring& save_name_default) {
539  return new InputWindow(cobject, bld, save_name_default);
540 }
541 
543 }
544 
545 InputWindow *InputWindow::create(const gx_system::CmdlineOptions& options, const Glib::ustring& save_name_default) {
546  Glib::RefPtr<gx_gui::GxBuilder> bld = gx_gui::GxBuilder::create_from_file(options.get_builder_filepath("pluginpreset_inputwindow.glade"));
547  InputWindow *w;
548  bld->get_toplevel_derived(
549  "PluginPresetInputWindow", w,
550  sigc::bind(sigc::ptr_fun(InputWindow::create_from_builder), bld, save_name_default));
551  return w;
552 }
553 
554 bool InputWindow::on_key_press_event(GdkEventKey *event) {
555  if (event->keyval == GDK_KEY_Escape && (event->state & Gtk::AccelGroup::get_default_mod_mask()) == 0) {
556  hide();
557  return true;
558  }
559  return Gtk::Window::on_key_press_event(event);
560 }
561 
562 void InputWindow::on_ok(Gtk::Entry *e) {
563  name = e->get_text();
564  hide();
565 }
566 
567 InputWindow::InputWindow(BaseObjectType* cobject, Glib::RefPtr<gx_gui::GxBuilder> bld,
568  const Glib::ustring& save_name_default)
569  : Gtk::Window(cobject), name() {
570  Gtk::Button *b;
571  bld->find_widget("cancelbutton", b);
572  b->signal_clicked().connect(
573  sigc::mem_fun(*this, &InputWindow::hide));
574  bld->find_widget("okbutton", b);
575  Gtk::Entry *e;
576  bld->find_widget("entry", e);
577  e->set_text(save_name_default);
578  e->select_region(0, -1);
579  b->signal_clicked().connect(
580  sigc::bind(sigc::mem_fun(*this, &InputWindow::on_ok), e));
581 }
582 
584  Gtk::Main::run(*this);
585 }
586 
587 /*
588 ** PluginPresetListWindow
589 */
590 
591 class TextListStore: public Gtk::ListStore {
592 public:
593  class TextListColumns : public Gtk::TreeModel::ColumnRecord {
594  public:
595  Gtk::TreeModelColumn<Glib::ustring> name;
596  TextListColumns() { add(name); }
597  } col;
598 private:
599  TextListStore(): Gtk::ListStore(), col() {
600  set_column_types(col);
601  }
602 public:
603  static Glib::RefPtr<TextListStore> create() { return Glib::RefPtr<TextListStore>(new TextListStore); }
604 };
605 
606 class PluginPresetListWindow: public Gtk::Window {
607 private:
608  Glib::RefPtr<TextListStore> textliststore;
609  PluginPresetPopup& presetlist;
610  //
611  Gtk::TreeView *treeview;
612  Gtk::Button *removebutton;
613  using Gtk::Window::on_remove;
614  void on_remove();
615  void on_selection_changed();
616  virtual bool on_key_press_event(GdkEventKey *event);
617  static PluginPresetListWindow* create_from_builder(
618  BaseObjectType* cobject, Glib::RefPtr<gx_gui::GxBuilder> bld, PluginPresetPopup& p);
619  PluginPresetListWindow(BaseObjectType* cobject, Glib::RefPtr<gx_gui::GxBuilder> bld, PluginPresetPopup& p);
620 public:
622  static PluginPresetListWindow *create(const gx_system::CmdlineOptions& options, PluginPresetPopup& p);
623  void run();
624 };
625 
626 PluginPresetListWindow *PluginPresetListWindow::create_from_builder(
627  BaseObjectType* cobject, Glib::RefPtr<gx_gui::GxBuilder> bld, PluginPresetPopup& p) {
628  return new PluginPresetListWindow(cobject, bld, p);
629 }
630 
632 }
633 
635  const gx_system::CmdlineOptions& options, PluginPresetPopup& p) {
636  Glib::RefPtr<gx_gui::GxBuilder> bld = gx_gui::GxBuilder::create_from_file(
637  options.get_builder_filepath("pluginpreset_listwindow.glade"));
639  bld->get_toplevel_derived(
640  "PluginPresetListWindow", w,
641  sigc::bind(sigc::ptr_fun(PluginPresetListWindow::create_from_builder), bld, sigc::ref(p)));
642  return w;
643 }
644 
645 bool PluginPresetListWindow::on_key_press_event(GdkEventKey *event) {
646  if (event->keyval == GDK_KEY_Escape && (event->state & Gtk::AccelGroup::get_default_mod_mask()) == 0) {
647  hide();
648  return true;
649  }
650  return Gtk::Window::on_key_press_event(event);
651 }
652 
653 void PluginPresetListWindow::on_remove() {
654  Gtk::TreeIter it = treeview->get_selection()->get_selected();
655  if (it) {
656  presetlist.get_machine().plugin_preset_list_remove(
657  presetlist.get_pdef(), it->get_value(textliststore->col.name));
658  textliststore->erase(it);
659  }
660 }
661 
662 PluginPresetListWindow::PluginPresetListWindow(
663  BaseObjectType* cobject, Glib::RefPtr<gx_gui::GxBuilder> bld, PluginPresetPopup& p)
664  : Gtk::Window(cobject),
665  textliststore(TextListStore::create()),
666  presetlist(p) {
667  Gtk::Button *b;
668  bld->find_widget("closebutton", b);
669  b->signal_clicked().connect(
670  sigc::mem_fun(*this, &PluginPresetListWindow::hide));
671  bld->find_widget("removebutton", removebutton);
672  removebutton->signal_clicked().connect(
673  sigc::mem_fun0(*this, &PluginPresetListWindow::on_remove));
674  bld->find_widget("treeview", treeview);
675  for (gx_preset::UnitPresetList::const_iterator i = presetlist.begin(); i != presetlist.end(); ++i) {
676  if (i->name.empty()) {
677  break;
678  }
679  textliststore->append()->set_value(textliststore->col.name, i->name);
680  }
681  treeview->set_model(textliststore);
682  removebutton->set_sensitive(false);
683  Glib::RefPtr<Gtk::TreeSelection> sel = treeview->get_selection();
684  sel->signal_changed().connect(
685  sigc::mem_fun(*this, &PluginPresetListWindow::on_selection_changed));
686 }
687 
688 void PluginPresetListWindow::on_selection_changed() {
689  removebutton->set_sensitive(treeview->get_selection()->get_selected());
690 }
691 
693  Gtk::Main::run(*this);
694 }
695 
696 /*
697 ** PluginPresetPopup
698 */
699 
700 void PluginPresetPopup::set_plugin_preset(bool factory, const Glib::ustring& name) {
701  if(strcmp(pdef->id,"seq")==0) {
702  machine.plugin_preset_list_sync_set(pdef, factory, name);
703  } else {
704  machine.plugin_preset_list_set(pdef, factory, name);
705  }
706 }
707 
708 void PluginPresetPopup::set_plugin_std_preset() {
709  machine.reset_unit(pdef);
710 }
711 
712 void PluginPresetPopup::save_plugin_preset() {
713  InputWindow *w = InputWindow::create(machine.get_options(), save_name_default);
714  w->run();
715  if (!w->get_name().empty()) {
716  // save loop file to plugin preset name
717  if(strcmp(pdef->id,"dubber")==0) {
718  Glib::ustring name = "";
719  machine.set_parameter_value("dubber.filename", name);
720  machine.set_parameter_value("dubber.savefile", true);
721  machine.set_parameter_value("dubber.filename", w->get_name());
722  }
723  machine.plugin_preset_list_save(pdef, w->get_name());
724  if(strcmp(pdef->id,"seq")==0) {
725  Glib::ustring id = "seq." + w->get_name();
726  if (!machine.parameter_hasId(id)) {
727  machine.insert_param("seq", w->get_name());
728  }
729  }
730  }
731  delete w;
732 }
733 
734 void PluginPresetPopup::remove_plugin_preset() {
735  PluginPresetListWindow *w = PluginPresetListWindow::create(machine.get_options(), *this);
736  w->run();
737  delete w;
738 }
739 
740 bool PluginPresetPopup::add_plugin_preset_list(bool *found) {
741  *found = false;
742  bool found_presets = false;
743  bool factory = false;
744  for (gx_preset::UnitPresetList::iterator i = presetnames.begin(); i != presetnames.end(); ++i) {
745  if (i->name.empty()) {
746  factory = true;
747  if (found_presets) {
748  append(*manage(new Gtk::SeparatorMenuItem()));
749  *found = true;
750  found_presets = false;
751  }
752  continue;
753  } else {
754  found_presets = true;
755  }
756  Gtk::CheckMenuItem *c = new Gtk::CheckMenuItem(i->name);
757  if (i->is_set) {
758  c->set_active(true);
759  }
760  c->signal_activate().connect(
761  sigc::bind(sigc::mem_fun(this, &PluginPresetPopup::set_plugin_preset), factory, i->name));
762  append(*manage(c));
763  }
764  return found_presets;
765 }
766 
767 static bool delete_plugin_preset_popup(PluginPresetPopup *p) {
768  delete p;
769  return false;
770 }
771 
773  Glib::signal_idle().connect(
774  sigc::bind(
775  sigc::ptr_fun(delete_plugin_preset_popup),
776  this));
777 }
778 
780  const Glib::ustring& save_name_default_)
781  : Gtk::Menu(),
782  pdef(pdef_),
783  machine(machine_),
784  save_name_default(save_name_default_),
785  presetnames() {
786  machine.plugin_preset_list_load(pdef, presetnames);
787  bool found_presets;
788  if (!add_plugin_preset_list(&found_presets)) {
789  Gtk::CheckMenuItem *c = new Gtk::CheckMenuItem(_("standard"));
790  if (machine.parameter_unit_has_std_values(pdef)) {
791  c->set_active(true);
792  }
793  c->signal_activate().connect(
794  sigc::mem_fun(this, &PluginPresetPopup::set_plugin_std_preset));
795  append(*manage(c));
796  }
797  append(*manage(new Gtk::SeparatorMenuItem()));
798  Gtk::MenuItem *mi = new Gtk::MenuItem(_("save..."));
799  append(*manage(mi));
800  mi->signal_activate().connect(
801  sigc::mem_fun(this, &PluginPresetPopup::save_plugin_preset));
802  if (found_presets) {
803  mi = new Gtk::MenuItem(_("remove..."));
804  append(*manage(mi));
805  mi->signal_activate().connect(
806  sigc::mem_fun(this, &PluginPresetPopup::remove_plugin_preset));
807  }
808  show_all();
809  popup(1, gtk_get_current_event_time());
810 }
811 
812 
813 /****************************************************************
814  ** class RackBox
815  */
816 
817 #ifdef USE_SZG
818 Glib::RefPtr<Gtk::SizeGroup> RackBox::szg;
819 #endif
820 
821 void RackBox::set_paintbox_unit_shrink(Gxw::PaintBox& pb, PluginType tp) {
822  pb.set_name("rackbox");
823  pb.property_paint_func().set_value("gx_rack_unit_shrink_expose");
824  pb.set_border_width(4);
825 }
826 
827 void RackBox::set_paintbox_unit(Gxw::PaintBox& pb, PluginType tp) {
828  pb.set_name("rackbox");
829  pb.property_paint_func().set_value("gx_rack_unit_expose");
830  pb.set_border_width(4);
831 }
832 
833 void RackBox::set_paintbox(Gxw::PaintBox& pb, PluginType tp) {
834  pb.set_name("rackbox");
835  // pb.property_paint_func().set_value("rectangle_skin_color_expose");
836  pb.set_border_width(4);
837 }
838 
839 Gtk::Widget *RackBox::make_label(const PluginUI& plugin, gx_system::CmdlineOptions& options, bool useshort) {
840  const char *effect_name = useshort ? plugin.get_shortname() : plugin.get_name();
841  Gtk::Label *effect_label = new Gtk::Label(effect_name);
842  effect_label->set_alignment(0.0, 0.5);
843  effect_label->set_name("effect_title");
844  if (plugin.get_type() == PLUGIN_TYPE_STEREO) {
845  effect_label->set_markup("◗◖ " + effect_label->get_label()); //♾⚮⦅◗◖⦆⚭ ⧓ Ꝏꝏ ⦅◉⦆● ▷◁ ▶◀
846  }
847  return effect_label;
848 }
849 
850 Gtk::Widget *RackBox::make_bar(int left, int right, bool sens) {
851  Gtk::Alignment *al = new Gtk::Alignment(0, 0, 1.0, 1.0);
852  //al->set_padding(4, 4, left, right);
853  Gtk::Button *button = new Gtk::Button();
854  button->set_size_request(32,-1);
855  //button->set_name("effect_reset");
856  button->set_tooltip_text(_("Drag'n' Drop Handle"));
857  button->set_relief(Gtk::RELIEF_NONE);
858  button->set_sensitive(sens);
859  al->add(*manage(button));
860  return al;
861 }
862 
863 bool RackBox::on_my_leave_out(GdkEventCrossing *focus) {
864  Glib::RefPtr<Gdk::Window> window = this->get_window();
865  window->set_cursor();
866  return true;
867 }
868 
869 bool RackBox::on_my_enter_in(GdkEventCrossing *focus) {
870  Glib::RefPtr<Gdk::Window> window = this->get_window();
871  Gdk::Cursor cursor(Gdk::HAND1);
872  window->set_cursor(cursor);
873  return true;
874 }
875 
876 bool RackBox::on_my_button_press(GdkEventButton* ev) {
877  if (ev->type == GDK_2BUTTON_PRESS && ev->button == 1) {
878  plugin.display(false, true);
879  }
880  return true;
881 }
882 
883 
884 Gtk::Widget *RackBox::wrap_bar(int left, int right, bool sens) {
885  Gtk::EventBox *ev = new Gtk::EventBox;
886  ev->set_visible_window(false);
887  ev->set_above_child(true);
888  ev->add(*manage(make_bar(left, right, sens)));
889  ev->signal_leave_notify_event().connect(sigc::mem_fun(*this, &RackBox::on_my_leave_out));
890  ev->signal_enter_notify_event().connect(sigc::mem_fun(*this, &RackBox::on_my_enter_in));
891  ev->signal_button_press_event().connect(sigc::mem_fun(*this, &RackBox::on_my_button_press));
892  ev->signal_drag_begin().connect(sigc::mem_fun(*this, &RackBox::on_my_drag_begin));
893  ev->signal_drag_end().connect(sigc::mem_fun(*this, &RackBox::on_my_drag_end));
894  ev->signal_drag_data_get().connect(sigc::mem_fun(*this, &RackBox::on_my_drag_data_get));
895  std::vector<Gtk::TargetEntry> listTargets;
896  listTargets.push_back(Gtk::TargetEntry(target, Gtk::TARGET_SAME_APP, 0));
897  ev->drag_source_set(listTargets, Gdk::BUTTON1_MASK, Gdk::ACTION_MOVE);
898  return ev;
899 }
900 
901 Gtk::Widget *RackBox::create_icon_widget(const PluginUI& plugin, gx_system::CmdlineOptions& options) {
902  Gxw::PaintBox *pb = new Gxw::PaintBox(Gtk::ORIENTATION_HORIZONTAL);
903  RackBox::set_paintbox(*pb, plugin.get_type());
904  Gtk::Widget *effect_label = RackBox::make_label(plugin, options);
905  Gtk::Alignment *al = new Gtk::Alignment(0.0, 0.0, 1.0, 1.0);
906  al->set_padding(0,2,2,0);
907  al->add(*manage(effect_label));
908  pb->pack_start(*manage(al), Gtk::PACK_SHRINK);
909  pb->show_all();
910  return pb;
911 }
912 
913 Gtk::Widget *RackBox::create_drag_widget(const PluginUI& plugin, gx_system::CmdlineOptions& options) {
914  Gxw::PaintBox *pb = new Gxw::PaintBox(Gtk::ORIENTATION_HORIZONTAL);
915  RackBox::set_paintbox_unit_shrink(*pb, plugin.get_type());
916  pb->set_name("drag_widget");
917  if (strcmp(plugin.get_id(), "ampstack") == 0) { // FIXME
918  pb->property_paint_func().set_value("gx_rack_amp_expose");
919  }
920  //Gxw::Switch *swtch = new Gxw::Switch("switchit");
921  //swtch->set_active(plugin.plugin->get_on_off());
922 #ifdef USE_SZG
923  //RackBox::szg->add_widget(*swtch);
924 #else
925  //swtch->set_size_request(35, -1);
926 #endif
927  Gtk::Widget *effect_label = RackBox::make_label(plugin, options);
928  Gtk::Alignment *al = new Gtk::Alignment(0.0, 0.0, 0.0, 0.0);
929  al->set_padding(0,0,4,20);
930  al->add(*manage(RackBox::make_bar(4, 4, true))); // FIXME: fix style and remove sens parameter
931  pb->pack_start(*manage(al), Gtk::PACK_SHRINK);
932  //pb->pack_start(*manage(swtch), Gtk::PACK_SHRINK);
933  pb->pack_start(*manage(effect_label), Gtk::PACK_SHRINK);
934  al = new Gtk::Alignment(0.0, 0.0, 0.0, 0.0);
935  al->set_size_request(70,30);
936  pb->pack_start(*manage(al), Gtk::PACK_SHRINK);
937  pb->show_all();
938  return pb;
939 }
940 
941 void RackBox::display(bool v, bool animate) {
942  assert(box_visible != v);
943  box_visible = v;
944  plugin.set_active(v);
945  if (v) {
946  if (animate) {
947  animate_insert();
948  } else {
949  show();
950  }
951  get_parent()->increment();
952  plugin.hidden_by_move = false;
953  plugin.toolitem->hide();
954  } else {
955  if (animate) {
956  animate_remove();
957  } else {
958  hide();
959  }
960  get_parent()->decrement();
961  plugin.hidden_by_move = true;
962  }
963 }
964 
965 RackBox::RackBox(PluginUI& plugin_, MainWindow& tl, Gtk::Widget* bare)
966  : Gtk::VBox(), plugin(plugin_), main(tl), config_mode(false), anim_tag(),
967  compress(true), delete_button(true), mbox(Gtk::ORIENTATION_HORIZONTAL), minibox(0),
968  fbox(0), target(), anim_height(0), anim_step(), drag_icon(), target_height(0),
969  box(Gtk::ORIENTATION_HORIZONTAL, 2), box_visible(true), on_off_switch("switchit"),
970  toggle_on_off(tl.get_machine(), &on_off_switch, plugin.plugin->id_on_off()) {
971  if (strcmp(plugin.get_id(), "ampstack") != 0) { // FIXME
972  gx_gui::connect_midi_controller(&on_off_switch, plugin.plugin->id_on_off().c_str(), main.get_machine());
973  }
974 #ifdef USE_SZG
975  if (!szg) {
976  szg = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_HORIZONTAL);
977  }
978 #endif
979  if (bare) {
980  compress = false;
981  delete_button = false;
982  }
983  set_paintbox_unit_shrink(mbox, plugin.get_type());
984  init_dnd();
985  minibox = new MiniRackBox(*this, tl.get_options());
986  mbox.pack_start(*manage(minibox));
987  pack_start(mbox, Gtk::PACK_SHRINK);
988  if (bare) {
989  add(*manage(bare));
990  fbox = bare;
991  mbox.property_paint_func().set_value("gx_rack_amp_expose");
992  } else {
993  Gxw::PaintBox *pb = new Gxw::PaintBox(Gtk::ORIENTATION_HORIZONTAL);
994  pb->show();
995  set_paintbox_unit(*pb, plugin.get_type());
996  pb->pack_start(*manage(make_full_box(tl.get_options())));
997  pack_start(*manage(pb), Gtk::PACK_SHRINK);
998  fbox = pb;
999  }
1000  show();
1001 }
1002 
1003 void RackBox::init_dnd() {
1004  target = "application/x-guitarix-";
1005  if (plugin.get_type() == PLUGIN_TYPE_MONO) {
1006  target += "mono";
1007  } else {
1008  target += "stereo";
1009  }
1010  if (!delete_button) {
1011  target += "-s";
1012  }
1013  mbox.signal_drag_begin().connect(sigc::mem_fun(*this, &RackBox::on_my_drag_begin));
1014  mbox.signal_drag_end().connect(sigc::mem_fun(*this, &RackBox::on_my_drag_end));
1015  mbox.signal_drag_data_get().connect(sigc::mem_fun(*this, &RackBox::on_my_drag_data_get));
1016 }
1017 
1018 void RackBox::enable_drag(bool v) {
1019  if (v) {
1020  std::vector<Gtk::TargetEntry> listTargets;
1021  listTargets.push_back(Gtk::TargetEntry(target, Gtk::TARGET_SAME_APP, 0));
1022  mbox.drag_source_set(listTargets, Gdk::BUTTON1_MASK, Gdk::ACTION_MOVE);
1023  } else {
1024  mbox.drag_source_unset();
1025  }
1026 }
1027 
1028 bool RackBox::animate_vanish() {
1029  anim_height -= anim_step;
1030  if (anim_height <= 0) {
1031  hide();
1032  set_visibility(true);
1033  set_size_request(-1,-1);
1035  return false;
1036  } else {
1037  set_size_request(-1, anim_height);
1038  return true;
1039  }
1040 }
1041 
1042 void RackBox::animate_remove() {
1043  if (!get_parent()->check_if_animate(*this)) {
1044  hide();
1045  } else {
1046  if (anim_tag.connected()) {
1047  //Glib::source_remove(anim_tag);
1048  anim_tag.disconnect();
1049  set_size_request(-1,-1);
1050  show();
1051  }
1052  anim_height = size_request().height;
1053  set_size_request(-1, anim_height);
1054  set_visibility(false);
1055  anim_step = anim_height / 5;
1056  anim_tag = Glib::signal_timeout().connect(sigc::mem_fun(*this, &RackBox::animate_vanish), 20);
1057  }
1058 }
1059 
1061  return dynamic_cast<RackContainer*>(Gtk::VBox::get_parent());
1062 }
1063 
1064 void RackBox::on_my_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) {
1065  int x, y;
1066  get_pointer(x, y);
1067  drag_icon = new DragIcon(plugin, context, main.get_options(), x);
1068  animate_remove();
1069 }
1070 
1071 bool RackBox::animate_create() {
1072  bool ret = true;
1073  anim_height += anim_step;
1074  if (anim_height >= target_height) {
1075  set_visibility(true);
1076  set_size_request(-1,-1);
1077  ret = false;
1078  } else {
1079  set_size_request(-1, anim_height);
1080  }
1081  get_parent()->ensure_visible(*this);
1082  return ret;
1083 }
1084 
1086  if (!get_parent()->check_if_animate(*this)) {
1087  show();
1088  get_parent()->ensure_visible(*this);
1089  } else {
1090  if (anim_tag.connected()) {
1091  hide();
1092  anim_tag.disconnect();
1093  set_size_request(-1,-1);
1094  }
1095  target_height = size_request().height;
1096  set_size_request(-1,0);
1097  set_visibility(false);
1098  show();
1099  anim_height = 0;
1100  anim_step = target_height / 5;
1101  anim_tag = Glib::signal_timeout().connect(mem_fun(*this, &RackBox::animate_create), 20);
1102  }
1103 }
1104 
1105 void RackBox::on_my_drag_end(const Glib::RefPtr<Gdk::DragContext>& context) {
1106  if (drag_icon) {
1107  delete drag_icon;
1108  drag_icon = 0;
1109  }
1110  if (plugin.plugin->get_box_visible()) {
1111  animate_insert();
1112  }
1113 }
1114 
1115 void RackBox::on_my_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection, int info, int timestamp) {
1116  selection.set(target, plugin.get_id());
1117 }
1118 
1119 void RackBox::vis_switch(Gtk::Widget& a, Gtk::Widget& b) {
1120  a.hide();
1121  b.show();
1122 }
1123 
1124 void RackBox::set_visibility(bool v) {
1125  if (config_mode || get_plug_visible()) {
1126  minibox->set_config_mode(false);
1127  mbox.set_visible(v);
1128  minibox->set_config_mode(config_mode);
1129  } else {
1130  fbox->set_visible(v);
1131  }
1132 }
1133 
1134 void RackBox::swtch(bool mini) {
1135  plugin.plugin->set_plug_visible(mini);
1136  if (!config_mode) {
1137  if (mini) {
1138  vis_switch(*fbox, mbox);
1139  } else {
1140  vis_switch(mbox, *fbox);
1141  }
1142  }
1143 }
1144 
1145 void RackBox::set_config_mode(bool mode) {
1146  config_mode = mode;
1147  if (!can_compress() || !get_plug_visible()) {
1148  if (mode) {
1149  vis_switch(*fbox, mbox);
1150  if (strcmp(plugin.get_id(), "ampstack") == 0) { // FIXME
1151  return;
1152  }
1153  } else {
1154  vis_switch(mbox, *fbox);
1155  }
1156  }
1157  minibox->set_config_mode(mode);
1158  enable_drag(mode);
1159 }
1160 
1161 void RackBox::setOrder(int pos, int post_pre) {
1162  plugin.plugin->set_position(pos);
1163  if (plugin.get_type() == PLUGIN_TYPE_MONO) {
1164  plugin.plugin->set_effect_post_pre(post_pre);
1165  }
1166 }
1167 
1168 void RackBox::do_expand() {
1169  swtch(false);
1170  Glib::signal_idle().connect_once(
1171  sigc::bind(
1172  sigc::mem_fun(get_parent(), &RackContainer::ensure_visible),
1173  sigc::ref(*this)));
1174 }
1175 
1176 Gtk::Button *RackBox::make_expand_button(bool expand) {
1177  const gchar *t;
1178  Gtk::Button *b = new Gtk::Button();
1179  //b->set_relief(Gtk::RELIEF_NONE);
1180  if (expand) {
1181  t = "rack_expand";
1182  b->set_tooltip_text(_("expand effect unit"));
1183  } else {
1184  t = "rack_shrink";
1185  b->set_tooltip_text(_("shrink effect unit"));
1186  }
1187  GtkWidget *l = gtk_image_new_from_stock(t, (GtkIconSize)-1);
1188  b->set_focus_on_click(false);
1189  b->add(*manage(Glib::wrap(l)));
1190  b->set_name("effect_on_off");
1191  if (expand) {
1192  b->signal_clicked().connect(
1193  sigc::mem_fun(*this, &RackBox::do_expand));
1194  } else {
1195  b->signal_clicked().connect(
1196  sigc::bind(sigc::mem_fun(*this, &RackBox::swtch), true));
1197  }
1198  return b;
1199 }
1200 
1201 Gtk::Button *RackBox::make_preset_button() {
1202  Gtk::Button *p = new Gtk::Button();
1203  //p->set_relief(Gtk::RELIEF_NONE);
1204  GtkWidget *l = gtk_image_new_from_stock("rack_preset", (GtkIconSize)-1);
1205  p->add(*manage(Glib::wrap(l)));
1206  p->set_can_default(false);
1207  p->set_can_focus(false);
1208  p->set_tooltip_text(_("manage effect unit presets"));
1209  p->set_name("effect_on_off");
1210  p->signal_clicked().connect(
1211  sigc::mem_fun(plugin, &PluginUI::on_plugin_preset_popup));
1212  return p;
1213 }
1214 
1215 void RackBox::pack(Gtk::Widget *main, Gtk::Widget *mini, const Glib::RefPtr<Gtk::SizeGroup>& szg) {
1216  if (!main) {
1217  return;
1218  }
1219  box.pack_start(*manage(main));
1220  minibox->pack(mini);
1221  szg->add_widget(*fbox);
1222  szg->add_widget(mbox);
1223 }
1224 
1225 Gtk::HBox *RackBox::make_full_box(gx_system::CmdlineOptions& options) {
1226  Gtk::HBox *bx = new Gtk::HBox();
1227  Gtk::Widget *effect_label = make_label(plugin, options, false);
1228 
1229  // overall hbox: drag-button - center vbox - drag button
1230  Gtk::HBox *main = new Gtk::HBox();
1231  // center vbox containing title bar and widgets
1232  Gtk::VBox *center = new Gtk::VBox();
1233  // title vbox on top
1234  Gtk::HBox *top = new Gtk::HBox();
1235 
1236  // spacing for bottom shadow
1237  Gtk::Alignment *al = new Gtk::Alignment();
1238  al->set_padding(0, 4, 0, 0);
1239  al->add(*manage(main));
1240 
1241  main->set_spacing(0);
1242 
1243  center->set_name("rack_unit_center");
1244  center->set_border_width(0);
1245  center->set_spacing(4);
1246  center->pack_start(*manage(top), Gtk::PACK_SHRINK);
1247  center->pack_start(box, Gtk::PACK_EXPAND_WIDGET);
1248 
1249  top->set_spacing(4);
1250  top->set_name("rack_unit_title_bar");
1251 
1252  top->pack_start(on_off_switch, Gtk::PACK_SHRINK);
1253  on_off_switch.set_name("effect_on_off");
1254  top->pack_start(*manage(effect_label), Gtk::PACK_SHRINK);
1255  top->pack_end(*manage(make_expand_button(false)), Gtk::PACK_SHRINK);
1256  if (!(plugin.plugin->get_pdef()->flags & PGN_NO_PRESETS))
1257  top->pack_end(*manage(make_preset_button()), Gtk::PACK_SHRINK);
1258 
1259  main->pack_start(*manage(wrap_bar()), Gtk::PACK_SHRINK);
1260  main->pack_start(*manage(center), Gtk::PACK_EXPAND_WIDGET);
1261  main->pack_end(*manage(wrap_bar()), Gtk::PACK_SHRINK);
1262 
1263  main->set_name(plugin.get_id());
1264  bx->pack_start(*manage(al), Gtk::PACK_EXPAND_WIDGET);
1265  //al->show_all();
1266  bx->show_all();
1267  return bx;
1268 }
1269 
1270 Gtk::VBox *RackBox::switcher_vbox(gx_system::CmdlineOptions& options) {
1271  Gtk::VBox *vbox = new Gtk::VBox();
1272 
1273  Gtk::HBox *hbox = new Gtk::HBox();
1274  vbox->pack_start(*manage(hbox));
1275  Gtk::HBox *hbox2 = new Gtk::HBox();
1276  hbox->pack_start(*manage(hbox2), Gtk::PACK_SHRINK);
1277  Gtk::VBox *vbox2 = new Gtk::VBox();
1278  hbox2->pack_start(*manage(vbox2));
1279  hbox2->pack_start(*manage(wrap_bar(4,4)), Gtk::PACK_SHRINK);
1280 #ifdef USE_SZG
1281  szg->add_widget(&on_off_switch);
1282 #endif
1283  Gtk::Alignment *al = new Gtk::Alignment(0.5, 0.5, 0.0, 0.0);
1284  al->add(on_off_switch);
1285  vbox2->pack_start(*manage(al));
1286  return vbox;
1287 }
1288 
1289 
1290 /****************************************************************
1291  ** class RackContainer
1292  */
1293 
1294 static const int min_containersize = 40;
1295 
1297  : Gtk::VBox(),
1298  tp(tp_),
1299  main(main_),
1300  config_mode(false),
1301  in_drag(-2),
1302  child_count(0),
1303  targets(),
1304  othertargets(),
1305  highlight_connection(),
1306  autoscroll_connection() {
1307  std::vector<std::string> *pm, *ps;
1308  if (tp == PLUGIN_TYPE_MONO) {
1309  pm = &targets;
1310  ps = &othertargets;
1311  } else {
1312  ps = &targets;
1313  pm = &othertargets;
1314  }
1315  pm->push_back("application/x-guitarix-mono");
1316  pm->push_back("application/x-guitarix-mono-s");
1317  pm->push_back("application/x-gtk-tool-palette-item-mono");
1318  ps->push_back("application/x-guitarix-stereo");
1319  ps->push_back("application/x-guitarix-stereo-s");
1320  ps->push_back("application/x-gtk-tool-palette-item-stereo");
1321  std::vector<Gtk::TargetEntry> listTargets;
1322  listTargets.push_back(Gtk::TargetEntry("application/x-guitarix-mono", Gtk::TARGET_SAME_APP, 0));
1323  listTargets.push_back(Gtk::TargetEntry("application/x-guitarix-mono-s", Gtk::TARGET_SAME_APP, 1));
1324  listTargets.push_back(Gtk::TargetEntry("application/x-gtk-tool-palette-item-mono", Gtk::TARGET_SAME_APP, 2));
1325  listTargets.push_back(Gtk::TargetEntry("application/x-guitarix-stereo", Gtk::TARGET_SAME_APP, 3));
1326  listTargets.push_back(Gtk::TargetEntry("application/x-guitarix-stereo-s", Gtk::TARGET_SAME_APP, 4));
1327  listTargets.push_back(Gtk::TargetEntry("application/x-gtk-tool-palette-item-stereo", Gtk::TARGET_SAME_APP, 5));
1328  drag_dest_set(listTargets, Gtk::DEST_DEFAULT_DROP, Gdk::ACTION_MOVE);
1330  sigc::mem_fun(this, &RackContainer::unit_order_changed));
1331  signal_remove().connect(sigc::mem_fun(*this, &RackContainer::on_my_remove));
1332  set_size_request(-1, min_containersize);
1333  show_all();
1334 }
1335 
1336 void RackContainer::unit_order_changed(bool stereo) {
1337  if (stereo == (tp == PLUGIN_TYPE_STEREO)) {
1338  check_order();
1339  }
1340 }
1341 
1342 bool RackContainer::drag_highlight_expose(GdkEventExpose *event, int y0) {
1343  if (!is_drawable()) {
1344  return false;
1345  }
1346  Cairo::RefPtr<Cairo::Context> cr = Glib::wrap(event->window, true)->create_cairo_context();
1347  int x, y, width, height;
1348  if (!get_has_window()) {
1349  Gtk::Allocation a = get_allocation();
1350  x = a.get_x();
1351  y = a.get_y();
1352  width = a.get_width();
1353  height = a.get_height();
1354  } else {
1355  int depth;
1356  get_window()->get_geometry(x, y, width, height, depth);
1357  x = 0;
1358  y = 0;
1359  }
1360  GdkPixbuf * pb_ = gtk_widget_render_icon(GTK_WIDGET(this->gobj()), "insert", (GtkIconSize)-1, NULL);
1361  if (pb_) {
1362  cairo_t *cr_ = gdk_cairo_create(unwrap(get_window()));
1363  gdk_cairo_set_source_pixbuf(cr_, pb_, x, y);
1364  cairo_pattern_set_extend(cairo_get_source(cr_), CAIRO_EXTEND_REPEAT);
1365  if (y0 < 0) {
1366  cairo_set_line_width(cr_, 4.0);
1367  cairo_rectangle(cr_, x, max(0, y), width, height);
1368  cairo_stroke(cr_);
1369  } else {
1370  cairo_rectangle(cr_, x, max(y, y0 - 3), width, 2);
1371  cairo_fill(cr_);
1372  }
1373  cairo_destroy(cr_);
1374  g_object_unref(pb_);
1375  }
1376  return false;
1377 }
1378 
1379 struct childpos {
1380  int y0, y1, pos;
1381  childpos(int y0_, int y1_, int pos_): y0(y0_), y1(y1_), pos(pos_) {}
1382  bool operator<(const childpos& p) { return y0 < p.y0; }
1383 };
1384 
1385 void RackContainer::find_index(int x, int y, int* len, int *ypos) {
1386  std::list<childpos> l;
1387  std::vector<RackBox*> children = get_children();
1388  int mpos = -1;
1389  for (std::vector<RackBox*>::iterator ch = children.begin(); ch != children.end(); ++ch) {
1390  ++mpos;
1391  if (!(*ch)->get_visible()) {
1392  continue;
1393  }
1394  Gtk::Allocation a = (*ch)->get_allocation();
1395  l.push_back(childpos(a.get_y(), a.get_y()+a.get_height(), mpos));
1396  }
1397  if (l.empty()) {
1398  *len = -1;
1399  *ypos = -1;
1400  return;
1401  }
1402  Gtk::Allocation a0 = get_allocation();
1403  y += a0.get_y();
1404  int sy = l.begin()->y0;
1405  for (std::list<childpos>::iterator cp = l.begin(); cp != l.end(); ++cp) {
1406  if (y < (cp->y0 + cp->y1) / 2) {
1407  *len = cp->pos;
1408  *ypos = (cp->y0+sy)/2;
1409  return;
1410  }
1411  sy = cp->y1;
1412  }
1413  *len = mpos+1;
1414  *ypos = sy;
1415 }
1416 
1417 void RackContainer::on_my_remove(Gtk::Widget *ch) {
1418  decrement();
1419  renumber();
1420 }
1421 
1422 bool RackContainer::check_targets(const std::vector<std::string>& tgts1, const std::vector<std::string>& tgts2) {
1423  for (std::vector<std::string>::const_iterator t1 = tgts1.begin(); t1 != tgts1.end(); ++t1) {
1424  for (std::vector<std::string>::const_iterator t2 = tgts2.begin(); t2 != tgts2.end(); ++t2) {
1425  if (*t1 == *t2) {
1426  return true;
1427  }
1428  }
1429  }
1430  return false;
1431 }
1432 
1433 bool RackContainer::on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint timestamp) {
1434  const std::vector<std::string>& tg = context->get_targets();
1435  if (!check_targets(tg, targets)) {
1436  if (check_targets(tg, othertargets)) {
1437  if (!autoscroll_connection.connected()) {
1438  autoscroll_connection = Glib::signal_timeout().connect(
1439  sigc::mem_fun(*this, &RackContainer::scrollother_timeout), 50);
1440  }
1441  context->drag_status(Gdk::DragAction(0), timestamp);
1442  return true;
1443  }
1444  return false;
1445  }
1446  context->drag_status(Gdk::ACTION_MOVE, timestamp);
1447  int i, ind;
1448  find_index(x, y, &i, &ind);
1449  if (in_drag == ind) {
1450  return true;
1451  }
1452  if (in_drag > -2) {
1453  highlight_connection.disconnect();
1454  }
1455  highlight_connection = signal_expose_event().connect(sigc::bind(sigc::mem_fun(*this, &RackContainer::drag_highlight_expose), ind), true);
1456  queue_draw();
1457  in_drag = ind;
1458  if (!autoscroll_connection.connected()) {
1459  autoscroll_connection = Glib::signal_timeout().connect(sigc::mem_fun(*this, &RackContainer::scroll_timeout), 50);
1460  }
1461  return true;
1462 }
1463 
1465  Gtk::Allocation alloc = child.get_allocation();
1466  Gtk::Viewport *p = dynamic_cast<Gtk::Viewport*>(get_ancestor(GTK_TYPE_VIEWPORT));
1467  p->get_vadjustment()->clamp_page(alloc.get_y(), alloc.get_y()+alloc.get_height());
1468 }
1469 
1470 static const double scroll_edge_size = 60.0;
1471 static const int step_size = 20;
1472 
1473 bool RackContainer::scrollother_timeout() {
1474  Gtk::Viewport *p = dynamic_cast<Gtk::Viewport*>(get_ancestor(GTK_TYPE_VIEWPORT));
1475  Gtk::Adjustment *a = p->get_vadjustment();
1476  double off = a->get_value();
1477  Gtk::Allocation alloc = get_allocation();
1478  int x, y;
1479  get_pointer(x, y);
1480  y -= alloc.get_height();
1481  double step;
1482  if (y < -scroll_edge_size) {
1483  step = step_size;
1484  } else {
1485  step = step_size * exp(-(y+scroll_edge_size)/(1.0*scroll_edge_size));
1486  if (step < 1.5) {
1487  return false;
1488  }
1489  }
1490  if (tp == PLUGIN_TYPE_MONO) {
1491  off = main.stop_at_stereo_bottom(off, step_size, a->get_page_size());
1492  } else {
1493  off = main.stop_at_mono_top(off, step_size);
1494  }
1495  if (off < a->get_lower()) {
1496  off = a->get_lower();
1497  }
1498  if (off > a->get_upper() - a->get_page_size()) {
1499  off = a->get_upper() - a->get_page_size();
1500  }
1501  a->set_value(off);
1502  return true;
1503 }
1504 
1505 bool RackContainer::scroll_timeout() {
1506  Gtk::Viewport *p = dynamic_cast<Gtk::Viewport*>(get_ancestor(GTK_TYPE_VIEWPORT));
1507  Gtk::Adjustment *a = p->get_vadjustment();
1508  double off = a->get_value();
1509  Gtk::Allocation alloc = get_allocation();
1510  int x, y;
1511  get_pointer(x, y);
1512  double sez = scroll_edge_size;
1513  if (sez > a->get_page_size() / 3) {
1514  sez = a->get_page_size() / 3;
1515  }
1516  double yw = y + alloc.get_y() - off;
1517  double step;
1518  if (yw <= sez) {
1519  step = step_size * (sez-yw) / sez;
1520  off = max(double(alloc.get_y()), off-step);
1521  } else {
1522  yw = a->get_page_size() - yw;
1523  if (yw <= sez) {
1524  step = step_size * (sez-yw) / sez;
1525  off = min(alloc.get_y()+alloc.get_height()-a->get_page_size(), off+step);
1526  } else {
1527  return true;
1528  }
1529  }
1530  if (off < a->get_lower()) {
1531  off = a->get_lower();
1532  }
1533  if (off > a->get_upper() - a->get_page_size()) {
1534  off = a->get_upper() - a->get_page_size();
1535  }
1536  a->set_value(off);
1537  return true;
1538 }
1539 
1540 void RackContainer::on_drag_leave(const Glib::RefPtr<Gdk::DragContext>& context, guint timestamp) {
1541  if (in_drag > -2) {
1542  highlight_connection.disconnect();
1543  queue_draw();
1544  in_drag = -2;
1545  }
1546  autoscroll_connection.disconnect();
1547 }
1548 
1549 void RackContainer::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& data, guint info, guint timestamp) {
1550  int i, ind;
1551  find_index(x, y, &i, &ind);
1552  std::string dtype = data.get_data_type();
1553  if (dtype == "application/x-gtk-tool-palette-item-mono" || dtype == "application/x-gtk-tool-palette-item-stereo") {
1554  main.get_plugin(data.get_data_as_string())->display_new(true);
1555  }
1556  reorder(data.get_data_as_string(), i);
1557 }
1558 
1560  for (PluginDict::iterator i = main.plugins_begin(); i != main.plugins_end(); ++i) {
1561  i->second->hidden = false;
1562  if (!i->second->hidden_by_move) {
1563  RackBox *r = i->second->rackbox;
1564  if (r) {
1565  r->show();
1566  }
1567  }
1568  }
1569 }
1570 
1572  for (PluginDict::iterator i = main.plugins_begin(); i != main.plugins_end(); ++i) {
1573  i->second->hidden = true;
1574  RackBox *r = i->second->rackbox;
1575  if (r) {
1576  if (r->can_compress()) {
1577  r->hide();
1578  }
1579  }
1580  }
1581 }
1582 
1583 void RackContainer::reorder(const std::string& name, unsigned int pos) {
1584  std::vector<RackBox*> l = get_children();
1585  main.get_machine().insert_rack_unit(name, ((pos >= l.size()) ? "" : l[pos]->get_id()), tp);
1586  check_order();
1587 }
1588 
1589 void RackContainer::on_add(Widget *ch) {
1590  add(*dynamic_cast<RackBox*>(ch));
1591 }
1592 
1593 void RackContainer::add(RackBox& r, int pos) {
1594  pack_start(r, Gtk::PACK_SHRINK);
1595  increment();
1596  if (config_mode) {
1597  r.set_config_mode(true);
1598  }
1599  reorder_child(r, pos);
1600  renumber();
1601 }
1602 
1604  ++child_count;
1605  if (child_count == 1) {
1606  set_size_request(-1, -1);
1607  }
1608 }
1609 
1611  --child_count;
1612  assert(child_count >= 0);
1613  if (child_count == 0) {
1614  set_size_request(-1, min_containersize);
1615  }
1616 }
1617 
1619  config_mode = mode;
1620  std::vector<RackBox*> l = get_children();
1621  for (std::vector<RackBox*>::iterator c = l.begin(); c != l.end(); ++c) {
1622  (*c)->set_config_mode(mode);
1623  }
1624 }
1625 
1627  const std::vector<std::string>& ol = main.get_machine().get_rack_unit_order(tp);
1628  bool in_order = true;
1629  std::set<std::string> unit_set(ol.begin(), ol.end());
1630  rackbox_list l = get_children();
1631  std::vector<std::string>::const_iterator oi = ol.begin();
1632  for (rackbox_list::iterator c = l.begin(); c != l.end(); ++c) {
1633  if (!(*c)->get_box_visible()) {
1634  continue;
1635  }
1636  if (unit_set.find((*c)->get_id()) == unit_set.end()) {
1637  main.get_plugin((*c)->get_id())->hide(false);
1638  continue;
1639  }
1640  if (!in_order) {
1641  continue;
1642  }
1643  if (oi == ol.end()) {
1644  in_order = false;
1645  continue;
1646  }
1647  if (*oi != (*c)->get_id()) {
1648  in_order = false;
1649  }
1650  ++oi;
1651  }
1652  if (oi != ol.end()) {
1653  in_order = false;
1654  }
1655  if (in_order) {
1656  return;
1657  }
1658  int n = 0;
1659  for (std::vector<std::string>::const_iterator oi = ol.begin(); oi != ol.end(); ++oi) {
1660  PluginUI *p = main.get_plugin(*oi);
1661  if (!p->rackbox) {
1662  p->show(false);
1663  } else {
1664  if (!p->rackbox->get_box_visible()) {
1665  p->rackbox->display(true, false);
1666  if (p->hidden) {
1667  p->rackbox->hide();
1668  }
1669  }
1670  }
1671  reorder_child(*p->rackbox, n++);
1672  }
1673  renumber();
1674 }
1675 
1676 void RackContainer::renumber() {
1677  rackbox_list l = get_children();
1678  int pos = 0;
1679  unsigned int post_pre = 1;
1680  for (rackbox_list::iterator c = l.begin(); c != l.end(); ++c, ++pos) {
1681  if (strcmp((*c)->get_id(), "ampstack") == 0) { // FIXME
1682  pos = 0;
1683  post_pre = 0;
1684  continue;
1685  }
1686  (*c)->setOrder(pos, post_pre);
1687  }
1688 }
MiniRackBox(RackBox &rb, gx_system::CmdlineOptions &options)
Definition: rack.cpp:380
CmdConnection::msg_type end
Definition: jsonrpc.cpp:256
void convert_bgra_to_rgba(guint8 const *src, guint8 *dst, int width, int height)
Definition: rack.cpp:239
bool can_compress()
Gtk::TreeModelColumn< Glib::ustring > name
Definition: rack.cpp:595
void run()
Definition: rack.cpp:583
void check_order()
Definition: rack.cpp:1626
void cleanup()
Definition: rack.cpp:213
void add(RackBox &r, int pos=-1)
Definition: rack.cpp:1593
#define GDK_KEY_Escape
Definition: guitarix.h:53
PluginDef * get_pdef()
static Glib::RefPtr< TextListStore > create()
Definition: rack.cpp:603
gx_engine::GxMachineBase & get_machine()
void add_icon(const std::string &name)
static InputWindow * create(const gx_system::CmdlineOptions &options, const Glib::ustring &save_name_default)
Definition: rack.cpp:545
void ensure_visible(RackBox &child)
Definition: rack.cpp:1464
virtual void on_selection_done()
Definition: rack.cpp:772
const char * get_shortname() const
std::string get_builder_filepath(const std::string &basename) const
Definition: gx_system.h:373
const std::string & id_on_off() const
~PluginDict()
Definition: rack.cpp:220
const char * get_name() const
bool get_plug_visible() const
void display(bool v, bool animate)
Definition: rack.cpp:137
bool get_plug_visible()
bool get_box_visible()
Glib::ustring tooltip
RackContainer(PluginType tp, MainWindow &main)
Definition: rack.cpp:1296
void set_config_mode(bool mode)
Definition: rack.cpp:1618
DragIcon(const PluginUI &plugin, Glib::RefPtr< Gdk::DragContext > context, gx_system::CmdlineOptions &options, int xoff=0)
Definition: rack.cpp:254
static bool is_registered(gx_engine::GxMachineBase &m, const char *name)
Definition: rack.cpp:86
void plugin_preset_popup(const PluginDef *pdef)
void set_config_mode(bool mode)
Definition: rack.cpp:1145
Glib::ustring & get_name()
Definition: rack.cpp:534
bool hidden_by_move
~DragIcon()
Definition: rack.cpp:279
const char * description
Definition: gx_plugin.h:191
RackBox(PluginUI &plugin, MainWindow &main, Gtk::Widget *bare=0)
Definition: rack.cpp:965
bool get_box_visible() const
void hide(bool animate)
Definition: rack.cpp:116
void hide_effect(const std::string &name)
void display(bool v, bool animate)
Definition: rack.cpp:941
virtual bool parameter_unit_has_std_values(const PluginDef *pdef) const =0
childpos(int y0_, int y1_, int pos_)
Definition: rack.cpp:1381
virtual void on_plugin_preset_popup()
Definition: rack.cpp:82
PluginType
Definition: machine.h:32
PluginPresetPopup(const PluginDef *pdef, gx_engine::GxMachineBase &machine, const Glib::ustring &save_name_default="")
Definition: rack.cpp:779
void pack(Gtk::Widget *mainbox, Gtk::Widget *minibox, const Glib::RefPtr< Gtk::SizeGroup > &szg)
Definition: rack.cpp:1215
void decrement()
Definition: rack.cpp:1610
static Gtk::Widget * create_icon_widget(const PluginUI &plugin, gx_system::CmdlineOptions &options)
Definition: rack.cpp:901
void show(bool animate)
Definition: rack.cpp:124
Gtk::ToolItemGroup * group
gx_engine::Plugin * plugin
void pack(Gtk::Widget *w)
Definition: rack.cpp:479
friend class MiniRackBox
bool operator<(const childpos &p)
Definition: rack.cpp:1382
gx_system::CmdlineOptions & get_options()
void increment()
Definition: rack.cpp:1603
void show_entries()
Definition: rack.cpp:1559
#define min(x, y)
void animate_insert()
Definition: rack.cpp:1085
virtual sigc::signal< void, bool > & signal_rack_unit_order_changed()=0
int y1
Definition: rack.cpp:1380
#define max(x, y)
RackBox * add_rackbox(PluginUI &pl, bool mini=false, int pos=-1, bool animate=false)
static PluginPresetListWindow * create(const gx_system::CmdlineOptions &options, PluginPresetPopup &p)
Definition: rack.cpp:634
PluginType get_type() const
void hide_entries()
Definition: rack.cpp:1571
int flags
Definition: gx_plugin.h:185
void set_active(bool v)
void set_action(Glib::RefPtr< Gtk::ToggleAction > &act)
Definition: rack.cpp:99
MainWindow & main
virtual void plugin_preset_list_load(const PluginDef *pdef, gx_preset::UnitPresetList &presetnames)=0
void connect_midi_controller(Gtk::Widget *w, const std::string &id, gx_engine::GxMachineBase &machine)
void set_config_mode(bool mode)
Definition: rack.cpp:485
virtual void remove_rack_unit(const std::string &unit, PluginType type)=0
rackbox_list get_children()
Gtk::ToolItem * toolitem
void set_effect_post_pre(int v) const
void set_position(int v) const
guint8 convert_color_channel(guint8 src, guint8 alpha)
Definition: rack.cpp:235
void unset_ui_merge_id(Glib::RefPtr< Gtk::UIManager > uimanager)
Definition: rack.cpp:75
RackContainer * get_parent()
Definition: rack.cpp:1060
void update_rackbox()
Definition: rack.cpp:164
gx_engine::GxMachineBase & get_machine()
void resize_finished()
int y0
Definition: rack.cpp:1380
int main(int argc, char *argv[])
Definition: gxw_demo.cc:62
void swtch(bool mini)
Definition: rack.cpp:1134
void add(PluginUI *p)
Definition: rack.cpp:203
void set_plug_visible(bool v) const
void compress(bool state)
Definition: rack.cpp:90
const char * get_id() const
void remove(PluginUI *p)
Definition: rack.cpp:207
Gxw::BigKnob * wrap(GxBigKnob *object, bool take_copy)
Definition: bigknob.cc:44
PluginUI(MainWindow &main, const char *id_, const Glib::ustring &tooltip_="")
Definition: rack.cpp:44
void display_new(bool unordered=false)
Definition: rack.cpp:153
void reorder(const std::string &name, unsigned int pos)
Definition: rack.cpp:1583
virtual Plugin * pluginlist_lookup_plugin(const std::string &id) const =0
virtual ~PluginUI()
Definition: rack.cpp:64
void set_box_visible(bool v) const
~InputWindow()
Definition: rack.cpp:542
void setOrder(int pos, int post_pre)
Definition: rack.cpp:1161
void set_on_off(bool v) const
virtual void insert_rack_unit(const std::string &unit, const std::string &before, PluginType type)=0
friend bool plugins_by_name_less(PluginUI *a, PluginUI *b)
Definition: rack.cpp:186
std::map< std::string, PluginUI * >::iterator iterator
RackBox * rackbox
Glib::ListHandle< RackBox * > rackbox_list
void compress(bool state)
Definition: rack.cpp:224
static Gtk::Widget * create_drag_widget(const PluginUI &plugin, gx_system::CmdlineOptions &options)
Definition: rack.cpp:913