119 lines
3.1 KiB
C++
119 lines
3.1 KiB
C++
|
|
#include "Voice.h"
|
||
|
|
|
||
|
|
void Voice::setup(Receiver &receiver)
|
||
|
|
{
|
||
|
|
_font = Font(_font_name, _size);
|
||
|
|
_tex = gl::TextureFont::create(_font);
|
||
|
|
|
||
|
|
/*- NET -*/
|
||
|
|
receiver.setListener(_channel + "/utterance",
|
||
|
|
[&](const osc::Message &m){
|
||
|
|
std::lock_guard<std::mutex> lock(_utterance_mutex);
|
||
|
|
std::string u = m[0].string();
|
||
|
|
if(_utterance != u) {
|
||
|
|
_utterance = u;
|
||
|
|
_utterance_cb(this);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
receiver.setListener(_channel + "/font/color",
|
||
|
|
[&](const osc::Message &m){
|
||
|
|
std::lock_guard<std::mutex> lock(_color_mutex);
|
||
|
|
float a = m[0].flt();
|
||
|
|
float r = m[1].flt();
|
||
|
|
float g = m[2].flt();
|
||
|
|
float b = m[3].flt();
|
||
|
|
ColorA c(r, g, b, a);
|
||
|
|
if(_color != c) {
|
||
|
|
_color = c;
|
||
|
|
_change_cb(this);
|
||
|
|
console() << _name << ": change color" << endl;
|
||
|
|
console() << r << ", " << g << ", " << b << ", " << a << endl;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
receiver.setListener(_channel + "/background",
|
||
|
|
[&](const osc::Message &m){
|
||
|
|
std::lock_guard<std::mutex> lock(_color_mutex);
|
||
|
|
float a = m[0].flt();
|
||
|
|
float r = m[1].flt();
|
||
|
|
float g = m[2].flt();
|
||
|
|
float b = m[3].flt();
|
||
|
|
ColorA c(r, g, b, a);
|
||
|
|
if(_background != c) {
|
||
|
|
_background = c;
|
||
|
|
_change_cb(this);
|
||
|
|
console() << _name << ": change background" << endl;
|
||
|
|
console() << r << ", " << g << ", " << b << ", " << a << endl;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
receiver.setListener(_channel + "/font/size",
|
||
|
|
[&](const osc::Message &m){
|
||
|
|
std::lock_guard<std::mutex> lock(_font_mutex);
|
||
|
|
int s = m[0].int32();
|
||
|
|
if(_size != s) {
|
||
|
|
_size = s;
|
||
|
|
_change_cb(this);
|
||
|
|
_update_font = true;
|
||
|
|
console() << _name << ": change font size" << endl;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
receiver.setListener(_channel + "/font/type",
|
||
|
|
[&](const osc::Message &m){
|
||
|
|
std::lock_guard<std::mutex> lock(_font_mutex);
|
||
|
|
std::string type = m[0].string();
|
||
|
|
if(_font.getName() != type) {
|
||
|
|
_font_name = type;
|
||
|
|
_change_cb(this);
|
||
|
|
_update_font = true;
|
||
|
|
console() << _name << ": change font type" << endl;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void Voice::update()
|
||
|
|
{
|
||
|
|
if(_update_font){
|
||
|
|
// need to check if the font name is valide... bof...
|
||
|
|
_font = Font(_font_name, _size);
|
||
|
|
_tex = gl::TextureFont::create(_font);
|
||
|
|
_update_font = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void Voice::draw(Rectf &bounds)
|
||
|
|
{
|
||
|
|
// gl::color(_color);
|
||
|
|
vec2 offset = vec2(0);
|
||
|
|
_tex->drawStringWrapped(_utterance, bounds + offset);
|
||
|
|
}
|
||
|
|
|
||
|
|
void VoiceAloud::setup()
|
||
|
|
{
|
||
|
|
auto ctx = audio::master();
|
||
|
|
|
||
|
|
mFilter = ctx->makeNode( new audio::FilterLowPassNode );
|
||
|
|
mGen = ctx->makeNode( new audio::GenSineNode );
|
||
|
|
mGain = ctx->makeNode( new audio::GainNode );
|
||
|
|
|
||
|
|
mGen->setFreq( _freq );
|
||
|
|
mFilter->setCutoffFreq(_freq / 2);
|
||
|
|
mFilter->setResonance(0.5f);
|
||
|
|
mGain->setValue( _amp );
|
||
|
|
|
||
|
|
mGen >> mFilter >> mGain >> ctx->getOutput();
|
||
|
|
mGen->enable();
|
||
|
|
|
||
|
|
ctx->enable();
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void VoiceAloud::update()
|
||
|
|
{
|
||
|
|
mGen->setFreq( _freq );
|
||
|
|
mGain->setValue( _amp );
|
||
|
|
}
|