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  machine.plugin_preset_list_set(pdef, factory, name);
702 }
703 
704 void PluginPresetPopup::set_plugin_std_preset() {
705  machine.reset_unit(pdef);
706 }
707 
708 void PluginPresetPopup::save_plugin_preset() {
709  InputWindow *w = InputWindow::create(machine.get_options(), save_name_default);
710  w->run();
711  if (!w->get_name().empty()) {
712  // save loop file to plugin preset name
713  if(strcmp(pdef->id,"dubber")==0) {
714  Glib::ustring name = "";
715  machine.set_parameter_value("dubber.filename", name);
716  machine.set_parameter_value("dubber.savefile", true);
717  machine.set_parameter_value("dubber.filename", w->get_name());
718  }
719  machine.plugin_preset_list_save(pdef, w->get_name());
720  }
721  delete w;
722 }
723 
724 void PluginPresetPopup::remove_plugin_preset() {
725  PluginPresetListWindow *w = PluginPresetListWindow::create(machine.get_options(), *this);
726  w->run();
727  delete w;
728 }
729 
730 bool PluginPresetPopup::add_plugin_preset_list(bool *found) {
731  *found = false;
732  bool found_presets = false;
733  bool factory = false;
734  for (gx_preset::UnitPresetList::iterator i = presetnames.begin(); i != presetnames.end(); ++i) {
735  if (i->name.empty()) {
736  factory = true;
737  if (found_presets) {
738  append(*manage(new Gtk::SeparatorMenuItem()));
739  *found = true;
740  found_presets = false;
741  }
742  continue;
743  } else {
744  found_presets = true;
745  }
746  Gtk::CheckMenuItem *c = new Gtk::CheckMenuItem(i->name);
747  if (i->is_set) {
748  c->set_active(true);
749  }
750  c->signal_activate().connect(
751  sigc::bind(sigc::mem_fun(this, &PluginPresetPopup::set_plugin_preset), factory, i->name));
752  append(*manage(c));
753  }
754  return found_presets;
755 }
756 
757 static bool delete_plugin_preset_popup(PluginPresetPopup *p) {
758  delete p;
759  return false;
760 }
761 
763  Glib::signal_idle().connect(
764  sigc::bind(
765  sigc::ptr_fun(delete_plugin_preset_popup),
766  this));
767 }
768 
770  const Glib::ustring& save_name_default_)
771  : Gtk::Menu(),
772  pdef(pdef_),
773  machine(machine_),
774  save_name_default(save_name_default_),
775  presetnames() {
776  machine.plugin_preset_list_load(pdef, presetnames);
777  bool found_presets;
778  if (!add_plugin_preset_list(&found_presets)) {
779  Gtk::CheckMenuItem *c = new Gtk::CheckMenuItem(_("standard"));
780  if (machine.parameter_unit_has_std_values(pdef)) {
781  c->set_active(true);
782  }
783  c->signal_activate().connect(
784  sigc::mem_fun(this, &PluginPresetPopup::set_plugin_std_preset));
785  append(*manage(c));
786  }
787  append(*manage(new Gtk::SeparatorMenuItem()));
788  Gtk::MenuItem *mi = new Gtk::MenuItem(_("save..."));
789  append(*manage(mi));
790  mi->signal_activate().connect(
791  sigc::mem_fun(this, &PluginPresetPopup::save_plugin_preset));
792  if (found_presets) {
793  mi = new Gtk::MenuItem(_("remove..."));
794  append(*manage(mi));
795  mi->signal_activate().connect(
796  sigc::mem_fun(this, &PluginPresetPopup::remove_plugin_preset));
797  }
798  show_all();
799  popup(1, gtk_get_current_event_time());
800 }
801 
802 
803 /****************************************************************
804  ** class RackBox
805  */
806 
807 #ifdef USE_SZG
808 Glib::RefPtr<Gtk::SizeGroup> RackBox::szg;
809 #endif
810 
811 void RackBox::set_paintbox_unit_shrink(Gxw::PaintBox& pb, PluginType tp) {
812  pb.set_name("rackbox");
813  pb.property_paint_func().set_value("gx_rack_unit_shrink_expose");
814  pb.set_border_width(4);
815 }
816 
817 void RackBox::set_paintbox_unit(Gxw::PaintBox& pb, PluginType tp) {
818  pb.set_name("rackbox");
819  pb.property_paint_func().set_value("gx_rack_unit_expose");
820  pb.set_border_width(4);
821 }
822 
823 void RackBox::set_paintbox(Gxw::PaintBox& pb, PluginType tp) {
824  pb.set_name("rackbox");
825  // pb.property_paint_func().set_value("rectangle_skin_color_expose");
826  pb.set_border_width(4);
827 }
828 
829 Gtk::Widget *RackBox::make_label(const PluginUI& plugin, gx_system::CmdlineOptions& options, bool useshort) {
830  const char *effect_name = useshort ? plugin.get_shortname() : plugin.get_name();
831  Gtk::Label *effect_label = new Gtk::Label(effect_name);
832  effect_label->set_alignment(0.0, 0.5);
833  effect_label->set_name("effect_title");
834  if (plugin.get_type() == PLUGIN_TYPE_STEREO)
835  effect_label->set_markup("◗◖ " + effect_label->get_label()); //♾⚮⦅◗◖⦆⚭ ⧓ Ꝏꝏ ⦅◉⦆● ▷◁ ▶◀
836  return effect_label;
837 }
838 
839 Gtk::Widget *RackBox::make_bar(int left, int right, bool sens) {
840  Gtk::Alignment *al = new Gtk::Alignment(0, 0, 1.0, 1.0);
841  //al->set_padding(4, 4, left, right);
842  Gtk::Button *button = new Gtk::Button();
843  button->set_size_request(32,-1);
844  //button->set_name("effect_reset");
845  button->set_tooltip_text(_("Drag'n' Drop Handle"));
846  button->set_relief(Gtk::RELIEF_NONE);
847  button->set_sensitive(sens);
848  al->add(*manage(button));
849  return al;
850 }
851 
852 bool RackBox::on_my_leave_out(GdkEventCrossing *focus) {
853  Glib::RefPtr<Gdk::Window> window = this->get_window();
854  window->set_cursor();
855  return true;
856 }
857 
858 bool RackBox::on_my_enter_in(GdkEventCrossing *focus) {
859  Glib::RefPtr<Gdk::Window> window = this->get_window();
860  Gdk::Cursor cursor(Gdk::HAND1);
861  window->set_cursor(cursor);
862  return true;
863 }
864 
865 bool RackBox::on_my_button_press(GdkEventButton* ev) {
866  if (ev->type == GDK_2BUTTON_PRESS && ev->button == 1) {
867  plugin.display(false, true);
868  }
869  return true;
870 }
871 
872 
873 Gtk::Widget *RackBox::wrap_bar(int left, int right, bool sens) {
874  Gtk::EventBox *ev = new Gtk::EventBox;
875  ev->set_visible_window(false);
876  ev->set_above_child(true);
877  ev->add(*manage(make_bar(left, right, sens)));
878  ev->signal_leave_notify_event().connect(sigc::mem_fun(*this, &RackBox::on_my_leave_out));
879  ev->signal_enter_notify_event().connect(sigc::mem_fun(*this, &RackBox::on_my_enter_in));
880  ev->signal_button_press_event().connect(sigc::mem_fun(*this, &RackBox::on_my_button_press));
881  ev->signal_drag_begin().connect(sigc::mem_fun(*this, &RackBox::on_my_drag_begin));
882  ev->signal_drag_end().connect(sigc::mem_fun(*this, &RackBox::on_my_drag_end));
883  ev->signal_drag_data_get().connect(sigc::mem_fun(*this, &RackBox::on_my_drag_data_get));
884  std::vector<Gtk::TargetEntry> listTargets;
885  listTargets.push_back(Gtk::TargetEntry(target, Gtk::TARGET_SAME_APP, 0));
886  ev->drag_source_set(listTargets, Gdk::BUTTON1_MASK, Gdk::ACTION_MOVE);
887  return ev;
888 }
889 
890 Gtk::Widget *RackBox::create_icon_widget(const PluginUI& plugin, gx_system::CmdlineOptions& options) {
891  Gxw::PaintBox *pb = new Gxw::PaintBox(Gtk::ORIENTATION_HORIZONTAL);
892  RackBox::set_paintbox(*pb, plugin.get_type());
893  Gtk::Widget *effect_label = RackBox::make_label(plugin, options);
894  Gtk::Alignment *al = new Gtk::Alignment(0.0, 0.0, 1.0, 1.0);
895  al->set_padding(0,2,2,0);
896  al->add(*manage(effect_label));
897  pb->pack_start(*manage(al), Gtk::PACK_SHRINK);
898  pb->show_all();
899  return pb;
900 }
901 
902 Gtk::Widget *RackBox::create_drag_widget(const PluginUI& plugin, gx_system::CmdlineOptions& options) {
903  Gxw::PaintBox *pb = new Gxw::PaintBox(Gtk::ORIENTATION_HORIZONTAL);
904  RackBox::set_paintbox_unit_shrink(*pb, plugin.get_type());
905  pb->set_name("drag_widget");
906  if (strcmp(plugin.get_id(), "ampstack") == 0) { // FIXME
907  pb->property_paint_func().set_value("gx_rack_amp_expose");
908  }
909  //Gxw::Switch *swtch = new Gxw::Switch("switchit");
910  //swtch->set_active(plugin.plugin->get_on_off());
911 #ifdef USE_SZG
912  //RackBox::szg->add_widget(*swtch);
913 #else
914  //swtch->set_size_request(35, -1);
915 #endif
916  Gtk::Widget *effect_label = RackBox::make_label(plugin, options);
917  Gtk::Alignment *al = new Gtk::Alignment(0.0, 0.0, 0.0, 0.0);
918  al->set_padding(0,0,4,20);
919  al->add(*manage(RackBox::make_bar(4, 4, true))); // FIXME: fix style and remove sens parameter
920  pb->pack_start(*manage(al), Gtk::PACK_SHRINK);
921  //pb->pack_start(*manage(swtch), Gtk::PACK_SHRINK);
922  pb->pack_start(*manage(effect_label), Gtk::PACK_SHRINK);
923  al = new Gtk::Alignment(0.0, 0.0, 0.0, 0.0);
924  al->set_size_request(70,30);
925  pb->pack_start(*manage(al), Gtk::PACK_SHRINK);
926  pb->show_all();
927  return pb;
928 }
929 
930 void RackBox::display(bool v, bool animate) {
931  assert(box_visible != v);
932  box_visible = v;
933  plugin.set_active(v);
934  if (v) {
935  if (animate) {
936  animate_insert();
937  } else {
938  show();
939  }
940  get_parent()->increment();
941  plugin.hidden_by_move = false;
942  plugin.toolitem->hide();
943  } else {
944  if (animate) {
945  animate_remove();
946  } else {
947  hide();
948  }
949  get_parent()->decrement();
950  plugin.hidden_by_move = true;
951  }
952 }
953 
954 RackBox::RackBox(PluginUI& plugin_, MainWindow& tl, Gtk::Widget* bare)
955  : Gtk::VBox(), plugin(plugin_), main(tl), config_mode(false), anim_tag(),
956  compress(true), delete_button(true), mbox(Gtk::ORIENTATION_HORIZONTAL), minibox(0),
957  fbox(0), target(), anim_height(0), anim_step(), drag_icon(), target_height(0),
958  box(Gtk::ORIENTATION_HORIZONTAL, 2), box_visible(true), on_off_switch("switchit"),
959  toggle_on_off(tl.get_machine(), &on_off_switch, plugin.plugin->id_on_off()) {
960  if (strcmp(plugin.get_id(), "ampstack") != 0) { // FIXME
961  gx_gui::connect_midi_controller(&on_off_switch, plugin.plugin->id_on_off().c_str(), main.get_machine());
962  }
963 #ifdef USE_SZG
964  if (!szg) {
965  szg = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_HORIZONTAL);
966  }
967 #endif
968  if (bare) {
969  compress = false;
970  delete_button = false;
971  }
972  set_paintbox_unit_shrink(mbox, plugin.get_type());
973  init_dnd();
974  minibox = new MiniRackBox(*this, tl.get_options());
975  mbox.pack_start(*manage(minibox));
976  pack_start(mbox, Gtk::PACK_SHRINK);
977  if (bare) {
978  add(*manage(bare));
979  fbox = bare;
980  mbox.property_paint_func().set_value("gx_rack_amp_expose");
981  } else {
982  Gxw::PaintBox *pb = new Gxw::PaintBox(Gtk::ORIENTATION_HORIZONTAL);
983  pb->show();
984  set_paintbox_unit(*pb, plugin.get_type());
985  pb->pack_start(*manage(make_full_box(tl.get_options())));
986  pack_start(*manage(pb), Gtk::PACK_SHRINK);
987  fbox = pb;
988  }
989  show();
990 }
991 
992 void RackBox::init_dnd() {
993  target = "application/x-guitarix-";
994  if (plugin.get_type() == PLUGIN_TYPE_MONO) {
995  target += "mono";
996  } else {
997  target += "stereo";
998  }
999  if (!delete_button) {
1000  target += "-s";
1001  }
1002  mbox.signal_drag_begin().connect(sigc::mem_fun(*this, &RackBox::on_my_drag_begin));
1003  mbox.signal_drag_end().connect(sigc::mem_fun(*this, &RackBox::on_my_drag_end));
1004  mbox.signal_drag_data_get().connect(sigc::mem_fun(*this, &RackBox::on_my_drag_data_get));
1005 }
1006 
1007 void RackBox::enable_drag(bool v) {
1008  if (v) {
1009  std::vector<Gtk::TargetEntry> listTargets;
1010  listTargets.push_back(Gtk::TargetEntry(target, Gtk::TARGET_SAME_APP, 0));
1011  mbox.drag_source_set(listTargets, Gdk::BUTTON1_MASK, Gdk::ACTION_MOVE);
1012  } else {
1013  mbox.drag_source_unset();
1014  }
1015 }
1016 
1017 bool RackBox::animate_vanish() {
1018  anim_height -= anim_step;
1019  if (anim_height <= 0) {
1020  hide();
1021  set_visibility(true);
1022  set_size_request(-1,-1);
1024  return false;
1025  } else {
1026  set_size_request(-1, anim_height);
1027  return true;
1028  }
1029 }
1030 
1031 void RackBox::animate_remove() {
1032  if (!get_parent()->check_if_animate(*this)) {
1033  hide();
1034  } else {
1035  if (anim_tag.connected()) {
1036  //Glib::source_remove(anim_tag);
1037  anim_tag.disconnect();
1038  set_size_request(-1,-1);
1039  show();
1040  }
1041  anim_height = size_request().height;
1042  set_size_request(-1, anim_height);
1043  set_visibility(false);
1044  anim_step = anim_height / 5;
1045  anim_tag = Glib::signal_timeout().connect(sigc::mem_fun(*this, &RackBox::animate_vanish), 20);
1046  }
1047 }
1048 
1050  return dynamic_cast<RackContainer*>(Gtk::VBox::get_parent());
1051 }
1052 
1053 void RackBox::on_my_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) {
1054  int x, y;
1055  get_pointer(x, y);
1056  drag_icon = new DragIcon(plugin, context, main.get_options(), x);
1057  animate_remove();
1058 }
1059 
1060 bool RackBox::animate_create() {
1061  bool ret = true;
1062  anim_height += anim_step;
1063  if (anim_height >= target_height) {
1064  set_visibility(true);
1065  set_size_request(-1,-1);
1066  ret = false;
1067  } else {
1068  set_size_request(-1, anim_height);
1069  }
1070  get_parent()->ensure_visible(*this);
1071  return ret;
1072 }
1073 
1075  if (!get_parent()->check_if_animate(*this)) {
1076  show();
1077  get_parent()->ensure_visible(*this);
1078  } else {
1079  if (anim_tag.connected()) {
1080  hide();
1081  anim_tag.disconnect();
1082  set_size_request(-1,-1);
1083  }
1084  target_height = size_request().height;
1085  set_size_request(-1,0);
1086  set_visibility(false);
1087  show();
1088  anim_height = 0;
1089  anim_step = target_height / 5;
1090  anim_tag = Glib::signal_timeout().connect(mem_fun(*this, &RackBox::animate_create), 20);
1091  }
1092 }
1093 
1094 void RackBox::on_my_drag_end(const Glib::RefPtr<Gdk::DragContext>& context) {
1095  if (drag_icon) {
1096  delete drag_icon;
1097  drag_icon = 0;
1098  }
1099  if (plugin.plugin->get_box_visible()) {
1100  animate_insert();
1101  }
1102 }
1103 
1104 void RackBox::on_my_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection, int info, int timestamp) {
1105  selection.set(target, plugin.get_id());
1106 }
1107 
1108 void RackBox::vis_switch(Gtk::Widget& a, Gtk::Widget& b) {
1109  a.hide();
1110  b.show();
1111 }
1112 
1113 void RackBox::set_visibility(bool v) {
1114  if (config_mode || get_plug_visible()) {
1115  minibox->set_config_mode(false);
1116  mbox.set_visible(v);
1117  minibox->set_config_mode(config_mode);
1118  } else {
1119  fbox->set_visible(v);
1120  }
1121 }
1122 
1123 void RackBox::swtch(bool mini) {
1124  plugin.plugin->set_plug_visible(mini);
1125  if (!config_mode) {
1126  if (mini) {
1127  vis_switch(*fbox, mbox);
1128  } else {
1129  vis_switch(mbox, *fbox);
1130  }
1131  }
1132 }
1133 
1134 void RackBox::set_config_mode(bool mode) {
1135  config_mode = mode;
1136  if (!can_compress() || !get_plug_visible()) {
1137  if (mode) {
1138  vis_switch(*fbox, mbox);
1139  if (strcmp(plugin.get_id(), "ampstack") == 0) { // FIXME
1140  return;
1141  }
1142  } else {
1143  vis_switch(mbox, *fbox);
1144  }
1145  }
1146  minibox->set_config_mode(mode);
1147  enable_drag(mode);
1148 }
1149 
1150 void RackBox::setOrder(int pos, int post_pre) {
1151  plugin.plugin->set_position(pos);
1152  if (plugin.get_type() == PLUGIN_TYPE_MONO) {
1153  plugin.plugin->set_effect_post_pre(post_pre);
1154  }
1155 }
1156 
1157 void RackBox::do_expand() {
1158  swtch(false);
1159  Glib::signal_idle().connect_once(
1160  sigc::bind(
1161  sigc::mem_fun(get_parent(), &RackContainer::ensure_visible),
1162  sigc::ref(*this)));
1163 }
1164 
1165 Gtk::Button *RackBox::make_expand_button(bool expand) {
1166  const gchar *t;
1167  Gtk::Button *b = new Gtk::Button();
1168  //b->set_relief(Gtk::RELIEF_NONE);
1169  if (expand) {
1170  t = "rack_expand";
1171  b->set_tooltip_text(_("expand effect unit"));
1172  } else {
1173  t = "rack_shrink";
1174  b->set_tooltip_text(_("shrink effect unit"));
1175  }
1176  GtkWidget *l = gtk_image_new_from_stock(t, (GtkIconSize)-1);
1177  b->set_focus_on_click(false);
1178  b->add(*manage(Glib::wrap(l)));
1179  b->set_name("effect_on_off");
1180  if (expand) {
1181  b->signal_clicked().connect(
1182  sigc::mem_fun(*this, &RackBox::do_expand));
1183  } else {
1184  b->signal_clicked().connect(
1185  sigc::bind(sigc::mem_fun(*this, &RackBox::swtch), true));
1186  }
1187  return b;
1188 }
1189 
1190 Gtk::Button *RackBox::make_preset_button() {
1191  Gtk::Button *p = new Gtk::Button();
1192  //p->set_relief(Gtk::RELIEF_NONE);
1193  GtkWidget *l = gtk_image_new_from_stock("rack_preset", (GtkIconSize)-1);
1194  p->add(*manage(Glib::wrap(l)));
1195  p->set_can_default(false);
1196  p->set_can_focus(false);
1197  p->set_tooltip_text(_("manage effect unit presets"));
1198  p->set_name("effect_on_off");
1199  p->signal_clicked().connect(
1200  sigc::mem_fun(plugin, &PluginUI::on_plugin_preset_popup));
1201  return p;
1202 }
1203 
1204 void RackBox::pack(Gtk::Widget *main, Gtk::Widget *mini, const Glib::RefPtr<Gtk::SizeGroup>& szg) {
1205  if (!main) {
1206  return;
1207  }
1208  box.pack_start(*manage(main));
1209  minibox->pack(mini);
1210  szg->add_widget(*fbox);
1211  szg->add_widget(mbox);
1212 }
1213 
1214 Gtk::HBox *RackBox::make_full_box(gx_system::CmdlineOptions& options) {
1215  Gtk::HBox *bx = new Gtk::HBox();
1216  Gtk::Widget *effect_label = make_label(plugin, options, false);
1217 
1218  // overall hbox: drag-button - center vbox - drag button
1219  Gtk::HBox *main = new Gtk::HBox();
1220  // center vbox containing title bar and widgets
1221  Gtk::VBox *center = new Gtk::VBox();
1222  // title vbox on top
1223  Gtk::HBox *top = new Gtk::HBox();
1224 
1225  // spacing for bottom shadow
1226  Gtk::Alignment *al = new Gtk::Alignment();
1227  al->set_padding(0, 4, 0, 0);
1228  al->add(*manage(main));
1229 
1230  main->set_spacing(0);
1231 
1232  center->set_name("rack_unit_center");
1233  center->set_border_width(0);
1234  center->set_spacing(4);
1235  center->pack_start(*manage(top), Gtk::PACK_SHRINK);
1236  center->pack_start(box, Gtk::PACK_EXPAND_WIDGET);
1237 
1238  top->set_spacing(4);
1239  top->set_name("rack_unit_title_bar");
1240 
1241  top->pack_start(on_off_switch, Gtk::PACK_SHRINK);
1242  on_off_switch.set_name("effect_on_off");
1243  top->pack_start(*manage(effect_label), Gtk::PACK_SHRINK);
1244  top->pack_end(*manage(make_expand_button(false)), Gtk::PACK_SHRINK);
1245  if (!(plugin.plugin->get_pdef()->flags & PGN_NO_PRESETS))
1246  top->pack_end(*manage(make_preset_button()), Gtk::PACK_SHRINK);
1247 
1248  main->pack_start(*manage(wrap_bar()), Gtk::PACK_SHRINK);
1249  main->pack_start(*manage(center), Gtk::PACK_EXPAND_WIDGET);
1250  main->pack_end(*manage(wrap_bar()), Gtk::PACK_SHRINK);
1251 
1252  main->set_name(plugin.get_id());
1253  bx->pack_start(*manage(al), Gtk::PACK_EXPAND_WIDGET);
1254  //al->show_all();
1255  bx->show_all();
1256  return bx;
1257 }
1258 
1259 Gtk::VBox *RackBox::switcher_vbox(gx_system::CmdlineOptions& options) {
1260  Gtk::VBox *vbox = new Gtk::VBox();
1261 
1262  Gtk::HBox *hbox = new Gtk::HBox();
1263  vbox->pack_start(*manage(hbox));
1264  Gtk::HBox *hbox2 = new Gtk::HBox();
1265  hbox->pack_start(*manage(hbox2), Gtk::PACK_SHRINK);
1266  Gtk::VBox *vbox2 = new Gtk::VBox();
1267  hbox2->pack_start(*manage(vbox2));
1268  hbox2->pack_start(*manage(wrap_bar(4,4)), Gtk::PACK_SHRINK);
1269 #ifdef USE_SZG
1270  szg->add_widget(&on_off_switch);
1271 #endif
1272  Gtk::Alignment *al = new Gtk::Alignment(0.5, 0.5, 0.0, 0.0);
1273  al->add(on_off_switch);
1274  vbox2->pack_start(*manage(al));
1275  return vbox;
1276 }
1277 
1278 
1279 /****************************************************************
1280  ** class RackContainer
1281  */
1282 
1283 static const int min_containersize = 40;
1284 
1286  : Gtk::VBox(),
1287  tp(tp_),
1288  main(main_),
1289  config_mode(false),
1290  in_drag(-2),
1291  child_count(0),
1292  targets(),
1293  othertargets(),
1294  highlight_connection(),
1295  autoscroll_connection() {
1296  std::vector<std::string> *pm, *ps;
1297  if (tp == PLUGIN_TYPE_MONO) {
1298  pm = &targets;
1299  ps = &othertargets;
1300  } else {
1301  ps = &targets;
1302  pm = &othertargets;
1303  }
1304  pm->push_back("application/x-guitarix-mono");
1305  pm->push_back("application/x-guitarix-mono-s");
1306  pm->push_back("application/x-gtk-tool-palette-item-mono");
1307  ps->push_back("application/x-guitarix-stereo");
1308  ps->push_back("application/x-guitarix-stereo-s");
1309  ps->push_back("application/x-gtk-tool-palette-item-stereo");
1310  std::vector<Gtk::TargetEntry> listTargets;
1311  listTargets.push_back(Gtk::TargetEntry("application/x-guitarix-mono", Gtk::TARGET_SAME_APP, 0));
1312  listTargets.push_back(Gtk::TargetEntry("application/x-guitarix-mono-s", Gtk::TARGET_SAME_APP, 1));
1313  listTargets.push_back(Gtk::TargetEntry("application/x-gtk-tool-palette-item-mono", Gtk::TARGET_SAME_APP, 2));
1314  listTargets.push_back(Gtk::TargetEntry("application/x-guitarix-stereo", Gtk::TARGET_SAME_APP, 3));
1315  listTargets.push_back(Gtk::TargetEntry("application/x-guitarix-stereo-s", Gtk::TARGET_SAME_APP, 4));
1316  listTargets.push_back(Gtk::TargetEntry("application/x-gtk-tool-palette-item-stereo", Gtk::TARGET_SAME_APP, 5));
1317  drag_dest_set(listTargets, Gtk::DEST_DEFAULT_DROP, Gdk::ACTION_MOVE);
1319  sigc::mem_fun(this, &RackContainer::unit_order_changed));
1320  signal_remove().connect(sigc::mem_fun(*this, &RackContainer::on_my_remove));
1321  set_size_request(-1, min_containersize);
1322  show_all();
1323 }
1324 
1325 void RackContainer::unit_order_changed(bool stereo) {
1326  if (stereo == (tp == PLUGIN_TYPE_STEREO)) {
1327  check_order();
1328  }
1329 }
1330 
1331 bool RackContainer::drag_highlight_expose(GdkEventExpose *event, int y0) {
1332  if (!is_drawable()) {
1333  return false;
1334  }
1335  Cairo::RefPtr<Cairo::Context> cr = Glib::wrap(event->window, true)->create_cairo_context();
1336  int x, y, width, height;
1337  if (!get_has_window()) {
1338  Gtk::Allocation a = get_allocation();
1339  x = a.get_x();
1340  y = a.get_y();
1341  width = a.get_width();
1342  height = a.get_height();
1343  } else {
1344  int depth;
1345  get_window()->get_geometry(x, y, width, height, depth);
1346  x = 0;
1347  y = 0;
1348  }
1349  GdkPixbuf * pb_ = gtk_widget_render_icon(GTK_WIDGET(this->gobj()), "insert", (GtkIconSize)-1, NULL);
1350  if (pb_) {
1351  cairo_t *cr_ = gdk_cairo_create(unwrap(get_window()));
1352  gdk_cairo_set_source_pixbuf(cr_, pb_, x, y);
1353  cairo_pattern_set_extend(cairo_get_source(cr_), CAIRO_EXTEND_REPEAT);
1354  if (y0 < 0) {
1355  cairo_set_line_width(cr_, 4.0);
1356  cairo_rectangle(cr_, x, max(0, y), width, height);
1357  cairo_stroke(cr_);
1358  } else {
1359  cairo_rectangle(cr_, x, max(y, y0 - 3), width, 2);
1360  cairo_fill(cr_);
1361  }
1362  cairo_destroy(cr_);
1363  g_object_unref(pb_);
1364  }
1365  return false;
1366 }
1367 
1368 struct childpos {
1369  int y0, y1, pos;
1370  childpos(int y0_, int y1_, int pos_): y0(y0_), y1(y1_), pos(pos_) {}
1371  bool operator<(const childpos& p) { return y0 < p.y0; }
1372 };
1373 
1374 void RackContainer::find_index(int x, int y, int* len, int *ypos) {
1375  std::list<childpos> l;
1376  std::vector<RackBox*> children = get_children();
1377  int mpos = -1;
1378  for (std::vector<RackBox*>::iterator ch = children.begin(); ch != children.end(); ++ch) {
1379  ++mpos;
1380  if (!(*ch)->get_visible()) {
1381  continue;
1382  }
1383  Gtk::Allocation a = (*ch)->get_allocation();
1384  l.push_back(childpos(a.get_y(), a.get_y()+a.get_height(), mpos));
1385  }
1386  if (l.empty()) {
1387  *len = -1;
1388  *ypos = -1;
1389  return;
1390  }
1391  Gtk::Allocation a0 = get_allocation();
1392  y += a0.get_y();
1393  int sy = l.begin()->y0;
1394  for (std::list<childpos>::iterator cp = l.begin(); cp != l.end(); ++cp) {
1395  if (y < (cp->y0 + cp->y1) / 2) {
1396  *len = cp->pos;
1397  *ypos = (cp->y0+sy)/2;
1398  return;
1399  }
1400  sy = cp->y1;
1401  }
1402  *len = mpos+1;
1403  *ypos = sy;
1404 }
1405 
1406 void RackContainer::on_my_remove(Gtk::Widget *ch) {
1407  decrement();
1408  renumber();
1409 }
1410 
1411 bool RackContainer::check_targets(const std::vector<std::string>& tgts1, const std::vector<std::string>& tgts2) {
1412  for (std::vector<std::string>::const_iterator t1 = tgts1.begin(); t1 != tgts1.end(); ++t1) {
1413  for (std::vector<std::string>::const_iterator t2 = tgts2.begin(); t2 != tgts2.end(); ++t2) {
1414  if (*t1 == *t2) {
1415  return true;
1416  }
1417  }
1418  }
1419  return false;
1420 }
1421 
1422 bool RackContainer::on_drag_motion(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, guint timestamp) {
1423  const std::vector<std::string>& tg = context->get_targets();
1424  if (!check_targets(tg, targets)) {
1425  if (check_targets(tg, othertargets)) {
1426  if (!autoscroll_connection.connected()) {
1427  autoscroll_connection = Glib::signal_timeout().connect(
1428  sigc::mem_fun(*this, &RackContainer::scrollother_timeout), 50);
1429  }
1430  context->drag_status(Gdk::DragAction(0), timestamp);
1431  return true;
1432  }
1433  return false;
1434  }
1435  context->drag_status(Gdk::ACTION_MOVE, timestamp);
1436  int i, ind;
1437  find_index(x, y, &i, &ind);
1438  if (in_drag == ind) {
1439  return true;
1440  }
1441  if (in_drag > -2) {
1442  highlight_connection.disconnect();
1443  }
1444  highlight_connection = signal_expose_event().connect(sigc::bind(sigc::mem_fun(*this, &RackContainer::drag_highlight_expose), ind), true);
1445  queue_draw();
1446  in_drag = ind;
1447  if (!autoscroll_connection.connected()) {
1448  autoscroll_connection = Glib::signal_timeout().connect(sigc::mem_fun(*this, &RackContainer::scroll_timeout), 50);
1449  }
1450  return true;
1451 }
1452 
1454  Gtk::Allocation alloc = child.get_allocation();
1455  Gtk::Viewport *p = dynamic_cast<Gtk::Viewport*>(get_ancestor(GTK_TYPE_VIEWPORT));
1456  p->get_vadjustment()->clamp_page(alloc.get_y(), alloc.get_y()+alloc.get_height());
1457 }
1458 
1459 static const double scroll_edge_size = 60.0;
1460 static const int step_size = 20;
1461 
1462 bool RackContainer::scrollother_timeout() {
1463  Gtk::Viewport *p = dynamic_cast<Gtk::Viewport*>(get_ancestor(GTK_TYPE_VIEWPORT));
1464  Gtk::Adjustment *a = p->get_vadjustment();
1465  double off = a->get_value();
1466  Gtk::Allocation alloc = get_allocation();
1467  int x, y;
1468  get_pointer(x, y);
1469  y -= alloc.get_height();
1470  double step;
1471  if (y < -scroll_edge_size) {
1472  step = step_size;
1473  } else {
1474  step = step_size * exp(-(y+scroll_edge_size)/(1.0*scroll_edge_size));
1475  if (step < 1.5) {
1476  return false;
1477  }
1478  }
1479  if (tp == PLUGIN_TYPE_MONO) {
1480  off = main.stop_at_stereo_bottom(off, step_size, a->get_page_size());
1481  } else {
1482  off = main.stop_at_mono_top(off, step_size);
1483  }
1484  if (off < a->get_lower()) {
1485  off = a->get_lower();
1486  }
1487  if (off > a->get_upper() - a->get_page_size()) {
1488  off = a->get_upper() - a->get_page_size();
1489  }
1490  a->set_value(off);
1491  return true;
1492 }
1493 
1494 bool RackContainer::scroll_timeout() {
1495  Gtk::Viewport *p = dynamic_cast<Gtk::Viewport*>(get_ancestor(GTK_TYPE_VIEWPORT));
1496  Gtk::Adjustment *a = p->get_vadjustment();
1497  double off = a->get_value();
1498  Gtk::Allocation alloc = get_allocation();
1499  int x, y;
1500  get_pointer(x, y);
1501  double sez = scroll_edge_size;
1502  if (sez > a->get_page_size() / 3) {
1503  sez = a->get_page_size() / 3;
1504  }
1505  double yw = y + alloc.get_y() - off;
1506  double step;
1507  if (yw <= sez) {
1508  step = step_size * (sez-yw) / sez;
1509  off = max(double(alloc.get_y()), off-step);
1510  } else {
1511  yw = a->get_page_size() - yw;
1512  if (yw <= sez) {
1513  step = step_size * (sez-yw) / sez;
1514  off = min(alloc.get_y()+alloc.get_height()-a->get_page_size(), off+step);
1515  } else {
1516  return true;
1517  }
1518  }
1519  if (off < a->get_lower()) {
1520  off = a->get_lower();
1521  }
1522  if (off > a->get_upper() - a->get_page_size()) {
1523  off = a->get_upper() - a->get_page_size();
1524  }
1525  a->set_value(off);
1526  return true;
1527 }
1528 
1529 void RackContainer::on_drag_leave(const Glib::RefPtr<Gdk::DragContext>& context, guint timestamp) {
1530  if (in_drag > -2) {
1531  highlight_connection.disconnect();
1532  queue_draw();
1533  in_drag = -2;
1534  }
1535  autoscroll_connection.disconnect();
1536 }
1537 
1538 void RackContainer::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, const Gtk::SelectionData& data, guint info, guint timestamp) {
1539  int i, ind;
1540  find_index(x, y, &i, &ind);
1541  std::string dtype = data.get_data_type();
1542  if (dtype == "application/x-gtk-tool-palette-item-mono" || dtype == "application/x-gtk-tool-palette-item-stereo") {
1543  main.get_plugin(data.get_data_as_string())->display_new(true);
1544  }
1545  reorder(data.get_data_as_string(), i);
1546 }
1547 
1549  for (PluginDict::iterator i = main.plugins_begin(); i != main.plugins_end(); ++i) {
1550  i->second->hidden = false;
1551  if (!i->second->hidden_by_move) {
1552  RackBox *r = i->second->rackbox;
1553  if (r) {
1554  r->show();
1555  }
1556  }
1557  }
1558 }
1559 
1561  for (PluginDict::iterator i = main.plugins_begin(); i != main.plugins_end(); ++i) {
1562  i->second->hidden = true;
1563  RackBox *r = i->second->rackbox;
1564  if (r) {
1565  if (r->can_compress()) {
1566  r->hide();
1567  }
1568  }
1569  }
1570 }
1571 
1572 void RackContainer::reorder(const std::string& name, unsigned int pos) {
1573  std::vector<RackBox*> l = get_children();
1574  main.get_machine().insert_rack_unit(name, ((pos >= l.size()) ? "" : l[pos]->get_id()), tp);
1575  check_order();
1576 }
1577 
1578 void RackContainer::on_add(Widget *ch) {
1579  add(*dynamic_cast<RackBox*>(ch));
1580 }
1581 
1582 void RackContainer::add(RackBox& r, int pos) {
1583  pack_start(r, Gtk::PACK_SHRINK);
1584  increment();
1585  if (config_mode) {
1586  r.set_config_mode(true);
1587  }
1588  reorder_child(r, pos);
1589  renumber();
1590 }
1591 
1593  ++child_count;
1594  if (child_count == 1) {
1595  set_size_request(-1, -1);
1596  }
1597 }
1598 
1600  --child_count;
1601  assert(child_count >= 0);
1602  if (child_count == 0) {
1603  set_size_request(-1, min_containersize);
1604  }
1605 }
1606 
1608  config_mode = mode;
1609  std::vector<RackBox*> l = get_children();
1610  for (std::vector<RackBox*>::iterator c = l.begin(); c != l.end(); ++c) {
1611  (*c)->set_config_mode(mode);
1612  }
1613 }
1614 
1616  const std::vector<std::string>& ol = main.get_machine().get_rack_unit_order(tp);
1617  bool in_order = true;
1618  std::set<std::string> unit_set(ol.begin(), ol.end());
1619  rackbox_list l = get_children();
1620  std::vector<std::string>::const_iterator oi = ol.begin();
1621  for (rackbox_list::iterator c = l.begin(); c != l.end(); ++c) {
1622  if (!(*c)->get_box_visible()) {
1623  continue;
1624  }
1625  if (unit_set.find((*c)->get_id()) == unit_set.end()) {
1626  main.get_plugin((*c)->get_id())->hide(false);
1627  continue;
1628  }
1629  if (!in_order) {
1630  continue;
1631  }
1632  if (oi == ol.end()) {
1633  in_order = false;
1634  continue;
1635  }
1636  if (*oi != (*c)->get_id()) {
1637  in_order = false;
1638  }
1639  ++oi;
1640  }
1641  if (oi != ol.end()) {
1642  in_order = false;
1643  }
1644  if (in_order) {
1645  return;
1646  }
1647  int n = 0;
1648  for (std::vector<std::string>::const_iterator oi = ol.begin(); oi != ol.end(); ++oi) {
1649  PluginUI *p = main.get_plugin(*oi);
1650  if (!p->rackbox) {
1651  p->show(false);
1652  } else {
1653  if (!p->rackbox->get_box_visible()) {
1654  p->rackbox->display(true, false);
1655  if (p->hidden) {
1656  p->rackbox->hide();
1657  }
1658  }
1659  }
1660  reorder_child(*p->rackbox, n++);
1661  }
1662  renumber();
1663 }
1664 
1665 void RackContainer::renumber() {
1666  rackbox_list l = get_children();
1667  int pos = 0;
1668  unsigned int post_pre = 1;
1669  for (rackbox_list::iterator c = l.begin(); c != l.end(); ++c, ++pos) {
1670  if (strcmp((*c)->get_id(), "ampstack") == 0) { // FIXME
1671  pos = 0;
1672  post_pre = 0;
1673  continue;
1674  }
1675  (*c)->setOrder(pos, post_pre);
1676  }
1677 }
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:1615
void cleanup()
Definition: rack.cpp:213
void add(RackBox &r, int pos=-1)
Definition: rack.cpp:1582
#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:1453
virtual void on_selection_done()
Definition: rack.cpp:762
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:1285
void set_config_mode(bool mode)
Definition: rack.cpp:1607
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:1134
Glib::ustring & get_name()
Definition: rack.cpp:534
bool hidden_by_move
~DragIcon()
Definition: rack.cpp:279
const char * description
Definition: gx_plugin.h:189
RackBox(PluginUI &plugin, MainWindow &main, Gtk::Widget *bare=0)
Definition: rack.cpp:954
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:930
virtual bool parameter_unit_has_std_values(const PluginDef *pdef) const =0
childpos(int y0_, int y1_, int pos_)
Definition: rack.cpp:1370
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:769
void pack(Gtk::Widget *mainbox, Gtk::Widget *minibox, const Glib::RefPtr< Gtk::SizeGroup > &szg)
Definition: rack.cpp:1204
void decrement()
Definition: rack.cpp:1599
static Gtk::Widget * create_icon_widget(const PluginUI &plugin, gx_system::CmdlineOptions &options)
Definition: rack.cpp:890
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:1371
gx_system::CmdlineOptions & get_options()
void increment()
Definition: rack.cpp:1592
void show_entries()
Definition: rack.cpp:1548
#define min(x, y)
void animate_insert()
Definition: rack.cpp:1074
virtual sigc::signal< void, bool > & signal_rack_unit_order_changed()=0
int y1
Definition: rack.cpp:1369
#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:1560
int flags
Definition: gx_plugin.h:183
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:1049
void update_rackbox()
Definition: rack.cpp:164
gx_engine::GxMachineBase & get_machine()
void resize_finished()
int y0
Definition: rack.cpp:1369
int main(int argc, char *argv[])
Definition: gxw_demo.cc:62
void swtch(bool mini)
Definition: rack.cpp:1123
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:1572
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:1150
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:902