annotate base/PlayParameterRepository.cpp @ 1886:f803d3c33f76 tip

Switch off copious debug in soft synth driving
author Chris Cannam
date Fri, 14 Aug 2020 10:44:44 +0100
parents 77543124651b
children
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@1751 36 PlayParameterRepository::addPlayable(int playableId, const Playable *playable)
Chris@30 37 {
Chris@1742 38 if (!getPlayParameters(playableId)) {
Chris@1742 39
Chris@1429 40 // Give all playables the same type of play parameters for the
Chris@1429 41 // moment
Chris@30 42
Chris@1751 43 auto params = std::make_shared<PlayParameters>();
Chris@1742 44 m_playParameters[playableId] = params;
Chris@30 45
Chris@866 46 params->setPlayClipId
Chris@866 47 (playable->getDefaultPlayClipId());
Chris@952 48
Chris@952 49 params->setPlayAudible
Chris@952 50 (playable->getDefaultPlayAudible());
Chris@391 51
Chris@1751 52 connect(params.get(), SIGNAL(playParametersChanged()),
Chris@391 53 this, SLOT(playParametersChanged()));
Chris@391 54
Chris@1751 55 connect(params.get(), SIGNAL(playClipIdChanged(QString)),
Chris@866 56 this, SLOT(playClipIdChanged(QString)));
Chris@30 57 }
Chris@30 58 }
Chris@30 59
Chris@30 60 void
Chris@1742 61 PlayParameterRepository::removePlayable(int playableId)
Chris@30 62 {
Chris@1742 63 if (m_playParameters.find(playableId) == m_playParameters.end()) {
Chris@391 64 return;
Chris@391 65 }
Chris@1742 66 m_playParameters.erase(playableId);
Chris@30 67 }
Chris@30 68
Chris@284 69 void
Chris@1742 70 PlayParameterRepository::copyParameters(int from, int to)
Chris@284 71 {
Chris@284 72 if (!getPlayParameters(from)) {
Chris@843 73 cerr << "ERROR: PlayParameterRepository::copyParameters: source playable unknown" << endl;
Chris@284 74 return;
Chris@284 75 }
Chris@284 76 if (!getPlayParameters(to)) {
Chris@1751 77 cerr << "ERROR: PlayParameterRepository::copyParameters: target playable unknown" << endl;
Chris@1751 78 return;
Chris@284 79 }
Chris@1751 80 getPlayParameters(to)->copyFrom(getPlayParameters(from).get());
Chris@284 81 }
Chris@284 82
Chris@1751 83 std::shared_ptr<PlayParameters>
Chris@1742 84 PlayParameterRepository::getPlayParameters(int playableId)
Chris@28 85 {
Chris@1742 86 if (m_playParameters.find(playableId) == m_playParameters.end()) {
Chris@1742 87 return nullptr;
Chris@1742 88 }
Chris@1742 89 return m_playParameters.find(playableId)->second;
Chris@28 90 }
Chris@28 91
Chris@28 92 void
Chris@29 93 PlayParameterRepository::playParametersChanged()
Chris@29 94 {
Chris@57 95 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
Chris@1751 96 for (auto i: m_playParameters) {
Chris@1751 97 if (i.second.get() == params) {
Chris@1751 98 emit playParametersChanged(i.first);
Chris@1751 99 return;
Chris@1751 100 }
Chris@1751 101 }
Chris@57 102 }
Chris@57 103
Chris@57 104 void
Chris@866 105 PlayParameterRepository::playClipIdChanged(QString id)
Chris@57 106 {
Chris@57 107 PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
Chris@1751 108 for (auto i: m_playParameters) {
Chris@1751 109 if (i.second.get() == params) {
Chris@1751 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@1751 119 m_playParameters.clear();
Chris@28 120 }
Chris@28 121
Chris@1751 122 PlayParameterRepository::EditCommand::EditCommand(std::shared_ptr<PlayParameters> params) :
Chris@391 123 m_params(params)
Chris@391 124 {
Chris@1751 125 m_from.copyFrom(m_params.get());
Chris@1751 126 m_to.copyFrom(m_params.get());
Chris@391 127 }
Chris@391 128
Chris@391 129 void
Chris@391 130 PlayParameterRepository::EditCommand::setPlayMuted(bool muted)
Chris@391 131 {
Chris@391 132 m_to.setPlayMuted(muted);
Chris@391 133 }
Chris@391 134
Chris@391 135 void
Chris@391 136 PlayParameterRepository::EditCommand::setPlayAudible(bool audible)
Chris@391 137 {
Chris@391 138 m_to.setPlayAudible(audible);
Chris@391 139 }
Chris@391 140
Chris@391 141 void
Chris@391 142 PlayParameterRepository::EditCommand::setPlayPan(float pan)
Chris@391 143 {
Chris@391 144 m_to.setPlayPan(pan);
Chris@391 145 }
Chris@391 146
Chris@391 147 void
Chris@391 148 PlayParameterRepository::EditCommand::setPlayGain(float gain)
Chris@391 149 {
Chris@391 150 m_to.setPlayGain(gain);
Chris@391 151 }
Chris@391 152
Chris@391 153 void
Chris@866 154 PlayParameterRepository::EditCommand::setPlayClipId(QString id)
Chris@391 155 {
Chris@866 156 m_to.setPlayClipId(id);
Chris@391 157 }
Chris@391 158
Chris@391 159 void
Chris@391 160 PlayParameterRepository::EditCommand::execute()
Chris@391 161 {
Chris@391 162 m_params->copyFrom(&m_to);
Chris@391 163 }
Chris@391 164
Chris@391 165 void
Chris@391 166 PlayParameterRepository::EditCommand::unexecute()
Chris@391 167 {
Chris@391 168 m_params->copyFrom(&m_from);
Chris@391 169 }
Chris@391 170
Chris@391 171 QString
Chris@391 172 PlayParameterRepository::EditCommand::getName() const
Chris@391 173 {
Chris@391 174 QString name;
Chris@391 175 QString multiname = tr("Adjust Playback Parameters");
Chris@391 176
Chris@391 177 int changed = 0;
Chris@391 178
Chris@391 179 if (m_to.isPlayAudible() != m_from.isPlayAudible()) {
Chris@391 180 name = tr("Change Playback Mute State");
Chris@391 181 if (++changed > 1) return multiname;
Chris@391 182 }
Chris@391 183
Chris@391 184 if (m_to.getPlayGain() != m_from.getPlayGain()) {
Chris@391 185 name = tr("Change Playback Gain");
Chris@391 186 if (++changed > 1) return multiname;
Chris@391 187 }
Chris@391 188
Chris@391 189 if (m_to.getPlayPan() != m_from.getPlayPan()) {
Chris@391 190 name = tr("Change Playback Pan");
Chris@391 191 if (++changed > 1) return multiname;
Chris@391 192 }
Chris@391 193
Chris@866 194 if (m_to.getPlayClipId() != m_from.getPlayClipId()) {
Chris@863 195 name = tr("Change Playback Sample");
Chris@391 196 if (++changed > 1) return multiname;
Chris@391 197 }
Chris@391 198
Chris@391 199 if (name == "") return multiname;
Chris@391 200 return name;
Chris@391 201 }
Chris@391 202