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@1089
|
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@1089
|
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@866
|
50 params->setPlayClipId
|
Chris@866
|
51 (playable->getDefaultPlayClipId());
|
Chris@952
|
52
|
Chris@952
|
53 params->setPlayAudible
|
Chris@952
|
54 (playable->getDefaultPlayAudible());
|
Chris@391
|
55
|
Chris@391
|
56 connect(params, SIGNAL(playParametersChanged()),
|
Chris@391
|
57 this, SLOT(playParametersChanged()));
|
Chris@391
|
58
|
Chris@866
|
59 connect(params, SIGNAL(playClipIdChanged(QString)),
|
Chris@866
|
60 this, SLOT(playClipIdChanged(QString)));
|
Chris@30
|
61
|
Chris@1089
|
62 // cerr << "Connected play parameters " << params << " for playable "
|
Chris@1089
|
63 // << playable << " to this " << this << endl;
|
Chris@30
|
64 }
|
Chris@30
|
65 }
|
Chris@30
|
66
|
Chris@30
|
67 void
|
Chris@391
|
68 PlayParameterRepository::removePlayable(const Playable *playable)
|
Chris@30
|
69 {
|
Chris@391
|
70 if (m_playParameters.find(playable) == m_playParameters.end()) {
|
Chris@843
|
71 cerr << "WARNING: PlayParameterRepository::removePlayable: unknown playable " << playable << endl;
|
Chris@391
|
72 return;
|
Chris@391
|
73 }
|
Chris@391
|
74 delete m_playParameters[playable];
|
Chris@391
|
75 m_playParameters.erase(playable);
|
Chris@30
|
76 }
|
Chris@30
|
77
|
Chris@284
|
78 void
|
Chris@391
|
79 PlayParameterRepository::copyParameters(const Playable *from, const Playable *to)
|
Chris@284
|
80 {
|
Chris@284
|
81 if (!getPlayParameters(from)) {
|
Chris@843
|
82 cerr << "ERROR: PlayParameterRepository::copyParameters: source playable unknown" << endl;
|
Chris@284
|
83 return;
|
Chris@284
|
84 }
|
Chris@284
|
85 if (!getPlayParameters(to)) {
|
Chris@843
|
86 cerr << "WARNING: PlayParameterRepository::copyParameters: target playable unknown, adding it now" << endl;
|
Chris@391
|
87 addPlayable(to);
|
Chris@284
|
88 }
|
Chris@284
|
89 getPlayParameters(to)->copyFrom(getPlayParameters(from));
|
Chris@284
|
90 }
|
Chris@284
|
91
|
Chris@28
|
92 PlayParameters *
|
Chris@391
|
93 PlayParameterRepository::getPlayParameters(const Playable *playable)
|
Chris@28
|
94 {
|
Chris@391
|
95 if (m_playParameters.find(playable) == m_playParameters.end()) return 0;
|
Chris@391
|
96 return m_playParameters.find(playable)->second;
|
Chris@28
|
97 }
|
Chris@28
|
98
|
Chris@28
|
99 void
|
Chris@29
|
100 PlayParameterRepository::playParametersChanged()
|
Chris@29
|
101 {
|
Chris@57
|
102 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
|
Chris@57
|
103 emit playParametersChanged(params);
|
Chris@57
|
104 }
|
Chris@57
|
105
|
Chris@57
|
106 void
|
Chris@866
|
107 PlayParameterRepository::playClipIdChanged(QString id)
|
Chris@57
|
108 {
|
Chris@57
|
109 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
|
Chris@391
|
110 for (PlayableParameterMap::iterator i = m_playParameters.begin();
|
Chris@57
|
111 i != m_playParameters.end(); ++i) {
|
Chris@57
|
112 if (i->second == params) {
|
Chris@866
|
113 emit playClipIdChanged(i->first, id);
|
Chris@57
|
114 return;
|
Chris@57
|
115 }
|
Chris@57
|
116 }
|
Chris@29
|
117 }
|
Chris@29
|
118
|
Chris@29
|
119 void
|
Chris@28
|
120 PlayParameterRepository::clear()
|
Chris@28
|
121 {
|
Chris@843
|
122 // cerr << "PlayParameterRepository: PlayParameterRepository::clear" << endl;
|
Chris@28
|
123 while (!m_playParameters.empty()) {
|
Chris@28
|
124 delete m_playParameters.begin()->second;
|
Chris@28
|
125 m_playParameters.erase(m_playParameters.begin());
|
Chris@28
|
126 }
|
Chris@28
|
127 }
|
Chris@28
|
128
|
Chris@391
|
129 PlayParameterRepository::EditCommand::EditCommand(PlayParameters *params) :
|
Chris@391
|
130 m_params(params)
|
Chris@391
|
131 {
|
Chris@391
|
132 m_from.copyFrom(m_params);
|
Chris@391
|
133 m_to.copyFrom(m_params);
|
Chris@391
|
134 }
|
Chris@391
|
135
|
Chris@391
|
136 void
|
Chris@391
|
137 PlayParameterRepository::EditCommand::setPlayMuted(bool muted)
|
Chris@391
|
138 {
|
Chris@391
|
139 m_to.setPlayMuted(muted);
|
Chris@391
|
140 }
|
Chris@391
|
141
|
Chris@391
|
142 void
|
Chris@391
|
143 PlayParameterRepository::EditCommand::setPlayAudible(bool audible)
|
Chris@391
|
144 {
|
Chris@391
|
145 m_to.setPlayAudible(audible);
|
Chris@391
|
146 }
|
Chris@391
|
147
|
Chris@391
|
148 void
|
Chris@391
|
149 PlayParameterRepository::EditCommand::setPlayPan(float pan)
|
Chris@391
|
150 {
|
Chris@391
|
151 m_to.setPlayPan(pan);
|
Chris@391
|
152 }
|
Chris@391
|
153
|
Chris@391
|
154 void
|
Chris@391
|
155 PlayParameterRepository::EditCommand::setPlayGain(float gain)
|
Chris@391
|
156 {
|
Chris@391
|
157 m_to.setPlayGain(gain);
|
Chris@391
|
158 }
|
Chris@391
|
159
|
Chris@391
|
160 void
|
Chris@866
|
161 PlayParameterRepository::EditCommand::setPlayClipId(QString id)
|
Chris@391
|
162 {
|
Chris@866
|
163 m_to.setPlayClipId(id);
|
Chris@391
|
164 }
|
Chris@391
|
165
|
Chris@391
|
166 void
|
Chris@391
|
167 PlayParameterRepository::EditCommand::execute()
|
Chris@391
|
168 {
|
Chris@391
|
169 m_params->copyFrom(&m_to);
|
Chris@391
|
170 }
|
Chris@391
|
171
|
Chris@391
|
172 void
|
Chris@391
|
173 PlayParameterRepository::EditCommand::unexecute()
|
Chris@391
|
174 {
|
Chris@391
|
175 m_params->copyFrom(&m_from);
|
Chris@391
|
176 }
|
Chris@391
|
177
|
Chris@391
|
178 QString
|
Chris@391
|
179 PlayParameterRepository::EditCommand::getName() const
|
Chris@391
|
180 {
|
Chris@391
|
181 QString name;
|
Chris@391
|
182 QString multiname = tr("Adjust Playback Parameters");
|
Chris@391
|
183
|
Chris@391
|
184 int changed = 0;
|
Chris@391
|
185
|
Chris@391
|
186 if (m_to.isPlayAudible() != m_from.isPlayAudible()) {
|
Chris@391
|
187 name = tr("Change Playback Mute State");
|
Chris@391
|
188 if (++changed > 1) return multiname;
|
Chris@391
|
189 }
|
Chris@391
|
190
|
Chris@391
|
191 if (m_to.getPlayGain() != m_from.getPlayGain()) {
|
Chris@391
|
192 name = tr("Change Playback Gain");
|
Chris@391
|
193 if (++changed > 1) return multiname;
|
Chris@391
|
194 }
|
Chris@391
|
195
|
Chris@391
|
196 if (m_to.getPlayPan() != m_from.getPlayPan()) {
|
Chris@391
|
197 name = tr("Change Playback Pan");
|
Chris@391
|
198 if (++changed > 1) return multiname;
|
Chris@391
|
199 }
|
Chris@391
|
200
|
Chris@866
|
201 if (m_to.getPlayClipId() != m_from.getPlayClipId()) {
|
Chris@863
|
202 name = tr("Change Playback Sample");
|
Chris@391
|
203 if (++changed > 1) return multiname;
|
Chris@391
|
204 }
|
Chris@391
|
205
|
Chris@391
|
206 if (name == "") return multiname;
|
Chris@391
|
207 return name;
|
Chris@391
|
208 }
|
Chris@391
|
209
|