Source info() gives type, InfoVisitor gives instance info

Changed (back) to clean use of source->info() to return type dependent info string. The InfoVisitor gives unified detailed information about instance.
This commit is contained in:
Bruno Herbelin
2022-04-03 00:02:20 +02:00
parent 548aba5b7c
commit 49ebc17334
16 changed files with 52 additions and 83 deletions

View File

@@ -104,10 +104,10 @@ std::string BaseToolkit::transliterate(const std::string &input)
}
std::string BaseToolkit::unspace(const std::string &input)
std::string BaseToolkit::unspace(const std::string &input, char delim)
{
std::string output = input;
std::replace( output.begin(), output.end(), ' ', '_');
std::replace_if( output.begin(), output.end(), ::isspace, delim);
return output;
}

View File

@@ -16,8 +16,8 @@ std::string uniqueName(const std::string &basename, std::list<std::string> exist
// get a transliteration to Latin of any string
std::string transliterate(const std::string &input);
// replaces spaces by underscores in a string
std::string unspace(const std::string &input);
// replaces spaces by delim in a string
std::string unspace(const std::string &input, char delim = '_');
// get a string to display memory size with unit KB, MB, GB, TB
std::string byte_to_string(long b);

View File

@@ -246,5 +246,5 @@ glm::ivec2 CloneSource::icon() const
std::string CloneSource::info() const
{
return std::string("clone of ") + cloning_provenance_label[provenance_] + " from '" + origin_->name() + "'";
return "Clone";
}

View File

@@ -687,7 +687,10 @@ glm::ivec2 DeviceSource::icon() const
std::string DeviceSource::info() const
{
return std::string("device '") + device_ + "'";
if ( device_.find("Screen") != std::string::npos )
return "Screen capture";
else
return "Device";
}

View File

@@ -576,17 +576,14 @@ void ImGuiVisitor::visit (Source& s)
ImGui::Spacing();
ImGui::PopID();
ImGuiToolkit::Icon(s.icon().x, s.icon().y);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text(s.info().c_str());
}
void ImGuiVisitor::visit (MediaSource& s)
{
ImGuiToolkit::Icon(s.icon().x, s.icon().y);
ImGui::SameLine(0, IMGUI_SAME_LINE);
if ( s.mediaplayer()->isImage() )
ImGui::Text("Image File");
else
ImGui::Text("Video File");
// Media info
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN);
s.accept(info);
@@ -618,10 +615,6 @@ void ImGuiVisitor::visit (SessionFileSource& s)
if (s.session() == nullptr)
return;
ImGuiToolkit::Icon(s.icon().x, s.icon().y);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("Session File");
// info
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN);
s.accept(info);
@@ -673,10 +666,6 @@ void ImGuiVisitor::visit (SessionGroupSource& s)
if (s.session() == nullptr)
return;
ImGuiToolkit::Icon(s.icon().x, s.icon().y);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("Session group");
// info
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN);
s.accept(info);
@@ -703,10 +692,6 @@ void ImGuiVisitor::visit (SessionGroupSource& s)
void ImGuiVisitor::visit (RenderSource& s)
{
ImGuiToolkit::Icon(s.icon().x, s.icon().y);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("Rendering Output");
// info
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN);
s.accept(info);
@@ -733,10 +718,6 @@ void ImGuiVisitor::visit (RenderSource& s)
void ImGuiVisitor::visit (CloneSource& s)
{
ImGuiToolkit::Icon(s.icon().x, s.icon().y);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("Clone");
// info
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN);
s.accept(info);
@@ -770,10 +751,6 @@ void ImGuiVisitor::visit (CloneSource& s)
void ImGuiVisitor::visit (PatternSource& s)
{
ImGuiToolkit::Icon(s.icon().x, s.icon().y);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("Pattern");
// stream info
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN);
s.accept(info);
@@ -810,10 +787,6 @@ void ImGuiVisitor::visit (PatternSource& s)
void ImGuiVisitor::visit (DeviceSource& s)
{
ImGuiToolkit::Icon(s.icon().x, s.icon().y);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("Device");
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN);
s.accept(info);
ImGui::Text("%s", info.str().c_str());
@@ -883,9 +856,6 @@ void ImGuiVisitor::visit (NetworkSource& s)
void ImGuiVisitor::visit (MultiFileSource& s)
{
ImGuiToolkit::Icon(s.icon().x, s.icon().y);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("Images sequence");
static uint64_t id = 0;
// information text
@@ -951,10 +921,6 @@ void ImGuiVisitor::visit (GenericStreamSource& s)
{
float w = ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN;
ImGuiToolkit::Icon(s.icon().x, s.icon().y);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("Custom");
// stream info
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + w);
s.accept(info);
@@ -988,10 +954,6 @@ void ImGuiVisitor::visit (GenericStreamSource& s)
void ImGuiVisitor::visit (SrtReceiverSource& s)
{
ImGuiToolkit::Icon(s.icon().x, s.icon().y);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("SRT Receiver");
// network info
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + ImGui::GetContentRegionAvail().x IMGUI_RIGHT_ALIGN);
s.accept(info);

View File

@@ -107,7 +107,7 @@ void InfoVisitor::visit(MediaPlayer &mp)
oss << mp.media().codec_name.substr(0, mp.media().codec_name.find_first_of(" (,")) << ", ";
oss << mp.width() << " x " << mp.height();
if (!mp.isImage())
oss << ", " << std::fixed << std::setprecision(1) << mp.frameRate() << " fps";
oss << ", " << std::fixed << std::setprecision(0) << mp.frameRate() << "fps";
}
else {
oss << mp.filename() << std::endl;
@@ -172,14 +172,14 @@ void InfoVisitor::visit (SessionGroupSource& s)
return;
std::ostringstream oss;
oss << s.session()->numSource() << " source" << (s.session()->numSource()>1 ? "s" : "");
if (s.session()->frame()){
std::string numsource = std::to_string(s.session()->numSource()) + " source" + (s.session()->numSource()>1 ? "s" : "");
if (brief_) {
oss << numsource << ", " ;
oss << "RGB, " << s.session()->frame()->width() << " x " << s.session()->frame()->height();
oss << ", RGB, " << s.session()->frame()->width() << " x " << s.session()->frame()->height();
}
else {
oss << "Group of " << numsource << std::endl;
oss << " in Group"<< std::endl;
oss << "RGB" << std::endl;
oss << s.session()->frame()->width() << " x " << s.session()->frame()->height();
}
@@ -275,7 +275,7 @@ void InfoVisitor::visit (DeviceSource& s)
if (brief_) {
oss << best.stream << " " << best.format << ", ";
oss << best.width << " x " << best.height << ", ";
oss << std::fixed << std::setprecision(1) << fps << " fps";
oss << std::fixed << std::setprecision(0) << fps << "fps";
}
else {
oss << s.device() << std::endl;

View File

@@ -75,7 +75,10 @@ glm::ivec2 MediaSource::icon() const
std::string MediaSource::info() const
{
return std::string("media '") + path_ + "'";
if (mediaplayer_->isImage())
return "Image File";
else
return "Video File";
}
bool MediaSource::failed() const

View File

@@ -53,6 +53,7 @@
#include "SrtReceiverSource.h"
#include "SourceCallback.h"
#include "InfoVisitor.h"
#include "ActionManager.h"
#include "MixingGroup.h"
#include "Streamer.h"
@@ -444,7 +445,10 @@ void Mixer::insertSource(Source *s, View::Mode m)
Action::manager().store(s->name() + std::string(": source inserted"));
// notify creation of source
Log::Notify("Added source '%s' with %s", s->name().c_str(), s->info().c_str());
static InfoVisitor _more_info;
s->accept(_more_info);
std::string moreinfo = BaseToolkit::unspace(_more_info.str(), ' ');
Log::Notify("Added %s source '%s' (%s)", s->info().c_str(), s->name().c_str(), moreinfo.c_str());
// if requested to show the source in a given view
// (known to work for View::MIXING et TRANSITION: other views untested)
@@ -724,10 +728,10 @@ void Mixer::groupSelection()
// store in action manager
std::ostringstream info;
info << sessiongroup->name() << " inserted: " << sessiongroup->session()->numSource() << " sources flatten.";
info << sessiongroup->name() << " inserted: " << sessiongroup->session()->numSource() << " sources groupped.";
Action::manager().store(info.str());
Log::Notify("Added source '%s' with %s", sessiongroup->name().c_str(), sessiongroup->info().c_str());
Log::Notify("Added %s source '%s' (group of %d sources)", sessiongroup->info().c_str(), sessiongroup->name().c_str(), sessiongroup->session()->numSource());
// give the hand to the user
Mixer::manager().setCurrentSource(sessiongroup);
@@ -780,7 +784,7 @@ void Mixer::groupAll()
addSource(sessiongroup);
// inform of creation
Log::Info("Source '%s' created with %s", sessiongroup->name().c_str(), sessiongroup->info().c_str());
Log::Info("%s Source '%s' created (%d sources groupped)", sessiongroup->info().c_str(), sessiongroup->name().c_str(), sessiongroup->session()->numSource());
}
else {
delete sessiongroup;
@@ -825,7 +829,7 @@ void Mixer::flattenSession()
// prevent deletion of session_ (now embedded into session group)
session_ = new Session;
Log::Notify("Switched to '%s' with %s", sessiongroup->name().c_str(), sessiongroup->info().c_str());
Log::Notify("Switched to session '%s'", sessiongroup->name().c_str());
}
void Mixer::renameSource(Source *s, const std::string &newname)

View File

@@ -266,7 +266,7 @@ glm::ivec2 MultiFileSource::icon () const
std::string MultiFileSource::info() const
{
return std::string("sequence '") + sequence_.location + "'";
return "Images sequence";
}

View File

@@ -352,6 +352,6 @@ glm::ivec2 NetworkSource::icon() const
std::string NetworkSource::info() const
{
return std::string("shared by '") + connection_name_ + "'";
return "Shared stream";
}

View File

@@ -181,5 +181,5 @@ glm::ivec2 PatternSource::icon() const
std::string PatternSource::info() const
{
return std::string("pattern '") + Pattern::get(pattern()->type()).label + "'";
return "Pattern";
}

View File

@@ -161,5 +161,5 @@ glm::ivec2 RenderSource::icon() const
std::string RenderSource::info() const
{
return std::string("Render ") + RenderSource::rendering_provenance_label[provenance_];
return "Rendering Output";
}

View File

@@ -299,7 +299,7 @@ glm::ivec2 SessionFileSource::icon() const
std::string SessionFileSource::info() const
{
return std::string("session vimix '") + path_ + "'";
return "Session File";
}
@@ -400,8 +400,5 @@ glm::ivec2 SessionGroupSource::icon() const
std::string SessionGroupSource::info() const
{
if (session_)
return std::string("group of ") + std::to_string(session_->numSource()) + " source" + (session_->numSource()>1 ? "s" : "");
else
return std::string("undefined group.");
return "Session group";
}

View File

@@ -52,5 +52,5 @@ glm::ivec2 SrtReceiverSource::icon() const
std::string SrtReceiverSource::info() const
{
return std::string("SRT receiver from '") + uri() + "'";
return "SRT receiver";
}

View File

@@ -82,11 +82,7 @@ glm::ivec2 GenericStreamSource::icon() const
std::string GenericStreamSource::info() const
{
if (gst_elements_.empty())
return "Gstreamer custom pipeline without source";
std::string src_element = gst_elements_.front();
src_element = src_element.substr(0, src_element.find(" "));
return std::string("Gstreamer custom pipeline with source '")+src_element+"'";
return "Custom gstreamer";
}
StreamSource::StreamSource(uint64_t id) : Source(id), stream_(nullptr)

View File

@@ -7218,7 +7218,7 @@ void SourcePreview::setSource(Source *s, const string &label)
delete source_;
source_ = s;
label_ = BaseToolkit::truncated(label, 35);
label_ = label;
reset_ = true;
}
@@ -7231,8 +7231,6 @@ Source * SourcePreview::getSource()
void SourcePreview::Render(float width)
{
static InfoVisitor _info;
if(source_) {
// cancel if failed
if (source_->failed()) {
@@ -7264,14 +7262,19 @@ void SourcePreview::Render(float width)
FrameBuffer *frame = source_->frame();
ImVec2 preview_size(width, width / frame->aspectRatio());
ImGui::Image((void*)(uintptr_t) frame->texture(), preview_size);
bool mouseover = ImGui::IsItemHovered();
if (mouseover) {
ImGui::BeginTooltip();
ImGui::TextUnformatted(label_.c_str());
ImGui::EndTooltip();
}
// if the source is playable and once its ready
if (source_->playable() && source_->ready()) {
// activate the source on mouse over
bool activate = ImGui::IsItemHovered();
if (source_->active() != activate)
source_->setActive(activate);
if (source_->active() != mouseover)
source_->setActive(mouseover);
// show icon '>' to indicate if we can activate it
if (!activate) {
if (!mouseover) {
ImVec2 pos = ImGui::GetCursorPos();
ImGui::SetCursorPos(pos + preview_size * ImVec2(0.5f, -0.6f));
ImGuiToolkit::Icon(12,7);
@@ -7281,8 +7284,9 @@ void SourcePreview::Render(float width)
// information text
ImGuiToolkit::Icon(source_->icon().x, source_->icon().y);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::Text("%s", label_.c_str());
ImGui::Text("%s", source_->info().c_str());
if (source_->ready()) {
static InfoVisitor _info;
source_->accept(_info);
ImGui::Text("%s", _info.str().c_str());
}