SessionFile source restore version snapshot from UI

This commit is contained in:
Bruno Herbelin
2022-04-10 00:50:31 +02:00
parent 220df8918c
commit aae1915519
4 changed files with 75 additions and 6 deletions

View File

@@ -41,7 +41,6 @@
#endif
#define HISTORY_NODE(i) std::to_string(i).insert(0,1,'H')
#define SNAPSHOT_NODE(i) std::to_string(i).insert(0,1,'S')
using namespace tinyxml2;

View File

@@ -636,22 +636,44 @@ void ImGuiVisitor::visit (SessionFileSource& s)
ImGui::SameLine();
ImGui::Text("Sources");
// versions
SessionSnapshots *versions = s.session()->snapshots();
if (versions->keys_.size()>0) {
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
if (ImGui::BeginCombo("Version", ICON_FA_CODE_BRANCH " Select" ) )
{
for (auto v = versions->keys_.crbegin() ; v != versions->keys_.crend(); ++v){
std::string label = std::to_string(*v);
const tinyxml2::XMLElement *snap = versions->xmlDoc_->FirstChildElement( SNAPSHOT_NODE(*v).c_str() );
if (snap)
label = snap->Attribute("label");
if (ImGui::Selectable( label.c_str() )) {
s.session()->applySnapshot(*v);
}
}
ImGui::EndCombo();
}
}
// fading
if (ImGuiToolkit::IconButton(2, 1)) s.session()->setFadingTarget(0.f);
float f = s.session()->fading();
int f = 100 - int(s.session()->fading() * 100.f);
ImGui::SameLine(0, IMGUI_SAME_LINE);
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
if (ImGui::SliderFloat("Fading", &f, 0.0, 1.0, f < 0.001 ? "None" : "%.2f") )
s.session()->setFadingTarget(f);
if (ImGui::SliderInt("Fading", &f, 0, 100, f > 99 ? "None" : "%d %%") )
s.session()->setFadingTarget( float(100 - f) * 0.01f );
if (ImGui::IsItemDeactivatedAfterEdit()){
std::ostringstream oss;
oss << s.name() << ": Fading " << std::setprecision(2) << f;
oss << s.name() << ": Fading " << f << " %";
Action::manager().store(oss.str());
}
// file open
if ( ImGui::Button( ICON_FA_FILE_UPLOAD " Open", ImVec2(IMGUI_RIGHT_ALIGN, 0)) )
Mixer::manager().set( s.detach() );
ImGui::SameLine();
ImGui::Text("File");
// file path
std::string path = SystemToolkit::path_filename(s.path());
std::string label = BaseToolkit::truncated(path, 25);
label = BaseToolkit::transliterate(label);

View File

@@ -19,6 +19,8 @@
#include <algorithm>
#include <tinyxml2.h>
#include "defines.h"
#include "BaseToolkit.h"
#include "Source.h"
@@ -874,3 +876,46 @@ Metronome::Synchronicity Session::inputSynchrony(uint input)
return input_sync_[input];
}
void Session::applySnapshot(uint64_t key)
{
tinyxml2::XMLElement *snapshot_node_ = snapshots_.xmlDoc_->FirstChildElement( SNAPSHOT_NODE(key).c_str() );;
if (snapshot_node_) {
SourceIdList session_sources = getIdList();
SessionLoader loader( this );
loader.load( snapshot_node_ );
// loaded_sources contains map of xml ids of all sources treated by loader
std::map< uint64_t, Source* > loaded_sources = loader.getSources();
// remove intersect of both lists (sources were updated by SessionLoader)
for( auto lsit = loaded_sources.begin(); lsit != loaded_sources.end(); ){
auto ssit = std::find(session_sources.begin(), session_sources.end(), (*lsit).first);
if ( ssit != session_sources.end() ) {
lsit = loaded_sources.erase(lsit);
session_sources.erase(ssit);
}
else
lsit++;
}
// remaining ids in list sessionsources : to remove
while ( !session_sources.empty() ){
SourceList::iterator its = find(session_sources.front());
// its in the list !
if (its != sources_.end()) {
#ifndef ACTION_DEBUG
Log::Info("Delete id %s\n", std::to_string(session_sources.front() ).c_str());
#endif
// delete source from session
deleteSource( *its );
}
session_sources.pop_front();
}
++View::need_deep_update_;
}
}

View File

@@ -27,6 +27,8 @@ struct SessionNote
SessionNote(const std::string &t = "", bool l = false, int s = 0);
};
#define SNAPSHOT_NODE(i) std::to_string(i).insert(0,1,'S')
struct SessionSnapshots {
tinyxml2::XMLDocument *xmlDoc_;
@@ -148,6 +150,7 @@ public:
// snapshots
SessionSnapshots * snapshots () { return &snapshots_; }
void applySnapshot(uint64_t key);
// playlists
void addPlayGroup(const SourceIdList &ids);