Skip to content

Commit

Permalink
Fix playback of same tag when adding new frames (fix https://communit…
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Jul 27, 2020
1 parent 0c0510b commit 2a48c68
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 25 deletions.
17 changes: 16 additions & 1 deletion src/app/cmd/set_tag_range.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
Expand All @@ -11,7 +11,11 @@

#include "app/cmd/set_tag_range.h"

#include "app/doc.h"
#include "app/doc_event.h"
#include "doc/sprite.h"
#include "doc/tag.h"
#include "doc/tags.h"

namespace app {
namespace cmd {
Expand All @@ -37,5 +41,16 @@ void SetTagRange::onUndo()
tag()->incrementVersion();
}

void SetTagRange::onFireNotifications()
{
Tag* tag = this->tag();
Sprite* sprite = tag->owner()->sprite();
Doc* doc = static_cast<Doc*>(sprite->document());
DocEvent ev(doc);
ev.sprite(sprite);
ev.tag(tag);
doc->notify_observers<DocEvent&>(&DocObserver::onTagChange, ev);
}

} // namespace cmd
} // namespace app
3 changes: 2 additions & 1 deletion src/app/cmd/set_tag_range.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
Expand All @@ -25,6 +25,7 @@ namespace cmd {
protected:
void onExecute() override;
void onUndo() override;
void onFireNotifications() override;
size_t onMemSize() const override {
return sizeof(*this);
}
Expand Down
5 changes: 4 additions & 1 deletion src/app/doc_observer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2018-2019 Igara Studio S.A.
// Copyright (C) 2018-2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -73,6 +73,9 @@ namespace app {
virtual void onSelectionChanged(DocEvent& ev) { }
virtual void onSelectionBoundariesChanged(DocEvent& ev) { }

// Tags
virtual void onTagChange(DocEvent& ev) { }

// Slices
virtual void onSliceNameChange(DocEvent& ev) { }

Expand Down
6 changes: 6 additions & 0 deletions src/app/ui/doc_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,12 @@ void DocView::onRemoveFrame(DocEvent& ev)
}
}

void DocView::onTagChange(DocEvent& ev)
{
if (m_previewDelegate)
m_previewDelegate->onTagChangeEditor(m_editor, ev);
}

void DocView::onAddCel(DocEvent& ev)
{
UIContext::instance()->notifyActiveSiteChanged();
Expand Down
2 changes: 2 additions & 0 deletions src/app/ui/doc_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace app {
virtual void onScrollOtherEditor(Editor* editor) = 0;
virtual void onDisposeOtherEditor(Editor* editor) = 0;
virtual void onPreviewOtherEditor(Editor* editor) = 0;
virtual void onTagChangeEditor(Editor* editor, DocEvent& ev) = 0;
};

class DocView : public ui::Box,
Expand Down Expand Up @@ -75,6 +76,7 @@ namespace app {
void onAddLayer(DocEvent& ev) override;
void onAddFrame(DocEvent& ev) override;
void onRemoveFrame(DocEvent& ev) override;
void onTagChange(DocEvent& ev) override;
void onAddCel(DocEvent& ev) override;
void onRemoveCel(DocEvent& ev) override;
void onTotalFramesChanged(DocEvent& ev) override;
Expand Down
5 changes: 5 additions & 0 deletions src/app/ui/editor/play_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ PlayState::PlayState(const bool playOnce,
&PlayState::onBeforeCommandExecution, this);
}

Tag* PlayState::playingTag() const
{
return m_tag;
}

void PlayState::onEnterState(Editor* editor)
{
StateWithWheelBehavior::onEnterState(editor);
Expand Down
3 changes: 3 additions & 0 deletions src/app/ui/editor/play_state.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -27,6 +28,8 @@ namespace app {
PlayState(const bool playOnce,
const bool playAll);

doc::Tag* playingTag() const;

void onEnterState(Editor* editor) override;
LeaveAction onLeaveState(Editor* editor, EditorState* newState) override;
bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override;
Expand Down
60 changes: 38 additions & 22 deletions src/app/ui/preview_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "app/app.h"
#include "app/doc.h"
#include "app/doc_event.h"
#include "app/ini_file.h"
#include "app/loop_tag.h"
#include "app/modules/editors.h"
Expand All @@ -22,6 +23,7 @@
#include "app/ui/editor/editor_customization_delegate.h"
#include "app/ui/editor/editor_view.h"
#include "app/ui/editor/navigate_state.h"
#include "app/ui/editor/play_state.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h"
#include "app/ui/toolbar.h"
Expand Down Expand Up @@ -396,28 +398,7 @@ void PreviewEditorWindow::updateUsingEditor(Editor* editor)
miniEditor->setFrame(editor->frame());
}
else {
if (miniEditor->isPlaying()) {
doc::Tag* tag = editor
->getCustomizationDelegate()
->getTagProvider()
->getTagByFrame(editor->frame(), true);

doc::Tag* playingTag = editor
->getCustomizationDelegate()
->getTagProvider()
->getTagByFrame(m_refFrame, true);

if (tag == playingTag)
return;

miniEditor->stop();
}

if (!miniEditor->isPlaying())
miniEditor->setFrame(m_refFrame = editor->frame());

miniEditor->play(Preferences::instance().preview.playOnce(),
Preferences::instance().preview.playAll());
adjustPlayingTag();
}
}

Expand Down Expand Up @@ -478,6 +459,11 @@ void PreviewEditorWindow::onPreviewOtherEditor(Editor* editor)
updateUsingEditor(editor);
}

void PreviewEditorWindow::onTagChangeEditor(Editor* editor, DocEvent& ev)
{
adjustPlayingTag();
}

void PreviewEditorWindow::hideWindow()
{
destroyDocView();
Expand All @@ -495,4 +481,34 @@ void PreviewEditorWindow::destroyDocView()
}
}

void PreviewEditorWindow::adjustPlayingTag()
{
Editor* editor = m_relatedEditor;
Editor* miniEditor = m_docView->editor();

ASSERT(editor);
ASSERT(miniEditor);

if (miniEditor->isPlaying()) {
doc::Tag* tag = editor
->getCustomizationDelegate()
->getTagProvider()
->getTagByFrame(editor->frame(), true);

auto playState = dynamic_cast<PlayState*>(miniEditor->getState().get());
doc::Tag* playingTag = (playState ? playState->playingTag(): nullptr);

if (tag == playingTag)
return;

miniEditor->stop();
}

if (!miniEditor->isPlaying())
miniEditor->setFrame(m_refFrame = editor->frame());

miniEditor->play(Preferences::instance().preview.playOnce(),
Preferences::instance().preview.playAll());
}

} // namespace app
3 changes: 3 additions & 0 deletions src/app/ui/preview_editor.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -42,6 +43,7 @@ namespace app {
void onScrollOtherEditor(Editor* editor) override;
void onDisposeOtherEditor(Editor* editor) override;
void onPreviewOtherEditor(Editor* editor) override;
void onTagChangeEditor(Editor* editor, DocEvent& ev) override;

protected:
bool onProcessMessage(ui::Message* msg) override;
Expand All @@ -59,6 +61,7 @@ namespace app {
void hideWindow();
void destroyDocView();
void saveScrollPref();
void adjustPlayingTag();

bool m_isEnabled;
DocView* m_docView;
Expand Down

0 comments on commit 2a48c68

Please sign in to comment.