2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Robert Nagy, ronag89@gmail.com
22 #include "../stdafx.h"
26 #include <boost/range/adaptor/transformed.hpp>
27 #include <boost/thread.hpp>
29 #include <tbb/spin_mutex.h>
33 namespace caspar { namespace diagnostics {
35 int color(float r, float g, float b, float a)
38 code |= static_cast<int>(r*255.0f+0.5f) << 24;
39 code |= static_cast<int>(g*255.0f+0.5f) << 16;
40 code |= static_cast<int>(b*255.0f+0.5f) << 8;
41 code |= static_cast<int>(a*255.0f+0.5f) << 0;
45 std::tuple<float, float, float, float> color(int code)
47 float r = static_cast<float>((code >> 24) & 255)/255.0f;
48 float g = static_cast<float>((code >> 16) & 255)/255.0f;
49 float b = static_cast<float>((code >> 8) & 255)/255.0f;
50 float a = static_cast<float>((code >> 0) & 255)/255.0f;
51 return std::make_tuple(r, g, b, a);
54 typedef std::vector<spi::sink_factory_t> sink_factories_t;
55 static boost::mutex g_sink_factories_mutex;
56 static sink_factories_t g_sink_factories;
58 std::vector<spl::shared_ptr<spi::graph_sink>> create_sinks()
60 boost::lock_guard<boost::mutex> lock(g_sink_factories_mutex);
61 auto sinks = g_sink_factories | boost::adaptors::transformed([](const spi::sink_factory_t& s){ return s(); });
62 return std::vector<spl::shared_ptr<spi::graph_sink>>(std::begin(sinks), std::end(sinks));
67 std::vector<spl::shared_ptr<spi::graph_sink>> sinks_ = create_sinks();
75 for (auto& sink : sinks_)
79 void set_text(const std::wstring& value)
81 for (auto& sink : sinks_)
82 sink->set_text(value);
85 void set_value(const std::string& name, double value)
87 for (auto& sink : sinks_)
88 sink->set_value(name, value);
91 void set_tag(const std::string& name)
93 for (auto& sink : sinks_)
97 void set_color(const std::string& name, int color)
99 for (auto& sink : sinks_)
100 sink->set_color(name, color);
105 for (auto& sink : sinks_)
111 impl& operator=(impl&);
114 graph::graph() : impl_(new impl)
118 void graph::set_text(const std::wstring& value) { impl_->set_text(value); }
119 void graph::set_value(const std::string& name, double value) { impl_->set_value(name, value); }
120 void graph::set_color(const std::string& name, int color) { impl_->set_color(name, color); }
121 void graph::set_tag(const std::string& name) { impl_->set_tag(name); }
122 void graph::auto_reset() { impl_->auto_reset(); }
124 void register_graph(const spl::shared_ptr<graph>& graph)
126 graph->impl_->activate();
131 void register_sink_factory(sink_factory_t factory)
133 boost::lock_guard<boost::mutex> lock(g_sink_factories_mutex);
135 g_sink_factories.push_back(std::move(factory));