GUI tweaks.
[ng-jackspa.git] / gui.cpp
blob695643205f2a970414b33493db59e89a0a626dc8
1 // jackspa, a dirt-simple LADSPA host for JACK
2 // Copyright (C) 2007 Nick Thomas
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of version 2 of the GNU General Public
6 // License as published by the Free Software Foundation; the terms of
7 // any later version are NOT APPLICABLE.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 #include <gtkmm/box.h>
19 #include <gtkmm/label.h>
20 #include <gtkmm/main.h>
21 #include <gtkmm/scale.h>
22 #include <gtkmm/window.h>
23 #include "jackspa.hpp"
24 using namespace Gtk;
26 class ControlSlider : public HScale
28 public:
29 ControlSlider(state_t *state, int port);
30 private:
31 void on_value_changed();
32 float *dest;
35 int main(int argc, char **argv)
37 Main kit(argc, argv);
39 state_t state;
40 jackspa_init(&state, argc, argv);
42 VBox slider_box;
44 for (int i = 0; i < (int)state.descriptor->PortCount; i++) {
45 if (LADSPA_IS_PORT_INPUT(state.descriptor->PortDescriptors[i]) &&
46 LADSPA_IS_PORT_CONTROL(state.descriptor->PortDescriptors[i])) {
47 HBox *box = new HBox;
48 box->set_spacing(10);
49 box->pack_start(*new Label(state.descriptor->PortNames[i],
50 ALIGN_RIGHT), PACK_SHRINK);
51 box->pack_start(*new ControlSlider(&state, i),
52 PACK_EXPAND_WIDGET);
53 slider_box.pack_start(*box, PACK_SHRINK);
57 Window main_window;
58 main_window.add(slider_box);
59 main_window.resize(400, main_window.get_height());
60 main_window.set_title(state.client_name);
61 main_window.show_all_children();
63 Main::run(main_window);
65 return 0;
68 ControlSlider::ControlSlider(state_t *state, int port)
70 LADSPA_PortRangeHint hint = state->descriptor->PortRangeHints[port];
71 LADSPA_PortRangeHintDescriptor descriptor = hint.HintDescriptor;
72 float lower_bound = hint.LowerBound;
73 float upper_bound = hint.UpperBound;
74 float default_value;
76 dest = &state->control_port_values[port];
78 if (LADSPA_IS_HINT_SAMPLE_RATE(descriptor)) {
79 int sample_rate = jack_get_sample_rate(state->jack_client);
80 lower_bound *= sample_rate;
81 upper_bound *= sample_rate;
84 if (LADSPA_IS_HINT_BOUNDED_BELOW(descriptor) &&
85 LADSPA_IS_HINT_BOUNDED_ABOVE(descriptor)) {
86 set_range(lower_bound, upper_bound);
87 } else if (LADSPA_IS_HINT_BOUNDED_BELOW(descriptor)) {
88 set_range(lower_bound, 1.0);
89 } else if (LADSPA_IS_HINT_BOUNDED_ABOVE(descriptor)) {
90 set_range(0.0, upper_bound);
91 } else {
92 set_range(-1.0, 1.0);
95 if (LADSPA_IS_HINT_TOGGLED(descriptor)) {
96 set_range(0.0, 1.0);
97 set_increments(1.0, 1.0);
100 if (LADSPA_IS_HINT_INTEGER(descriptor)) {
101 set_increments(1.0, 1.0);
102 set_digits(0);
103 } else {
104 set_increments(0.05, 0.1);
105 set_digits(2);
108 if (LADSPA_IS_HINT_HAS_DEFAULT(descriptor)) {
109 switch (descriptor & LADSPA_HINT_DEFAULT_MASK) {
110 case LADSPA_HINT_DEFAULT_MINIMUM:
111 default_value = lower_bound;
112 break;
113 case LADSPA_HINT_DEFAULT_LOW:
114 default_value = lower_bound * 0.75 + upper_bound * 0.25;
115 break;
116 case LADSPA_HINT_DEFAULT_MIDDLE:
117 default_value = lower_bound * 0.5 + upper_bound * 0.5;
118 break;
119 case LADSPA_HINT_DEFAULT_HIGH:
120 default_value = lower_bound * 0.5 + upper_bound * 0.5;
121 break;
122 case LADSPA_HINT_DEFAULT_MAXIMUM:
123 default_value = upper_bound;
124 break;
125 case LADSPA_HINT_DEFAULT_0:
126 default_value = 0.0;
127 break;
128 case LADSPA_HINT_DEFAULT_1:
129 default_value = 1.0;
130 break;
131 case LADSPA_HINT_DEFAULT_100:
132 default_value = 100.0;
133 break;
134 case LADSPA_HINT_DEFAULT_440:
135 default_value = 440.0;
136 break;
139 *dest = default_value;
143 void ControlSlider::on_value_changed()
145 *dest = get_value();