File indexing completed on 2024-05-12 16:23:26
0001 /*************************************************************************** 0002 * Copyright (C) 2005-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 #ifndef SCENE_H 0021 #define SCENE_H 0022 0023 #include "src/config.h" 0024 0025 #include <exception> 0026 #include <vector> 0027 0028 class FileNameVisitor; 0029 class Frame; 0030 class Sound; 0031 class WorkspaceFile; 0032 0033 class FrameOutOfRangeException : public std::exception { 0034 public: 0035 FrameOutOfRangeException(); 0036 const char* what() const throw(); 0037 }; 0038 0039 /** 0040 * Class representing the scenes in the animation 0041 * 0042 * @author Bjoern Erik Nilsen & Fredrik Berg Kjoelstad 0043 */ 0044 class Scene { 0045 public: 0046 /** 0047 * Initializes the scene 0048 */ 0049 Scene(); 0050 0051 /** 0052 * Cleans up the scene and delete the frames. 0053 */ 0054 ~Scene(); 0055 0056 /** 0057 * Retrieves the size of the scene (the number of frames in it). 0058 * @return the number of frames in the scene. 0059 */ 0060 int getSize() const; 0061 0062 /** 0063 * Retrieves the frame at position frameNumber in the scene. 0064 * @param frameNumber the number of the frame to retrieve. 0065 * @return the frame at position frameNumber. 0066 */ 0067 const Frame* getFrame(int frameNumber) const; 0068 0069 /** 0070 * Removes a frame from the scene. 0071 * @param frame The frame to remove. 0072 * @return The removed frame. Ownership is returned. 0073 */ 0074 Frame* removeFrame(int frame); 0075 0076 /** 0077 * Removes frames from the animation. 0078 * @param frame The index from which to begin removing. 0079 * @param count The number of frames to remove. 0080 * @param [out] out The removed frames. 0081 */ 0082 void removeFrames(int frame, int count, 0083 std::vector<Frame*>& out); 0084 0085 /** 0086 * Moves the frames at the positions from fromFrame to toFrame (inclusive) 0087 * to the position movePosition inside the scene. 0088 * @param fromFrame the first frame to move. 0089 * @param toFrame the lst frame to move. 0090 * @param movePosition the position to move the frames to. 0091 */ 0092 void moveFrames(int fromFrame, int toFrame, int movePosition); 0093 0094 /** 0095 * Cleans frames from the scene without moving them around. Used when the user 0096 * aborts while adding frames. 0097 * @param fromFrame the first frame to remove. 0098 * @param toFrame the last frame to remove. 0099 */ 0100 void cleanFrames(int fromFrame, int toFrame); 0101 0102 /** 0103 * Adds a frame at @a index. Will not fail if {@ref preallocateFrames} 0104 * has been called with the appropriate number beforehand. 0105 * @param f The frame to add. 0106 * @param index The index at which to add the frame. Must be between 0107 * 0 and @code{.cpp} getSize() @endcode inclusive. 0108 */ 0109 void addFrame(Frame* f, int index); 0110 0111 /** 0112 * Adds frames to the scene. 0113 * @param where Frame index to add the new frames. 0114 * @param fs The frames to add. 0115 */ 0116 void addFrames(int where, const std::vector<Frame*>& fs); 0117 0118 /** 0119 * Reserves space for @a count more frames to be added without the risk of 0120 * an exception being thrown. 0121 * @param count The number of frames that need to be added. 0122 */ 0123 void preallocateFrames(int count); 0124 0125 /** 0126 * Replaces the image of the frame at index {@a frameNumber}. 0127 * @param frameNumber The index of the frame to alter. 0128 * @param [in,out] The image to swap with. On exit, the frame at index 0129 * {@a frameNumber} will have the image formerly held by 0130 * {@a otherImage} and {@a otherImage} will have the image formerly held 0131 * by the frame. 0132 */ 0133 void replaceImage(int frameNumber, WorkspaceFile& otherImage); 0134 0135 /** 0136 * Adds an already saved frame. 0137 * @param f the frame to add 0138 */ 0139 void addSavedFrame(Frame *f); 0140 0141 /** 0142 * Adds the sound in the file filename to the end of the sounds in the 0143 * frame with index {@a frameNumber}, giving it an arbitrary name. 0144 * @param file The file that holds the sound. 0145 * @return zero on success, less than zero on failure; 0146 * -1 = file is not readable 0147 * -2 = not a valid audio file 0148 */ 0149 int newSound(int frameNumber, WorkspaceFile& file); 0150 0151 /** 0152 * Adds a sound to the frame specified. 0153 * @param frameNumber Index of the frame to add a sound to. 0154 * @param soundNumber Index that the sound is to have. 0155 * @param sound The sound to add. 0156 */ 0157 void addSound(int frameNumber, int soundNumber, Sound* sound); 0158 0159 /** 0160 * Removes a sound from the specified frame. 0161 * @param frameNumber The frame from which to remove the sound. 0162 * @param index Which sound to remove. 0163 * @return The removed sound. Ownership is passed. 0164 */ 0165 Sound* removeSound(int frameNumber, int index); 0166 0167 /** 0168 * Gets a sound from a frame. 0169 * @param frameNumber The index of the frame. 0170 * @param index The index of the sound. 0171 * @return The sound. Ownership is not passed. 0172 */ 0173 const Sound* getSound(int frameNumber, int index) const; 0174 0175 /** 0176 * Returns the number of sounds in the specified frame. 0177 * @param frameNumber Index of the frame. 0178 * @return the number of sounds in frame {@a frameNumber}. 0179 */ 0180 int soundCount(int frameNumber) const; 0181 0182 /** 0183 * Returns the total number of sounds in all the frames in this scene. 0184 * @return the number of sounds. 0185 */ 0186 int soundCount() const; 0187 0188 /** 0189 * Sets the name of the sound at index soundNumber in the specified frame 0190 * to soundName 0191 * @param frameNumber Index of the frame. 0192 * @param soundNumber the number of the sound to change the name of. 0193 * @param soundName the new name of the sound. Ownership is passed; must 0194 * have been allocated with new char[]. 0195 * @return The old name for this sound. Ownership is returned; must be 0196 * freed with delete[]. 0197 */ 0198 const char* setSoundName(int frameNumber, int soundNumber, 0199 const char* soundName); 0200 0201 /** 0202 * Retrieves the name of the sound at index soundNumber in the specified 0203 * frame. 0204 * @param frameNumber Index of the frame. 0205 * @param soundNumber the sound to return. 0206 * @return the sound at index soundNumber in this frame. Ownership is 0207 * not returned. 0208 */ 0209 const char* getSoundName(int frameNumber, int soundNumber) const; 0210 0211 /** 0212 * Have v visit all the files referenced (images and sounds) 0213 */ 0214 void accept(FileNameVisitor& v) const; 0215 0216 private: 0217 typedef std::vector<Frame*> FrameVector; 0218 FrameVector frames; 0219 }; 0220 0221 #endif