Chris@49
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@28
|
2
|
Chris@28
|
3 /*
|
Chris@52
|
4 Sonic Visualiser
|
Chris@52
|
5 An audio file viewer and annotation editor.
|
Chris@52
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@52
|
7 This file copyright 2006 Chris Cannam.
|
Chris@28
|
8
|
Chris@52
|
9 This program is free software; you can redistribute it and/or
|
Chris@52
|
10 modify it under the terms of the GNU General Public License as
|
Chris@52
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@52
|
12 License, or (at your option) any later version. See the file
|
Chris@52
|
13 COPYING included with this distribution for more information.
|
Chris@28
|
14 */
|
Chris@28
|
15
|
Chris@28
|
16 #include "PlayParameterRepository.h"
|
Chris@28
|
17 #include "PlayParameters.h"
|
Chris@391
|
18 #include "Playable.h"
|
Chris@30
|
19
|
Chris@29
|
20 #include <iostream>
|
Chris@29
|
21
|
Chris@28
|
22 PlayParameterRepository *
|
Chris@28
|
23 PlayParameterRepository::m_instance = new PlayParameterRepository;
|
Chris@28
|
24
|
Chris@28
|
25 PlayParameterRepository *
|
Chris@145
|
26 PlayParameterRepository::getInstance()
|
Chris@28
|
27 {
|
Chris@28
|
28 return m_instance;
|
Chris@28
|
29 }
|
Chris@28
|
30
|
Chris@28
|
31 PlayParameterRepository::~PlayParameterRepository()
|
Chris@28
|
32 {
|
Chris@28
|
33 }
|
Chris@28
|
34
|
Chris@30
|
35 void
|
Chris@391
|
36 PlayParameterRepository::addPlayable(const Playable *playable)
|
Chris@30
|
37 {
|
Chris@847
|
38 cerr << "PlayParameterRepository:addPlayable playable = " << playable << endl;
|
Chris@82
|
39
|
Chris@391
|
40 if (!getPlayParameters(playable)) {
|
Chris@30
|
41
|
Chris@391
|
42 // Give all playables the same type of play parameters for the
|
Chris@391
|
43 // moment
|
Chris@30
|
44
|
Chris@847
|
45 cerr << "PlayParameterRepository:addPlayable: Adding play parameters for " << playable << endl;
|
Chris@30
|
46
|
Chris@391
|
47 PlayParameters *params = new PlayParameters;
|
Chris@391
|
48 m_playParameters[playable] = params;
|
Chris@30
|
49
|
Chris@391
|
50 params->setPlayPluginId
|
Chris@391
|
51 (playable->getDefaultPlayPluginId());
|
Chris@391
|
52
|
Chris@391
|
53 params->setPlayPluginConfiguration
|
Chris@391
|
54 (playable->getDefaultPlayPluginConfiguration());
|
Chris@391
|
55
|
Chris@391
|
56 connect(params, SIGNAL(playParametersChanged()),
|
Chris@391
|
57 this, SLOT(playParametersChanged()));
|
Chris@391
|
58
|
Chris@391
|
59 connect(params, SIGNAL(playPluginIdChanged(QString)),
|
Chris@391
|
60 this, SLOT(playPluginIdChanged(QString)));
|
Chris@30
|
61
|
Chris@391
|
62 connect(params, SIGNAL(playPluginConfigurationChanged(QString)),
|
Chris@391
|
63 this, SLOT(playPluginConfigurationChanged(QString)));
|
Chris@391
|
64
|
Chris@847
|
65 cerr << "Connected play parameters " << params << " for playable "
|
Chris@847
|
66 << playable << " to this " << this << endl;
|
Chris@30
|
67 }
|
Chris@30
|
68 }
|
Chris@30
|
69
|
Chris@30
|
70 void
|
Chris@391
|
71 PlayParameterRepository::removePlayable(const Playable *playable)
|
Chris@30
|
72 {
|
Chris@391
|
73 if (m_playParameters.find(playable) == m_playParameters.end()) {
|
Chris@843
|
74 cerr << "WARNING: PlayParameterRepository::removePlayable: unknown playable " << playable << endl;
|
Chris@391
|
75 return;
|
Chris@391
|
76 }
|
Chris@391
|
77 delete m_playParameters[playable];
|
Chris@391
|
78 m_playParameters.erase(playable);
|
Chris@30
|
79 }
|
Chris@30
|
80
|
Chris@284
|
81 void
|
Chris@391
|
82 PlayParameterRepository::copyParameters(const Playable *from, const Playable *to)
|
Chris@284
|
83 {
|
Chris@284
|
84 if (!getPlayParameters(from)) {
|
Chris@843
|
85 cerr << "ERROR: PlayParameterRepository::copyParameters: source playable unknown" << endl;
|
Chris@284
|
86 return;
|
Chris@284
|
87 }
|
Chris@284
|
88 if (!getPlayParameters(to)) {
|
Chris@843
|
89 cerr << "WARNING: PlayParameterRepository::copyParameters: target playable unknown, adding it now" << endl;
|
Chris@391
|
90 addPlayable(to);
|
Chris@284
|
91 }
|
Chris@284
|
92 getPlayParameters(to)->copyFrom(getPlayParameters(from));
|
Chris@284
|
93 }
|
Chris@284
|
94
|
Chris@28
|
95 PlayParameters *
|
Chris@391
|
96 PlayParameterRepository::getPlayParameters(const Playable *playable)
|
Chris@28
|
97 {
|
Chris@391
|
98 if (m_playParameters.find(playable) == m_playParameters.end()) return 0;
|
Chris@391
|
99 return m_playParameters.find(playable)->second;
|
Chris@28
|
100 }
|
Chris@28
|
101
|
Chris@28
|
102 void
|
Chris@29
|
103 PlayParameterRepository::playParametersChanged()
|
Chris@29
|
104 {
|
Chris@57
|
105 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
|
Chris@57
|
106 emit playParametersChanged(params);
|
Chris@57
|
107 }
|
Chris@57
|
108
|
Chris@57
|
109 void
|
Chris@57
|
110 PlayParameterRepository::playPluginIdChanged(QString id)
|
Chris@57
|
111 {
|
Chris@57
|
112 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
|
Chris@391
|
113 for (PlayableParameterMap::iterator i = m_playParameters.begin();
|
Chris@57
|
114 i != m_playParameters.end(); ++i) {
|
Chris@57
|
115 if (i->second == params) {
|
Chris@57
|
116 emit playPluginIdChanged(i->first, id);
|
Chris@57
|
117 return;
|
Chris@57
|
118 }
|
Chris@57
|
119 }
|
Chris@57
|
120 }
|
Chris@57
|
121
|
Chris@57
|
122 void
|
Chris@57
|
123 PlayParameterRepository::playPluginConfigurationChanged(QString config)
|
Chris@57
|
124 {
|
Chris@57
|
125 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
|
Chris@690
|
126 // SVDEBUG << "PlayParameterRepository::playPluginConfigurationChanged" << endl;
|
Chris@391
|
127 for (PlayableParameterMap::iterator i = m_playParameters.begin();
|
Chris@57
|
128 i != m_playParameters.end(); ++i) {
|
Chris@57
|
129 if (i->second == params) {
|
Chris@57
|
130 emit playPluginConfigurationChanged(i->first, config);
|
Chris@57
|
131 return;
|
Chris@57
|
132 }
|
Chris@57
|
133 }
|
Chris@29
|
134 }
|
Chris@29
|
135
|
Chris@29
|
136 void
|
Chris@28
|
137 PlayParameterRepository::clear()
|
Chris@28
|
138 {
|
Chris@843
|
139 // cerr << "PlayParameterRepository: PlayParameterRepository::clear" << endl;
|
Chris@28
|
140 while (!m_playParameters.empty()) {
|
Chris@28
|
141 delete m_playParameters.begin()->second;
|
Chris@28
|
142 m_playParameters.erase(m_playParameters.begin());
|
Chris@28
|
143 }
|
Chris@28
|
144 }
|
Chris@28
|
145
|
Chris@391
|
146 PlayParameterRepository::EditCommand::EditCommand(PlayParameters *params) :
|
Chris@391
|
147 m_params(params)
|
Chris@391
|
148 {
|
Chris@391
|
149 m_from.copyFrom(m_params);
|
Chris@391
|
150 m_to.copyFrom(m_params);
|
Chris@391
|
151 }
|
Chris@391
|
152
|
Chris@391
|
153 void
|
Chris@391
|
154 PlayParameterRepository::EditCommand::setPlayMuted(bool muted)
|
Chris@391
|
155 {
|
Chris@391
|
156 m_to.setPlayMuted(muted);
|
Chris@391
|
157 }
|
Chris@391
|
158
|
Chris@391
|
159 void
|
Chris@391
|
160 PlayParameterRepository::EditCommand::setPlayAudible(bool audible)
|
Chris@391
|
161 {
|
Chris@391
|
162 m_to.setPlayAudible(audible);
|
Chris@391
|
163 }
|
Chris@391
|
164
|
Chris@391
|
165 void
|
Chris@391
|
166 PlayParameterRepository::EditCommand::setPlayPan(float pan)
|
Chris@391
|
167 {
|
Chris@391
|
168 m_to.setPlayPan(pan);
|
Chris@391
|
169 }
|
Chris@391
|
170
|
Chris@391
|
171 void
|
Chris@391
|
172 PlayParameterRepository::EditCommand::setPlayGain(float gain)
|
Chris@391
|
173 {
|
Chris@391
|
174 m_to.setPlayGain(gain);
|
Chris@391
|
175 }
|
Chris@391
|
176
|
Chris@391
|
177 void
|
Chris@391
|
178 PlayParameterRepository::EditCommand::setPlayPluginId(QString id)
|
Chris@391
|
179 {
|
Chris@391
|
180 m_to.setPlayPluginId(id);
|
Chris@391
|
181 }
|
Chris@391
|
182
|
Chris@391
|
183 void
|
Chris@391
|
184 PlayParameterRepository::EditCommand::setPlayPluginConfiguration(QString conf)
|
Chris@391
|
185 {
|
Chris@391
|
186 m_to.setPlayPluginConfiguration(conf);
|
Chris@391
|
187 }
|
Chris@391
|
188
|
Chris@391
|
189 void
|
Chris@391
|
190 PlayParameterRepository::EditCommand::execute()
|
Chris@391
|
191 {
|
Chris@391
|
192 m_params->copyFrom(&m_to);
|
Chris@391
|
193 }
|
Chris@391
|
194
|
Chris@391
|
195 void
|
Chris@391
|
196 PlayParameterRepository::EditCommand::unexecute()
|
Chris@391
|
197 {
|
Chris@391
|
198 m_params->copyFrom(&m_from);
|
Chris@391
|
199 }
|
Chris@391
|
200
|
Chris@391
|
201 QString
|
Chris@391
|
202 PlayParameterRepository::EditCommand::getName() const
|
Chris@391
|
203 {
|
Chris@391
|
204 QString name;
|
Chris@391
|
205 QString multiname = tr("Adjust Playback Parameters");
|
Chris@391
|
206
|
Chris@391
|
207 int changed = 0;
|
Chris@391
|
208
|
Chris@391
|
209 if (m_to.isPlayAudible() != m_from.isPlayAudible()) {
|
Chris@391
|
210 name = tr("Change Playback Mute State");
|
Chris@391
|
211 if (++changed > 1) return multiname;
|
Chris@391
|
212 }
|
Chris@391
|
213
|
Chris@391
|
214 if (m_to.getPlayGain() != m_from.getPlayGain()) {
|
Chris@391
|
215 name = tr("Change Playback Gain");
|
Chris@391
|
216 if (++changed > 1) return multiname;
|
Chris@391
|
217 }
|
Chris@391
|
218
|
Chris@391
|
219 if (m_to.getPlayPan() != m_from.getPlayPan()) {
|
Chris@391
|
220 name = tr("Change Playback Pan");
|
Chris@391
|
221 if (++changed > 1) return multiname;
|
Chris@391
|
222 }
|
Chris@391
|
223
|
Chris@391
|
224 if (m_to.getPlayPluginId() != m_from.getPlayPluginId()) {
|
Chris@391
|
225 name = tr("Change Playback Plugin");
|
Chris@391
|
226 if (++changed > 1) return multiname;
|
Chris@391
|
227 }
|
Chris@391
|
228
|
Chris@391
|
229 if (m_to.getPlayPluginConfiguration() != m_from.getPlayPluginConfiguration()) {
|
Chris@391
|
230 name = tr("Configure Playback Plugin");
|
Chris@391
|
231 if (++changed > 1) return multiname;
|
Chris@391
|
232 }
|
Chris@391
|
233
|
Chris@391
|
234 if (name == "") return multiname;
|
Chris@391
|
235 return name;
|
Chris@391
|
236 }
|
Chris@391
|
237
|