njackspa: only highlight the alternate value of the selected control
[ng-jackspa.git] / gjackspa.cpp
blobf392a81e21aa63958a62c945395d7ca92389b82e
1 // gjackspa.cpp - simple GTK+ LADSPA host for the Jack Audio Connection Kit
2 // Copyright © 2007 Nick Thomas
3 // Copyright © 2013 Géraud Meyer <graud@gmx.com>
4 //
5 // This file is part of ng-jackspa.
6 //
7 // ng-jackspa is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU General Public License version 2 as published by the
9 // Free Software Foundation.
11 // This program is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // more details.
16 // You should have received a copy of the GNU General Public License along
17 // with ng-jackspa. If not, see <http://www.gnu.org/licenses/>.
19 #include <gtkmm/box.h>
20 #include <gtkmm/label.h>
21 #include <gtkmm/main.h>
22 #include <gtkmm/adjustment.h>
23 #include <gtkmm/scale.h>
24 #include <gtkmm/window.h>
25 #include "jackspa.h"
26 using namespace Gtk;
28 class ControlSlider : public HScale
30 public:
31 ControlSlider(state_t *state, int port);
32 private:
33 void on_value_changed();
34 float *dest;
37 int main(int argc, char **argv)
39 Main kit(argc, argv);
41 state_t state;
42 if (!jackspa_init(&state, argc, argv))
43 return 1;
45 VBox slider_box;
47 for (int i = 0; i < (int)state.descriptor->PortCount; i++)
48 if ( LADSPA_IS_PORT_INPUT(state.descriptor->PortDescriptors[i]) &&
49 LADSPA_IS_PORT_CONTROL(state.descriptor->PortDescriptors[i]) )
51 HBox *box = new HBox;
52 box->set_spacing(10);
53 box->pack_start
54 ( *new Label(state.descriptor->PortNames[i], ALIGN_RIGHT),
55 PACK_SHRINK );
56 box->pack_start
57 ( *new ControlSlider(&state, i), PACK_EXPAND_WIDGET );
58 slider_box.pack_start(*box, PACK_SHRINK);
61 Window main_window;
62 main_window.add(slider_box);
63 main_window.resize(400, main_window.get_height());
64 main_window.set_title(state.client_name);
65 main_window.show_all_children();
67 Main::run(main_window);
69 return 0;
72 ControlSlider::ControlSlider(state_t *state, int port)
74 LADSPA_PortRangeHint hint = state->descriptor->PortRangeHints[port];
75 LADSPA_PortRangeHintDescriptor descriptor = hint.HintDescriptor;
76 float lower_bound = hint.LowerBound;
77 float upper_bound = hint.UpperBound;
79 dest = &state->control_port_values[port];
81 if (LADSPA_IS_HINT_SAMPLE_RATE(descriptor)) {
82 int sample_rate = jack_get_sample_rate(state->jack_client);
83 lower_bound *= sample_rate;
84 upper_bound *= sample_rate;
87 if ( LADSPA_IS_HINT_BOUNDED_BELOW(descriptor) &&
88 LADSPA_IS_HINT_BOUNDED_ABOVE(descriptor) )
89 set_range(lower_bound, upper_bound);
90 else if (LADSPA_IS_HINT_BOUNDED_BELOW(descriptor))
91 set_range(lower_bound, 1.0);
92 else if (LADSPA_IS_HINT_BOUNDED_ABOVE(descriptor))
93 set_range(0.0, upper_bound);
94 else
95 set_range(-1.0, 1.0);
97 if (LADSPA_IS_HINT_TOGGLED(descriptor)) {
98 set_range(0.0, 1.0);
99 set_increments(1.0, 1.0);
102 if (LADSPA_IS_HINT_INTEGER(descriptor)) {
103 set_increments(1.0, 1.0);
104 set_digits(0);
106 else {
107 set_increments(0.05, 0.1);
108 set_digits(2);
111 *dest = get_adjustment()->get_lower();
112 if (LADSPA_IS_HINT_HAS_DEFAULT(descriptor))
113 switch (descriptor & LADSPA_HINT_DEFAULT_MASK) {
114 case LADSPA_HINT_DEFAULT_MINIMUM:
115 *dest = lower_bound;
116 break;
117 case LADSPA_HINT_DEFAULT_LOW:
118 *dest = lower_bound * 0.75 + upper_bound * 0.25;
119 break;
120 case LADSPA_HINT_DEFAULT_MIDDLE:
121 *dest = lower_bound * 0.5 + upper_bound * 0.5;
122 break;
123 case LADSPA_HINT_DEFAULT_HIGH:
124 *dest = lower_bound * 0.25 + upper_bound * 0.75;
125 break;
126 case LADSPA_HINT_DEFAULT_MAXIMUM:
127 *dest = upper_bound;
128 break;
129 case LADSPA_HINT_DEFAULT_0:
130 *dest = 0.0;
131 break;
132 case LADSPA_HINT_DEFAULT_1:
133 *dest = 1.0;
134 break;
135 case LADSPA_HINT_DEFAULT_100:
136 *dest = 100.0;
137 break;
138 case LADSPA_HINT_DEFAULT_440:
139 *dest = 440.0;
140 break;
142 set_value(*dest);
145 void ControlSlider::on_value_changed()
147 *dest = get_value();