mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
Using new basetoolkit function for unique naming
applied to source and snapshot names
This commit is contained in:
@@ -185,10 +185,12 @@ void Action::restore(uint target)
|
|||||||
|
|
||||||
void Action::snapshot(const std::string &label)
|
void Action::snapshot(const std::string &label)
|
||||||
{
|
{
|
||||||
// ignore if locked or if no label is given
|
// ignore if locked
|
||||||
if (locked_ || label.empty())
|
if (locked_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
std::string snap_label = BaseToolkit::uniqueName(label, labels());
|
||||||
|
|
||||||
// create snapshot id
|
// create snapshot id
|
||||||
u_int64_t id = BaseToolkit::uniqueId();
|
u_int64_t id = BaseToolkit::uniqueId();
|
||||||
|
|
||||||
@@ -197,10 +199,10 @@ void Action::snapshot(const std::string &label)
|
|||||||
se->snapshots()->keys_.push_back(id);
|
se->snapshots()->keys_.push_back(id);
|
||||||
|
|
||||||
// threaded capture state of current session
|
// threaded capture state of current session
|
||||||
std::thread(captureMixerSession, se->snapshots()->xmlDoc_, SNAPSHOT_NODE(id), label).detach();
|
std::thread(captureMixerSession, se->snapshots()->xmlDoc_, SNAPSHOT_NODE(id), snap_label).detach();
|
||||||
|
|
||||||
#ifdef ACTION_DEBUG
|
#ifdef ACTION_DEBUG
|
||||||
Log::Info("Snapshot stored %d '%s'", id, label.c_str());
|
Log::Info("Snapshot stored %d '%s'", id, snap_label.c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,6 +254,17 @@ std::list<uint64_t> Action::snapshots() const
|
|||||||
return Mixer::manager().session()->snapshots()->keys_;
|
return Mixer::manager().session()->snapshots()->keys_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::list<std::string> Action::labels() const
|
||||||
|
{
|
||||||
|
std::list<std::string> names;
|
||||||
|
|
||||||
|
tinyxml2::XMLDocument *doc = Mixer::manager().session()->snapshots()->xmlDoc_;
|
||||||
|
for ( XMLElement *snap = doc->FirstChildElement(); snap ; snap = snap->NextSiblingElement() )
|
||||||
|
names.push_back( snap->Attribute("label"));
|
||||||
|
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
std::string Action::label(uint64_t snapshotid) const
|
std::string Action::label(uint64_t snapshotid) const
|
||||||
{
|
{
|
||||||
std::string label = "";
|
std::string label = "";
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
FrameBufferImage *thumbnail (uint s) const;
|
FrameBufferImage *thumbnail (uint s) const;
|
||||||
|
|
||||||
// Snapshots
|
// Snapshots
|
||||||
void snapshot (const std::string &label);
|
void snapshot (const std::string &label = "");
|
||||||
|
|
||||||
std::list<uint64_t> snapshots () const;
|
std::list<uint64_t> snapshots () const;
|
||||||
uint64_t currentSnapshot () const { return snapshot_id_; }
|
uint64_t currentSnapshot () const { return snapshot_id_; }
|
||||||
@@ -49,6 +49,7 @@ public:
|
|||||||
void remove (uint64_t snapshotid = 0);
|
void remove (uint64_t snapshotid = 0);
|
||||||
|
|
||||||
std::string label (uint64_t snapshotid) const;
|
std::string label (uint64_t snapshotid) const;
|
||||||
|
std::list<std::string> labels () const;
|
||||||
void setLabel (uint64_t snapshotid, const std::string &label);
|
void setLabel (uint64_t snapshotid, const std::string &label);
|
||||||
FrameBufferImage *thumbnail (uint64_t snapshotid) const;
|
FrameBufferImage *thumbnail (uint64_t snapshotid) const;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#include <unicode/ustream.h>
|
#include <unicode/ustream.h>
|
||||||
@@ -18,6 +19,33 @@ uint64_t BaseToolkit::uniqueId()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::string BaseToolkit::uniqueName(const std::string &basename, std::list<std::string> existingnames)
|
||||||
|
{
|
||||||
|
std::string tentativename = basename;
|
||||||
|
int count = 1;
|
||||||
|
int max = 100;
|
||||||
|
|
||||||
|
// while tentativename can be found in the list of existingnames
|
||||||
|
while ( std::find( existingnames.begin(), existingnames.end(), tentativename ) != existingnames.end() )
|
||||||
|
{
|
||||||
|
for( auto it = existingnames.cbegin(); it != existingnames.cend(); ++it) {
|
||||||
|
if ( it->find(tentativename) != std::string::npos)
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count > 1)
|
||||||
|
tentativename = basename + "_" + std::to_string( count );
|
||||||
|
else
|
||||||
|
tentativename += "_";
|
||||||
|
|
||||||
|
if ( --max < 0 ) // for safety only, should never be needed
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tentativename;
|
||||||
|
}
|
||||||
|
|
||||||
// Using ICU transliteration :
|
// Using ICU transliteration :
|
||||||
// https://unicode-org.github.io/icu/userguide/transforms/general/#icu-transliterators
|
// https://unicode-org.github.io/icu/userguide/transforms/general/#icu-transliterators
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef BASETOOLKIT_H
|
#ifndef BASETOOLKIT_H
|
||||||
#define BASETOOLKIT_H
|
#define BASETOOLKIT_H
|
||||||
|
|
||||||
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace BaseToolkit
|
namespace BaseToolkit
|
||||||
@@ -9,6 +10,9 @@ namespace BaseToolkit
|
|||||||
// get integer with unique id
|
// get integer with unique id
|
||||||
uint64_t uniqueId();
|
uint64_t uniqueId();
|
||||||
|
|
||||||
|
// proposes a name that is not already in the list
|
||||||
|
std::string uniqueName(const std::string &basename, std::list<std::string> existingnames);
|
||||||
|
|
||||||
// get a transliteration to Latin of any string
|
// get a transliteration to Latin of any string
|
||||||
std::string transliterate(std::string input);
|
std::string transliterate(std::string input);
|
||||||
|
|
||||||
@@ -18,6 +22,7 @@ std::string byte_to_string(long b);
|
|||||||
// get a string to display bit size with unit Kbit, MBit, Gbit, Tbit
|
// get a string to display bit size with unit Kbit, MBit, Gbit, Tbit
|
||||||
std::string bits_to_string(long b);
|
std::string bits_to_string(long b);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
31
Mixer.cpp
31
Mixer.cpp
@@ -18,6 +18,7 @@
|
|||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "View.h"
|
#include "View.h"
|
||||||
#include "ImageShader.h"
|
#include "ImageShader.h"
|
||||||
|
#include "BaseToolkit.h"
|
||||||
#include "SystemToolkit.h"
|
#include "SystemToolkit.h"
|
||||||
#include "SessionCreator.h"
|
#include "SessionCreator.h"
|
||||||
#include "SessionVisitor.h"
|
#include "SessionVisitor.h"
|
||||||
@@ -251,7 +252,10 @@ Source * Mixer::createSourceRender()
|
|||||||
s->setSession(session_);
|
s->setSession(session_);
|
||||||
|
|
||||||
// propose a new name based on session name
|
// propose a new name based on session name
|
||||||
|
if ( !session_->filename().empty() )
|
||||||
s->setName(SystemToolkit::base_filename(session_->filename()));
|
s->setName(SystemToolkit::base_filename(session_->filename()));
|
||||||
|
else
|
||||||
|
s->setName("Output");
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@@ -263,8 +267,7 @@ Source * Mixer::createSourceStream(const std::string &gstreamerpipeline)
|
|||||||
s->setDescription(gstreamerpipeline);
|
s->setDescription(gstreamerpipeline);
|
||||||
|
|
||||||
// propose a new name based on pattern name
|
// propose a new name based on pattern name
|
||||||
std::string name = gstreamerpipeline.substr(0, gstreamerpipeline.find(" "));
|
s->setName( gstreamerpipeline.substr(0, gstreamerpipeline.find(" ")) );
|
||||||
s->setName(name);
|
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@@ -289,8 +292,7 @@ Source * Mixer::createSourceDevice(const std::string &namedevice)
|
|||||||
Source *s = Device::manager().createSource(namedevice);
|
Source *s = Device::manager().createSource(namedevice);
|
||||||
|
|
||||||
// propose a new name based on pattern name
|
// propose a new name based on pattern name
|
||||||
std::string name = namedevice.substr(0, namedevice.find(" "));
|
s->setName( namedevice.substr(0, namedevice.find(" ")) );
|
||||||
s->setName(name);
|
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@@ -333,24 +335,18 @@ Source * Mixer::createSourceClone(const std::string &namesource)
|
|||||||
origin = current_source_;
|
origin = current_source_;
|
||||||
|
|
||||||
// have an origin, can clone it
|
// have an origin, can clone it
|
||||||
if (origin != session_->end()) {
|
if (origin != session_->end())
|
||||||
|
|
||||||
// create a source
|
// create a source
|
||||||
s = (*origin)->clone();
|
s = (*origin)->clone();
|
||||||
|
|
||||||
// propose new name (this automatically increments name)
|
|
||||||
s->setName((*origin)->name());
|
|
||||||
}
|
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mixer::addSource(Source *s)
|
void Mixer::addSource(Source *s)
|
||||||
{
|
{
|
||||||
if (s != nullptr) {
|
if (s != nullptr)
|
||||||
candidate_sources_.push_back(s);
|
candidate_sources_.push_back(s);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Mixer::insertSource(Source *s, View::Mode m)
|
void Mixer::insertSource(Source *s, View::Mode m)
|
||||||
{
|
{
|
||||||
@@ -656,16 +652,7 @@ void Mixer::renameSource(Source *s, const std::string &newname)
|
|||||||
if ( !newname.empty() )
|
if ( !newname.empty() )
|
||||||
tentativename = newname;
|
tentativename = newname;
|
||||||
|
|
||||||
// search for a source of the name 'tentativename'
|
tentativename = BaseToolkit::uniqueName(tentativename, session_->getNameList());
|
||||||
std::string basename = tentativename;
|
|
||||||
int count = 1;
|
|
||||||
for( auto it = session_->begin(); it != session_->end(); it++){
|
|
||||||
if ( s->id() != (*it)->id() && (*it)->name() == tentativename )
|
|
||||||
tentativename = basename + std::to_string( ++count );
|
|
||||||
}
|
|
||||||
|
|
||||||
// std::list<std::string> names = session_->getNameList();
|
|
||||||
|
|
||||||
|
|
||||||
// ok to rename
|
// ok to rename
|
||||||
s->setName(tentativename);
|
s->setName(tentativename);
|
||||||
|
|||||||
@@ -316,6 +316,7 @@ Source::~Source()
|
|||||||
|
|
||||||
void Source::setName (const std::string &name)
|
void Source::setName (const std::string &name)
|
||||||
{
|
{
|
||||||
|
if (!name.empty())
|
||||||
name_ = BaseToolkit::transliterate(name);
|
name_ = BaseToolkit::transliterate(name);
|
||||||
|
|
||||||
initials_[0] = std::toupper( name_.front(), std::locale("C") );
|
initials_[0] = std::toupper( name_.front(), std::locale("C") );
|
||||||
@@ -817,6 +818,7 @@ CloneSource *Source::clone(uint64_t id)
|
|||||||
|
|
||||||
CloneSource::CloneSource(Source *origin, uint64_t id) : Source(id), origin_(origin)
|
CloneSource::CloneSource(Source *origin, uint64_t id) : Source(id), origin_(origin)
|
||||||
{
|
{
|
||||||
|
name_ = origin->name();
|
||||||
// set symbol
|
// set symbol
|
||||||
symbol_ = new Symbol(Symbol::CLONE, glm::vec3(0.75f, 0.75f, 0.01f));
|
symbol_ = new Symbol(Symbol::CLONE, glm::vec3(0.75f, 0.75f, 0.01f));
|
||||||
symbol_->scale_.y = 1.5f;
|
symbol_->scale_.y = 1.5f;
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ void UserInterface::handleKeyboard()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ImGui::IsKeyPressed( GLFW_KEY_Y )) {
|
else if (ImGui::IsKeyPressed( GLFW_KEY_Y )) {
|
||||||
Action::manager().snapshot( SystemToolkit::date_time_string() );
|
Action::manager().snapshot( "Snap" );
|
||||||
}
|
}
|
||||||
else if (ImGui::IsKeyPressed( GLFW_KEY_Z )) {
|
else if (ImGui::IsKeyPressed( GLFW_KEY_Z )) {
|
||||||
if (shift_modifier_active)
|
if (shift_modifier_active)
|
||||||
@@ -807,7 +807,7 @@ void UserInterface::showMenuEdit()
|
|||||||
if ( ImGui::MenuItem( ICON_FA_REDO " Redo", CTRL_MOD "Shift+Z") )
|
if ( ImGui::MenuItem( ICON_FA_REDO " Redo", CTRL_MOD "Shift+Z") )
|
||||||
Action::manager().redo();
|
Action::manager().redo();
|
||||||
if ( ImGui::MenuItem( ICON_FA_STAR "+ Snapshot", CTRL_MOD "Y") )
|
if ( ImGui::MenuItem( ICON_FA_STAR "+ Snapshot", CTRL_MOD "Y") )
|
||||||
Action::manager().snapshot( SystemToolkit::date_time_string() );
|
Action::manager().snapshot( "Snap" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserInterface::showMenuFile()
|
void UserInterface::showMenuFile()
|
||||||
@@ -3236,7 +3236,7 @@ void Navigator::RenderMainPannelVimix()
|
|||||||
// right buttons
|
// right buttons
|
||||||
ImGui::SetCursorPos( ImVec2( pannel_width_ IMGUI_RIGHT_ALIGN, pos_top.y ));
|
ImGui::SetCursorPos( ImVec2( pannel_width_ IMGUI_RIGHT_ALIGN, pos_top.y ));
|
||||||
if ( ImGuiToolkit::IconButton( ICON_FA_STAR "+"))
|
if ( ImGuiToolkit::IconButton( ICON_FA_STAR "+"))
|
||||||
Action::manager().snapshot( SystemToolkit::date_time_string() );
|
Action::manager().snapshot( "Snap" );
|
||||||
if (ImGui::IsItemHovered())
|
if (ImGui::IsItemHovered())
|
||||||
ImGuiToolkit::ToolTip("Take Snapshot ", CTRL_MOD "Y");
|
ImGuiToolkit::ToolTip("Take Snapshot ", CTRL_MOD "Y");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user