Guitarix
gx_jconv_settings.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010, 2013 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 
21 #include "guitarix.h" // NOLINT
22 
23 namespace gx_jconv {
24 
25 /****************************************************************
26  ** Convolver Parameter Window
27  */
28 
29 /*
30 ** static class variables and functions
31 */
32 
33 IRWindow *IRWindow::create(const std::string& unit_id,
34  Glib::RefPtr<Gdk::Pixbuf> icon, gx_engine::GxMachineBase& machine,
35  Glib::RefPtr<Gtk::AccelGroup> accels, int nchan) {
36  Glib::RefPtr<gx_gui::GxBuilder> bld = gx_gui::GxBuilder::create_from_file(
37  machine.get_options().get_builder_filepath(nchan == 1 ? "iredit_mono.glade" : "iredit.glade"), &machine);
38  Gtk::Widget *w;
39  if (!machine.get_jack()) {
40  bld->find_widget("file_selector_box", w);
41  //w->hide();
42  //bld->find_widget("dir_combo:rack_button", w);
43  //w->show();
44  }
45  gx_engine::JConvParameter *jcp = dynamic_cast<gx_engine::JConvParameter*>(&machine.get_parameter(unit_id+".convolver"));
46  assert(jcp);
47  return new IRWindow(bld, jcp, icon, machine, accels, nchan);
48 }
49 
50 /*
51  ** Constructor
52  */
53 
54 void IRWindow::init_connect() {
55  builder->find_widget("iredit", wIredit);
56  wIredit->signal_delay_changed().connect(sigc::mem_fun(*this,
57  &IRWindow::on_delay_changed));
58  wIredit->signal_offset_changed().connect(sigc::mem_fun(*this,
59  &IRWindow::on_offset_changed));
60  wIredit->signal_length_changed().connect(sigc::mem_fun(*this,
61  &IRWindow::on_length_changed));
62  wIredit->signal_scale_max_reached().connect(sigc::mem_fun(*this,
63  &IRWindow::on_max_scale_reached));
64  wIredit->signal_scale_min_reached().connect(sigc::mem_fun(*this,
65  &IRWindow::on_min_scale_reached));
66 
67  builder->find_widget("file_combo:rack_button", wcombo);
68  wcombo->signal_changed().connect(
69  sigc::mem_fun(*this, &IRWindow::on_combo_changed));
70  wcombo->set_model(model);
71 
72  builder->find_widget("dir_combo:rack_button", dircombo);
73  if (dircombo->is_visible()) {
74  Gtk::TreeModelColumnRecord rec;
75  Gtk::TreeModelColumn<std::string> fname_col;
76  rec.add(fname_col);
77  Gtk::TreeModelColumn<Glib::ustring> dname_col;
78  rec.add(dname_col);
79  Glib::RefPtr<Gtk::ListStore> st = Gtk::ListStore::create(rec);
80  std::vector<gx_system::FileName> dirs;
81  machine.load_impresp_dirs(dirs);
82  for (std::vector<gx_system::FileName>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
83  Gtk::TreeIter j = st->append();
84  j->set_value(0, i->displayname);
85  j->set_value(1, i->filename);
86  }
87  dircombo->set_model(st);
88  dircombo->signal_changed().connect(
89  sigc::mem_fun(*this, &IRWindow::on_dircombo_changed));
90  }
91 
92  if (nchan != 1) {
93  builder->find_widget("left", wLeft);
94  wLeft->signal_toggled().connect(sigc::mem_fun(*this, &IRWindow::on_left));
95  builder->find_widget("right", wRight);
96  wRight->signal_toggled().connect(sigc::mem_fun(*this, &IRWindow::on_right));
97  builder->find_widget("sum", wSum);
98  wSum->set_active(true);
99  wSum->signal_toggled().connect(sigc::mem_fun(*this, &IRWindow::on_sum));
100  } else {
101  wLeft = wRight = wSum = 0;
102  }
103 
104  builder->find_widget("log", wLog);
105  wLog->set_active(true);
106  builder->find_widget("linear", wLinear);
107  wLinear->signal_toggled().connect(sigc::mem_fun(*this, &IRWindow::on_linear));
108 
109  builder->find_widget("delay:show_always", wDelay);
110  wDelay->signal_value_changed().connect(sigc::mem_fun(*this,
111  &IRWindow::on_m_delay_changed));
112  builder->find_widget("offset:show_always", wOffset);
113  wOffset->signal_value_changed().connect(sigc::mem_fun(*this,
114  &IRWindow::on_m_offset_changed));
115  builder->find_widget("irlength:show_always", wLength);
116  wLength->signal_value_changed().connect(sigc::mem_fun(*this,
117  &IRWindow::on_m_length_changed));
118  builder->find_widget("delay_ms:show_always", wDelay_ms);
119  wDelay_ms->signal_value_changed().connect(sigc::mem_fun(*this,
120  &IRWindow::on_ms_delay_changed));
121  builder->find_widget("offset_ms:show_always", wOffset_ms);
122  wOffset_ms->signal_value_changed().connect(sigc::mem_fun(*this,
123  &IRWindow::on_ms_offset_changed));
124  builder->find_widget("irlength_ms:show_always", wLength_ms);
125  wLength_ms->signal_value_changed().connect(sigc::mem_fun(*this,
126  &IRWindow::on_ms_length_changed));
127 
128  if (nchan != 1) {
129  builder->find_widget("delay_delta", wDelay_delta);
130  wDelay_delta->signal_format_value().connect(sigc::mem_fun(*this,
131  &IRWindow::on_delay_delta_format_value));
132  }
133 
134  builder->find_widget("home", wHome);
135  wHome->signal_clicked().connect(sigc::mem_fun(*this, &IRWindow::on_home));
136  builder->find_widget("jump_zoom_mark", wJump_zoom_mark);
137  wJump_zoom_mark->signal_clicked().connect(sigc::mem_fun(*this,
138  &IRWindow::on_jump_zoom_mark));
139  builder->find_widget("incr", wIncr);
140  wIncr->signal_clicked().connect(sigc::mem_fun(*this, &IRWindow::on_incr));
141  builder->find_widget("decr", wDecr);
142  wDecr->signal_clicked().connect(sigc::mem_fun(*this, &IRWindow::on_decr));
143 
144  builder->find_widget("reset_button", wReset);
145  wReset->signal_clicked().connect(sigc::mem_fun(*this, &IRWindow::on_reset_clicked));
146  builder->find_widget("open_button", wOpen);
147  wOpen->signal_clicked().connect(sigc::mem_fun(*this, &IRWindow::on_open));
148 
149  builder->find_widget("apply_button", wApply);
150  wApply->signal_clicked().connect(sigc::mem_fun(*this,
151  &IRWindow::on_apply_button_clicked));
152 
153  builder->find_widget("cancel_button", wCancel);
154  wCancel->signal_clicked().connect(sigc::mem_fun(*this,
155  &IRWindow::on_cancel_button_clicked));
156  builder->find_widget("ok_button", wOk);
157  wOk->signal_clicked().connect(sigc::mem_fun(*this,
158  &IRWindow::on_ok_button_clicked));
159 
160  builder->find_widget("gain_button", wGain_correction);
161  autogain_conn = wGain_correction->signal_toggled().connect(
162  sigc::mem_fun(*this, &IRWindow::on_gain_button_toggled));
163 
164  builder->find_widget("length", wSamples);
165  builder->find_widget("samplerate", wSampleRate);
166  builder->find_widget("format", wFormat);
167  builder->find_widget("channels", wChan);
168  builder->find_widget("filename", wFilename);
169 
170  if (nchan == 1) {
171  wChannelbox = 0;
172  } else {
173  builder->find_widget("channelbox", wChannelbox);
174  }
175  Gtk::Button* button;
176  builder->find_widget("help_button", button);
177  button->signal_clicked().connect(sigc::mem_fun(*this, &IRWindow::on_help_clicked));
178  builder->find_widget("HelpIR", wHelp);
179  builder->find_widget("close_irhelp", button);
180  button->signal_clicked().connect(sigc::mem_fun(wHelp, &Gtk::Widget::hide));
181 
182  builder->find_widget("preset_button", button);
183  button->signal_clicked().connect(
184  sigc::mem_fun(this, &IRWindow::on_preset_popup_clicked));
185 
186  gtk_window->signal_key_press_event().connect(
187  sigc::mem_fun(this, &IRWindow::on_key_press_event));
188 }
189 
190 IRWindow::IRWindow(const Glib::RefPtr<gx_gui::GxBuilder>& bld, gx_engine::JConvParameter *jcp_,
191  Glib::RefPtr<Gdk::Pixbuf> icon, gx_engine::GxMachineBase& machine_,
192  Glib::RefPtr<Gtk::AccelGroup> accels, int nchan_)
193  : machine(machine_),
194  builder(bld),
195  filename(),
196  ms(0.0),
197  audio_buffer(0),
198  audio_size(0),
199  audio_chan(0),
200  jcp(jcp_),
201  gtk_window(0),
202  autogain_conn(),
203  nchan(nchan_),
204  //skipped all gtk widget pointers, will be set in init_connect()
205  columns(),
206  model(Gtk::TreeStore::create(columns)),
207  current_combo_dir() {
208  bld->get_toplevel("DisplayIR", gtk_window);
209 
210  init_connect();
211  gtk_window->set_icon(icon);
212  gtk_window->add_accel_group(accels);
213  jcp->signal_changed().connect(
214  sigc::mem_fun(this, &IRWindow::load_state));
215  machine.signal_impresp_list().connect(
216  sigc::mem_fun(this, &IRWindow::on_enumerate));
217 
218  // reset display
219  file_changed("", 0, 0, 0, "");
220  on_delay_changed(0, 0);
221  on_offset_changed(0, 0);
222  on_length_changed(0, 0);
223 }
224 
225 IRWindow::~IRWindow() {
226  delete gtk_window;
227  delete audio_buffer;
228 }
229 
230 /*
231 ** helper functions
232 */
233 
234 int IRWindow::set_val(Gxw::ControlParameter *sample_display,
235  Gxw::ControlParameter *ms_display,
236  double value, int fs) {
237  double s1, s2;
238  if (fs) {
239  s1 = value;
240  s2 = (value*1000.0)/fs;
241  } else {
242  s1 = 0;
243  s2 = 0;
244  }
245  ms_display->cp_set_value(s2);
246  sample_display->cp_set_value(s1);
247  return sample_display->cp_get_int_value();
248 }
249 
250 void IRWindow::file_changed(Glib::ustring filename, int rate, int length,
251  int channels, Glib::ustring format) {
252  Glib::ustring s_rate, s_length, s_channels;
253  if (filename.empty()) {
254  filename = "no file selected";
255  s_length = s_rate = format = s_channels = "--";
256  } else {
257  ms = rate/1000.0;
258  wDelay->set_range(0, 5*rate);
259  wDelay_ms->set_range(0, 5*1000);
260  wOffset->set_range(0, length-1);
261  wOffset_ms->set_range(0, (length-1)*1000.0/rate);
262  wLength->set_range(0, length);
263  wLength_ms->set_range(0, (length)*1000.0/rate);
264  s_length = (boost::format("%1%") % length).str();
265  s_rate = (boost::format("%1%") % rate).str();
266  s_channels = (boost::format("%1%") % channels).str();
267  }
268  wSamples->set_text(s_length);
269  wSampleRate->set_text(s_rate);
270  wFormat->set_text(format);
271  wChan->set_text(s_channels);
272  if (nchan != 1) {
273  wChannelbox->set_sensitive(channels >= 2);
274  }
275  wFilename->set_text(Glib::path_get_dirname(filename));
276 }
277 
278 void IRWindow::load_state(const gx_engine::GxJConvSettings* jcs) {
279  string path = jcs->getFullIRPath();
280  if (path.empty()) {
281  wIredit->set_ir_data(0, 0, 0, 0);
282  return;
283  }
285  make_state(jc);
286  if (jc == *jcs) {
287  return;
288  }
289  autogain_conn.block();
290  wGain_correction->set_active(jcs->getGainCor());
291  autogain_conn.unblock();
292  load_data(path, jcs->getOffset(), jcs->getDelay(), jcs->getLength(), jcs->getGainline());
293  reload_impresp_list();
294 }
295 
296 Gainline IRWindow::gain0 = Gainline();
297 
298 bool IRWindow::load_data(Glib::ustring f, int offset, int delay, int length, const Gainline& gain) {
299  filename = f;
300  int audio_type, audio_form, audio_rate;
301  float *buffer;
302  if (!machine.read_audio(filename, &audio_size, &audio_chan, &audio_type, &audio_form, &audio_rate, &buffer)) {
303  return false;
304  }
305  Glib::ustring enc;
306  switch (audio_type) {
307  case gx_engine::Audiofile::TYPE_OTHER: enc = "???"; break;
308  case gx_engine::Audiofile::TYPE_CAF: enc = "CAF"; break;
309  case gx_engine::Audiofile::TYPE_WAV: enc = "WAV"; break;
310  case gx_engine::Audiofile::TYPE_AIFF: enc = "AIFF"; break;
311  case gx_engine::Audiofile::TYPE_AMB: enc = "AMB"; break;
312  }
313  enc += " ";
314  switch (audio_form) {
315  case gx_engine::Audiofile::FORM_OTHER: enc += "?"; break;
316  case gx_engine::Audiofile::FORM_16BIT: enc += "16 bit"; break;
317  case gx_engine::Audiofile::FORM_24BIT: enc += "24 bit"; break;
318  case gx_engine::Audiofile::FORM_32BIT: enc += "32 bit"; break;
319  case gx_engine::Audiofile::FORM_FLOAT: enc += "float"; break;
320  }
321  delete[] audio_buffer;
322  audio_buffer = buffer;
323  file_changed(filename, audio_rate, audio_size, audio_chan, enc);
324  if (!length) {
325  length = audio_size;
326  }
327  wIredit->set_state(audio_buffer, audio_chan, audio_size, audio_rate, offset, offset+length, delay-offset, gain);
328  if (wSum) {
329  wSum->set_active(true);
330  }
331  wLog->set_active(true);
332  return true;
333 }
334 
335 double IRWindow::calc_normalized_gain(int offset, int length, const Gainline& points) {
336  if (audio_chan == 0) {
337  return 1.0;
338  }
339  double gain = 0.0;
340  unsigned int idx = 0; // current index in gainline point array
341  double gp = 0.0, fct = 0.0; // calculated parameter of interpolation line
342  if (points.size()) {
343  while (points[idx].i < offset) {
344  idx++;
345  assert(idx < points.size());
346  }
347  if (points[idx].i > offset) {
348  idx--;
349  gx_engine::GxConvolver::compute_interpolation(fct, gp, idx, points, 0);
350  }
351  }
352  for (int i = offset; i < offset+length; i++) {
353  if (idx+1 < points.size() && points[idx].i == i) {
354  gx_engine::GxConvolver::compute_interpolation(fct, gp, idx, points, 0);
355  }
356  double g = pow(10, gp + i*fct);
357  for (int j = 0; j < audio_chan; j++) {
358  double v = audio_buffer[i*audio_chan+j] * g;
359  gain += v*v;
360  }
361  }
362  gain = sqrt(gain / audio_chan);
363  if (gain != 0.0) {
364  gain = 1 / gain;
365  }
366  return gain;
367 }
368 
369 void IRWindow::make_state(gx_engine::GxJConvSettings& jc) {
370  Gainline gainline = wIredit->get_gain();
371  unsigned int offset = wIredit->get_offset();
372  unsigned int length = wIredit->get_length();
373  double gain = calc_normalized_gain(offset, length, gainline);
374  jc.setDelay(wIredit->get_delay());
375  jc.setOffset(offset);
376  jc.setLength(length);
377  jc.setFullIRPath(filename);
378  jc.setGainline(gainline);
379  jc.setGain(gain);
380  jc.setGainCor(wGain_correction->get_active());
381 }
382 
383 void IRWindow::save_state() {
385  make_state(jc);
386  jcp->set(jc);
387 }
388 
393 void IRWindow::on_combo_changed() {
394  Gtk::TreeModel::iterator iter = wcombo->get_active();
395  if (iter) {
396  Gtk::TreeModel::Row row = *iter;
397  if (row) {
398  std::string fname = row[columns.filename];
399  if (fname != jcp->get_value().getIRFile()) {
400  load_data(Glib::build_filename(current_combo_dir, fname));
401  save_state();
402  }
403  }
404  }
405 }
406 
407 void IRWindow::on_dircombo_changed() {
408  Gtk::TreeModel::iterator iter = dircombo->get_active();
409  if (iter) {
410  std::string dir;
411  iter->get_value(1, dir);
412  if (dir != current_combo_dir) {
413  machine.reload_impresp_list(dir);
414  }
415  }
416 }
417 
418 void IRWindow::reload_impresp_list() {
419  std::string path = jcp->get_value().getIRDir();
420  if (path == "~/") { // cruft in old files
421  path = getenv("HOME");
422  }
423  string irfile = jcp->get_value().getIRFile();
424  if (current_combo_dir == path) {
425  Gtk::TreeNodeChildren ch = model->children();
426  for (Gtk::TreeIter i = ch.begin(); i != ch.end(); ++i) {
427  if (i->get_value(columns.filename) == irfile) {
428  wcombo->set_active(i);
429  }
430  }
431  return;
432  }
433  machine.reload_impresp_list(path);
434 }
435 
436 // reload the treelist for the combobox
437 void IRWindow::on_enumerate(const std::string& path, const std::vector<gx_system::FileName>& l) {
438  if (current_combo_dir == path) {
439  return;
440  }
441  current_combo_dir = path;
442  string irfile = jcp->get_value().getIRFile();
443  model->clear();
444  Gtk::TreeIter j;
445  wcombo->unset_model();
446  model->set_sort_column(Gtk::TreeSortable::DEFAULT_UNSORTED_COLUMN_ID, Gtk::SORT_ASCENDING);
447  for (std::vector<gx_system::FileName>::const_iterator f = l.begin(); f != l.end(); ++f) {
448  Gtk::TreeIter i = model->append();
449  i->set_value(columns.displayname, f->displayname);
450  i->set_value(columns.filename, f->filename);
451  if (f->filename == irfile) {
452  j = i;
453  }
454  }
455  model->set_sort_column(columns.displayname, Gtk::SORT_ASCENDING);
456  wcombo->set_model(model);
457  if (j) {
458  wcombo->set_active(j);
459  }
460  if (dircombo->is_visible()) {
461  Gtk::TreeNodeChildren ch = dircombo->get_model()->children();
462  for (Gtk::TreeIter di = ch.begin(); di != ch.end(); ++di) {
463  std::string p;
464  di->get_value(1, p);
465  if (p == current_combo_dir) {
466  dircombo->set_active(di);
467  break;
468  }
469  }
470  }
471 }
472 
473 void IRWindow::on_linear() {
474  wIredit->set_log(not wLinear->get_active());
475 }
476 
477 void IRWindow::on_left() {
478  if (wLeft->get_active()) {
479  wIredit->set_channel(0);
480  }
481 }
482 
483 void IRWindow::on_right() {
484  if (wRight->get_active()) {
485  wIredit->set_channel(1);
486  }
487 }
488 
489 void IRWindow::on_sum() {
490  if (wSum->get_active()) {
491  wIredit->set_channel(-1);
492  }
493 }
494 
495 void IRWindow::on_delay_changed(int delay, int fs) {
496  int d = static_cast<int>(round(set_val(wDelay, wDelay_ms, delay, fs)));
497  if (d != delay) {
498  wIredit->set_delay(d);
499  }
500 }
501 
502 void IRWindow::on_offset_changed(int offset, int fs) {
503  set_val(wOffset, wOffset_ms, offset, fs);
504 }
505 
506 void IRWindow::on_length_changed(int length, int fs) {
507  set_val(wLength, wLength_ms, length, fs);
508 }
509 
510 void IRWindow::on_reset_clicked() {
512  jc.setDelay(0);
513  jc.setOffset(0);
514  jc.setLength(audio_size);
515  jc.setFullIRPath(filename);
516  jc.setGainline(gain0);
517  jc.setGain(calc_normalized_gain(0, audio_size, gain0));
518  jc.setGainCor(true);
519  jcp->set(jc);
520  const char *params[] = {"jconv.balance", "jconv.diff_delay", "jconv.gain", "jconv.wet_dry", 0};
521  for (const char **p = params; *p; ++p) {
522  gx_engine::Parameter& pm = machine.get_parameter(*p);
523  pm.stdJSON_value();
524  pm.setJSON_value();
525  }
526 }
527 
528 Glib::ustring IRWindow::on_delay_delta_format_value(double v) {
529  Glib::ustring s = "";
530  if (v < 0.0) {
531  v = -v;
532  s = " R";
533  } else if (v > 0.0) {
534  s = " L";
535  }
536  // boost::format does not support "%*f"
537  Glib::ustring fmt = (boost::format("%%.%df%%s") % wDelay_delta->property_digits()).str();
538  return (boost::format(fmt) % v % s).str();
539 }
540 
541 void IRWindow::on_max_scale_reached(bool v) {
542  wIncr->set_sensitive(not v);
543 }
544 
545 void IRWindow::on_min_scale_reached(bool v) {
546  wDecr->set_sensitive(not v);
547 }
548 
549 void IRWindow::on_open() {
550  static Glib::ustring hostname = "localhost";
551  if (! machine.get_jack()) {
552  hostname = Gio::Resolver::get_default()->lookup_by_address
553  (Gio::InetAddress::create( machine.get_options().get_rpcaddress()));
554  }
555  Glib::ustring title = hostname + ": Select Impulse Response";
556  Gtk::FileChooserDialog d(*gtk_window, title);
557  d.set_local_only(false);
558  d.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
559  d.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
560  d.add_shortcut_folder_uri(Glib::filename_to_uri(GX_SOUND_BPA_DIR, hostname));
561  d.add_shortcut_folder_uri(Glib::filename_to_uri(GX_SOUND_BPB_DIR, hostname));
562  d.add_shortcut_folder_uri(Glib::filename_to_uri(string(getenv("HOME")) + string("/.config/guitarix/IR"), hostname));
563  Gtk::FileFilter wav;
564  wav.set_name("WAV Files");
565  wav.add_mime_type("audio/x-wav");
566  wav.add_mime_type("audio/x-aiff");
567  d.add_filter(wav);
568  Gtk::FileFilter audio;
569  audio.set_name("Audio Files");
570  audio.add_mime_type("audio/*");
571  d.add_filter(audio);
572  Gtk::FileFilter all;
573  all.add_pattern("*");
574  all.set_name("All Files");
575  d.add_filter(all);
576  if (!filename.empty()) {
577  d.set_uri(Glib::filename_to_uri (filename, hostname));
578  } else {
579  d.set_current_folder_uri(Glib::filename_to_uri (string(getenv("HOME")) + string("/"), hostname));
580  }
581  if (d.run() != Gtk::RESPONSE_OK) {
582  return;
583  }
584  filename = Glib::filename_from_uri(d.get_uri(), hostname);
585  Gtk::RecentManager::Data data;
586  bool result_uncertain;
587  data.mime_type = Gio::content_type_guess(filename, "", result_uncertain);
588  data.app_name = "guitarix";
589  data.groups.push_back("impulseresponse");
590  Gtk::RecentManager::get_default()->add_item(d.get_uri(), data);
591  load_data(filename);
592  save_state();
593  reload_impresp_list();
594 }
595 
596 void IRWindow::on_home() {
597  wIredit->home();
598 }
599 
600 void IRWindow::on_jump_zoom_mark() {
601  wIredit->jump_zoom_mark();
602 }
603 
604 void IRWindow::on_decr() {
605  wIredit->decr_scale(0.0);
606 }
607 
608 void IRWindow::on_incr() {
609  wIredit->incr_scale(0.0);
610 }
611 
612 void IRWindow::on_m_delay_changed() {
613  wIredit->set_delay(wDelay->cp_get_int_value());
614 }
615 
616 void IRWindow::on_ms_delay_changed() {
617  wIredit->set_delay(get_ms(wDelay_ms));
618 }
619 
620 void IRWindow::on_m_offset_changed() {
621  wIredit->set_offset(wOffset->cp_get_int_value());
622 }
623 
624 void IRWindow::on_ms_offset_changed() {
625  wIredit->set_offset(get_ms(wOffset_ms));
626 }
627 
628 void IRWindow::on_m_length_changed() {
629  wIredit->set_length(wLength->cp_get_int_value());
630 }
631 
632 void IRWindow::on_ms_length_changed() {
633  wIredit->set_length(get_ms(wLength_ms));
634 }
635 
636 void IRWindow::on_apply_button_clicked() {
637  machine.pluginlist_lookup_plugin(jcp->group_id())->set_on_off(true);
638  save_state();
639 }
640 
641 void IRWindow::destroy_self() {
642  delete this;
643 }
644 
645 void IRWindow::on_window_hide() {
646  Glib::signal_idle().connect(
647  sigc::bind_return(sigc::mem_fun(*this, &IRWindow::destroy_self), false));
648 }
649 
650 void IRWindow::on_cancel_button_clicked() {
651  gtk_window->hide();
652 }
653 
654 void IRWindow::on_ok_button_clicked() {
655  save_state();
656  gtk_window->hide();
657 }
658 
659 void IRWindow::on_preset_popup_clicked() {
660  Glib::ustring name = Glib::path_get_basename(filename);
661  Glib::ustring::size_type n = name.find_last_of('.');
662  if (n != Glib::ustring::npos) {
663  name.erase(n);
664  }
665  save_state();
666  new PluginPresetPopup(machine.pluginlist_lookup_plugin(jcp->group_id())->get_pdef(), machine, name);
667 }
668 
669 void IRWindow::on_help_clicked() {
670  wHelp->show();
671 }
672 
673 void IRWindow::on_gain_button_toggled() {
674  save_state();
675 }
676 
677 bool IRWindow::on_key_press_event(GdkEventKey *event) {
678  if (event->keyval == GDK_KEY_Escape && (event->state & Gtk::AccelGroup::get_default_mod_mask()) == 0) {
679  gtk_window->hide();
680  return true;
681  }
682  return false;
683 }
684 
686  if (gtk_window->get_visible() && !(gtk_window->get_window()->get_state() & Gdk::WINDOW_STATE_ICONIFIED)) {
687  gtk_window->hide();
688  } else {
689  load_state(&jcp->get_value());
690  gtk_window->present();
691  }
692 }
693 
694 } // namespace gx_jconv
#define GDK_KEY_Escape
Definition: guitarix.h:53
Glib::SignalProxy2< void, int, int > signal_length_changed()
Definition: iredit.cc:407
std::string get_builder_filepath(const std::string &basename) const
Definition: gx_system.h:373
const Gainline & getGainline() const
virtual Parameter & get_parameter(const std::string &id)=0
void set_ir_data(float *p1, int p2, int p3, int p4)
Definition: iredit.cc:329
bool set(const GxJConvSettings &val) const
void home()
Definition: iredit.cc:334
Glib::SignalProxy2< void, int, int > signal_delay_changed()
Definition: iredit.cc:395
static IRWindow * create(const std::string &unit_id, Glib::RefPtr< Gdk::Pixbuf > icon, gx_engine::GxMachineBase &machine, Glib::RefPtr< Gtk::AccelGroup > accels, int nchan)
const std::string & getIRDir() const
virtual gx_jack::GxJack * get_jack()=0
sigc::signal< void, const GxJConvSettings * > & signal_changed()
void set_log(bool p1)
Definition: iredit.cc:359
void set_delay(int p1)
Definition: iredit.cc:369
void set_channel(int p1)
Definition: iredit.cc:344
const Glib::ustring & get_rpcaddress()
Definition: gx_system.h:492
void set_length(int p1)
Definition: iredit.cc:389
int get_length()
Definition: iredit.cc:384
void decr_scale(double p1)
Definition: iredit.cc:354
sigc::signal< void, const std::string &, std::vector< gx_system::FileName > > & signal_impresp_list()
Definition: machine.h:183
std::string group_id() const
Definition: gx_parameter.h:132
void cp_set_value(double value)
Glib::SignalProxy1< void, bool > signal_scale_max_reached()
Definition: iredit.cc:413
Gainline get_gain()
Definition: iredit.cc:42
void jump_zoom_mark()
Definition: iredit.cc:339
const std::string & getIRFile() const
void set_offset(int p1)
Definition: iredit.cc:379
Glib::SignalProxy1< Glib::ustring, double > signal_format_value()
Definition: regler.cc:510
virtual gx_system::CmdlineOptions & get_options() const =0
Glib::SignalProxy1< void, bool > signal_scale_min_reached()
Definition: iredit.cc:419
const GxJConvSettings & get_value() const
Glib::SignalProxy2< void, int, int > signal_offset_changed()
Definition: iredit.cc:401
int get_offset()
Definition: iredit.cc:374
virtual void stdJSON_value()=0
void setGainline(const Gainline &gain)
void set_state(float *data, int chan, int data_len, int samplerate, int cutoff_low, int cutoff_high, int offset, const Gainline &gain)
Definition: iredit.cc:33
virtual Plugin * pluginlist_lookup_plugin(const std::string &id) const =0
void incr_scale(double p1)
Definition: iredit.cc:349
virtual void load_impresp_dirs(std::vector< gx_system::FileName > &dirs)=0
virtual void setJSON_value()=0
virtual bool read_audio(const std::string &filename, unsigned int *audio_size, int *audio_chan, int *audio_type, int *audio_form, int *audio_rate, float **buffer)=0
int get_delay()
Definition: iredit.cc:364
virtual void reload_impresp_list(const std::string &path)=0
static void compute_interpolation(double &fct, double &gp, unsigned int &idx, const Gainline &points, int offset)
Definition: gx_convolver.h:145