File indexing completed on 2024-05-12 16:23:25

0001 /***************************************************************************
0002  *   Copyright (C) 2013 by Linuxstopmotion contributors;                   *
0003  *   see the AUTHORS file for details.                                     *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 
0022 #ifndef ANIMATIONIMPL_H_
0023 #define ANIMATIONIMPL_H_
0024 
0025 #include <vector>
0026 
0027 class WorkspaceFile;
0028 class Scene;
0029 class Frame;
0030 class Sound;
0031 class FileNameVisitor;
0032 class AudioDriver;
0033 
0034 /**
0035  * Base class for implementation class of the animation, and any wrappers.
0036  * Represents an animation that can be updated by the undo system. This
0037  * interface should therefore not be used by any code upstream of the
0038  * undo system.
0039  */
0040 class AnimationImpl {
0041 public:
0042     virtual ~AnimationImpl() = 0;
0043     /**
0044      * Clears the animation so that there are no scenes and no frames.
0045      */
0046     virtual void clear() = 0;
0047     /**
0048      * Returns the number of scenes in the animation.
0049      * @return The number of scenes.
0050      */
0051     virtual int sceneCount() const = 0;
0052     /**
0053      * Adds a scene to the animation.
0054      * @param where Where in the sequence of scenes to insert this one. Must be
0055      * between 0 and {@c SceneCount()} inclusive.
0056      * @param newScene The scene to be inserted; ownership is passed.
0057      */
0058     virtual void addScene(int where, Scene* newScene) = 0;
0059     /**
0060      * Adds a fresh empty scene.
0061      * @param where The scene number that this new scene will have.
0062      */
0063     virtual void addScene(int where) = 0;
0064     /**
0065      * Preallocates memory so that AddScene can be called without the risk of
0066      * throwing an exception.
0067      * @param count Number of calls to @ref AddScene required without
0068      * exceptions being thrown.
0069      */
0070     virtual void preallocateScenes(int count) = 0;
0071     /**
0072      * Removes a scene from the animation, together with all its frames.
0073      * @param from The scene to remove. Must be between 0 and @code{.cpp}
0074      * SceneCount() - 1 @endcode inclusive.
0075      * @return The removed scene. Ownership is returned.
0076      */
0077     virtual Scene* removeScene(int from) = 0;
0078     /**
0079      * Moves a scene.
0080      * @param from The scene number to move. Must be between 0 and
0081      * {@c SceneCount()} inclusive.
0082      * @param from The number the scene is to become. Must be between 0 and
0083      * {@c SceneCount()} inclusive.
0084      */
0085     virtual void moveScene(int from, int to) = 0;
0086     /**
0087      * Returns the scene requested, which must not be modified.
0088      * @param which The number of the scene to be returned.
0089      * @return The scene requested.
0090      */
0091     virtual const Scene* getScene(int which) const = 0;
0092     /**
0093      * Returns the number of frames in scene number @a scene.
0094      * @param scene The number of the scene to query.
0095      * @return The number of frames in scene number @a scene.
0096      */
0097     virtual int frameCount(int scene) const = 0;
0098     /**
0099      * Adds a frame to the animation.
0100      * @param scene The number of the scene to add the frames to.
0101      * @param where The number of the frame within scene number @a scene to
0102      * add the frame.
0103      * @param frame The frame to add. Ownership is passed.
0104      */
0105     virtual void addFrame(int scene, int where, Frame* frame) = 0;
0106     /**
0107      * Adds frames to the animation.
0108      * @param scene The scene to which the frames will be added.
0109      * @param where The frame number for the first of the added frames.
0110      * @param frames The frames to add.
0111      * @note On failure, no frames will have been added.
0112      */
0113     virtual void addFrames(int scene, int where,
0114             const std::vector<Frame*>& frames) = 0;
0115     /**
0116      * Preallocates enough memory for @ref AddFrames to add @a count frames
0117      * to scene number @scene.
0118      */
0119     virtual void preallocateFrames(int scene, int count) = 0;
0120     /**
0121      * Removes a frame from the animation.
0122      * @param scene The scene to remove the frame from.
0123      * @param frame The number of the first frame within scene @a scene
0124      * to remove.
0125      * @return The removed frame; ownership is returned.
0126      * @throws Will not throw.
0127      */
0128     virtual Frame* removeFrame(int scene, int frame) = 0;
0129     /**
0130      * Removes frames from the animation.
0131      * @param scene The scene from which to remove the frames.
0132      * @param frame The first frame to remove.
0133      * @param count The number of frames to remove.
0134      * @param [out] out The removed frames will be added to the end of this
0135      * vector. Ownership is returned.
0136      * @note Upon failure, {@a out} and the animation will both be untouched.
0137      * @pre The scene must have at least @code{.cpp} frame + count @endcode
0138      * frames.
0139      */
0140     virtual void removeFrames(int scene, int frame, int count,
0141             std::vector<Frame*>& out) = 0;
0142     /**
0143      * Moves frames.
0144      * @param fromScene The number of the scene from which to move frames.
0145      * @param fromFrame The number of the frame within scene @a fromScene from
0146      * which frames should be moved.
0147      * @param frameCount The number of frames to move. All the frames must be
0148      * from the same scene.
0149      * @param toScene The number of the scene to which to move the frames.
0150      * @param toFrame The number of the frame within scene @a toScene to which
0151      * the frames should be moved.
0152      */
0153     virtual void moveFrames(int fromScene, int fromFrame, int frameCount,
0154             int toScene, int toFrame) = 0;
0155     /**
0156      * Replaces the image of the frame at index {@a frameNumber} of scene
0157      * {@a sceneNumber}.
0158      * @param sceneNumber The index of the scene containing the frame to alter.
0159      * @param frameNumber The index of the frame to alter.
0160      * @param [in,out] The image to swap with. On exit, the frame at index
0161      * {@a frameNumber} will have the image formerly held by
0162      * {@a otherImage} and {@a otherImage} will have the image formerly held
0163      * by the frame.
0164      */
0165     virtual void replaceImage(int sceneNumber, int frameNumber,
0166             WorkspaceFile& otherImage) = 0;
0167     /**
0168      * Returns the number of sounds attached to a frame.
0169      * @param scene The number of the scene that contains the frame that you
0170      * need to examine.
0171      * @param frame The number of the frame from @a scene to examine.
0172      * @return The number of sounds attached to frame number @a frame of scene
0173      * @a scene.
0174      */
0175     virtual int soundCount(int scene, int frame) const = 0;
0176     /**
0177      * Returns the number of sounds in the animation.
0178      * @return Sum of the number of sounds attached to each frame.
0179      */
0180     virtual int soundCount() const = 0;
0181     /**
0182      * Adds a sound to a frame of animation.
0183      * @param scene The number of the scene containing the frame to add the
0184      * sound to.
0185      * @param frame The number of the frame within scene number @a scene to
0186      * add the sound to.
0187      * @param soundNumber The position of the sound to add. Must be between
0188      * 0 and @code{.cpp} SoundCount(scene, frame) @endcode inclusive.
0189      * @param sound The name sound to add. Ownership is passed.
0190      */
0191     virtual void addSound(int scene, int frame, int soundNumber,
0192             Sound* sound) = 0;
0193     /**
0194      * changes the name of a sound of a frame.
0195      * @param scene The number of the scene containing the frame to change.
0196      * @param frame The number of the frame within scene number @a scene
0197      * containing the sound to be named.
0198      * @param soundNumber Which sound within frame number @a frame of scene
0199      * number @a scene to be replaced.
0200      * @param soundName The new name of the sound to be added. Ownership
0201      * is passed; must have been created with {@c new char[]}.
0202      * @return The old name of the sound. Ownership is returned; must be
0203      * deleted with {@c delete[]}.
0204      * @throws Nothing.
0205      */
0206     virtual const char* setSoundName(int scene, int frame, int soundNumber,
0207             const char* soundName) = 0;
0208     /**
0209      * Removes a sound of a frame.
0210      * @param scene The number of the scene containing the frame to change.
0211      * @param frame The number of the frame within scene number @a scene
0212      * containing the sound to be changed.
0213      * @param soundNumber Which sound within frame number @a frame of scene
0214      * number @a scene to be removed.
0215      * @return The file name of the sound that is being removed. Ownership
0216      * is returned.
0217      * @throws Nothing.
0218      */
0219     virtual Sound* removeSound(int scene, int frame, int soundNumber) = 0;
0220     /**
0221      * Plays the sounds from the frame specified.
0222      * @param scene The scene to which the frame belongs.
0223      * @param frame The frame within that scene.
0224      * @param driver The audio driver with which to play the sounds.
0225      */
0226     virtual void playSounds(int scene, int frame, AudioDriver* driver) const = 0;
0227     virtual void accept(FileNameVisitor& v) const = 0;
0228 };
0229 
0230 #endif /* ANIMATIONIMPL_H_ */