diff base/PlayParameterRepository.cpp @ 30:a6ef94ecbe74

* As previous commit
author Chris Cannam
date Fri, 17 Feb 2006 18:11:08 +0000
parents 8460b3bf8f04
children 39ae3dee27b9
line wrap: on
line diff
--- 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());