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

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 #include "sound.h"
0022 
0023 #include "src/technical/audio/audioformat.h"
0024 #include "src/technical/audio/oggvorbis.h"
0025 #include "src/technical/audio/audiodriver.h"
0026 
0027 #include <assert.h>
0028 #include <string.h>
0029 #include <memory>
0030 
0031 Sound::Sound() : af(0), name(0) {
0032 }
0033 
0034 Sound::~Sound() {
0035     delete af;
0036     delete[] name;
0037 }
0038 
0039 /**
0040  *@todo check audio type (ogg, mp3, wav ...)
0041  */
0042 void Sound::open(WorkspaceFile& file, ErrorHandler& e) {
0043     std::unique_ptr<OggVorbis> a(new OggVorbis());
0044     a->setFilename(file, e);
0045     delete af;
0046     af = a.release();
0047     af->open();
0048 }
0049 
0050 const char* Sound::setName(const char* n) {
0051     const char* r = name;
0052     name = n;
0053     return r;
0054 }
0055 
0056 void Sound::setName(std::string& n) {
0057     assert(!name);
0058     int size = n.size() + 1;
0059     char* a = new char[size];
0060     name = a;
0061     strncpy(a, n.c_str(), size);
0062 }
0063 
0064 const char* Sound::getName() const {
0065     return name;
0066 }
0067 
0068 const char* Sound::getSoundPath() const {
0069     return af->getSoundPath();
0070 }
0071 
0072 const char* Sound::getBasename() const {
0073     return af->getBasename();
0074 }
0075 
0076 void Sound::addToDriver(AudioDriver& ad) const {
0077     ad.addAudioFile(af);
0078 }