1 // jackspa, a dirt-simple LADSPA host for JACK
2 // Copyright (C) 2007 Nick Thomas
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.
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"
26 class ControlSlider
: public HScale
29 ControlSlider(state_t
*state
, int port
);
31 void on_value_changed();
35 int main(int argc
, char **argv
)
40 jackspa_init(&state
, argc
, argv
);
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
])) {
49 box
->pack_start(*new Label(state
.descriptor
->PortNames
[i
],
50 ALIGN_RIGHT
), PACK_SHRINK
);
51 box
->pack_start(*new ControlSlider(&state
, i
),
53 slider_box
.pack_start(*box
, PACK_SHRINK
);
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
);
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
;
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
);
95 if (LADSPA_IS_HINT_TOGGLED(descriptor
)) {
97 set_increments(1.0, 1.0);
100 if (LADSPA_IS_HINT_INTEGER(descriptor
)) {
101 set_increments(1.0, 1.0);
104 set_increments(0.05, 0.1);
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
;
113 case LADSPA_HINT_DEFAULT_LOW
:
114 default_value
= lower_bound
* 0.75 + upper_bound
* 0.25;
116 case LADSPA_HINT_DEFAULT_MIDDLE
:
117 default_value
= lower_bound
* 0.5 + upper_bound
* 0.5;
119 case LADSPA_HINT_DEFAULT_HIGH
:
120 default_value
= lower_bound
* 0.5 + upper_bound
* 0.5;
122 case LADSPA_HINT_DEFAULT_MAXIMUM
:
123 default_value
= upper_bound
;
125 case LADSPA_HINT_DEFAULT_0
:
128 case LADSPA_HINT_DEFAULT_1
:
131 case LADSPA_HINT_DEFAULT_100
:
132 default_value
= 100.0;
134 case LADSPA_HINT_DEFAULT_440
:
135 default_value
= 440.0;
139 *dest
= default_value
;
143 void ControlSlider::on_value_changed()