annotate base/PlayParameterRepository.cpp @ 661:a4faa1840384

* If a FileSource URL won't convert at all in strict mode, try again in tolerant mode (necessary for e.g. filenames with square brackets in them)
author Chris Cannam
date Tue, 19 Oct 2010 21:47:55 +0100
parents 5858cc462d0a
children 06f13a3b9e9e
rev   line source
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@391 38 // std::cerr << "PlayParameterRepository:addPlayable " << playable << std::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@391 45 // std::cerr << "PlayParameterRepository: Adding play parameters for " << playable << std::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@391 65 // std::cerr << "Connected play parameters " << params << " for playable "
Chris@391 66 // << playable << " to this " << this << std::endl;
Chris@57 67
Chris@30 68 }
Chris@30 69 }
Chris@30 70
Chris@30 71 void
Chris@391 72 PlayParameterRepository::removePlayable(const Playable *playable)
Chris@30 73 {
Chris@391 74 if (m_playParameters.find(playable) == m_playParameters.end()) {
Chris@391 75 std::cerr << "WARNING: PlayParameterRepository::removePlayable: unknown playable " << playable << std::endl;
Chris@391 76 return;
Chris@391 77 }
Chris@391 78 delete m_playParameters[playable];
Chris@391 79 m_playParameters.erase(playable);
Chris@30 80 }
Chris@30 81
Chris@284 82 void
Chris@391 83 PlayParameterRepository::copyParameters(const Playable *from, const Playable *to)
Chris@284 84 {
Chris@284 85 if (!getPlayParameters(from)) {
Chris@391 86 std::cerr << "ERROR: PlayParameterRepository::copyParameters: source playable unknown" << std::endl;
Chris@284 87 return;
Chris@284 88 }
Chris@284 89 if (!getPlayParameters(to)) {
Chris@391 90 std::cerr << "WARNING: PlayParameterRepository::copyParameters: target playable unknown, adding it now" << std::endl;
Chris@391 91 addPlayable(to);
Chris@284 92 }
Chris@284 93 getPlayParameters(to)->copyFrom(getPlayParameters(from));
Chris@284 94 }
Chris@284 95
Chris@28 96 PlayParameters *
Chris@391 97 PlayParameterRepository::getPlayParameters(const Playable *playable)
Chris@28 98 {
Chris@391 99 if (m_playParameters.find(playable) == m_playParameters.end()) return 0;
Chris@391 100 return m_playParameters.find(playable)->second;
Chris@28 101 }
Chris@28 102
Chris@28 103 void
Chris@29 104 PlayParameterRepository::playParametersChanged()
Chris@29 105 {
Chris@57 106 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
Chris@57 107 emit playParametersChanged(params);
Chris@57 108 }
Chris@57 109
Chris@57 110 void
Chris@57 111 PlayParameterRepository::playPluginIdChanged(QString id)
Chris@57 112 {
Chris@57 113 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
Chris@391 114 for (PlayableParameterMap::iterator i = m_playParameters.begin();
Chris@57 115 i != m_playParameters.end(); ++i) {
Chris@57 116 if (i->second == params) {
Chris@57 117 emit playPluginIdChanged(i->first, id);
Chris@57 118 return;
Chris@57 119 }
Chris@57 120 }
Chris@57 121 }
Chris@57 122
Chris@57 123 void
Chris@57 124 PlayParameterRepository::playPluginConfigurationChanged(QString config)
Chris@57 125 {
Chris@57 126 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
Chris@117 127 // std::cerr << "PlayParameterRepository::playPluginConfigurationChanged" << std::endl;
Chris@391 128 for (PlayableParameterMap::iterator i = m_playParameters.begin();
Chris@57 129 i != m_playParameters.end(); ++i) {
Chris@57 130 if (i->second == params) {
Chris@57 131 emit playPluginConfigurationChanged(i->first, config);
Chris@57 132 return;
Chris@57 133 }
Chris@57 134 }
Chris@29 135 }
Chris@29 136
Chris@29 137 void
Chris@28 138 PlayParameterRepository::clear()
Chris@28 139 {
Chris@117 140 // std::cerr << "PlayParameterRepository: PlayParameterRepository::clear" << std::endl;
Chris@28 141 while (!m_playParameters.empty()) {
Chris@28 142 delete m_playParameters.begin()->second;
Chris@28 143 m_playParameters.erase(m_playParameters.begin());
Chris@28 144 }
Chris@28 145 }
Chris@28 146
Chris@391 147 PlayParameterRepository::EditCommand::EditCommand(PlayParameters *params) :
Chris@391 148 m_params(params)
Chris@391 149 {
Chris@391 150 m_from.copyFrom(m_params);
Chris@391 151 m_to.copyFrom(m_params);
Chris@391 152 }
Chris@391 153
Chris@391 154 void
Chris@391 155 PlayParameterRepository::EditCommand::setPlayMuted(bool muted)
Chris@391 156 {
Chris@391 157 m_to.setPlayMuted(muted);
Chris@391 158 }
Chris@391 159
Chris@391 160 void
Chris@391 161 PlayParameterRepository::EditCommand::setPlayAudible(bool audible)
Chris@391 162 {
Chris@391 163 m_to.setPlayAudible(audible);
Chris@391 164 }
Chris@391 165
Chris@391 166 void
Chris@391 167 PlayParameterRepository::EditCommand::setPlayPan(float pan)
Chris@391 168 {
Chris@391 169 m_to.setPlayPan(pan);
Chris@391 170 }
Chris@391 171
Chris@391 172 void
Chris@391 173 PlayParameterRepository::EditCommand::setPlayGain(float gain)
Chris@391 174 {
Chris@391 175 m_to.setPlayGain(gain);
Chris@391 176 }
Chris@391 177
Chris@391 178 void
Chris@391 179 PlayParameterRepository::EditCommand::setPlayPluginId(QString id)
Chris@391 180 {
Chris@391 181 m_to.setPlayPluginId(id);
Chris@391 182 }
Chris@391 183
Chris@391 184 void
Chris@391 185 PlayParameterRepository::EditCommand::setPlayPluginConfiguration(QString conf)
Chris@391 186 {
Chris@391 187 m_to.setPlayPluginConfiguration(conf);
Chris@391 188 }
Chris@391 189
Chris@391 190 void
Chris@391 191 PlayParameterRepository::EditCommand::execute()
Chris@391 192 {
Chris@391 193 m_params->copyFrom(&m_to);
Chris@391 194 }
Chris@391 195
Chris@391 196 void
Chris@391 197 PlayParameterRepository::EditCommand::unexecute()
Chris@391 198 {
Chris@391 199 m_params->copyFrom(&m_from);
Chris@391 200 }
Chris@391 201
Chris@391 202 QString
Chris@391 203 PlayParameterRepository::EditCommand::getName() const
Chris@391 204 {
Chris@391 205 QString name;
Chris@391 206 QString multiname = tr("Adjust Playback Parameters");
Chris@391 207
Chris@391 208 int changed = 0;
Chris@391 209
Chris@391 210 if (m_to.isPlayAudible() != m_from.isPlayAudible()) {
Chris@391 211 name = tr("Change Playback Mute State");
Chris@391 212 if (++changed > 1) return multiname;
Chris@391 213 }
Chris@391 214
Chris@391 215 if (m_to.getPlayGain() != m_from.getPlayGain()) {
Chris@391 216 name = tr("Change Playback Gain");
Chris@391 217 if (++changed > 1) return multiname;
Chris@391 218 }
Chris@391 219
Chris@391 220 if (m_to.getPlayPan() != m_from.getPlayPan()) {
Chris@391 221 name = tr("Change Playback Pan");
Chris@391 222 if (++changed > 1) return multiname;
Chris@391 223 }
Chris@391 224
Chris@391 225 if (m_to.getPlayPluginId() != m_from.getPlayPluginId()) {
Chris@391 226 name = tr("Change Playback Plugin");
Chris@391 227 if (++changed > 1) return multiname;
Chris@391 228 }
Chris@391 229
Chris@391 230 if (m_to.getPlayPluginConfiguration() != m_from.getPlayPluginConfiguration()) {
Chris@391 231 name = tr("Configure Playback Plugin");
Chris@391 232 if (++changed > 1) return multiname;
Chris@391 233 }
Chris@391 234
Chris@391 235 if (name == "") return multiname;
Chris@391 236 return name;
Chris@391 237 }
Chris@391 238