calculate, temp, etc.
This commit is contained in:
parent
554b10a8f7
commit
b4c923408e
@ -4,6 +4,7 @@ void Voice::setup(Receiver &receiver)
|
|||||||
{
|
{
|
||||||
_font = Font(_font_name, _size);
|
_font = Font(_font_name, _size);
|
||||||
_tex = gl::TextureFont::create(_font);
|
_tex = gl::TextureFont::create(_font);
|
||||||
|
_tex_name = gl::TextureFont::create(_font);
|
||||||
|
|
||||||
/*- NET -*/
|
/*- NET -*/
|
||||||
receiver.setListener(_channel + "/utterance",
|
receiver.setListener(_channel + "/utterance",
|
||||||
@ -16,6 +17,30 @@ void Voice::setup(Receiver &receiver)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
receiver.setListener(_channel + "/calculate",
|
||||||
|
[&](const osc::Message &m){
|
||||||
|
std::lock_guard<std::mutex> 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<std::mutex> lock(_temperatue_mutex);
|
||||||
|
float t = m[0].flt();
|
||||||
|
if(_temperature != t) _temperature = t;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
receiver.setListener(_channel + "/font/color",
|
receiver.setListener(_channel + "/font/color",
|
||||||
[&](const osc::Message &m){
|
[&](const osc::Message &m){
|
||||||
std::lock_guard<std::mutex> lock(_color_mutex);
|
std::lock_guard<std::mutex> lock(_color_mutex);
|
||||||
@ -80,39 +105,52 @@ void Voice::update()
|
|||||||
// need to check if the font name is valide... bof...
|
// need to check if the font name is valide... bof...
|
||||||
_font = Font(_font_name, _size);
|
_font = Font(_font_name, _size);
|
||||||
_tex = gl::TextureFont::create(_font);
|
_tex = gl::TextureFont::create(_font);
|
||||||
|
_tex_name = gl::TextureFont::create(_font);
|
||||||
_update_font = false;
|
_update_font = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Voice::draw(Rectf &bounds)
|
void Voice::draw(Rectf &bounds, bool name, bool debug)
|
||||||
{
|
{
|
||||||
// gl::color(_color);
|
// gl::color(_color);
|
||||||
vec2 offset = vec2(0);
|
if(name && debug) {
|
||||||
_tex->drawStringWrapped(_utterance, bounds + offset);
|
|
||||||
|
_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()
|
//void VoiceAloud::setup()
|
||||||
{
|
//{
|
||||||
auto ctx = audio::master();
|
// auto ctx = audio::master();
|
||||||
|
//
|
||||||
mFilter = ctx->makeNode( new audio::FilterLowPassNode );
|
// mFilter = ctx->makeNode( new audio::FilterLowPassNode );
|
||||||
mGen = ctx->makeNode( new audio::GenSineNode );
|
// mGen = ctx->makeNode( new audio::GenSineNode );
|
||||||
mGain = ctx->makeNode( new audio::GainNode );
|
// mGain = ctx->makeNode( new audio::GainNode );
|
||||||
|
//
|
||||||
mGen->setFreq( _freq );
|
// mGen->setFreq( _freq );
|
||||||
mFilter->setCutoffFreq(_freq / 2);
|
// mFilter->setCutoffFreq(_freq / 2);
|
||||||
mFilter->setResonance(0.5f);
|
// mFilter->setResonance(0.5f);
|
||||||
mGain->setValue( _amp );
|
// mGain->setValue( _amp );
|
||||||
|
//
|
||||||
mGen >> mFilter >> mGain >> ctx->getOutput();
|
// mGen >> mFilter >> mGain >> ctx->getOutput();
|
||||||
mGen->enable();
|
// mGen->enable();
|
||||||
|
//
|
||||||
ctx->enable();
|
// ctx->enable();
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
void VoiceAloud::update()
|
//void VoiceAloud::update()
|
||||||
{
|
//{
|
||||||
mGen->setFreq( _freq );
|
// mGen->setFreq( _freq );
|
||||||
mGain->setValue( _amp );
|
// mGain->setValue( _amp );
|
||||||
}
|
//}
|
||||||
|
|||||||
60
src/Voice.h
60
src/Voice.h
@ -25,7 +25,7 @@ using Receiver = osc::ReceiverUdp;
|
|||||||
/*- Voice -*/
|
/*- Voice -*/
|
||||||
class Voice {
|
class Voice {
|
||||||
public:
|
public:
|
||||||
Voice(std::string name, std::string channel, std::string font, int size, ColorA8u color, ColorA8u background, std::function<void(Voice*)> utterance_cb, std::function<void(Voice*)> change_cb)
|
Voice(std::string name, std::string channel, std::string font, int size, ColorA8u color, ColorA8u background, Rectf bounds, std::function<void(Voice*)> utterance_cb, std::function<void(Voice*)> change_cb)
|
||||||
: _name(name),
|
: _name(name),
|
||||||
_channel(channel),
|
_channel(channel),
|
||||||
_utterance(name),
|
_utterance(name),
|
||||||
@ -33,46 +33,54 @@ public:
|
|||||||
_size(size),
|
_size(size),
|
||||||
_color(color),
|
_color(color),
|
||||||
_background(background),
|
_background(background),
|
||||||
|
_bounds(bounds),
|
||||||
|
_offset(vec2(0)),
|
||||||
_utterance_cb(utterance_cb),
|
_utterance_cb(utterance_cb),
|
||||||
_change_cb(change_cb)
|
_change_cb(change_cb)
|
||||||
{};
|
{};
|
||||||
void setup(Receiver &receiver);
|
void setup(Receiver &receiver);
|
||||||
void update();
|
void update();
|
||||||
void draw(Rectf &bounds);
|
void draw(Rectf &bounds, bool name=false, bool debug=false);
|
||||||
|
void bounds(int W, int H);
|
||||||
|
|
||||||
|
std::string _name;
|
||||||
|
std::string _channel;
|
||||||
|
std::string _utterance;
|
||||||
|
Font _font;
|
||||||
|
std::string _font_name;
|
||||||
|
ColorA8u _color;
|
||||||
|
ColorA8u _background;
|
||||||
|
Rectf _bounds;
|
||||||
|
vec2 _offset;
|
||||||
|
int _size;
|
||||||
|
bool _update_font = false;
|
||||||
|
float _temperature;
|
||||||
|
|
||||||
std::string _name;
|
|
||||||
std::string _channel;
|
|
||||||
std::string _utterance;
|
|
||||||
Font _font;
|
|
||||||
std::string _font_name;
|
|
||||||
ColorA8u _color;
|
|
||||||
ColorA8u _background;
|
|
||||||
int _size;
|
|
||||||
bool _update_font = false;
|
|
||||||
gl::TextureFontRef _tex;
|
gl::TextureFontRef _tex;
|
||||||
|
gl::TextureFontRef _tex_name;
|
||||||
|
|
||||||
gl::GlslProgRef _glsl;
|
gl::GlslProgRef _glsl;
|
||||||
|
|
||||||
std::mutex _color_mutex, _font_mutex, _utterance_mutex;
|
std::mutex _color_mutex, _font_mutex, _utterance_mutex, _temperatue_mutex;
|
||||||
|
|
||||||
std::function<void(Voice*)> _utterance_cb, _change_cb;
|
std::function<void(Voice*)> _utterance_cb, _change_cb;
|
||||||
|
|
||||||
audio::VoiceRef _sound;
|
// audio::VoiceRef _sound;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class VoiceAloud {
|
//class VoiceAloud {
|
||||||
public:
|
//public:
|
||||||
VoiceAloud(float freq, float amp) : _freq(freq), _amp(amp) {};
|
// VoiceAloud(float freq, float amp) : _freq(freq), _amp(amp) {};
|
||||||
void setup();
|
// void setup();
|
||||||
void update();
|
// void update();
|
||||||
|
//
|
||||||
audio::GenNodeRef mGen; // Gen's generate audio signals
|
// audio::GenNodeRef mGen; // Gen's generate audio signals
|
||||||
audio::FilterLowPassNodeRef mFilter;
|
// audio::FilterLowPassNodeRef mFilter;
|
||||||
audio::GainNodeRef mGain; // Gain modifies the volume of the signal
|
// audio::GainNodeRef mGain; // Gain modifies the volume of the signal
|
||||||
|
//
|
||||||
Anim<float> _freq;
|
// Anim<float> _freq;
|
||||||
Anim<float> _amp;
|
// Anim<float> _amp;
|
||||||
};
|
//};
|
||||||
|
|
||||||
#endif /* Voice_hpp */
|
#endif /* Voice_hpp */
|
||||||
|
|||||||
@ -89,11 +89,23 @@ void VoiceMachineApp::stage_config()
|
|||||||
try {
|
try {
|
||||||
const JsonTree config(loadAsset("voice.config.json"));
|
const JsonTree config(loadAsset("voice.config.json"));
|
||||||
|
|
||||||
|
bool fullscreen = config["fullscreen"].getValue<bool>();
|
||||||
|
|
||||||
|
if (fullscreen) {
|
||||||
|
// FullScreenOptions& exclusive( bool enable = true );
|
||||||
|
// setFullScreen(exclusive);
|
||||||
|
setFullScreen(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// RECEIVER PORT
|
// RECEIVER PORT
|
||||||
int port = config["port_voicemachine"].getValue<int>();
|
int port = config["port_voicemachine"].getValue<int>();
|
||||||
_receiver = std::shared_ptr<Receiver>(new Receiver(port, protocol::v4(), *_io_service));
|
_receiver = std::shared_ptr<Receiver>(new Receiver(port, protocol::v4(), *_io_service));
|
||||||
|
|
||||||
//VOICES
|
//VOICES
|
||||||
|
|
||||||
|
Rectf bounds( 40, 40, getWindowWidth() - 40, getWindowHeight() - 40 );
|
||||||
|
|
||||||
for(auto &voice: config["voices"].getChildren()){
|
for(auto &voice: config["voices"].getChildren()){
|
||||||
std::string name = voice["name"].getValue();
|
std::string name = voice["name"].getValue();
|
||||||
std::string channel = voice["osc_channel"]["root"].getValue();
|
std::string channel = voice["osc_channel"]["root"].getValue();
|
||||||
@ -112,12 +124,9 @@ void VoiceMachineApp::stage_config()
|
|||||||
this->change(v);
|
this->change(v);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Voice* v = new Voice(name, channel, font, size, color, background, bounds, utterance_cb, change_cb);
|
||||||
Voice* v = new Voice(name, channel, font, size, color, background, utterance_cb, change_cb);
|
|
||||||
_map_voices[name] = v;
|
_map_voices[name] = v;
|
||||||
|
|
||||||
// //garbage
|
|
||||||
// _current_voice = v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string command_channel = config["command_osc_channel"].getValue();
|
std::string command_channel = config["command_osc_channel"].getValue();
|
||||||
@ -230,7 +239,6 @@ void VoiceMachineApp::update()
|
|||||||
{
|
{
|
||||||
for(const auto& [n, v]: _map_voices)
|
for(const auto& [n, v]: _map_voices)
|
||||||
v->update();
|
v->update();
|
||||||
|
|
||||||
// audio.update();
|
// audio.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +252,7 @@ void VoiceMachineApp::draw()
|
|||||||
|
|
||||||
if(_current_voice){
|
if(_current_voice){
|
||||||
Rectf bounds( 40, _current_voice->_tex->getAscent() + 40, getWindowWidth() - 40, getWindowHeight() - 40 );
|
Rectf bounds( 40, _current_voice->_tex->getAscent() + 40, getWindowWidth() - 40, getWindowHeight() - 40 );
|
||||||
_current_voice->draw(bounds);
|
_current_voice->draw(bounds, _debug, _debug);
|
||||||
if(_debug){
|
if(_debug){
|
||||||
gl::color(Color(1, 0, 0));
|
gl::color(Color(1, 0, 0));
|
||||||
gl::drawStrokedRect(bounds);
|
gl::drawStrokedRect(bounds);
|
||||||
@ -268,10 +276,12 @@ void VoiceMachineApp::keyDown( KeyEvent event )
|
|||||||
save_config();
|
save_config();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// case '-':
|
case 'd':
|
||||||
// mFont = Font( mFont.getName(), mFont.getSize() - 1 );
|
{
|
||||||
// mTextureFont = gl::TextureFont::create( mFont );
|
CI_LOG_D("debug mode...");
|
||||||
// break;
|
_debug = !_debug;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user