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 FRAME_H
0021 #define FRAME_H
0022 
0023 #include "workspacefile.h"
0024 
0025 #include <vector>
0026 
0027 class FileNameVisitor;
0028 class Sound;
0029 class AudioDriver;
0030 
0031 /**
0032  * Class representing the frames in the animation
0033  *
0034  * @author Bjoern Erik Nilsen & Fredrik Berg Kjoelstad
0035  */
0036 class Frame {
0037 public:
0038     /**
0039      * Creates a frame with the specified file for its picture.
0040      * @param file The picture for this frame. The WorkspaceFile object is
0041      * emptied by this call.
0042      */
0043     Frame(WorkspaceFile& file);
0044 
0045     /**
0046      * Cleans up after the frame
0047      */
0048     ~Frame();
0049 
0050     /**
0051      * Adds the sound in the file filename to the end of the sounds in this
0052      * frame, giving it an arbitrary name.
0053      * @param file The file that holds the sound.
0054      * @return zero on success, less than zero on failure;
0055      * -1 = file is not readable
0056      * -2 = not a valid audio file
0057      */
0058     int newSound(WorkspaceFile& file);
0059 
0060     /**
0061      * Adds a sound.
0062      * @param sound Ownership is passed. May not be null.
0063      * @param index Must be between 0 and @code{.cpp} getNumberOfSounds()
0064      * @endcode
0065      * @note This is guaranteed not to fail for @c n calls after a call to
0066      * @code{.cpp} preallocateSounds(n) @endcode
0067      */
0068     void addSound(int index, Sound* sound);
0069 
0070     /**
0071      * Allocates space for @a extra more calls to @ref addSound
0072      * @param extra Number of slots to reserve.
0073      */
0074     void preallocateSounds(int extra);
0075 
0076     /**
0077      * Removes sound number soundNumber from this frame.
0078      * @param soundNumber The index of the sound to remove. Must be between
0079      * 0 and @code{.cpp} getNumberOfSounds() - 1 @encode
0080      * @return The sound that was removed. Ownership is returned.
0081      */
0082     Sound* removeSound(int index);
0083 
0084     /**
0085      * Returns the sound.
0086      * @param index Which sound to return.
0087      */
0088     Sound* getSound(int index);
0089 
0090     /**
0091      * Returns the sound.
0092      * @param index Which sound to return.
0093      */
0094     const Sound* getSound(int index) const;
0095 
0096     /**
0097      * Returns the number of sounds in this frame.
0098      * @return the number of sounds in this frame.
0099      */
0100     int soundCount() const;
0101 
0102     /**
0103      * Sets the name of the sound at index soundNumber in this frame to
0104      * soundName
0105      * @param soundNumber the number of the sound to change the name of.
0106      * @param soundName the new name of the sound. Ownership is passed; must
0107      * have been allocated with new char[].
0108      * @return The old name for this sound. Ownership is returned; must be
0109      * freed with delete[].
0110      */
0111     const char* setSoundName(int soundNumber, const char* soundName);
0112 
0113     /**
0114      * Retrieves the name of the sound at index soundNumber in this frame.
0115      * @param soundNumber the sound to return.
0116      * @return the sound at index soundNumber in this frame. Ownership is
0117      * not returned.
0118      */
0119     const char* getSoundName(int soundNumber) const;
0120 
0121     /**
0122      * Retrieves the absolute path to the picture of this frame.
0123      * @return the absolute path to the picture of this frame.
0124      */
0125     const char* getImagePath() const;
0126 
0127     /**
0128      * Retrieves the base name of the picture of this frame.
0129      * @return The picture file's silename and extension without any path.
0130      */
0131     const char* getBasename() const;
0132 
0133     /**
0134      * Replaces the image path.
0135      * @param [in, out] otherImage The new image to set. On return, this will
0136      * hold the old image.
0137      */
0138     void replaceImage(WorkspaceFile& otherImage);
0139 
0140     /**
0141      * Plays the sounds belonging to this frame.
0142      */
0143     void playSounds(AudioDriver *driver) const;
0144 
0145     /**
0146      * Makes v visit all the files referenced (image and sounds)
0147      */
0148     void accept(FileNameVisitor& v) const;
0149 
0150 private:
0151 
0152     WorkspaceFile imagePath;
0153 
0154     typedef std::vector<Sound*> SoundVector;
0155 
0156     /** Contains the sounds belonging to this frame. */
0157     SoundVector sounds;
0158 };
0159 
0160 #endif