changeset 30:a6ef94ecbe74

* As previous commit
author Chris Cannam
date Fri, 17 Feb 2006 18:11:08 +0000
parents 8460b3bf8f04
children 4afaf0df4d51
files base/Layer.cpp base/Model.cpp base/Model.h base/PlayParameterRepository.cpp base/PlayParameterRepository.h base/PlayParameters.cpp base/PlayParameters.h base/View.h
diffstat 8 files changed, 73 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/base/Layer.cpp	Fri Feb 17 18:04:26 2006 +0000
+++ b/base/Layer.cpp	Fri Feb 17 18:11:08 2006 +0000
@@ -78,7 +78,7 @@
 PlayParameters *
 Layer::getPlayParameters() 
 {
-    std::cerr << "Layer (" << this << ")::getPlayParameters: model is "<< getModel() << std::endl;
+    std::cerr << "Layer (" << this << ", " << objectName().toStdString() << ")::getPlayParameters: model is "<< getModel() << std::endl;
     const Model *model = getModel();
     if (model) {
 	return PlayParameterRepository::instance()->getPlayParameters(model);
--- a/base/Model.cpp	Fri Feb 17 18:04:26 2006 +0000
+++ b/base/Model.cpp	Fri Feb 17 18:11:08 2006 +0000
@@ -8,9 +8,19 @@
 */
 
 #include "Model.h"
+#include "PlayParameterRepository.h"
 
 const int Model::COMPLETION_UNKNOWN = -1;
 
+Model::~Model()
+{
+    // Subclasses have to handle adding themselves to the repository,
+    // if they want to be played.  We can't do it from here because
+    // the repository would be unable to tell whether we were playable
+    // or not (because dynamic_cast won't work from the base class ctor)
+    PlayParameterRepository::instance()->removeModel(this);
+}
+
 QString
 Model::toXmlString(QString indent, QString extraAttributes) const
 {
--- a/base/Model.h	Fri Feb 17 18:04:26 2006 +0000
+++ b/base/Model.h	Fri Feb 17 18:11:08 2006 +0000
@@ -28,6 +28,8 @@
     Q_OBJECT
 
 public:
+    virtual ~Model();
+
     /**
      * Return true if the model was constructed successfully.  Classes
      * that refer to the model should always test this before use.
--- a/base/PlayParameterRepository.cpp	Fri Feb 17 18:04:26 2006 +0000
+++ b/base/PlayParameterRepository.cpp	Fri Feb 17 18:11:08 2006 +0000
@@ -10,6 +10,9 @@
 #include "PlayParameterRepository.h"
 #include "PlayParameters.h"
 
+//!!! shouldn't be including this here -- restructure needed
+#include "audioio/AudioGenerator.h"
+
 #include <iostream>
 
 PlayParameterRepository *
@@ -25,18 +28,42 @@
 {
 }
 
+void
+PlayParameterRepository::addModel(const Model *model)
+{
+    if (!getPlayParameters(model)) {
+
+	// Give all models the same type of play parameters for the
+	// moment, provided they can be played at all
+
+	if (AudioGenerator::canPlay(model)) {
+
+	    std::cerr << "PlayParameterRepository: Adding play parameters for " << model << std::endl;
+
+	    m_playParameters[model] = new PlayParameters;
+
+	    connect(m_playParameters[model], SIGNAL(playParametersChanged()),
+		    this, SLOT(playParametersChanged()));
+
+	} else {
+
+	    std::cerr << "PlayParameterRepository: Model " << model << " not playable" <<  std::endl;
+	}	    
+    }
+}    
+
+void
+PlayParameterRepository::removeModel(const Model *model)
+{
+    delete m_playParameters[model];
+    m_playParameters.erase(model);
+}
+
 PlayParameters *
-PlayParameterRepository::getPlayParameters(const Model *model)
+PlayParameterRepository::getPlayParameters(const Model *model) const
 {
-    if (m_playParameters.find(model) == m_playParameters.end()) {
-	// Give all models the same type of play parameters for the moment
-	std::cerr << "Creating new PlayParameters for model " << model << std::endl;
-	m_playParameters[model] = new PlayParameters;
-	connect(m_playParameters[model], SIGNAL(playParametersChanged()),
-		this, SLOT(playParametersChanged()));
-    }
-
-    return m_playParameters[model];
+    if (m_playParameters.find(model) == m_playParameters.end()) return 0;
+    return m_playParameters.find(model)->second;
 }
 
 void
@@ -48,6 +75,7 @@
 void
 PlayParameterRepository::clear()
 {
+    std::cerr << "PlayParameterRepository: PlayParameterRepository::clear" << std::endl;
     while (!m_playParameters.empty()) {
 	delete m_playParameters.begin()->second;
 	m_playParameters.erase(m_playParameters.begin());
--- a/base/PlayParameterRepository.h	Fri Feb 17 18:04:26 2006 +0000
+++ b/base/PlayParameterRepository.h	Fri Feb 17 18:11:08 2006 +0000
@@ -26,8 +26,10 @@
 
     virtual ~PlayParameterRepository();
 
-//!!! No way to remove a model!
-    PlayParameters *getPlayParameters(const Model *model);
+    void addModel(const Model *model);
+    void removeModel(const Model *model);
+
+    PlayParameters *getPlayParameters(const Model *model) const;
 
     void clear();
 
--- a/base/PlayParameters.cpp	Fri Feb 17 18:04:26 2006 +0000
+++ b/base/PlayParameters.cpp	Fri Feb 17 18:11:08 2006 +0000
@@ -17,13 +17,14 @@
     std::cerr << "PlayParameters: setPlayMuted(" << muted << ")" << std::endl;
     m_playMuted = muted;
     emit playMutedChanged(muted);
+    emit playAudibleChanged(!muted);
     emit playParametersChanged();
 }
 
 void
 PlayParameters::setPlayAudible(bool audible)
 {
-    std::cerr << "PlayParameters: setPlayAudible(" << audible << ")" << std::endl;
+    std::cerr << "PlayParameters(" << this << "): setPlayAudible(" << audible << ")" << std::endl;
     setPlayMuted(!audible);
 }
 
--- a/base/PlayParameters.h	Fri Feb 17 18:04:26 2006 +0000
+++ b/base/PlayParameters.h	Fri Feb 17 18:11:08 2006 +0000
@@ -23,18 +23,19 @@
     virtual float getPlayPan() const { return m_playPan; } // -1.0 -> 1.0
     virtual float getPlayGain() const { return m_playGain; }
 
-signals:
-    void playParametersChanged();
-    void playMutedChanged(bool);
-    void playPanChanged(float);
-    void playGainChanged(float);
-
 public slots:
     virtual void setPlayMuted(bool muted);
     virtual void setPlayAudible(bool nonMuted);
     virtual void setPlayPan(float pan);
     virtual void setPlayGain(float gain);
 
+signals:
+    void playParametersChanged();
+    void playMutedChanged(bool);
+    void playAudibleChanged(bool);
+    void playPanChanged(float);
+    void playGainChanged(float);
+
 protected:
     bool m_playMuted;
     float m_playPan;
--- a/base/View.h	Fri Feb 17 18:04:26 2006 +0000
+++ b/base/View.h	Fri Feb 17 18:11:08 2006 +0000
@@ -159,20 +159,23 @@
     virtual void setPlaybackFollow(PlaybackFollowMode m);
     virtual PlaybackFollowMode getPlaybackFollow() const { return m_followPlay; }
 
+    typedef PropertyContainer::PropertyName PropertyName;
+
     // We implement the PropertyContainer API, although we don't
     // actually subclass PropertyContainer.  We have our own
     // PropertyContainer that we can return on request that just
     // delegates back to us.
     virtual PropertyContainer::PropertyList getProperties() const;
-    virtual PropertyContainer::PropertyType getPropertyType(const PropertyContainer::PropertyName &) const;
-    virtual int getPropertyRangeAndValue(const PropertyContainer::PropertyName &,
+    virtual PropertyContainer::PropertyType getPropertyType(const PropertyName &) const;
+    virtual int getPropertyRangeAndValue(const PropertyName &,
 					 int *min, int *max) const;
-    virtual QString getPropertyValueLabel(const PropertyContainer::PropertyName &,
+    virtual QString getPropertyValueLabel(const PropertyName &,
 					  int value) const;
-    virtual void setProperty(const PropertyContainer::PropertyName &, int value);
+    virtual void setProperty(const PropertyName &, int value);
     virtual QString getPropertyContainerName() const {
 	return objectName();
     }
+    virtual QString getPropertyContainerIconName() const = 0;
 
     virtual size_t getPropertyContainerCount() const;
 
@@ -187,6 +190,7 @@
     void propertyContainerRemoved(PropertyContainer *pc);
     void propertyContainerPropertyChanged(PropertyContainer *pc);
     void propertyContainerNameChanged(PropertyContainer *pc);
+    void propertyChanged(PropertyName);
 
     void centreFrameChanged(void *, unsigned long, bool);
     void zoomLevelChanged(void *, unsigned long, bool);
@@ -294,7 +298,7 @@
 	return m_v->getPropertyContainerName();
     }
     QString getPropertyContainerIconName() const {
-	return "view";
+	return m_v->getPropertyContainerIconName();
     }
 
 public slots: