#include "Voice.h" void Voice::setup(Receiver &receiver) { _font = Font(_font_name, _size); _tex = gl::TextureFont::create(_font); _tex_name = gl::TextureFont::create(_font); /*- NET -*/ receiver.setListener(_channel + "/utterance", [&](const osc::Message &m){ std::lock_guard lock(_utterance_mutex); std::string u = m[0].string(); if(_utterance != u) { _utterance = u; _utterance_cb(this); } }); receiver.setListener(_channel + "/calculate", [&](const osc::Message &m){ std::lock_guard lock(_utterance_mutex); std::string u = m[0].string(); vec2 v = _tex->measureStringWrapped(u, _bounds); int h = _bounds.getHeight(); if(v.y > h) { console() << "Texture too large for screen..." << endl; } else { _offset.y = (h - v.y) / 2; console() << "Texture offset = " << _offset.y << endl; } }); receiver.setListener(_channel + "/temperature", [&](const osc::Message &m){ std::lock_guard lock(_temperatue_mutex); float t = m[0].flt(); if(_temperature != t) _temperature = t; }); receiver.setListener(_channel + "/font/color", [&](const osc::Message &m){ std::lock_guard 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 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 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 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); _tex_name = gl::TextureFont::create(_font); _update_font = false; } } void Voice::draw(Rectf &bounds, bool name, bool debug) { // gl::color(_color); if(name && debug) { _tex_name->drawStringWrapped(_name + " " + std::to_string(_temperature), bounds); } else if(name) _tex_name->drawStringWrapped(_name, bounds); _tex->drawStringWrapped(_utterance, bounds + _offset); if(debug) { gl::color(Color(0, 0, 1)); Rectf b = _bounds; b.y1 += _offset.y; b.y2 -= _offset.y; gl::drawStrokedRect(b); } } //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 ); //}