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/scrolledwindow.h>
20 #include <gtkmm/box.h>
21 #include <gtkmm/label.h>
22 #include <gtkmm/main.h>
23 #include <gtkmm/adjustment.h>
24 #include <gtkmm/scale.h>
25 #include <gtkmm/window.h>
29 class ControlSlider
: public HScale
32 ControlSlider(state_t
*state
, int port
);
34 void on_value_changed();
38 int main(int argc
, char **argv
)
43 if (!jackspa_init(&state
, argc
, argv
))
46 ScrolledWindow scroll
;
47 scroll
.set_policy(POLICY_AUTOMATIC
, POLICY_AUTOMATIC
);
50 (*new Label(state
.descriptor
->Name
, 0.0, 0.5, false), PACK_SHRINK
);
52 for (int i
= 0; i
< (int)state
.descriptor
->PortCount
; i
++)
53 if ( LADSPA_IS_PORT_INPUT(state
.descriptor
->PortDescriptors
[i
]) &&
54 LADSPA_IS_PORT_CONTROL(state
.descriptor
->PortDescriptors
[i
]) )
59 ( *new Label(state
.descriptor
->PortNames
[i
], ALIGN_RIGHT
),
62 ( *new ControlSlider(&state
, i
), PACK_EXPAND_WIDGET
);
63 slider_box
.pack_start(*box
, PACK_SHRINK
);
67 scroll
.add(slider_box
);
68 main_window
.add(scroll
);
69 main_window
.resize(400, main_window
.get_height());
70 main_window
.set_title(state
.client_name
);
71 main_window
.show_all_children();
73 Main::run(main_window
);
78 ControlSlider::ControlSlider(state_t
*state
, int port
)
80 LADSPA_PortRangeHint hint
= state
->descriptor
->PortRangeHints
[port
];
81 LADSPA_PortRangeHintDescriptor descriptor
= hint
.HintDescriptor
;
82 float lower_bound
= hint
.LowerBound
;
83 float upper_bound
= hint
.UpperBound
;
85 set_update_policy(UPDATE_DISCONTINUOUS
);
86 dest
= &state
->control_port_values
[port
];
88 if (LADSPA_IS_HINT_SAMPLE_RATE(descriptor
)) {
89 int sample_rate
= jack_get_sample_rate(state
->jack_client
);
90 lower_bound
*= sample_rate
;
91 upper_bound
*= sample_rate
;
94 if ( LADSPA_IS_HINT_BOUNDED_BELOW(descriptor
) &&
95 LADSPA_IS_HINT_BOUNDED_ABOVE(descriptor
) )
96 set_range(lower_bound
, upper_bound
);
97 else if (LADSPA_IS_HINT_BOUNDED_BELOW(descriptor
))
98 set_range(lower_bound
, 1.0);
99 else if (LADSPA_IS_HINT_BOUNDED_ABOVE(descriptor
))
100 set_range(0.0, upper_bound
);
102 set_range(-1.0, 1.0);
104 if (LADSPA_IS_HINT_TOGGLED(descriptor
)) {
106 set_increments(1.0, 1.0);
109 if (LADSPA_IS_HINT_INTEGER(descriptor
)) {
110 set_increments(1.0, 1.0);
114 set_increments(0.05, 0.1);
118 *dest
= get_adjustment()->get_lower();
119 if (LADSPA_IS_HINT_HAS_DEFAULT(descriptor
))
120 switch (descriptor
& LADSPA_HINT_DEFAULT_MASK
) {
121 case LADSPA_HINT_DEFAULT_MINIMUM
:
124 case LADSPA_HINT_DEFAULT_LOW
:
125 *dest
= lower_bound
* 0.75 + upper_bound
* 0.25;
127 case LADSPA_HINT_DEFAULT_MIDDLE
:
128 *dest
= lower_bound
* 0.5 + upper_bound
* 0.5;
130 case LADSPA_HINT_DEFAULT_HIGH
:
131 *dest
= lower_bound
* 0.25 + upper_bound
* 0.75;
133 case LADSPA_HINT_DEFAULT_MAXIMUM
:
136 case LADSPA_HINT_DEFAULT_0
:
139 case LADSPA_HINT_DEFAULT_1
:
142 case LADSPA_HINT_DEFAULT_100
:
145 case LADSPA_HINT_DEFAULT_440
:
152 void ControlSlider::on_value_changed()