3D Audio GSoC:
[blender.git] / intern / audaspace / intern / AUD_SequencerFactory.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * Copyright 2009-2011 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 General Public License as published by
12  * the Free Software Foundation; either version 2 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 General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Audaspace; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file audaspace/intern/AUD_SequencerFactory.cpp
28  *  \ingroup audaspaceintern
29  */
30
31
32 #include "AUD_SequencerFactory.h"
33 #include "AUD_SequencerReader.h"
34
35 typedef std::list<AUD_Reference<AUD_SequencerReader> >::iterator AUD_ReaderIterator;
36
37 AUD_SequencerFactory::AUD_SequencerFactory(AUD_Specs specs, bool muted,
38                                                                                    void* data,
39                                                                                    AUD_volumeFunction volume) :
40         m_specs(specs),
41         m_muted(muted),
42         m_data(data),
43         m_volume(volume)
44 {
45 }
46
47 AUD_SequencerFactory::~AUD_SequencerFactory()
48 {
49 }
50
51 void AUD_SequencerFactory::setThis(AUD_Reference<AUD_SequencerFactory>* self)
52 {
53         m_this = self;
54 }
55
56 void AUD_SequencerFactory::mute(bool muted)
57 {
58         m_muted = muted;
59 }
60
61 bool AUD_SequencerFactory::getMute() const
62 {
63         return m_muted;
64 }
65
66 AUD_Reference<AUD_SequencerEntry> AUD_SequencerFactory::add(AUD_Reference<AUD_IFactory>** sound, float begin, float end, float skip, void* data)
67 {
68         AUD_Reference<AUD_SequencerEntry> entry = new AUD_SequencerEntry;
69         entry->sound = sound;
70         entry->begin = begin;
71         entry->skip = skip;
72         entry->end = end;
73         entry->muted = false;
74         entry->data = data;
75
76         m_entries.push_front(entry);
77
78         for(AUD_ReaderIterator i = m_readers.begin(); i != m_readers.end(); i++)
79                 (*i)->add(entry);
80
81         return entry;
82 }
83
84 void AUD_SequencerFactory::remove(AUD_Reference<AUD_SequencerEntry> entry)
85 {
86         for(AUD_ReaderIterator i = m_readers.begin(); i != m_readers.end(); i++)
87                 (*i)->remove(entry);
88
89         m_entries.remove(entry);
90 }
91
92 void AUD_SequencerFactory::move(AUD_Reference<AUD_SequencerEntry> entry, float begin, float end, float skip)
93 {
94         entry->begin = begin;
95         entry->skip = skip;
96         entry->end = end;
97 }
98
99 void AUD_SequencerFactory::mute(AUD_Reference<AUD_SequencerEntry> entry, bool mute)
100 {
101         entry->muted = mute;
102 }
103
104 AUD_Reference<AUD_IReader> AUD_SequencerFactory::createReader()
105 {
106         AUD_Reference<AUD_SequencerReader> reader = new AUD_SequencerReader(*m_this, m_entries,
107                                                                                                                   m_specs, m_data,
108                                                                                                                   m_volume);
109         m_readers.push_front(reader);
110
111         return AUD_Reference<AUD_IReader>(reader);
112 }
113
114 void AUD_SequencerFactory::removeReader(AUD_Reference<AUD_SequencerReader> reader)
115 {
116         m_readers.remove(reader);
117 }