PlayParameterRepository.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
17 #include "PlayParameters.h"
18 #include "Playable.h"
19 
20 #include <iostream>
21 
24 
27 {
28  return m_instance;
29 }
30 
32 {
33 }
34 
35 void
36 PlayParameterRepository::addPlayable(int playableId, const Playable *playable)
37 {
38  if (!getPlayParameters(playableId)) {
39 
40  // Give all playables the same type of play parameters for the
41  // moment
42 
43  auto params = std::make_shared<PlayParameters>();
44  m_playParameters[playableId] = params;
45 
46  params->setPlayClipId
47  (playable->getDefaultPlayClipId());
48 
49  params->setPlayAudible
50  (playable->getDefaultPlayAudible());
51 
52  connect(params.get(), SIGNAL(playParametersChanged()),
53  this, SLOT(playParametersChanged()));
54 
55  connect(params.get(), SIGNAL(playClipIdChanged(QString)),
56  this, SLOT(playClipIdChanged(QString)));
57  }
58 }
59 
60 void
62 {
63  if (m_playParameters.find(playableId) == m_playParameters.end()) {
64  return;
65  }
66  m_playParameters.erase(playableId);
67 }
68 
69 void
71 {
72  if (!getPlayParameters(from)) {
73  cerr << "ERROR: PlayParameterRepository::copyParameters: source playable unknown" << endl;
74  return;
75  }
76  if (!getPlayParameters(to)) {
77  cerr << "ERROR: PlayParameterRepository::copyParameters: target playable unknown" << endl;
78  return;
79  }
80  getPlayParameters(to)->copyFrom(getPlayParameters(from).get());
81 }
82 
83 std::shared_ptr<PlayParameters>
85 {
86  if (m_playParameters.find(playableId) == m_playParameters.end()) {
87  return nullptr;
88  }
89  return m_playParameters.find(playableId)->second;
90 }
91 
92 void
94 {
95  PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
96  for (auto i: m_playParameters) {
97  if (i.second.get() == params) {
98  emit playParametersChanged(i.first);
99  return;
100  }
101  }
102 }
103 
104 void
106 {
107  PlayParameters *params = dynamic_cast<PlayParameters *>(sender());
108  for (auto i: m_playParameters) {
109  if (i.second.get() == params) {
110  emit playClipIdChanged(i.first, id);
111  return;
112  }
113  }
114 }
115 
116 void
118 {
119  m_playParameters.clear();
120 }
121 
122 PlayParameterRepository::EditCommand::EditCommand(std::shared_ptr<PlayParameters> params) :
123  m_params(params)
124 {
125  m_from.copyFrom(m_params.get());
126  m_to.copyFrom(m_params.get());
127 }
128 
129 void
131 {
132  m_to.setPlayMuted(muted);
133 }
134 
135 void
137 {
138  m_to.setPlayAudible(audible);
139 }
140 
141 void
143 {
144  m_to.setPlayPan(pan);
145 }
146 
147 void
149 {
150  m_to.setPlayGain(gain);
151 }
152 
153 void
155 {
156  m_to.setPlayClipId(id);
157 }
158 
159 void
161 {
162  m_params->copyFrom(&m_to);
163 }
164 
165 void
167 {
168  m_params->copyFrom(&m_from);
169 }
170 
171 QString
173 {
174  QString name;
175  QString multiname = tr("Adjust Playback Parameters");
176 
177  int changed = 0;
178 
179  if (m_to.isPlayAudible() != m_from.isPlayAudible()) {
180  name = tr("Change Playback Mute State");
181  if (++changed > 1) return multiname;
182  }
183 
184  if (m_to.getPlayGain() != m_from.getPlayGain()) {
185  name = tr("Change Playback Gain");
186  if (++changed > 1) return multiname;
187  }
188 
189  if (m_to.getPlayPan() != m_from.getPlayPan()) {
190  name = tr("Change Playback Pan");
191  if (++changed > 1) return multiname;
192  }
193 
194  if (m_to.getPlayClipId() != m_from.getPlayClipId()) {
195  name = tr("Change Playback Sample");
196  if (++changed > 1) return multiname;
197  }
198 
199  if (name == "") return multiname;
200  return name;
201 }
202 
std::shared_ptr< PlayParameters > getPlayParameters(int id)
Retrieve the play parameters for a playable.
static PlayParameterRepository * getInstance()
EditCommand(std::shared_ptr< PlayParameters > params)
virtual QString getPlayClipId() const
virtual float getPlayPan() const
virtual void setPlayAudible(bool nonMuted)
static PlayParameterRepository * m_instance
virtual QString getDefaultPlayClipId() const
Definition: Playable.h:27
virtual float getPlayGain() const
virtual void setPlayClipId(QString id)
virtual bool getDefaultPlayAudible() const
Definition: Playable.h:28
PlayableParameterMap m_playParameters
void removePlayable(int id)
Unregister a playable.
virtual bool isPlayAudible() const
std::shared_ptr< PlayParameters > m_params
void copyParameters(int fromId, int toId)
Copy the play parameters from one playable to another.
virtual void copyFrom(const PlayParameters *)
void addPlayable(int id, const Playable *)
Register a playable.
virtual void setPlayGain(float gain)
virtual void setPlayMuted(bool muted)
void playClipIdChanged(int playableId, QString)
virtual void setPlayPan(float pan)