Guitarix
gx_jack_options.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
3  * Copyright (C) 2011 Pete Shorthose
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  * ---------------------------------------------------------------------------
19  *
20  * This is the gx_head GUI main class
21  *
22  * ----------------------------------------------------------------------------
23  */
24 
25 #include "guitarix.h" // NOLINT
26 
27 #include <glibmm/i18n.h> // NOLINT
28 
29 #include <iomanip> // NOLINT
30 #include <cstring> // NOLINT
31 #include <string> // NOLINT
32 
33 namespace gx_gui {
34 
35 /****************************************************************
36  ** class SelectJackControlPgm
37  */
38 
39 SelectJackControlPgm::SelectJackControlPgm(BaseObjectType* cobject, Glib::RefPtr<GxBuilder> bld, gx_engine::GxMachineBase& m)
40  : Gtk::Window(cobject),
41  description(),
42  customstarter(),
43  startercombo(),
44  dontask(),
45  machine(m),
46  close() {
47  signal_delete_event().connect(sigc::mem_fun(*this, &SelectJackControlPgm::on_delete_event));
48  bld->find_widget("description", description);
49  bld->find_widget("customstarter", customstarter);
50  customstarter->set_text(machine.get_parameter_value<string>("ui.jack_starter"));
51  bld->find_widget("startercombo", startercombo);
52  const char *v_id = machine.get_parameter("ui.jack_starter_idx").getValueNames()[machine.get_parameter_value<int>("ui.jack_starter_idx")].value_id;
53  int n = 0;
54  Glib::RefPtr<Gtk::TreeModel> model = startercombo->get_model();
55  for (Gtk::TreeIter i = model->children().begin(); i; ++i, ++n) {
56  Glib::ustring s;
57  i->get_value(1, s);
58  if (s == v_id) {
59  startercombo->set_active(n);
60  }
61  }
62  startercombo->signal_changed().connect(sigc::mem_fun(*this, &SelectJackControlPgm::on_starter_changed));
63  bld->find_widget("dontask", dontask);
64  dontask->set_active(!machine.get_parameter_value<bool>("ui.ask_for_jack_starter"));
65  Gtk::Button *button;
66  bld->find_widget("ok_button", button);
67  button->signal_clicked().connect(
68  sigc::mem_fun(*this, &SelectJackControlPgm::on_ok_button));
69  bld->find_widget("cancel_button", button);
70  button->signal_clicked().connect(
71  sigc::mem_fun(*this, &SelectJackControlPgm::on_cancel_button));
72  on_starter_changed();
73 }
74 
76 }
77 
78 //static
80  Glib::RefPtr<GxBuilder> bld = GxBuilder::create_from_file(opt.get_builder_filepath("jackstarter.glade"), &m);
82  bld->get_toplevel_derived("selectjackstarter", w,
83  sigc::bind(sigc::ptr_fun(SelectJackControlPgm::create_from_builder), bld, sigc::ref(m)));
84  return w;
85 }
86 
87 bool SelectJackControlPgm::on_key_press_event(GdkEventKey *event) {
88  if (event->keyval == GDK_KEY_Escape && (event->state & Gtk::AccelGroup::get_default_mod_mask()) == 0) {
89  close();
90  return true;
91  }
92  return Gtk::Window::on_key_press_event(event);
93 }
94 
95 bool SelectJackControlPgm::on_delete_event(GdkEventAny* event) {
96  close();
97  return true;
98 }
99 
100 void SelectJackControlPgm::on_starter_changed() {
101  Gtk::TreeModel::iterator i = startercombo->get_active();
102  if (!i) {
103  return;
104  }
105  Glib::ustring s;
106  i->get_value(2,s);
107  description->set_markup(s);
108  i->get_value(1, s);
109  if (s == "other") {
110  customstarter->show();
111  } else {
112  customstarter->hide();
113  }
114 }
115 
116 void SelectJackControlPgm::on_ok_button() {
117  machine.set_parameter_value("ui.jack_starter", customstarter->get_text());
118  Glib::ustring s;
119  startercombo->get_active()->get_value(1, s);
120  int n = machine.get_parameter("ui.jack_starter_idx").getInt().idx_from_id(s);
121  if (n >= 0) {
122  machine.set_parameter_value("ui.jack_starter_idx", n);
123  } else {
124  gx_print_error("load error", "starter id not found");
125  }
126  machine.set_parameter_value("ui.ask_for_jack_starter", !dontask->get_active());
127  close();
128 }
129 
130 void SelectJackControlPgm::on_cancel_button() {
131  close();
132 }
133 
134 /****************************************************************
135  ** Jackstart Dialog
136  */
137 
138 // ----- pop up a dialog for starting jack
139 bool gx_start_jack_dialog(Glib::RefPtr<Gdk::Pixbuf> gw_ib) {
140  // --- run dialog and check response
141  const guint nchoices = 3;
142 
143  const char* labels[] = {
144  _("Start Jack"), _("Ignore Jack"), _("Exit")
145  };
146 
147  const gint responses[] = {
148  GTK_RESPONSE_YES, GTK_RESPONSE_NO, GTK_RESPONSE_CANCEL
149  };
150 
151  gint response =
153  _(" Jack Starter "),
154  _("\n WARNING \n\n"
155  " The jack server is not currently running\n"
156  " You can choose to activate it or terminate gx_head \n\n"
157  " 1) activate jack \n"
158  " 2) ignore jack, start gx_head anyway \n"
159  " 3) exit gx_head \n"
160  "\n"
161  " use options menu \"jack startup control\" to\n"
162  " set a jack start program\n"),
163  nchoices,
164  labels,
165  responses,
166  GTK_RESPONSE_YES,
167  gw_ib);
168 
169  // we are cancelling
170  bool retstat = false;
171 
172  switch (response) {
173  case GTK_RESPONSE_NO:
174  //set_jack_down(true); FIXME
175  break;
176 
177  case GTK_RESPONSE_CANCEL:
179  break;
180 
181  case GTK_RESPONSE_YES:
182  retstat = true;
183  break;
184  default:
186  break;
187 
188  }
189 
190  // start jack
191  return retstat;
192 }
193 } // end namespace gx_gui
194 
#define GDK_KEY_Escape
Definition: guitarix.h:53
virtual Parameter & get_parameter(const std::string &id)=0
gint gx_nchoice_dialog_without_entry(const char *window_title, const char *msg, const guint nchoice, const char *label[], const gint resp[], const gint default_response, Glib::RefPtr< Gdk::Pixbuf > gw_ib)
void gx_print_error(const char *, const std::string &)
Definition: gx_logging.cpp:166
static GxExit & get_instance()
Definition: gx_logging.cpp:205
virtual void set_parameter_value(const std::string &id, int value)=0
bool gx_start_jack_dialog(Glib::RefPtr< Gdk::Pixbuf > gw_ib)
void exit_program(std::string msg="", int errcode=1)
Definition: gx_logging.cpp:196
IntParameter & getInt()
Definition: gx_parameter.h:456
std::string get_builder_filepath(const std::string &basename) const
Definition: gx_system.h:373
virtual int idx_from_id(string v_id)
static SelectJackControlPgm * create(gx_system::CmdlineOptions &opt, gx_engine::GxMachineBase &machine)