From b9249ed7aff7253cfb9ff8e6f8ba4f947c002f2e Mon Sep 17 00:00:00 2001 From: NATURESPEAK Date: Mon, 4 Apr 2022 10:49:14 +0200 Subject: [PATCH] better temp --- src/Voice.cpp | 19 ++++++++++++++----- src/Voice.h | 4 +++- src/voicemachineApp.cpp | 4 +++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Voice.cpp b/src/Voice.cpp index c3e14ec..5923caa 100644 --- a/src/Voice.cpp +++ b/src/Voice.cpp @@ -1,4 +1,5 @@ #include "Voice.h" +#include void Voice::setup(Receiver &receiver) { @@ -6,6 +7,11 @@ void Voice::setup(Receiver &receiver) _tex = gl::TextureFont::create(_font); _tex_name = gl::TextureFont::create(_font); + std::ostringstream out; + out.precision(2); + out << std::fixed << _temperature; + _temperature_str = out.str(); + /*- NET -*/ receiver.setListener(_channel + "/utterance", [&](const osc::Message &m){ @@ -37,7 +43,13 @@ void Voice::setup(Receiver &receiver) [&](const osc::Message &m){ std::lock_guard lock(_temperatue_mutex); float t = m[0].flt(); - if(_temperature != t) _temperature = t; + if(_temperature != t) { + _temperature = t; + std::ostringstream out; + out.precision(2); + out << std::fixed << _temperature; + _temperature_str = out.str(); + } }); @@ -113,10 +125,7 @@ void Voice::update() void Voice::draw(Rectf &bounds, bool name, bool debug) { // gl::color(_color); - if(name && debug) { - - _tex_name->drawStringWrapped(_name + " " + std::to_string(_temperature), bounds); - } + if(name && debug) _tex_name->drawStringWrapped(_name + " " + _temperature_str, bounds); else if(name) _tex_name->drawStringWrapped(_name, bounds); _tex->drawStringWrapped(_utterance, bounds + _offset); diff --git a/src/Voice.h b/src/Voice.h index 72cc354..a324b5f 100644 --- a/src/Voice.h +++ b/src/Voice.h @@ -25,7 +25,7 @@ using Receiver = osc::ReceiverUdp; /*- Voice -*/ class Voice { public: - Voice(std::string name, std::string channel, std::string font, int size, ColorA8u color, ColorA8u background, Rectf bounds, std::function utterance_cb, std::function change_cb) + Voice(std::string name, std::string channel, std::string font, int size, ColorA8u color, ColorA8u background, float temp, Rectf bounds, std::function utterance_cb, std::function change_cb) : _name(name), _channel(channel), _utterance(name), @@ -33,6 +33,7 @@ public: _size(size), _color(color), _background(background), + _temperature(temp), _bounds(bounds), _offset(vec2(0)), _utterance_cb(utterance_cb), @@ -55,6 +56,7 @@ public: int _size; bool _update_font = false; float _temperature; + std::string _temperature_str; gl::TextureFontRef _tex; gl::TextureFontRef _tex_name; diff --git a/src/voicemachineApp.cpp b/src/voicemachineApp.cpp index 9937bfb..b0b42a4 100644 --- a/src/voicemachineApp.cpp +++ b/src/voicemachineApp.cpp @@ -115,6 +115,8 @@ void VoiceMachineApp::stage_config() ColorA8u color = ColorA8u::hexA(std::stoul(hexcolor, nullptr, 16)); std::string hexbackground = voice["background"].getValue(); ColorA background = ColorA::hexA(std::stoul(hexbackground, nullptr, 16)); + std::string tempstr = voice["model"]["temperature"].getValue(); + float temp = std::stof(tempstr); std::function utterance_cb = [=](Voice* v) { this->utterance(v); @@ -124,7 +126,7 @@ void VoiceMachineApp::stage_config() 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, temp, bounds, utterance_cb, change_cb); _map_voices[name] = v; }