All Classes Namespaces Functions Variables Enumerations Properties Pages
playbackmanager.h
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #ifndef PLAYBACKMANAGER_H
19 #define PLAYBACKMANAGER_H
20 
21 #include "basemanager.h"
22 #include <QVector>
23 
24 class QTimer;
25 class QElapsedTimer;
26 class SoundClip;
27 
28 
30 {
31  Q_OBJECT
32 public:
33  explicit PlaybackManager(Editor* editor);
34  ~PlaybackManager() override;
35 
36  bool init() override;
37  Status load(Object*) override;
38  Status save(Object*) override;
39 
40  bool isPlaying();
41  bool isLooping() { return mIsLooping; }
42  void setCheckForSoundsHalfway(bool newCheck) { mCheckForSoundsHalfway = newCheck; }
43 
44  void play();
45  void stop();
46  void playFlipRoll();
47  void playFlipInBetween();
48  void playScrub(int frame);
49  void setSoundScrubMsec(int mSec) { mMsecSoundScrub = mSec; }
50  int getSoundScrubMsec() { return mMsecSoundScrub; }
51  void setSoundScrubActive(bool b) { mSoundScrub = b; }
52  bool getSoundScrubActive() { return mSoundScrub; }
53 
54  int fps() { return mFps; }
55  int startFrame() { return mStartFrame; }
56  int endFrame() { return mEndFrame; }
57 
58  bool isRangedPlaybackOn() { return mIsRangedPlayback; }
59  int markInFrame() { return mMarkInFrame; }
60  int markOutFrame() { return mMarkOutFrame; }
61 
62  void setFps(int fps);
63  void setLooping(bool isLoop);
64  void enableRangedPlayback(bool b);
65  void setRangedStartFrame(int frame);
66  void setRangedEndFrame(int frame);
67  void enableSound(bool b);
68 
69  void stopSounds();
70 
71 private slots:
72  void stopScrubPlayback();
73 
74 signals:
75  void fpsChanged(int fps);
76  void loopStateChanged(bool b);
77  void rangedPlaybackStateChanged(bool b);
78  void playStateChanged(bool isPlaying);
79 
80 private:
81  void timerTick();
82  void flipTimerTick();
83  void playSounds(int frame);
84  bool skipFrame();
85 
86  int mStartFrame = 1;
87  int mEndFrame = 60;
88 
89  void updateStartFrame();
90  void updateEndFrame();
91 
92  bool mIsLooping = false;
93  bool mIsPlaySound = true;
94 
95  bool mIsRangedPlayback = false;
96  int mMarkInFrame = 1;
97  int mMarkOutFrame = 10;
98  int mActiveSoundFrame = 0;
99 
100  int mFps = 12;
101 
102  int mFlipRollInterval = 100;
103  int mFlipInbetweenInterval = 100;
104  int mFlipRollMax = 5;
105  int mMsecSoundScrub = 100;
106  bool mSoundScrub = false;
107 
108  QTimer* mTimer = nullptr;
109  QTimer* mFlipTimer = nullptr;
110  QTimer* mScrubTimer = nullptr;
111  QElapsedTimer* mElapsedTimer = nullptr;
112  int mPlayingFrameCounter = 0; // how many frames has passed after pressing play
113 
114  bool mCheckForSoundsHalfway = false;
115  QVector<int> mListOfActiveSoundFrames;
116  QVector<SoundClip*> mSoundclipsToPLay;
117  QVector<int> mFlipList;
118 };
119 
120 #endif // PLAYBACKMANAGER_H
Q_OBJECTQ_OBJECT
bool skipFrame()
PlaybackManager::skipFrame() Small errors accumulate while playing animation If the error is greater ...
Definition: object.h:41
Definition: editor.h:55