mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
BugFix Storing Play status of source in XML
Undo and restore play status of Source. Fix reload / restore play speed.
This commit is contained in:
@@ -302,7 +302,7 @@ void MediaPlayer::open (const std::string & filename, const std::string &uri)
|
|||||||
void MediaPlayer::reopen()
|
void MediaPlayer::reopen()
|
||||||
{
|
{
|
||||||
// re-openning is meaningfull only if it was already open
|
// re-openning is meaningfull only if it was already open
|
||||||
if (pipeline_ != nullptr) {
|
if (pipeline_ != nullptr && opened_) {
|
||||||
// reload : terminate pipeline and re-create it
|
// reload : terminate pipeline and re-create it
|
||||||
close();
|
close();
|
||||||
execute_open();
|
execute_open();
|
||||||
@@ -1348,7 +1348,7 @@ void MediaPlayer::execute_seek_command(GstClockTime target, bool force)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Log::Warning("MediaPlayer %s Seek failed", std::to_string(id_).c_str());
|
Log::Info("MediaPlayer %s Seek failed", std::to_string(id_).c_str());
|
||||||
|
|
||||||
// Force update
|
// Force update
|
||||||
if (force) {
|
if (force) {
|
||||||
@@ -1359,6 +1359,15 @@ void MediaPlayer::execute_seek_command(GstClockTime target, bool force)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MediaPlayer::setRate(double s)
|
||||||
|
{
|
||||||
|
// bound to interval [-MAX_PLAY_SPEED MAX_PLAY_SPEED]
|
||||||
|
rate_ = CLAMP(s, -MAX_PLAY_SPEED, MAX_PLAY_SPEED);
|
||||||
|
// skip interval [-MIN_PLAY_SPEED MIN_PLAY_SPEED]
|
||||||
|
if (ABS(rate_) < MIN_PLAY_SPEED)
|
||||||
|
rate_ = SIGN(rate_) * MIN_PLAY_SPEED;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void MediaPlayer::setPlaySpeed(double s)
|
void MediaPlayer::setPlaySpeed(double s)
|
||||||
{
|
{
|
||||||
@@ -1367,11 +1376,7 @@ void MediaPlayer::setPlaySpeed(double s)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set rate to requested value (may be executed later)
|
// Set rate to requested value (may be executed later)
|
||||||
// bound to interval [-MAX_PLAY_SPEED MAX_PLAY_SPEED]
|
setRate(s);
|
||||||
rate_ = CLAMP(s, -MAX_PLAY_SPEED, MAX_PLAY_SPEED);
|
|
||||||
// skip interval [-MIN_PLAY_SPEED MIN_PLAY_SPEED]
|
|
||||||
if (ABS(rate_) < MIN_PLAY_SPEED)
|
|
||||||
rate_ = SIGN(rate_) * MIN_PLAY_SPEED;
|
|
||||||
|
|
||||||
// discard if too early or not possible
|
// discard if too early or not possible
|
||||||
if (pipeline_ == nullptr || !media_.seekable)
|
if (pipeline_ == nullptr || !media_.seekable)
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ public:
|
|||||||
* Set the speed factor for playing
|
* Set the speed factor for playing
|
||||||
* Can be negative.
|
* Can be negative.
|
||||||
* */
|
* */
|
||||||
|
void setRate(double s);
|
||||||
void setPlaySpeed(double s);
|
void setPlaySpeed(double s);
|
||||||
/**
|
/**
|
||||||
* Loop Mode: Behavior when reaching an extremity
|
* Loop Mode: Behavior when reaching an extremity
|
||||||
|
|||||||
@@ -894,16 +894,21 @@ void SessionLoader::visit(MediaPlayer &n)
|
|||||||
n.setTimeline(tl);
|
n.setTimeline(tl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// change play status only if different id (e.g. new media player)
|
// change play rate: will be activated in SessionLoader::visit (MediaSource& s)
|
||||||
if ( n.id() != id__ ) {
|
|
||||||
|
|
||||||
const char *pFilter = mediaplayerNode->Attribute("video_effect");
|
|
||||||
if (pFilter)
|
|
||||||
n.setVideoEffect(std::string(pFilter));
|
|
||||||
|
|
||||||
double speed = 1.0;
|
double speed = 1.0;
|
||||||
mediaplayerNode->QueryDoubleAttribute("speed", &speed);
|
mediaplayerNode->QueryDoubleAttribute("speed", &speed);
|
||||||
n.setPlaySpeed(speed);
|
n.setRate(speed);
|
||||||
|
|
||||||
|
// change video effect only if effect given is different
|
||||||
|
const char *pFilter = mediaplayerNode->Attribute("video_effect");
|
||||||
|
if (pFilter) {
|
||||||
|
if (n.videoEffect().compare(pFilter) != 0) {
|
||||||
|
n.setVideoEffect(pFilter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// change play status only if different id (e.g. new media player)
|
||||||
|
if ( n.id() != id__ ) {
|
||||||
|
|
||||||
int loop = 1;
|
int loop = 1;
|
||||||
mediaplayerNode->QueryIntAttribute("loop", &loop);
|
mediaplayerNode->QueryIntAttribute("loop", &loop);
|
||||||
@@ -921,6 +926,7 @@ void SessionLoader::visit(MediaPlayer &n)
|
|||||||
mediaplayerNode->QueryIntAttribute("sync_to_metronome", &sync_to_metronome);
|
mediaplayerNode->QueryIntAttribute("sync_to_metronome", &sync_to_metronome);
|
||||||
n.setSyncToMetronome( (Metronome::Synchronicity) sync_to_metronome);
|
n.setSyncToMetronome( (Metronome::Synchronicity) sync_to_metronome);
|
||||||
|
|
||||||
|
/// obsolete
|
||||||
// only read media player play attribute if the source has no play attribute (backward compatibility)
|
// only read media player play attribute if the source has no play attribute (backward compatibility)
|
||||||
if ( !xmlCurrent_->Attribute( "play" ) ) {
|
if ( !xmlCurrent_->Attribute( "play" ) ) {
|
||||||
bool play = true;
|
bool play = true;
|
||||||
|
|||||||
@@ -424,7 +424,6 @@ void SessionVisitor::visit(MediaPlayer &n)
|
|||||||
newelement->SetAttribute("id", n.id());
|
newelement->SetAttribute("id", n.id());
|
||||||
|
|
||||||
if (!n.singleFrame()) {
|
if (!n.singleFrame()) {
|
||||||
newelement->SetAttribute("play", n.isPlaying());
|
|
||||||
newelement->SetAttribute("loop", (int) n.loop());
|
newelement->SetAttribute("loop", (int) n.loop());
|
||||||
newelement->SetAttribute("speed", n.playSpeed());
|
newelement->SetAttribute("speed", n.playSpeed());
|
||||||
newelement->SetAttribute("video_effect", n.videoEffect().c_str());
|
newelement->SetAttribute("video_effect", n.videoEffect().c_str());
|
||||||
|
|||||||
@@ -551,7 +551,7 @@ void PlaySpeed::writeValue(Source *s, float val)
|
|||||||
{
|
{
|
||||||
// access media player if target source is a media source
|
// access media player if target source is a media source
|
||||||
MediaSource *ms = dynamic_cast<MediaSource *>(s);
|
MediaSource *ms = dynamic_cast<MediaSource *>(s);
|
||||||
if (ms != nullptr) {
|
if (ms != nullptr && ms->ready()) {
|
||||||
ms->mediaplayer()->setPlaySpeed((double) val);
|
ms->mediaplayer()->setPlaySpeed((double) val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ void SourceControlWindow::Update()
|
|||||||
|
|
||||||
for (auto source = selectedsources.begin(); source != selectedsources.end(); ++source)
|
for (auto source = selectedsources.begin(); source != selectedsources.end(); ++source)
|
||||||
(*source)->play( n_play < n_source );
|
(*source)->play( n_play < n_source );
|
||||||
|
Action::manager().store( n_play < n_source ? "Sources Play" : "Sources Pause" );
|
||||||
|
|
||||||
play_toggle_request_ = false;
|
play_toggle_request_ = false;
|
||||||
}
|
}
|
||||||
@@ -393,6 +394,7 @@ void SourceControlWindow::Render()
|
|||||||
mediaplayer_timeline_zoom_ = 1.f;
|
mediaplayer_timeline_zoom_ = 1.f;
|
||||||
mediaplayer_active_->timeline()->clearFading();
|
mediaplayer_active_->timeline()->clearFading();
|
||||||
mediaplayer_active_->timeline()->clearGaps();
|
mediaplayer_active_->timeline()->clearGaps();
|
||||||
|
mediaplayer_active_->setVideoEffect("");
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << SystemToolkit::base_filename( mediaplayer_active_->filename() );
|
oss << SystemToolkit::base_filename( mediaplayer_active_->filename() );
|
||||||
oss << ": Reset timeline";
|
oss << ": Reset timeline";
|
||||||
@@ -419,7 +421,8 @@ void SourceControlWindow::Render()
|
|||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
if (ImGuiToolkit::MenuItemIcon(16, 16, "Gstreamer effect", nullptr,
|
if (ImGuiToolkit::MenuItemIcon(16, 16, "Gstreamer effect", nullptr,
|
||||||
false, mediaplayer_active_->videoEffectAvailable()) )
|
!mediaplayer_active_->videoEffect().empty(),
|
||||||
|
mediaplayer_active_->videoEffectAvailable()) )
|
||||||
mediaplayer_edit_pipeline_ = true;
|
mediaplayer_edit_pipeline_ = true;
|
||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
@@ -685,8 +688,10 @@ void SourceControlWindow::RenderSelection(size_t i)
|
|||||||
ImVec2 image_top = ImGui::GetCursorPos();
|
ImVec2 image_top = ImGui::GetCursorPos();
|
||||||
const ImVec2 framesize(1.5f * timeline_height_ * (*source)->frame()->aspectRatio(), 1.5f * timeline_height_);
|
const ImVec2 framesize(1.5f * timeline_height_ * (*source)->frame()->aspectRatio(), 1.5f * timeline_height_);
|
||||||
int action = SourceButton(*source, framesize);
|
int action = SourceButton(*source, framesize);
|
||||||
if (action > 1)
|
if (action > 1) {
|
||||||
(*source)->play( ! (*source)->playing() );
|
(*source)->play( ! (*source)->playing() );
|
||||||
|
Action::manager().store((*source)->playing() ? "Source Play" : "Source Pause" );
|
||||||
|
}
|
||||||
else if (action > 0)
|
else if (action > 0)
|
||||||
UserInterface::manager().showSourceEditor(*source);
|
UserInterface::manager().showSourceEditor(*source);
|
||||||
|
|
||||||
@@ -840,8 +845,10 @@ void SourceControlWindow::RenderSelection(size_t i)
|
|||||||
///
|
///
|
||||||
const ImVec2 framesize(1.5f * timeline_height_ * (*source)->frame()->aspectRatio(), 1.5f * timeline_height_);
|
const ImVec2 framesize(1.5f * timeline_height_ * (*source)->frame()->aspectRatio(), 1.5f * timeline_height_);
|
||||||
int action = SourceButton(*source, framesize);
|
int action = SourceButton(*source, framesize);
|
||||||
if (action > 1)
|
if (action > 1) {
|
||||||
(*source)->play( ! (*source)->playing() );
|
(*source)->play( ! (*source)->playing() );
|
||||||
|
Action::manager().store((*source)->playing() ? "Source Play" : "Source Pause" );
|
||||||
|
}
|
||||||
else if (action > 0)
|
else if (action > 0)
|
||||||
UserInterface::manager().showSourceEditor(*source);
|
UserInterface::manager().showSourceEditor(*source);
|
||||||
|
|
||||||
@@ -1240,8 +1247,10 @@ void SourceControlWindow::RenderSelectedSources()
|
|||||||
ImVec2 image_top = ImGui::GetCursorPos();
|
ImVec2 image_top = ImGui::GetCursorPos();
|
||||||
ImVec2 framesize(widthcolumn, widthcolumn / (*source)->frame()->aspectRatio());
|
ImVec2 framesize(widthcolumn, widthcolumn / (*source)->frame()->aspectRatio());
|
||||||
int action = SourceButton(*source, framesize);
|
int action = SourceButton(*source, framesize);
|
||||||
if (action > 1)
|
if (action > 1) {
|
||||||
(*source)->play( ! (*source)->playing() );
|
(*source)->play( ! (*source)->playing() );
|
||||||
|
Action::manager().store((*source)->playing() ? "Source Play" : "Source Pause" );
|
||||||
|
}
|
||||||
else if (action > 0)
|
else if (action > 0)
|
||||||
UserInterface::manager().showSourceEditor(*source);
|
UserInterface::manager().showSourceEditor(*source);
|
||||||
|
|
||||||
@@ -1702,8 +1711,11 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms)
|
|||||||
// display buttons Play/Stop depending on current playing mode
|
// display buttons Play/Stop depending on current playing mode
|
||||||
ImGui::SameLine(0, h_space_);
|
ImGui::SameLine(0, h_space_);
|
||||||
if (mediaplayer_mode_) {
|
if (mediaplayer_mode_) {
|
||||||
if (ImGui::Button(ICON_FA_PAUSE))
|
if (ImGui::Button(ICON_FA_PAUSE)){
|
||||||
mediaplayer_mode_ = false;
|
mediaplayer_mode_ = false;
|
||||||
|
oss << ": Pause";
|
||||||
|
Action::manager().store(oss.str());
|
||||||
|
}
|
||||||
ImGui::SameLine(0, h_space_);
|
ImGui::SameLine(0, h_space_);
|
||||||
|
|
||||||
ImGui::PushButtonRepeat(true);
|
ImGui::PushButtonRepeat(true);
|
||||||
@@ -1712,8 +1724,11 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms)
|
|||||||
ImGui::PopButtonRepeat();
|
ImGui::PopButtonRepeat();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (ImGui::Button(ICON_FA_PLAY))
|
if (ImGui::Button(ICON_FA_PLAY)) {
|
||||||
mediaplayer_mode_ = true;
|
mediaplayer_mode_ = true;
|
||||||
|
oss << ": Play";
|
||||||
|
Action::manager().store(oss.str());
|
||||||
|
}
|
||||||
ImGui::SameLine(0, h_space_);
|
ImGui::SameLine(0, h_space_);
|
||||||
|
|
||||||
ImGui::PushButtonRepeat(true);
|
ImGui::PushButtonRepeat(true);
|
||||||
@@ -1926,7 +1941,7 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms)
|
|||||||
_effect_description = mediaplayer_active_->videoEffect();
|
_effect_description = mediaplayer_active_->videoEffect();
|
||||||
_effect_description_changed = true;
|
_effect_description_changed = true;
|
||||||
}
|
}
|
||||||
const ImVec2 mpp_dialog_size(buttons_width_ * 3.f, buttons_height_ * 6);
|
const ImVec2 mpp_dialog_size(buttons_width_ * 3.f, buttons_height_ * 6.2f);
|
||||||
ImGui::SetNextWindowSize(mpp_dialog_size, ImGuiCond_Always);
|
ImGui::SetNextWindowSize(mpp_dialog_size, ImGuiCond_Always);
|
||||||
const ImVec2 mpp_dialog_pos = top + rendersize * 0.5f - mpp_dialog_size * 0.5f;
|
const ImVec2 mpp_dialog_pos = top + rendersize * 0.5f - mpp_dialog_size * 0.5f;
|
||||||
ImGui::SetNextWindowPos(mpp_dialog_pos, ImGuiCond_Always);
|
ImGui::SetNextWindowPos(mpp_dialog_pos, ImGuiCond_Always);
|
||||||
@@ -2028,7 +2043,7 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms)
|
|||||||
if (_status > 1) {
|
if (_status > 1) {
|
||||||
// On Error
|
// On Error
|
||||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0, 0.2, 0.2, 0.95f));
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0, 0.2, 0.2, 0.95f));
|
||||||
ImGui::Text("Error - %s", _status_message.c_str());
|
ImGui::TextWrapped("Error - %s", _status_message.c_str());
|
||||||
ImGui::PopStyleColor(1);
|
ImGui::PopStyleColor(1);
|
||||||
}
|
}
|
||||||
else if (_status > 0) {
|
else if (_status > 0) {
|
||||||
@@ -2052,6 +2067,8 @@ void SourceControlWindow::RenderMediaPlayer(MediaSource *ms)
|
|||||||
|
|
||||||
// apply to pipeline
|
// apply to pipeline
|
||||||
mediaplayer_active_->setVideoEffect(_effect_description);
|
mediaplayer_active_->setVideoEffect(_effect_description);
|
||||||
|
oss << " gst effect";
|
||||||
|
Action::manager().store(oss.str());
|
||||||
}
|
}
|
||||||
ImGui::PopStyleColor(1);
|
ImGui::PopStyleColor(1);
|
||||||
}
|
}
|
||||||
@@ -2160,12 +2177,14 @@ void SourceControlWindow::DrawButtonBar(ImVec2 bottom, float width)
|
|||||||
if (ImGui::Button(ICON_FA_PAUSE) && enabled) {
|
if (ImGui::Button(ICON_FA_PAUSE) && enabled) {
|
||||||
for (auto source = selection_.begin(); source != selection_.end(); ++source)
|
for (auto source = selection_.begin(); source != selection_.end(); ++source)
|
||||||
(*source)->play(false);
|
(*source)->play(false);
|
||||||
|
Action::manager().store("Sources Pause");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (ImGui::Button(ICON_FA_PLAY) && enabled){
|
if (ImGui::Button(ICON_FA_PLAY) && enabled){
|
||||||
for (auto source = selection_.begin(); source != selection_.end(); ++source)
|
for (auto source = selection_.begin(); source != selection_.end(); ++source)
|
||||||
(*source)->play(true);
|
(*source)->play(true);
|
||||||
|
Action::manager().store("Sources Play");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2174,11 +2193,13 @@ void SourceControlWindow::DrawButtonBar(ImVec2 bottom, float width)
|
|||||||
if (ImGui::Button(ICON_FA_PLAY) && enabled) {
|
if (ImGui::Button(ICON_FA_PLAY) && enabled) {
|
||||||
for (auto source = selection_.begin(); source != selection_.end(); ++source)
|
for (auto source = selection_.begin(); source != selection_.end(); ++source)
|
||||||
(*source)->play(true);
|
(*source)->play(true);
|
||||||
|
Action::manager().store("Sources Play");
|
||||||
}
|
}
|
||||||
ImGui::SameLine(0, h_space_);
|
ImGui::SameLine(0, h_space_);
|
||||||
if (ImGui::Button(ICON_FA_PAUSE) && enabled) {
|
if (ImGui::Button(ICON_FA_PAUSE) && enabled) {
|
||||||
for (auto source = selection_.begin(); source != selection_.end(); ++source)
|
for (auto source = selection_.begin(); source != selection_.end(); ++source)
|
||||||
(*source)->play(false);
|
(*source)->play(false);
|
||||||
|
Action::manager().store("Sources Pause");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui::SameLine(0, h_space_);
|
ImGui::SameLine(0, h_space_);
|
||||||
|
|||||||
Reference in New Issue
Block a user