annotate base/PlayParameterRepository.h @ 1742:52705a328b34 by-id

Rejig ById so as to put everything in a single pool, so that at the core you can go from numeric id (untyped) to anything the object can be dynamic_cast to. Useful for building other abstractions like PlayParameter-type registrations that don't know about e.g. Models. Probably some more tweaking needed. Also add tests
author Chris Cannam
date Fri, 28 Jun 2019 17:36:30 +0100
parents c01cbe41aeb5
children 77543124651b
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@1580 16 #ifndef SV_PLAY_PARAMETER_REPOSITORY_H
Chris@1580 17 #define SV_PLAY_PARAMETER_REPOSITORY_H
Chris@28 18
Chris@391 19 #include "PlayParameters.h"
Chris@391 20 #include "Command.h"
Chris@391 21
Chris@391 22 class Playable;
Chris@28 23
Chris@28 24 #include <map>
Chris@28 25
Chris@29 26 #include <QObject>
Chris@391 27 #include <QString>
Chris@29 28
Chris@29 29 class PlayParameterRepository : public QObject
Chris@28 30 {
Chris@29 31 Q_OBJECT
Chris@29 32
Chris@28 33 public:
Chris@145 34 static PlayParameterRepository *getInstance();
Chris@28 35
Chris@28 36 virtual ~PlayParameterRepository();
Chris@28 37
Chris@1742 38 /**
Chris@1742 39 * Register a playable.
Chris@1742 40 *
Chris@1742 41 * The id must be of an object that is registered with the ById
Chris@1742 42 * store and that can be dynamic_cast to Playable.
Chris@1742 43 */
Chris@1742 44 void addPlayable(int playableId);
Chris@30 45
Chris@1742 46 /**
Chris@1742 47 * Unregister a playable.
Chris@1742 48 *
Chris@1742 49 * The id must be of an object that is registered with the ById
Chris@1742 50 * store and that can be dynamic_cast to Playable.
Chris@1742 51 */
Chris@1742 52 void removePlayable(int playableId);
Chris@1742 53
Chris@1742 54 /**
Chris@1742 55 * Copy the play parameters from one playable to another.
Chris@1742 56 *
Chris@1742 57 * The ids must be of objects that are registered with the ById
Chris@1742 58 * store and that can be dynamic_cast to Playable.
Chris@1742 59 */
Chris@1742 60 void copyParameters(int fromId, int toId);
Chris@1742 61
Chris@1742 62 /**
Chris@1742 63 * Retrieve the play parameters for a playable.
Chris@1742 64 *
Chris@1742 65 * The id must be of an object that is registered with the ById
Chris@1742 66 * store and that can be dynamic_cast to Playable.
Chris@1742 67 */
Chris@1742 68 PlayParameters *getPlayParameters(int playableId);
Chris@28 69
Chris@28 70 void clear();
Chris@28 71
Chris@391 72 class EditCommand : public Command
Chris@391 73 {
Chris@391 74 public:
Chris@391 75 EditCommand(PlayParameters *params);
Chris@391 76 void setPlayMuted(bool);
Chris@391 77 void setPlayAudible(bool);
Chris@391 78 void setPlayPan(float);
Chris@391 79 void setPlayGain(float);
Chris@866 80 void setPlayClipId(QString);
Chris@1580 81 void execute() override;
Chris@1580 82 void unexecute() override;
Chris@1580 83 QString getName() const override;
Chris@391 84
Chris@391 85 protected:
Chris@391 86 PlayParameters *m_params;
Chris@391 87 PlayParameters m_from;
Chris@391 88 PlayParameters m_to;
Chris@391 89 };
Chris@391 90
Chris@29 91 signals:
Chris@29 92 void playParametersChanged(PlayParameters *);
Chris@1742 93 void playClipIdChanged(int playableId, QString);
Chris@29 94
Chris@29 95 protected slots:
Chris@29 96 void playParametersChanged();
Chris@866 97 void playClipIdChanged(QString);
Chris@29 98
Chris@28 99 protected:
Chris@1742 100 typedef std::map<int, PlayParameters *> PlayableParameterMap;
Chris@391 101 PlayableParameterMap m_playParameters;
Chris@28 102
Chris@28 103 static PlayParameterRepository *m_instance;
Chris@28 104 };
Chris@28 105
Chris@28 106 #endif