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