Merge with -r 22620:23107.
[blender.git] / intern / audaspace / FX / AUD_PingPongFactory.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN LGPL LICENSE BLOCK *****
5  *
6  * Copyright 2009 Jörg Hermann Müller
7  *
8  * This file is part of AudaSpace.
9  *
10  * AudaSpace is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * AudaSpace is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with AudaSpace.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * ***** END LGPL LICENSE BLOCK *****
24  */
25
26 #include "AUD_PingPongFactory.h"
27 #include "AUD_DoubleReader.h"
28 #include "AUD_ReverseFactory.h"
29
30 AUD_PingPongFactory::AUD_PingPongFactory(AUD_IFactory* factory) :
31                 AUD_EffectFactory(factory) {}
32
33 AUD_IReader* AUD_PingPongFactory::createReader()
34 {
35         if(m_factory == 0)
36                 return 0;
37
38         AUD_IReader* reader = m_factory->createReader();
39
40         if(reader != 0)
41         {
42                 AUD_IReader* reader2;
43                 AUD_ReverseFactory factory(m_factory);
44
45                 try
46                 {
47                         reader2 = factory.createReader();
48                 }
49                 catch(AUD_Exception)
50                 {
51                         reader2 = 0;
52                 }
53
54                 if(reader2 != 0)
55                 {
56                         reader = new AUD_DoubleReader(reader, reader2);
57                         AUD_NEW("reader")
58                 }
59                 else
60                 {
61                         delete reader; AUD_DELETE("reader")
62                         reader = 0;
63                 }
64         }
65
66         return reader;
67 }