version/1.0
[ng-jackspa.git] / gjackspa.cpp
blobf253031b6b3c856ab71a389d3e88194525cd5204
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 ~ControlWidget();
39 void on_button_pressed();
40 void exchange_control();
42 protected:
43 HScale slider;
44 Label label;
45 Button button;
46 VBox box;
47 control_t control;
48 void on_value_changed();
51 int main(int argc, char **argv)
53 Main kit(argc, argv,
54 *new Glib::OptionContext(interface_context(), true));
56 state_t state;
57 if (!jackspa_init(&state, argc, argv)) {
58 if (verbose) {
59 MessageDialog dialog( "Cannot initialise jackspa", false,
60 MESSAGE_ERROR, BUTTONS_CLOSE, true );
61 dialog.set_title(PACKAGE_NAME " error");
62 dialog.set_position(WIN_POS_CENTER);
63 dialog.run();
65 return 1;
68 VBox slider_box(true, 4);
70 Button button("_Def", true);
71 Button toggle("_Xch", true);
73 HBox *box = new HBox;
74 box->set_spacing(10);
75 VBox *button_box = new VBox;
76 button_box->set_spacing(0);
77 button_box->pack_start(button, PACK_SHRINK);
78 button_box->pack_start(toggle, PACK_SHRINK);
79 box->pack_start(*manage(button_box), PACK_SHRINK);
80 box->pack_start
81 (*manage(new Label(state.descriptor->Name, 0.0, 0.5, false)), PACK_SHRINK);
82 slider_box.pack_start(*manage(box), PACK_SHRINK);
84 for (unsigned long p = 0, c = 0; p < state.descriptor->PortCount; p++)
85 if ( LADSPA_IS_PORT_INPUT(state.descriptor->PortDescriptors[p]) &&
86 LADSPA_IS_PORT_CONTROL(state.descriptor->PortDescriptors[p]) )
88 ControlWidget *control = new ControlWidget(&state, p, c++);
89 slider_box.pack_start(*manage(control), PACK_SHRINK);
91 button.signal_pressed().connect
92 (sigc::mem_fun(control, &ControlWidget::on_button_pressed));
93 button.signal_activate().connect
94 (sigc::mem_fun(control, &ControlWidget::on_button_pressed));
95 toggle.signal_pressed().connect
96 (sigc::mem_fun(control, &ControlWidget::exchange_control));
97 toggle.signal_activate().connect
98 (sigc::mem_fun(control, &ControlWidget::exchange_control));
101 ScrolledWindow scroll;
102 scroll.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC);
103 scroll.set_border_width(1);
104 scroll.add(slider_box);
105 Window main_window;
106 main_window.add(scroll);
107 main_window.resize(400, main_window.get_height());
108 main_window.set_title(state.client_name);
109 main_window.show_all_children();
111 Main::run(main_window);
113 jackspa_fini(&state);
115 return 0;
118 ControlWidget::ControlWidget(state_t *state, unsigned long port, unsigned long ctrl) :
119 HBox(false, 10),
120 label("", ALIGN_LEFT),
121 button("Def"),
122 box(false, 0)
124 control_init(&control, state, port, ctrl);
125 label.set_text(control.name);
126 slider.set_range(control.min, control.max);
127 slider.set_value(*control.val);
128 slider.set_increments(control.inc.fine, control.inc.coarse);
129 if (control.type == JACKSPA_INT || control.type == JACKSPA_TOGGLE)
130 slider.set_digits(0);
131 else
132 slider.set_digits(2);
134 slider.set_update_policy(UPDATE_DISCONTINUOUS);
135 pack_start(button, PACK_SHRINK);
136 pack_start(box, PACK_EXPAND_WIDGET);
137 box.pack_start(label, PACK_EXPAND_WIDGET);
138 box.pack_start(slider, PACK_EXPAND_WIDGET);
139 slider.signal_value_changed().connect
140 (sigc::mem_fun(*this, &ControlWidget::on_value_changed));
141 button.signal_pressed().connect
142 (sigc::mem_fun(*this, &ControlWidget::on_button_pressed));
145 ControlWidget::~ControlWidget()
147 control_fini(&control);
150 void ControlWidget::on_value_changed()
152 *control.val = slider.get_value();
155 void ControlWidget::on_button_pressed()
157 if (control.def) slider.set_value(*control.def);
160 void ControlWidget::exchange_control()
162 control_exchange(&control);
163 slider.set_value(*control.val);