1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
|
/*
LV2 plugin for pitch shifting, pitch correction, vocoding and harmonizing
singing voice
(c) Igor Brkic 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gtkmm.h>
#include <lv2gui.hpp>
#include "vocproc.peg"
#include <iostream>
#include <string.h>
using namespace sigc;
using namespace Gtk;
using namespace std;
// maybe a bit messy but it works
class ScalesHelper {
public:
ScalesHelper(){}
~ScalesHelper(){}
protected:
void scale_change();
};
class VocProcGUI : public LV2::GUI<VocProcGUI>, public ScalesHelper {
public:
VocProcGUI(const std::string& URI) {
refBuilder = Builder::create();
try
{
char tmp2[1024];
strcpy(tmp2, bundle_path());
strcat(tmp2, "vocproc_gui.ui");
refBuilder->add_from_file(tmp2);
}
catch(const Glib::FileError& ex)
{
cerr << "FileError: " << ex.what() << endl;
}
catch(const BuilderError& ex)
{
cerr << "BuilderError: " << ex.what() << endl;
}
HBox *main_box;
refBuilder->get_widget("main_box", main_box);
if(main_box)
{
// -----------------
refBuilder->get_widget("sPitchFactor", s_pitch_factor);
s_pitch_factor->set_range(-12, 12);
s_pitch_factor->set_increments(1, 2);
slot<void> slot_pitch = compose(bind<0>(mem_fun(*this, &VocProcGUI::write_control), p_pitch_factor),
mem_fun(*s_pitch_factor, &VScale::get_value));
s_pitch_factor->signal_value_changed().connect(slot_pitch);
refBuilder->get_widget("sEffect", s_effect);
s_effect->set_range(0, 1);
s_effect->set_increments(0.01, 0.2);
slot<void> slot_effect = compose(bind<0>(mem_fun(*this, &VocProcGUI::write_control), p_effect),
mem_fun(*s_effect, &VScale::get_value));
s_effect->signal_value_changed().connect(slot_effect);
// -----------------
refBuilder->get_widget("cForVoc", c_for_voc);
slot<void> slot_for_voc_switch = compose(bind<0>(mem_fun(*this, &VocProcGUI::write_control), p_fc_voc_switch),
mem_fun(*c_for_voc, &CheckButton::get_active));
c_for_voc->signal_toggled().connect(slot_for_voc_switch);
HBox *b;
#ifndef NO_VOCODER
refBuilder->get_widget("hbox3", b);
d_for_voc=new ComboBoxText();
d_for_voc->append_text("Formant correction");
d_for_voc->append_text("Vocoder");
d_for_voc->set_active(0);
b->pack_start(*d_for_voc);
d_for_voc->show();
slot<void> slot_for_voc = compose(bind<0>(mem_fun(*this, &VocProcGUI::write_control), p_fc_voc),
mem_fun(*d_for_voc, &ComboBoxText::get_active_row_number));
d_for_voc->signal_changed().connect(slot_for_voc);
#else
Label *tmp_l;
refBuilder->get_widget("label2", tmp_l);
tmp_l->set_markup("<b>formant correction</b>");
#endif
// -----------------
refBuilder->get_widget("cAutoTune", c_autotune);
slot<void> slot_autotune = compose(bind<0>(mem_fun(*this, &VocProcGUI::write_control), p_pitch_correction),
mem_fun(*c_autotune, &CheckButton::get_active));
c_autotune->signal_toggled().connect(slot_autotune);
// scales
refBuilder->get_widget("hbox4", b);
d_scales_key=new ComboBoxText();
d_scales_mode=new ComboBoxText();
d_scales_key->append_text("C"); d_scales_key->append_text("C#"); d_scales_key->append_text("D");
d_scales_key->append_text("D#");d_scales_key->append_text("E"); d_scales_key->append_text("F");
d_scales_key->append_text("F#");d_scales_key->append_text("G"); d_scales_key->append_text("G#");
d_scales_key->append_text("A"); d_scales_key->append_text("A#"); d_scales_key->append_text("B");
d_scales_key->set_active(0);
b->pack_start(*d_scales_key);
d_scales_key->show();
d_scales_mode->append_text("Chromatic");
d_scales_mode->append_text("Major");
d_scales_mode->append_text("Minor");
d_scales_mode->append_text("Melodic minor 1");
d_scales_mode->append_text("Melodic minor 2");
d_scales_mode->append_text("Harmonic minor");
d_scales_mode->append_text("Whole tone");
d_scales_mode->append_text("Pentatonic 1");
d_scales_mode->append_text("Pentatonic 2");
d_scales_mode->set_active(0);
b->pack_start(*d_scales_mode);
d_scales_mode->show();
d_scales_key->signal_changed().connect( sigc::mem_fun(*this, &VocProcGUI::scale_change) );
d_scales_mode->signal_changed().connect( sigc::mem_fun(*this, &VocProcGUI::scale_change) );
refBuilder->get_widget("sThreshold", s_threshold);
s_threshold->set_range(0, 1);
s_threshold->set_increments(0.01, 0.1);
slot<void> slot_threshold = compose(bind<0>(mem_fun(*this, &VocProcGUI::write_control), p_threshold),
mem_fun(*s_threshold, &VScale::get_value));
s_threshold->signal_value_changed().connect(slot_threshold);
refBuilder->get_widget("sAttack", s_attack);
s_attack->set_range(0, 1);
s_attack->set_increments(0.01, 0.1);
slot<void> slot_attack = compose(bind<0>(mem_fun(*this, &VocProcGUI::write_control), p_attack),
mem_fun(*s_attack, &VScale::get_value));
s_attack->signal_value_changed().connect(slot_attack);
refBuilder->get_widget("sTranspose", s_transpose);
s_transpose->set_range(-12, 12);
s_transpose->set_increments(1, 2);
slot<void> slot_transpose = compose(bind<0>(mem_fun(*this, &VocProcGUI::write_control), p_transpose),
mem_fun(*s_transpose, &VScale::get_value));
s_transpose->signal_value_changed().connect(slot_transpose);
// next line crashes ardour if enabled (ingen is OK with it)
//scale_change();
// -----------------
add(*main_box);
}
}
void scale_change(){
int params[]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
// intervals
int chromatic[]={11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int major[]={7, 2, 2, 1, 2, 2, 2, 1};
int minor[]={7, 2, 1, 2, 2, 1, 2, 2};
int melodic_minor_1[]={7, 2, 1, 2, 2, 2, 2, 1};
int melodic_minor_2[]={7, 2, 2, 1, 2, 2, 1, 2};
int harmonic_minor[]={7, 2, 1, 2, 2, 1, 3, 1};
int whole_tone[]={5, 2, 2, 2, 2, 2};
int pentatonic_1[]={4, 2, 3, 2, 2};
int pentatonic_2[]={4, 2, 2, 3, 2};
int *mode;
int idx=d_scales_key->get_active_row_number();
switch(d_scales_mode->get_active_row_number()){
case 0:
mode=chromatic;
break;
case 1:
mode=major;
break;
case 2:
mode=minor;
break;
case 3:
mode=melodic_minor_1;
break;
case 4:
mode=melodic_minor_2;
break;
case 5:
mode=harmonic_minor;
break;
case 6:
mode=whole_tone;
break;
case 7:
mode=pentatonic_1;
break;
case 8:
mode=pentatonic_2;
break;
default:
mode=chromatic;
}
params[idx]=1;
for(int i=0;i<mode[0];i++){
idx=(idx+mode[i+1])%12;
params[idx]=1;
}
s_transpose->set_range(-mode[0]-1, mode[0]+1);
if(s_transpose->get_value() < -mode[0]-1) s_transpose->set_value(-mode[0]-1);
if(s_transpose->get_value() > mode[0]+1) s_transpose->set_value(mode[0]+1);
// write controls
for(int i=0;i<12;i++) write_control(p_c+i, params[i]);
}
void port_event(uint32_t port, uint32_t buffer_size, uint32_t format, const void* buffer) {
float val=*static_cast<const float*>(buffer);
switch(port){
case p_pitch_factor:
s_pitch_factor->set_value(val);
break;
case p_effect:
s_effect->set_value(val);
Label *l;
refBuilder->get_widget("l_effect", l);
if(val==0.0) l->set_text("effect off");
else l->set_text("effect");
break;
case p_fc_voc_switch:
if(val<0.5) c_for_voc->set_active(false);
else c_for_voc->set_active(true);
break;
#ifndef NO_VOCODER
case p_fc_voc:
d_for_voc->set_active((int)(val+0.5));
break;
#endif
case p_pitch_correction:
if(val<0.5){
s_pitch_factor->set_sensitive(true);
c_autotune->set_active(false);
}
else{
s_pitch_factor->set_value(0);
s_pitch_factor->set_sensitive(false);
c_autotune->set_active(true);
}
break;
case p_threshold:
s_threshold->set_value(val);
break;
case p_attack:
s_attack->set_value(val);
break;
case p_transpose:
s_transpose->set_value(val);
break;
case p_offset:
refBuilder->get_widget("pLeft", p_left);
refBuilder->get_widget("pCenter", p_center);
refBuilder->get_widget("pRight", p_right);
if(val==-100){
p_left->set_fraction(1.0);
p_center->set_fraction(0.0);
p_right->set_fraction(0.0);
}
else if(val==100){
p_left->set_fraction(0.0);
p_center->set_fraction(0.0);
p_right->set_fraction(1.0);
}
else if(val<0){
p_left->set_fraction(-val/100.0);
p_center->set_fraction(1.0);
p_right->set_fraction(0.0);
}
else if(val>0){
p_left->set_fraction(0.0);
p_center->set_fraction(1.0);
p_right->set_fraction(val/100.0);
}
else if(val==0){
p_left->set_fraction(0.0);
p_center->set_fraction(1.0);
p_right->set_fraction(0.0);
}
break;
}
}
protected:
Glib::RefPtr<Builder> refBuilder;
VScale *s_pitch_factor;
VScale *s_effect;
VScale *s_attack;
VScale *s_threshold;
VScale *s_transpose;
CheckButton *c_for_voc;
CheckButton *c_autotune;
ProgressBar *p_left;
ProgressBar *p_right;
ProgressBar *p_center;
ComboBoxText *d_for_voc;
ComboBoxText *d_scales_key;
ComboBoxText *d_scales_mode;
};
static int _ = VocProcGUI::register_class("http://hyperglitch.com/dev/VocProc/gui");
|