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>
5 // This file is part of ng-jackspa.
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
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>
28 class ControlSlider
: public HScale
31 ControlSlider(state_t
*state
, int port
);
33 void on_value_changed();
37 int main(int argc
, char **argv
)
42 if (!jackspa_init(&state
, argc
, argv
))
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
]) )
54 ( *new Label(state
.descriptor
->PortNames
[i
], ALIGN_RIGHT
),
57 ( *new ControlSlider(&state
, i
), PACK_EXPAND_WIDGET
);
58 slider_box
.pack_start(*box
, PACK_SHRINK
);
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
);
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
);
97 if (LADSPA_IS_HINT_TOGGLED(descriptor
)) {
99 set_increments(1.0, 1.0);
102 if (LADSPA_IS_HINT_INTEGER(descriptor
)) {
103 set_increments(1.0, 1.0);
107 set_increments(0.05, 0.1);
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
:
117 case LADSPA_HINT_DEFAULT_LOW
:
118 *dest
= lower_bound
* 0.75 + upper_bound
* 0.25;
120 case LADSPA_HINT_DEFAULT_MIDDLE
:
121 *dest
= lower_bound
* 0.5 + upper_bound
* 0.5;
123 case LADSPA_HINT_DEFAULT_HIGH
:
124 *dest
= lower_bound
* 0.25 + upper_bound
* 0.75;
126 case LADSPA_HINT_DEFAULT_MAXIMUM
:
129 case LADSPA_HINT_DEFAULT_0
:
132 case LADSPA_HINT_DEFAULT_1
:
135 case LADSPA_HINT_DEFAULT_100
:
138 case LADSPA_HINT_DEFAULT_440
:
145 void ControlSlider::on_value_changed()