Mercurial > hg > svcore
changeset 1751:77543124651b by-id
Overhaul PlayParameters bits
author | Chris Cannam |
---|---|
date | Thu, 04 Jul 2019 18:04:21 +0100 |
parents | d0ef65d8dd89 |
children | 6d09d68165a4 |
files | base/PlayParameterRepository.cpp base/PlayParameterRepository.h base/PropertyContainer.h data/model/DenseTimeValueModel.cpp data/model/DenseTimeValueModel.h data/model/NoteModel.h data/model/ReadOnlyWaveFileModel.cpp data/model/SparseOneDimensionalModel.h data/model/SparseTimeValueModel.h data/model/WritableWaveFileModel.cpp |
diffstat | 10 files changed, 76 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/base/PlayParameterRepository.cpp Thu Jul 04 14:30:48 2019 +0100 +++ b/base/PlayParameterRepository.cpp Thu Jul 04 18:04:21 2019 +0100 @@ -17,8 +17,6 @@ #include "PlayParameters.h" #include "Playable.h" -#include "ById.h" - #include <iostream> PlayParameterRepository * @@ -35,24 +33,14 @@ } void -PlayParameterRepository::addPlayable(int playableId) +PlayParameterRepository::addPlayable(int playableId, const Playable *playable) { -// cerr << "PlayParameterRepository:addPlayable playable = " << playable << endl; - if (!getPlayParameters(playableId)) { - - auto playable = AnyById::getAs<Playable>(playableId); - if (!playable) { - SVCERR << "ERROR: id passed to PlayParameterRepository::addPlayable is not that of a Playable" << endl; - return; - } // Give all playables the same type of play parameters for the // moment -// cerr << "PlayParameterRepository:addPlayable: Adding play parameters for " << playable << endl; - - PlayParameters *params = new PlayParameters; + auto params = std::make_shared<PlayParameters>(); m_playParameters[playableId] = params; params->setPlayClipId @@ -61,14 +49,11 @@ params->setPlayAudible (playable->getDefaultPlayAudible()); - connect(params, SIGNAL(playParametersChanged()), + connect(params.get(), SIGNAL(playParametersChanged()), this, SLOT(playParametersChanged())); - connect(params, SIGNAL(playClipIdChanged(QString)), + connect(params.get(), SIGNAL(playClipIdChanged(QString)), this, SLOT(playClipIdChanged(QString))); - -// cerr << "Connected play parameters " << params << " for playable " -// << playable << " to this " << this << endl; } } @@ -76,10 +61,8 @@ PlayParameterRepository::removePlayable(int playableId) { if (m_playParameters.find(playableId) == m_playParameters.end()) { - SVCERR << "WARNING: PlayParameterRepository::removePlayable: unknown playable " << playableId << endl; return; } - delete m_playParameters[playableId]; m_playParameters.erase(playableId); } @@ -91,13 +74,13 @@ return; } if (!getPlayParameters(to)) { - cerr << "WARNING: PlayParameterRepository::copyParameters: target playable unknown, adding it now" << endl; - addPlayable(to); + cerr << "ERROR: PlayParameterRepository::copyParameters: target playable unknown" << endl; + return; } - getPlayParameters(to)->copyFrom(getPlayParameters(from)); + getPlayParameters(to)->copyFrom(getPlayParameters(from).get()); } -PlayParameters * +std::shared_ptr<PlayParameters> PlayParameterRepository::getPlayParameters(int playableId) { if (m_playParameters.find(playableId) == m_playParameters.end()) { @@ -110,17 +93,21 @@ PlayParameterRepository::playParametersChanged() { PlayParameters *params = dynamic_cast<PlayParameters *>(sender()); - emit playParametersChanged(params); + for (auto i: m_playParameters) { + if (i.second.get() == params) { + emit playParametersChanged(i.first); + return; + } + } } void PlayParameterRepository::playClipIdChanged(QString id) { PlayParameters *params = dynamic_cast<PlayParameters *>(sender()); - for (PlayableParameterMap::iterator i = m_playParameters.begin(); - i != m_playParameters.end(); ++i) { - if (i->second == params) { - emit playClipIdChanged(i->first, id); + for (auto i: m_playParameters) { + if (i.second.get() == params) { + emit playClipIdChanged(i.first, id); return; } } @@ -129,18 +116,14 @@ void PlayParameterRepository::clear() { -// cerr << "PlayParameterRepository: PlayParameterRepository::clear" << endl; - while (!m_playParameters.empty()) { - delete m_playParameters.begin()->second; - m_playParameters.erase(m_playParameters.begin()); - } + m_playParameters.clear(); } -PlayParameterRepository::EditCommand::EditCommand(PlayParameters *params) : +PlayParameterRepository::EditCommand::EditCommand(std::shared_ptr<PlayParameters> params) : m_params(params) { - m_from.copyFrom(m_params); - m_to.copyFrom(m_params); + m_from.copyFrom(m_params.get()); + m_to.copyFrom(m_params.get()); } void
--- a/base/PlayParameterRepository.h Thu Jul 04 14:30:48 2019 +0100 +++ b/base/PlayParameterRepository.h Thu Jul 04 18:04:21 2019 +0100 @@ -22,6 +22,7 @@ class Playable; #include <map> +#include <memory> #include <QObject> #include <QString> @@ -36,43 +37,33 @@ virtual ~PlayParameterRepository(); /** - * Register a playable. - * - * The id must be of an object that is registered with the ById - * store and that can be dynamic_cast to Playable. + * Register a playable. The id can be anything you like, so long + * as it is unique among playables. */ - void addPlayable(int playableId); + void addPlayable(int id, const Playable *); /** - * Unregister a playable. - * - * The id must be of an object that is registered with the ById - * store and that can be dynamic_cast to Playable. + * Unregister a playable. This must happen before a playable is + * deleted. */ - void removePlayable(int playableId); + void removePlayable(int id); /** * Copy the play parameters from one playable to another. - * - * The ids must be of objects that are registered with the ById - * store and that can be dynamic_cast to Playable. */ void copyParameters(int fromId, int toId); /** * Retrieve the play parameters for a playable. - * - * The id must be of an object that is registered with the ById - * store and that can be dynamic_cast to Playable. */ - PlayParameters *getPlayParameters(int playableId); + std::shared_ptr<PlayParameters> getPlayParameters(int id); void clear(); class EditCommand : public Command { public: - EditCommand(PlayParameters *params); + EditCommand(std::shared_ptr<PlayParameters> params); void setPlayMuted(bool); void setPlayAudible(bool); void setPlayPan(float); @@ -83,13 +74,13 @@ QString getName() const override; protected: - PlayParameters *m_params; + std::shared_ptr<PlayParameters> m_params; PlayParameters m_from; PlayParameters m_to; }; signals: - void playParametersChanged(PlayParameters *); + void playParametersChanged(int playableId); void playClipIdChanged(int playableId, QString); protected slots: @@ -97,7 +88,7 @@ void playClipIdChanged(QString); protected: - typedef std::map<int, PlayParameters *> PlayableParameterMap; + typedef std::map<int, std::shared_ptr<PlayParameters>> PlayableParameterMap; PlayableParameterMap m_playParameters; static PlayParameterRepository *m_instance;
--- a/base/PropertyContainer.h Thu Jul 04 14:30:48 2019 +0100 +++ b/base/PropertyContainer.h Thu Jul 04 18:04:21 2019 +0100 @@ -21,6 +21,7 @@ #include <QString> #include <QObject> #include <vector> +#include <memory> class PlayParameters; class RangeMapper; @@ -111,7 +112,13 @@ virtual QString getPropertyContainerName() const = 0; virtual QString getPropertyContainerIconName() const = 0; - virtual PlayParameters *getPlayParameters() { return 0; } + /** + * Return the play parameters for this layer, if any. The return + * value is a shared_ptr that, if not null, can be passed to + * e.g. PlayParameterRepository::EditCommand to change the + * parameters. + */ + virtual std::shared_ptr<PlayParameters> getPlayParameters() { return {}; } signals: void propertyChanged(PropertyContainer::PropertyName);
--- a/data/model/DenseTimeValueModel.cpp Thu Jul 04 14:30:48 2019 +0100 +++ b/data/model/DenseTimeValueModel.cpp Thu Jul 04 18:04:21 2019 +0100 @@ -14,19 +14,8 @@ */ #include "DenseTimeValueModel.h" -#include "base/PlayParameterRepository.h" #include <QStringList> - -DenseTimeValueModel::DenseTimeValueModel() -{ - PlayParameterRepository::getInstance()->addPlayable(getId().untyped); -} - -DenseTimeValueModel::~DenseTimeValueModel() -{ - PlayParameterRepository::getInstance()->removePlayable(getId().untyped); -} QString DenseTimeValueModel::toDelimitedDataString(QString delimiter,
--- a/data/model/DenseTimeValueModel.h Thu Jul 04 14:30:48 2019 +0100 +++ b/data/model/DenseTimeValueModel.h Thu Jul 04 18:04:21 2019 +0100 @@ -32,9 +32,9 @@ Q_OBJECT public: - DenseTimeValueModel(); + DenseTimeValueModel() { } - virtual ~DenseTimeValueModel(); + virtual ~DenseTimeValueModel() { } /** * Return the minimum possible value found in this model type.
--- a/data/model/NoteModel.h Thu Jul 04 14:30:48 2019 +0100 +++ b/data/model/NoteModel.h Thu Jul 04 18:04:21 2019 +0100 @@ -66,7 +66,8 @@ m_valueMinimum = 33.f; m_valueMaximum = 88.f; } - PlayParameterRepository::getInstance()->addPlayable(getId().untyped); + PlayParameterRepository::getInstance()->addPlayable + (getId().untyped, this); } NoteModel(sv_samplerate_t sampleRate, int resolution, @@ -87,11 +88,13 @@ DeferredNotifier::NOTIFY_ALWAYS : DeferredNotifier::NOTIFY_DEFERRED), m_completion(100) { - PlayParameterRepository::getInstance()->addPlayable(getId().untyped); + PlayParameterRepository::getInstance()->addPlayable + (getId().untyped, this); } virtual ~NoteModel() { - PlayParameterRepository::getInstance()->removePlayable(getId().untyped); + PlayParameterRepository::getInstance()->removePlayable + (getId().untyped); } QString getTypeName() const override { return tr("Note"); }
--- a/data/model/ReadOnlyWaveFileModel.cpp Thu Jul 04 14:30:48 2019 +0100 +++ b/data/model/ReadOnlyWaveFileModel.cpp Thu Jul 04 18:04:21 2019 +0100 @@ -21,12 +21,12 @@ #include "system/System.h" #include "base/Preferences.h" +#include "base/PlayParameterRepository.h" #include <QFileInfo> #include <QTextStream> #include <iostream> -//#include <unistd.h> #include <cmath> #include <sndfile.h> @@ -85,6 +85,9 @@ if (m_reader) setObjectName(m_reader->getTitle()); if (objectName() == "") setObjectName(QFileInfo(m_path).fileName()); if (isOK()) fillCache(); + + PlayParameterRepository::getInstance()->addPlayable + (getId().untyped, this); } ReadOnlyWaveFileModel::ReadOnlyWaveFileModel(FileSource source, AudioFileReader *reader) : @@ -106,10 +109,16 @@ if (m_reader) setObjectName(m_reader->getTitle()); if (objectName() == "") setObjectName(QFileInfo(m_path).fileName()); fillCache(); + + PlayParameterRepository::getInstance()->addPlayable + (getId().untyped, this); } ReadOnlyWaveFileModel::~ReadOnlyWaveFileModel() { + PlayParameterRepository::getInstance()->removePlayable + (getId().untyped); + m_exiting = true; if (m_fillThread) m_fillThread->wait(); if (m_myReader) delete m_reader;
--- a/data/model/SparseOneDimensionalModel.h Thu Jul 04 14:30:48 2019 +0100 +++ b/data/model/SparseOneDimensionalModel.h Thu Jul 04 18:04:21 2019 +0100 @@ -53,11 +53,13 @@ DeferredNotifier::NOTIFY_ALWAYS : DeferredNotifier::NOTIFY_DEFERRED), m_completion(100) { - PlayParameterRepository::getInstance()->addPlayable(getId().untyped); + PlayParameterRepository::getInstance()->addPlayable + (getId().untyped, this); } virtual ~SparseOneDimensionalModel() { - PlayParameterRepository::getInstance()->removePlayable(getId().untyped); + PlayParameterRepository::getInstance()->removePlayable + (getId().untyped); } QString getTypeName() const override { return tr("Sparse 1-D"); }
--- a/data/model/SparseTimeValueModel.h Thu Jul 04 14:30:48 2019 +0100 +++ b/data/model/SparseTimeValueModel.h Thu Jul 04 18:04:21 2019 +0100 @@ -54,7 +54,8 @@ m_completion(100) { // Model is playable, but may not sound (if units not Hz or // range unsuitable) - PlayParameterRepository::getInstance()->addPlayable(getId().untyped); + PlayParameterRepository::getInstance()->addPlayable + (getId().untyped, this); } SparseTimeValueModel(sv_samplerate_t sampleRate, int resolution, @@ -73,11 +74,13 @@ m_completion(100) { // Model is playable, but may not sound (if units not Hz or // range unsuitable) - PlayParameterRepository::getInstance()->addPlayable(getId().untyped); + PlayParameterRepository::getInstance()->addPlayable + (getId().untyped, this); } virtual ~SparseTimeValueModel() { - PlayParameterRepository::getInstance()->removePlayable(getId().untyped); + PlayParameterRepository::getInstance()->removePlayable + (getId().untyped); } QString getTypeName() const override { return tr("Sparse Time-Value"); }
--- a/data/model/WritableWaveFileModel.cpp Thu Jul 04 14:30:48 2019 +0100 +++ b/data/model/WritableWaveFileModel.cpp Thu Jul 04 18:04:21 2019 +0100 @@ -19,6 +19,7 @@ #include "base/TempDirectory.h" #include "base/Exceptions.h" +#include "base/PlayParameterRepository.h" #include "fileio/WavFileWriter.h" #include "fileio/WavFileReader.h" @@ -160,10 +161,16 @@ connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), this, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t))); + + PlayParameterRepository::getInstance()->addPlayable + (getId().untyped, this); } WritableWaveFileModel::~WritableWaveFileModel() { + PlayParameterRepository::getInstance()->removePlayable + (getId().untyped); + delete m_model; delete m_targetWriter; delete m_temporaryWriter;