comparison base/PlayParameterRepository.cpp @ 391:5858cc462d0a

* Fix #1628781 changes to layer visibility and mute should use a command * Also use a command for changes to layer playback pan, gain, plugin settings * Refactor PlayParameterRepository to remove dependency on audioio from base * Fix failure to save play parameters for main model in session file
author Chris Cannam
date Thu, 13 Mar 2008 14:06:03 +0000
parents 1dc99b430d2a
children 06f13a3b9e9e
comparison
equal deleted inserted replaced
390:21e79997e80f 391:5858cc462d0a
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "PlayParameterRepository.h" 16 #include "PlayParameterRepository.h"
17 #include "PlayParameters.h" 17 #include "PlayParameters.h"
18 18 #include "Playable.h"
19 //!!! shouldn't be including this here -- restructure needed
20
21 //!!! should the AudioGenerator actually implement all this stuff itself? do we even want this class?
22 #include "audioio/AudioGenerator.h"
23 19
24 #include <iostream> 20 #include <iostream>
25 21
26 PlayParameterRepository * 22 PlayParameterRepository *
27 PlayParameterRepository::m_instance = new PlayParameterRepository; 23 PlayParameterRepository::m_instance = new PlayParameterRepository;
35 PlayParameterRepository::~PlayParameterRepository() 31 PlayParameterRepository::~PlayParameterRepository()
36 { 32 {
37 } 33 }
38 34
39 void 35 void
40 PlayParameterRepository::addModel(const Model *model) 36 PlayParameterRepository::addPlayable(const Playable *playable)
41 { 37 {
42 // std::cerr << "PlayParameterRepository:addModel " << model << std::endl; 38 // std::cerr << "PlayParameterRepository:addPlayable " << playable << std::endl;
43 39
44 if (!getPlayParameters(model)) { 40 if (!getPlayParameters(playable)) {
45 41
46 // Give all models the same type of play parameters for the 42 // Give all playables the same type of play parameters for the
47 // moment, provided they can be played at all 43 // moment
48 44
49 if (AudioGenerator::canPlay(model)) { 45 // std::cerr << "PlayParameterRepository: Adding play parameters for " << playable << std::endl;
50 46
51 // std::cerr << "PlayParameterRepository: Adding play parameters for " << model << std::endl; 47 PlayParameters *params = new PlayParameters;
52 48 m_playParameters[playable] = params;
53 PlayParameters *params = new PlayParameters; 49
54 m_playParameters[model] = params; 50 params->setPlayPluginId
55 51 (playable->getDefaultPlayPluginId());
56 params->setPlayPluginId 52
57 (AudioGenerator::getDefaultPlayPluginId(model)); 53 params->setPlayPluginConfiguration
58 54 (playable->getDefaultPlayPluginConfiguration());
59 params->setPlayPluginConfiguration 55
60 (AudioGenerator::getDefaultPlayPluginConfiguration(model)); 56 connect(params, SIGNAL(playParametersChanged()),
61 57 this, SLOT(playParametersChanged()));
62 connect(params, SIGNAL(playParametersChanged()), 58
63 this, SLOT(playParametersChanged())); 59 connect(params, SIGNAL(playPluginIdChanged(QString)),
64 60 this, SLOT(playPluginIdChanged(QString)));
65 connect(params, SIGNAL(playPluginIdChanged(QString)), 61
66 this, SLOT(playPluginIdChanged(QString))); 62 connect(params, SIGNAL(playPluginConfigurationChanged(QString)),
67 63 this, SLOT(playPluginConfigurationChanged(QString)));
68 connect(params, SIGNAL(playPluginConfigurationChanged(QString)), 64
69 this, SLOT(playPluginConfigurationChanged(QString))); 65 // std::cerr << "Connected play parameters " << params << " for playable "
70 66 // << playable << " to this " << this << std::endl;
71 // std::cerr << "Connected play parameters " << params << " for model " 67
72 // << model << " to this " << this << std::endl;
73
74 } else {
75
76 // std::cerr << "PlayParameterRepository: Model " << model << " not playable" << std::endl;
77 }
78 } 68 }
79 } 69 }
80 70
81 void 71 void
82 PlayParameterRepository::removeModel(const Model *model) 72 PlayParameterRepository::removePlayable(const Playable *playable)
83 { 73 {
84 delete m_playParameters[model]; 74 if (m_playParameters.find(playable) == m_playParameters.end()) {
85 m_playParameters.erase(model); 75 std::cerr << "WARNING: PlayParameterRepository::removePlayable: unknown playable " << playable << std::endl;
86 } 76 return;
87 77 }
88 void 78 delete m_playParameters[playable];
89 PlayParameterRepository::copyParameters(const Model *from, const Model *to) 79 m_playParameters.erase(playable);
80 }
81
82 void
83 PlayParameterRepository::copyParameters(const Playable *from, const Playable *to)
90 { 84 {
91 if (!getPlayParameters(from)) { 85 if (!getPlayParameters(from)) {
92 std::cerr << "ERROR: PlayParameterRepository::copyParameters: source model unknown" << std::endl; 86 std::cerr << "ERROR: PlayParameterRepository::copyParameters: source playable unknown" << std::endl;
93 return; 87 return;
94 } 88 }
95 if (!getPlayParameters(to)) { 89 if (!getPlayParameters(to)) {
96 std::cerr << "WARNING: PlayParameterRepository::copyParameters: target model unknown, adding it now" << std::endl; 90 std::cerr << "WARNING: PlayParameterRepository::copyParameters: target playable unknown, adding it now" << std::endl;
97 addModel(to); 91 addPlayable(to);
98 } 92 }
99 getPlayParameters(to)->copyFrom(getPlayParameters(from)); 93 getPlayParameters(to)->copyFrom(getPlayParameters(from));
100 } 94 }
101 95
102 PlayParameters * 96 PlayParameters *
103 PlayParameterRepository::getPlayParameters(const Model *model) 97 PlayParameterRepository::getPlayParameters(const Playable *playable)
104 { 98 {
105 if (m_playParameters.find(model) == m_playParameters.end()) return 0; 99 if (m_playParameters.find(playable) == m_playParameters.end()) return 0;
106 return m_playParameters.find(model)->second; 100 return m_playParameters.find(playable)->second;
107 } 101 }
108 102
109 void 103 void
110 PlayParameterRepository::playParametersChanged() 104 PlayParameterRepository::playParametersChanged()
111 { 105 {
115 109
116 void 110 void
117 PlayParameterRepository::playPluginIdChanged(QString id) 111 PlayParameterRepository::playPluginIdChanged(QString id)
118 { 112 {
119 PlayParameters *params = dynamic_cast<PlayParameters *>(sender()); 113 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
120 for (ModelParameterMap::iterator i = m_playParameters.begin(); 114 for (PlayableParameterMap::iterator i = m_playParameters.begin();
121 i != m_playParameters.end(); ++i) { 115 i != m_playParameters.end(); ++i) {
122 if (i->second == params) { 116 if (i->second == params) {
123 emit playPluginIdChanged(i->first, id); 117 emit playPluginIdChanged(i->first, id);
124 return; 118 return;
125 } 119 }
129 void 123 void
130 PlayParameterRepository::playPluginConfigurationChanged(QString config) 124 PlayParameterRepository::playPluginConfigurationChanged(QString config)
131 { 125 {
132 PlayParameters *params = dynamic_cast<PlayParameters *>(sender()); 126 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
133 // std::cerr << "PlayParameterRepository::playPluginConfigurationChanged" << std::endl; 127 // std::cerr << "PlayParameterRepository::playPluginConfigurationChanged" << std::endl;
134 for (ModelParameterMap::iterator i = m_playParameters.begin(); 128 for (PlayableParameterMap::iterator i = m_playParameters.begin();
135 i != m_playParameters.end(); ++i) { 129 i != m_playParameters.end(); ++i) {
136 if (i->second == params) { 130 if (i->second == params) {
137 emit playPluginConfigurationChanged(i->first, config); 131 emit playPluginConfigurationChanged(i->first, config);
138 return; 132 return;
139 } 133 }
148 delete m_playParameters.begin()->second; 142 delete m_playParameters.begin()->second;
149 m_playParameters.erase(m_playParameters.begin()); 143 m_playParameters.erase(m_playParameters.begin());
150 } 144 }
151 } 145 }
152 146
147 PlayParameterRepository::EditCommand::EditCommand(PlayParameters *params) :
148 m_params(params)
149 {
150 m_from.copyFrom(m_params);
151 m_to.copyFrom(m_params);
152 }
153
154 void
155 PlayParameterRepository::EditCommand::setPlayMuted(bool muted)
156 {
157 m_to.setPlayMuted(muted);
158 }
159
160 void
161 PlayParameterRepository::EditCommand::setPlayAudible(bool audible)
162 {
163 m_to.setPlayAudible(audible);
164 }
165
166 void
167 PlayParameterRepository::EditCommand::setPlayPan(float pan)
168 {
169 m_to.setPlayPan(pan);
170 }
171
172 void
173 PlayParameterRepository::EditCommand::setPlayGain(float gain)
174 {
175 m_to.setPlayGain(gain);
176 }
177
178 void
179 PlayParameterRepository::EditCommand::setPlayPluginId(QString id)
180 {
181 m_to.setPlayPluginId(id);
182 }
183
184 void
185 PlayParameterRepository::EditCommand::setPlayPluginConfiguration(QString conf)
186 {
187 m_to.setPlayPluginConfiguration(conf);
188 }
189
190 void
191 PlayParameterRepository::EditCommand::execute()
192 {
193 m_params->copyFrom(&m_to);
194 }
195
196 void
197 PlayParameterRepository::EditCommand::unexecute()
198 {
199 m_params->copyFrom(&m_from);
200 }
201
202 QString
203 PlayParameterRepository::EditCommand::getName() const
204 {
205 QString name;
206 QString multiname = tr("Adjust Playback Parameters");
207
208 int changed = 0;
209
210 if (m_to.isPlayAudible() != m_from.isPlayAudible()) {
211 name = tr("Change Playback Mute State");
212 if (++changed > 1) return multiname;
213 }
214
215 if (m_to.getPlayGain() != m_from.getPlayGain()) {
216 name = tr("Change Playback Gain");
217 if (++changed > 1) return multiname;
218 }
219
220 if (m_to.getPlayPan() != m_from.getPlayPan()) {
221 name = tr("Change Playback Pan");
222 if (++changed > 1) return multiname;
223 }
224
225 if (m_to.getPlayPluginId() != m_from.getPlayPluginId()) {
226 name = tr("Change Playback Plugin");
227 if (++changed > 1) return multiname;
228 }
229
230 if (m_to.getPlayPluginConfiguration() != m_from.getPlayPluginConfiguration()) {
231 name = tr("Configure Playback Plugin");
232 if (++changed > 1) return multiname;
233 }
234
235 if (name == "") return multiname;
236 return name;
237 }
238