annotate base/PlayParameterRepository.cpp @ 925:3efc20c59a94 tonioni

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