Guitarix
gx_sequencer_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_seq {
24 
25 /****************************************************************
26  ** Sequencer Parameter Window
27  */
28 
29 /*
30 ** static class variables and functions
31 */
32 
33 SEQWindow *SEQWindow::create(const std::string& unit_id, gx_engine::GxMachineBase& machine) {
34  Glib::RefPtr<gx_gui::GxBuilder> bld = gx_gui::GxBuilder::create_from_file(
35  machine.get_options().get_builder_filepath("Sequencer.glade"), &machine);
36  gx_engine::SeqParameter *tomp = dynamic_cast<gx_engine::SeqParameter*>(&machine.get_parameter("seq.sequencer.tom"));
37  gx_engine::SeqParameter *kickp = dynamic_cast<gx_engine::SeqParameter*>(&machine.get_parameter("seq.sequencer.kick"));
38  gx_engine::SeqParameter *snarep = dynamic_cast<gx_engine::SeqParameter*>(&machine.get_parameter("seq.sequencer.snare"));
39  gx_engine::SeqParameter *hatp = dynamic_cast<gx_engine::SeqParameter*>(&machine.get_parameter("seq.sequencer.hat"));
40  assert(tomp);
41  return new SEQWindow(bld, tomp, kickp, snarep, hatp, machine);
42 }
43 
44 /*
45  ** Constructor
46  */
47 
48 SEQWindow::SEQWindow(const Glib::RefPtr<gx_gui::GxBuilder>& bld,gx_engine::SeqParameter *tomp_,
51  : machine(machine_),
52  builder(bld),
53  tomp(tomp_),
54  kickp(kickp_),
55  snarep(snarep_),
56  hatp(hatp_),
57  gtk_window(0) {
58  bld->get_toplevel("SequencerWindow", gtk_window);
59 
60  init_connect();
61 
62  // reset display
63 }
64 
65 void SEQWindow::init_connect() {
66 
67 
68  builder->find_widget("hbox1", tom_box);
69  builder->find_widget("hbox2", kick_box);
70  builder->find_widget("hbox3", snare_box);
71  builder->find_widget("hbox4", hat_box);
72  builder->find_widget("gxplayhead1", seq_pos);
73  builder->find_widget("gxsmallknob6", seq_count);
74  builder->find_widget("hbox12", preset_button);
75 
76  on_sec_length_changed(false);
77 
78  make_preset_button(preset_button);
79 
80  tomp->signal_changed().connect(sigc::bind(
81  sigc::mem_fun(this, &SEQWindow::seq_changed), tom_box));
82  kickp->signal_changed().connect(sigc::bind(
83  sigc::mem_fun(this, &SEQWindow::seq_changed), kick_box));
84  snarep->signal_changed().connect(sigc::bind(
85  sigc::mem_fun(this, &SEQWindow::seq_changed), snare_box));
86  hatp->signal_changed().connect(sigc::bind(
87  sigc::mem_fun(this, &SEQWindow::seq_changed), hat_box));
88 
89  Glib::ListHandle<Gtk::Widget*> tomList = tom_box->get_children();
90  for (Glib::ListHandle<Gtk::Widget*>::iterator itt = tomList.begin();itt != tomList.end(); ++itt) {
91  dynamic_cast<Gtk::ToggleButton*>((*itt))->signal_clicked().connect(
92  sigc::bind(sigc::bind(sigc::mem_fun(this, &SEQWindow::on_seq_button_clicked),tomp),tom_box));
93  }
94 
95  Glib::ListHandle<Gtk::Widget*> kickList = kick_box->get_children();
96  for (Glib::ListHandle<Gtk::Widget*>::iterator itt = kickList.begin();itt != kickList.end(); ++itt) {
97  dynamic_cast<Gtk::ToggleButton*>((*itt))->signal_clicked().connect(
98  sigc::bind(sigc::bind(sigc::mem_fun(this, &SEQWindow::on_seq_button_clicked),kickp),kick_box));
99  }
100 
101  Glib::ListHandle<Gtk::Widget*> snareList = snare_box->get_children();
102  for (Glib::ListHandle<Gtk::Widget*>::iterator itt = snareList.begin();itt != snareList.end(); ++itt) {
103  dynamic_cast<Gtk::ToggleButton*>((*itt))->signal_clicked().connect(
104  sigc::bind(sigc::bind(sigc::mem_fun(this, &SEQWindow::on_seq_button_clicked),snarep),snare_box));
105  }
106 
107  Glib::ListHandle<Gtk::Widget*> hatList = hat_box->get_children();
108  for (Glib::ListHandle<Gtk::Widget*>::iterator itt = hatList.begin();itt != hatList.end(); ++itt) {
109  dynamic_cast<Gtk::ToggleButton*>((*itt))->signal_clicked().connect(
110  sigc::bind(sigc::bind(sigc::mem_fun(this, &SEQWindow::on_seq_button_clicked),hatp),hat_box));
111  }
112 
113  seq_pos->cp_set_value(0.0);
114  std::string id;
115  seq_pos->get_property("var_id",id);
116  Glib::signal_timeout().connect(sigc::bind<Gxw::Regler*>(sigc::bind<const std::string>(
117  sigc::mem_fun(*this, &SEQWindow::get_sequencer_pos),id), seq_pos), 60);
118 
119  seq_count->signal_value_changed().connect(sigc::bind(sigc::mem_fun(*this,
120  &SEQWindow::on_sec_length_changed), true));
121 
122  gtk_window->signal_key_press_event().connect(
123  sigc::mem_fun(this, &SEQWindow::on_key_press_event));
124 }
125 
126 void SEQWindow::make_preset_button(Gtk::HBox * box) {
127  Gtk::Button *p = new Gtk::Button();
128  Gtk::Image *l = new Gtk::Image(Gdk::Pixbuf::create_from_file(machine.get_options().get_style_filepath("rack_preset.png")));
129  p->add(*Gtk::manage(l));
130  p->set_can_default(false);
131  p->set_can_focus(false);
132  p->set_tooltip_text(_("manage effect unit presets"));
133  p->set_name("effect_on_off");
134  box->pack_start(*Gtk::manage(p),Gtk::PACK_SHRINK);
135  p->signal_clicked().connect(
136  sigc::mem_fun(*this, &SEQWindow::on_preset_popup_clicked));
137  p->show_all();
138 }
139 
140 void SEQWindow::on_preset_popup_clicked() {
141  new PluginPresetPopup(machine.pluginlist_lookup_plugin("seq")->get_pdef(), machine);
142 }
143 
144 void SEQWindow::on_sec_length_changed(bool update) {
145  static int r_save = 24;
146  int r = int(seq_count->cp_get_value());
147  if ( r_save > r) {
148  remove_seq_block(tom_box, r);
149  remove_seq_block(kick_box, r);
150  remove_seq_block(snare_box, r);
151  remove_seq_block(hat_box, r);
152  r_save = r;
153  } else if( r_save < r) {
154  append_seq_block(tom_box,tomp, r,r_save);
155  append_seq_block(kick_box,kickp, r,r_save);
156  append_seq_block(snare_box,snarep, r,r_save);
157  append_seq_block(hat_box,hatp, r,r_save);
158  r_save = r;
159  }
160  if (update) {
161  on_seq_button_clicked(tom_box,tomp);
162  on_seq_button_clicked(kick_box,kickp);
163  on_seq_button_clicked(snare_box,snarep);
164  on_seq_button_clicked(hat_box,hatp);
165  }
166 }
167 
168 
169 void SEQWindow::append_seq_block(Gtk::HBox * box, gx_engine::SeqParameter *p, int r, int r_save) {
170  Gtk::ToggleButton * ab;
171  for(int j = r_save; j<r; ++j) {
172  ab = new Gtk::ToggleButton();
173  box->pack_start(*Gtk::manage(ab),Gtk::PACK_EXPAND_WIDGET);
174  ab->signal_clicked().connect(
175  sigc::bind(sigc::bind(sigc::mem_fun(this, &SEQWindow::on_seq_button_clicked),p),box));
176  ab->show();
177  }
178 }
179 
180 void SEQWindow::remove_seq_block(Gtk::HBox * box, int r) {
181  Glib::ListHandle<Gtk::Widget*> boxList = box->get_children();
182  int i = 0;
183  for (Glib::ListHandle<Gtk::Widget*>::iterator itt = boxList.begin();itt != boxList.end(); ++itt) {
184  if (i>=r) {
185  box->remove(*(*itt));
186  delete((*itt));
187  }
188  ++i;
189  }
190 }
191 
192 bool SEQWindow::get_sequencer_pos(Gxw::Regler * regler, const std::string id) {
193  if (machine.parameter_hasId(id)) {
194  if (machine.get_parameter_value<bool>(id.substr(0,id.find_last_of(".")+1)+"on_off")) {
195  machine.signal_parameter_value<float>(id)(machine.get_parameter_value<float>(id));
196  }
197  return true;
198  } else {
199  return false;
200  }
201 }
202 
203 bool SEQWindow::on_key_press_event(GdkEventKey *event) {
204  return true;
205 }
206 
207 void SEQWindow::on_seq_button_clicked(Gtk::HBox *box, gx_engine::SeqParameter *p) {
208  std::vector<int> sequence;
210  Glib::ListHandle<Gtk::Widget*> seqList = box->get_children();
211  for (Glib::ListHandle<Gtk::Widget*>::iterator itt = seqList.begin();itt != seqList.end(); ++itt) {
212  sequence.push_back(dynamic_cast<Gtk::ToggleButton*>((*itt))->get_active());
213  }
214  seqc.setseqline(sequence);
215  p->set(seqc);
216 }
217 
218 void SEQWindow::seq_changed(const gx_engine::GxSeqSettings* seqc, Gtk::HBox *box) {
219 
220  Glib::ListHandle<Gtk::Widget*> seqList = box->get_children();
221  Glib::ListHandle<Gtk::Widget*>::iterator itt = seqList.begin();
222  std::vector<int> sequence = seqc->getseqline();
223  for (std::vector<int>::const_iterator i = sequence.begin(); i != sequence.end(); ++i) {
224  if (itt == seqList.end()) break;
225  dynamic_cast<Gtk::ToggleButton*>((*itt))->set_active(*i);
226  ++itt;
227  }
228 }
229 
231  if (gtk_window->get_visible() && !(gtk_window->get_window()->get_state() & Gdk::WINDOW_STATE_ICONIFIED)) {
232  gtk_window->hide();
233  } else {
234  seq_changed(&tomp->get_value(), tom_box);
235  seq_changed(&kickp->get_value(), kick_box);
236  seq_changed(&snarep->get_value(), snare_box);
237  seq_changed(&hatp->get_value(), hat_box);
238  gtk_window->present();
239  }
240 }
241 
242 SEQWindow::~SEQWindow() {
243  delete gtk_window;
244 }
245 
246 } // end namespace
void setseqline(const std::vector< int > &seq)
PluginDef * get_pdef()
const std::vector< int > & getseqline() const
std::string get_builder_filepath(const std::string &basename) const
Definition: gx_system.h:373
virtual Parameter & get_parameter(const std::string &id)=0
static SEQWindow * create(const std::string &unit_id, gx_engine::GxMachineBase &machine)
bool set(const GxSeqSettings &val) const
std::string get_style_filepath(const std::string &basename) const
Definition: gx_system.h:461
void cp_set_value(double value)
T get_parameter_value(const std::string &id)
virtual bool parameter_hasId(const char *p)=0
virtual gx_system::CmdlineOptions & get_options() const =0
virtual Plugin * pluginlist_lookup_plugin(const std::string &id) const =0
sigc::signal< void, const GxSeqSettings * > & signal_changed()
sigc::signal< void, T > & signal_parameter_value(const std::string &id)
const GxSeqSettings & get_value() const