Fix for [#26652] "Audio Muted" in Time Line Editor is not working
[blender-staging.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_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         AUD_SequencerReader* reader;
50         AUD_SequencerEntry* entry;
51
52         while(!m_readers.empty())
53         {
54                 reader = m_readers.front();
55                 m_readers.pop_front();
56                 reader->destroy();
57         }
58
59         while(!m_entries.empty())
60         {
61                 entry = m_entries.front();
62                 m_entries.pop_front();
63                 delete entry;
64         }
65 }
66
67 void AUD_SequencerFactory::mute(bool muted)
68 {
69         m_muted = muted;
70 }
71
72 bool AUD_SequencerFactory::getMute() const
73 {
74         return m_muted;
75 }
76
77 AUD_IReader* AUD_SequencerFactory::newReader()
78 {
79         AUD_SequencerReader* reader = new AUD_SequencerReader(this, m_entries,
80                                                                                                                   m_specs, m_data,
81                                                                                                                   m_volume);
82         m_readers.push_front(reader);
83
84         return reader;
85 }
86
87 AUD_SequencerEntry* AUD_SequencerFactory::add(AUD_IFactory** sound, float begin, float end, float skip, void* data)
88 {
89         AUD_SequencerEntry* entry = new AUD_SequencerEntry;
90         entry->sound = sound;
91         entry->begin = begin;
92         entry->skip = skip;
93         entry->end = end;
94         entry->muted = false;
95         entry->data = data;
96
97         m_entries.push_front(entry);
98
99         for(AUD_ReaderIterator i = m_readers.begin(); i != m_readers.end(); i++)
100                 (*i)->add(entry);
101
102         return entry;
103 }
104
105 void AUD_SequencerFactory::remove(AUD_SequencerEntry* entry)
106 {
107         for(AUD_ReaderIterator i = m_readers.begin(); i != m_readers.end(); i++)
108                 (*i)->remove(entry);
109
110         m_entries.remove(entry);
111
112         delete entry;
113 }
114
115 void AUD_SequencerFactory::move(AUD_SequencerEntry* entry, float begin, float end, float skip)
116 {
117         entry->begin = begin;
118         entry->skip = skip;
119         entry->end = end;
120 }
121
122 void AUD_SequencerFactory::mute(AUD_SequencerEntry* entry, bool mute)
123 {
124         entry->muted = mute;
125 }
126
127 AUD_IReader* AUD_SequencerFactory::createReader() const
128 {
129         return const_cast<AUD_SequencerFactory*>(this)->newReader();
130 }
131
132 void AUD_SequencerFactory::removeReader(AUD_SequencerReader* reader)
133 {
134         m_readers.remove(reader);
135 }