mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
Bugfix: prevent crash with current source when reordering
This commit is contained in:
20
Mixer.cpp
20
Mixer.cpp
@@ -772,6 +772,19 @@ void Mixer::setCurrentIndex(int index)
|
||||
setCurrentSource( session_->at(index) );
|
||||
}
|
||||
|
||||
void Mixer::moveIndex (int current_index, int target_index)
|
||||
{
|
||||
// remember ptr to current source
|
||||
Source *previous_current_source_ = currentSource();
|
||||
|
||||
// change order
|
||||
session_->move(current_index, target_index);
|
||||
|
||||
// restore current
|
||||
unsetCurrentSource();
|
||||
setCurrentSource(previous_current_source_);
|
||||
}
|
||||
|
||||
void Mixer::setCurrentNext()
|
||||
{
|
||||
if (session_->numSource() > 0) {
|
||||
@@ -831,11 +844,10 @@ int Mixer::indexCurrentSource()
|
||||
|
||||
Source *Mixer::currentSource()
|
||||
{
|
||||
if ( current_source_ == session_->end() )
|
||||
if ( current_source_ != session_->end() )
|
||||
return (*current_source_);
|
||||
else
|
||||
return nullptr;
|
||||
else {
|
||||
return *(current_source_);
|
||||
}
|
||||
}
|
||||
|
||||
// management of view
|
||||
|
||||
1
Mixer.h
1
Mixer.h
@@ -73,6 +73,7 @@ public:
|
||||
void unsetCurrentSource ();
|
||||
|
||||
void setCurrentIndex (int index);
|
||||
void moveIndex (int current_index, int target_index);
|
||||
int indexCurrentSource ();
|
||||
|
||||
// browsing into sources
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "ImageShader.h"
|
||||
#include "ImageProcessingShader.h"
|
||||
#include "MediaPlayer.h"
|
||||
#include "SystemToolkit.h"
|
||||
|
||||
#include <tinyxml2.h>
|
||||
#include "tinyxml2Toolkit.h"
|
||||
@@ -26,12 +27,13 @@ std::string SessionCreator::info(const std::string& filename)
|
||||
{
|
||||
std::string ret = "";
|
||||
|
||||
// if the file exists
|
||||
if (SystemToolkit::file_exists(filename)) {
|
||||
// try to load the file
|
||||
XMLDocument doc;
|
||||
XMLError eResult = doc.LoadFile(filename.c_str());
|
||||
if ( XMLResultError(eResult)) {
|
||||
Log::Warning("%s could not be openned.", filename.c_str());
|
||||
return ret;
|
||||
}
|
||||
// silently ignore on error
|
||||
if ( !XMLResultError(eResult, false)) {
|
||||
|
||||
XMLElement *header = doc.FirstChildElement(APP_NAME);
|
||||
if (header != nullptr && header->Attribute("date") != 0) {
|
||||
@@ -48,6 +50,8 @@ std::string SessionCreator::info(const std::string& filename)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1582,19 +1582,22 @@ void MediaController::setMediaPlayer(MediaPlayer *mp)
|
||||
void MediaController::followCurrentSource()
|
||||
{
|
||||
Source *s = Mixer::manager().currentSource();
|
||||
if ( s != nullptr) {
|
||||
MediaSource *ms = dynamic_cast<MediaSource *>(s);
|
||||
if (ms) {
|
||||
MediaSource *ms = nullptr;
|
||||
|
||||
if ( s != nullptr)
|
||||
ms = dynamic_cast<MediaSource *>(s);
|
||||
|
||||
if ( ms != nullptr) {
|
||||
// update the internal mediaplayer if changed
|
||||
if (mp_ != ms->mediaplayer()) {
|
||||
mp_ = ms->mediaplayer();
|
||||
media_playing_mode_ = mp_->isPlaying();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
mp_ = nullptr;
|
||||
media_playing_mode_ = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2153,11 +2156,11 @@ void Navigator::Render()
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("DND_SOURCE"))
|
||||
{
|
||||
if ( payload->DataSize == sizeof(int) ) {
|
||||
// drop means move index and reorder
|
||||
int payload_index = *(const int*)payload->Data;
|
||||
int current_source_index = Mixer::manager().indexCurrentSource();
|
||||
Mixer::manager().session()->move(payload_index, index);
|
||||
if (payload_index == current_source_index)
|
||||
applyButtonSelection(index);
|
||||
Mixer::manager().moveIndex(payload_index, index);
|
||||
// index of current source changed
|
||||
applyButtonSelection(Mixer::manager().indexCurrentSource());
|
||||
}
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
@@ -2831,7 +2834,7 @@ void Navigator::RenderMainPannel()
|
||||
for(auto it = sessions_list.begin(); it != sessions_list.end(); it++) {
|
||||
std::string sessionfilename(*it);
|
||||
if (sessionfilename.empty())
|
||||
break;
|
||||
continue;
|
||||
std::string shortname = SystemToolkit::filename(*it);
|
||||
if (ImGui::Selectable( shortname.c_str(), false, ImGuiSelectableFlags_AllowDoubleClick )) {
|
||||
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) || file_selected == it) {
|
||||
@@ -2857,7 +2860,7 @@ void Navigator::RenderMainPannel()
|
||||
file_info.clear();
|
||||
file_selected = sessions_list.end();
|
||||
}
|
||||
if (!file_info.empty()) {
|
||||
else if (!file_info.empty()) {
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::Text("%s", file_info.c_str());
|
||||
ImGui::EndTooltip();
|
||||
|
||||
@@ -237,11 +237,12 @@ bool tinyxml2::XMLSaveDoc(XMLDocument * const doc, std::string filename)
|
||||
return !XMLResultError(eResult);
|
||||
}
|
||||
|
||||
bool tinyxml2::XMLResultError(int result)
|
||||
bool tinyxml2::XMLResultError(int result, bool verbose)
|
||||
{
|
||||
XMLError xmlresult = (XMLError) result;
|
||||
if ( xmlresult != XML_SUCCESS)
|
||||
{
|
||||
if (verbose)
|
||||
Log::Info("XML error %i: %s", result, tinyxml2::XMLDocument::ErrorIDToName(xmlresult));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ XMLElement *XMLElementEncodeArray(XMLDocument *doc, const void *array, uint arra
|
||||
bool XMLElementDecodeArray(XMLElement *elem, void *array, uint arraysize);
|
||||
|
||||
bool XMLSaveDoc(tinyxml2::XMLDocument * const doc, std::string filename);
|
||||
bool XMLResultError(int result);
|
||||
bool XMLResultError(int result, bool verbose = true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user