njackspa: [bug] fix the fields' widths
[ng-jackspa.git] / gjackspa.cpp
blob772113bdd9f3e8febcc38700f4e16941453552d8
1 // gjackspa.cpp - simple GTK+ LADSPA host for the Jack Audio Connection Kit
2 // Copyright © 2013 Géraud Meyer <graud@gmx.com>
3 //
4 // This file is part of ng-jackspa.
5 //
6 // ng-jackspa is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License version 2 as published by the
8 // Free Software Foundation.
9 //
10 // This program is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 // more details.
15 // You should have received a copy of the GNU General Public License along
16 // with ng-jackspa. If not, see <http://www.gnu.org/licenses/>.
18 #include <gtkmm/main.h>
19 #include <gtkmm/messagedialog.h>
20 #include <gtkmm/window.h>
21 #include <gtkmm/scrolledwindow.h>
22 #include <gtkmm/box.h>
23 #include <gtkmm/button.h>
24 #include <gtkmm/label.h>
25 #include <gtkmm/adjustment.h>
26 #include <gtkmm/scale.h>
27 #include "jackspa.h"
28 #include "control.h"
30 #define PROGRAM_NAME "gjackspa"
31 #include "interface.c"
32 using namespace Gtk;
34 class ControlWidget : public HBox
36 public:
37 ControlWidget(state_t *state, unsigned long port, unsigned long ctrl);
38 void on_button_pressed();
39 void exchange_control();
41 protected:
42 HScale slider;
43 Label label;
44 Button button;
45 VBox box;
46 control_t control;
47 void on_value_changed();
50 int main(int argc, char **argv)
52 Main kit(argc, argv,
53 *new Glib::OptionContext(interface_context(), true));
55 state_t state;
56 if (!jackspa_init(&state, argc, argv)) {
57 if (verbose) {
58 MessageDialog dialog( "Cannot initialise jackspa", false,
59 MESSAGE_ERROR, BUTTONS_CLOSE, true );
60 dialog.set_title(PACKAGE_NAME " error");
61 dialog.set_position(WIN_POS_CENTER);
62 dialog.run();
64 return 1;
67 VBox slider_box(true, 4);
69 Button button("_Def", true);
70 Button toggle("_Xch", true);
72 HBox *box = new HBox;
73 box->set_spacing(10);
74 VBox *button_box = new VBox;
75 button_box->set_spacing(0);
76 button_box->pack_start(button, PACK_SHRINK);
77 button_box->pack_start(toggle, PACK_SHRINK);
78 box->pack_start(*manage(button_box), PACK_SHRINK);
79 box->pack_start
80 (*manage(new Label(state.descriptor->Name, 0.0, 0.5, false)), PACK_SHRINK);
81 slider_box.pack_start(*manage(box), PACK_SHRINK);
83 for (unsigned long p = 0, c = 0; p < state.descriptor->PortCount; p++)
84 if ( LADSPA_IS_PORT_INPUT(state.descriptor->PortDescriptors[p]) &&
85 LADSPA_IS_PORT_CONTROL(state.descriptor->PortDescriptors[p]) )
87 ControlWidget *control = new ControlWidget(&state, p, c++);
88 slider_box.pack_start(*manage(control), PACK_SHRINK);
90 button.signal_pressed().connect
91 (sigc::mem_fun(control, &ControlWidget::on_button_pressed));
92 button.signal_activate().connect
93 (sigc::mem_fun(control, &ControlWidget::on_button_pressed));
94 toggle.signal_pressed().connect
95 (sigc::mem_fun(control, &ControlWidget::exchange_control));
96 toggle.signal_activate().connect
97 (sigc::mem_fun(control, &ControlWidget::exchange_control));
100 ScrolledWindow scroll;
101 scroll.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC);
102 scroll.set_border_width(1);
103 scroll.add(slider_box);
104 Window main_window;
105 main_window.add(scroll);
106 main_window.resize(400, main_window.get_height());
107 main_window.set_title(state.client_name);
108 main_window.show_all_children();
110 Main::run(main_window);
112 return 0;
115 ControlWidget::ControlWidget(state_t *state, unsigned long port, unsigned long ctrl) :
116 HBox(false, 10),
117 label("", ALIGN_LEFT),
118 button("Def"),
119 box(false, 0)
121 control_init(&control, state, port, ctrl);
122 label.set_text(control.name);
123 slider.set_range(control.min, control.max);
124 slider.set_value(*control.val);
125 slider.set_increments(control.inc.fine, control.inc.coarse);
126 if (control.type == JACKSPA_INT || control.type == JACKSPA_TOGGLE)
127 slider.set_digits(0);
128 else
129 slider.set_digits(2);
131 slider.set_update_policy(UPDATE_DISCONTINUOUS);
132 pack_start(button, PACK_SHRINK);
133 pack_start(box, PACK_EXPAND_WIDGET);
134 box.pack_start(label, PACK_EXPAND_WIDGET);
135 box.pack_start(slider, PACK_EXPAND_WIDGET);
136 slider.signal_value_changed().connect
137 (sigc::mem_fun(*this, &ControlWidget::on_value_changed));
138 button.signal_pressed().connect
139 (sigc::mem_fun(*this, &ControlWidget::on_button_pressed));
142 void ControlWidget::on_value_changed()
144 *control.val = slider.get_value();
147 void ControlWidget::on_button_pressed()
149 if (control.def) slider.set_value(*control.def);
152 void ControlWidget::exchange_control()
154 control_exchange(&control);
155 slider.set_value(*control.val);