changeset 203:74d1b3bda5a3

allow to save and restore the filter settings from an easaier session
author lbajardsilogic
date Tue, 29 Jan 2008 17:21:42 +0000
parents bb04d9df8b41
children c5970f7af886
files sv/document/Document.cpp sv/document/ESFileReader.cpp sv/document/ESFileReader.h sv/filter/Filter.cpp sv/filter/Filter.h sv/filter/FilterStack.cpp sv/filter/FilterStack.h sv/filter/TimeStretchFilter.cpp sv/main/MainWindow.cpp widgets/ItemAudioFilterList.cpp widgets/PropertyBox.cpp widgets/RealTimeFilterPropertyStack.cpp
diffstat 12 files changed, 123 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/sv/document/Document.cpp	Tue Jan 29 12:46:03 2008 +0000
+++ b/sv/document/Document.cpp	Tue Jan 29 17:21:42 2008 +0000
@@ -909,6 +909,8 @@
 
 	s += indent + indent + indent + QString("</audio>\n");
 
+	s += m_filterStack->toEasaierXmlString(indent + indent + indent, extraAttributes);
+
     s += indent + indent + QString("</easaierResources>\n");
 
     s += indent + "</data>\n";
--- a/sv/document/ESFileReader.cpp	Tue Jan 29 12:46:03 2008 +0000
+++ b/sv/document/ESFileReader.cpp	Tue Jan 29 17:21:42 2008 +0000
@@ -109,6 +109,14 @@
 		QString filename = attributes.value("value");
 		m_document->setAudioSourceInfoFileName(filename);
 
+    } else if (name == "filters") {
+		// nothing needed
+		ok = true;
+
+    } else if (name == "filter") {
+		// nothing needed
+		ok = readFilter(attributes);;
+
     } else if (name == "display") {
 		// nothing needed
 		ok = true;
@@ -346,3 +354,32 @@
     return true;
 }
 
+bool
+ESFileReader::readFilter(const QXmlAttributes &attributes)
+{
+	QString name = attributes.value("name");
+
+	FilterStack	*filterStack = m_document->getRealTimeFilterStack();
+
+	if (!filterStack)
+	{
+		std::cerr << "WARNING: Easaier session-XML: Failed to get filterStack \""
+		  << name.toLocal8Bit().data()
+		  << "\"" << std::endl;
+		return false;
+	}
+
+	Filter *curFilter = filterStack->findFilter(name);
+
+	if (!curFilter)
+	{
+		std::cerr << "WARNING: Easaier session-XML: Failed to get filter \""
+		  << name.toLocal8Bit().data()
+		  << "\"" << std::endl;
+		return false;
+	}
+
+	curFilter->setProperties(attributes);
+
+    return true;
+}
--- a/sv/document/ESFileReader.h	Tue Jan 29 12:46:03 2008 +0000
+++ b/sv/document/ESFileReader.h	Tue Jan 29 17:21:42 2008 +0000
@@ -71,6 +71,7 @@
     bool readWindow(const QXmlAttributes &);
     bool readView(const QXmlAttributes &);
     bool readLayer(const QXmlAttributes &);
+	bool readFilter(const QXmlAttributes &);
 
     Document *m_document;
     ESFileReaderPaneCallback &m_paneCallback;
--- a/sv/filter/Filter.cpp	Tue Jan 29 12:46:03 2008 +0000
+++ b/sv/filter/Filter.cpp	Tue Jan 29 17:21:42 2008 +0000
@@ -21,19 +21,53 @@
 Filter::~Filter()
 {}
 
-bool Filter::isFilterEnabled(){
+bool Filter::isFilterEnabled() const {
 	return filterEnabled;
 }
 
 
 void Filter::setFilterEnabled(bool b){
 	filterEnabled=b;
-	emit filterEnableChanged(b);
 }
 
 void Filter::setFilterEnabled(int b){
-	filterEnabled=b;
-	emit filterEnableChanged(b);
+	filterEnabled=(bool)b;
+	
 }
 
+QString Filter::toEasaierXmlString(QString indent, QString extraAttributes) const
+{
+    QString s;
+
+	int enable = isFilterEnabled();
+	s += indent + QString("<filter name=\"%1\" enable=\"%2\" ").arg(objectName()).arg(enable);
+
+	PropertyContainer::PropertyList propertyList = getProperties();
+	for(int i=0; i< ((int) propertyList.size());i++)
+	{
+		int min, max, deflt;
+		int value = getPropertyRangeAndValue(propertyList[i], &min, &max, &deflt);
+		s += propertyList[i] + QString("=\"%1\" ").arg(value);
+	}
+
+	s += QString(" %1 />\n").arg(extraAttributes);
+
+    return s;
+}
 
+void Filter::setProperties(const QXmlAttributes &attributes)
+{
+	int enable = attributes.value("enable").toInt();
+	setFilterEnabled(enable);
+	emit filterEnableChange(enable);
+
+	PropertyContainer::PropertyList propertyList = getProperties();
+	int value;
+	for(int i=0; i< ((int) propertyList.size());i++)
+	{
+		 value = attributes.value(propertyList[i]).toInt(); 
+		 setProperty(propertyList[i], value);
+	}
+
+	emit propertiesChanged(this);
+}
\ No newline at end of file
--- a/sv/filter/Filter.h	Tue Jan 29 12:46:03 2008 +0000
+++ b/sv/filter/Filter.h	Tue Jan 29 17:21:42 2008 +0000
@@ -14,6 +14,8 @@
 #ifndef _FILTER_H_
 #define _FILTER_H_
 
+#include <QXmlAttributes>
+
 #include "base/PropertyContainer.h"
 
 class Filter : public PropertyContainer
@@ -45,13 +47,19 @@
 
 	inline void setSourceChannelCount(size_t channel){m_sourceChannelCount = channel;}
 	inline size_t getSourceChannelCount(){return m_sourceChannelCount;}
-	bool isFilterEnabled();
+	bool isFilterEnabled() const;
 
 	/*allow or not to add another filter of this type*/
 	virtual bool allowMultiple() = 0;
 
+	QString toEasaierXmlString(QString indent, QString extraAttributes) const;
+
+	void setProperties(const QXmlAttributes &attributes);
+
 signals :
-	void filterEnableChanged(bool);
+	void filterEnableChange(bool);
+
+	void propertiesChanged(PropertyContainer *);
 
 protected:
 
--- a/sv/filter/FilterStack.cpp	Tue Jan 29 12:46:03 2008 +0000
+++ b/sv/filter/FilterStack.cpp	Tue Jan 29 17:21:42 2008 +0000
@@ -190,4 +190,22 @@
 	}
 
 	return true;
+}
+
+QString FilterStack::toEasaierXmlString(QString indent, QString extraAttributes) const
+{
+    QString s;
+
+    s += indent + QString("<filters>\n");
+
+	std::map<int, Filter *>::const_iterator iter;
+	for (iter = m_filters.begin(); iter != m_filters.end(); iter++)
+	{
+		Filter * filter = iter->second;
+		s += filter->toEasaierXmlString(indent + indent, extraAttributes);
+	}
+
+    s += indent + "</filters>\n";
+
+    return s;
 }
\ No newline at end of file
--- a/sv/filter/FilterStack.h	Tue Jan 29 12:46:03 2008 +0000
+++ b/sv/filter/FilterStack.h	Tue Jan 29 17:21:42 2008 +0000
@@ -46,6 +46,8 @@
 
 	bool allowOtherFilter(QString &labelType);
 
+	QString toEasaierXmlString(QString indent, QString extraAttributes) const;
+
 signals:
 	void newFilterAdded(Filter *);
 	void filterRemoved(QString);
--- a/sv/filter/TimeStretchFilter.cpp	Tue Jan 29 12:46:03 2008 +0000
+++ b/sv/filter/TimeStretchFilter.cpp	Tue Jan 29 17:21:42 2008 +0000
@@ -452,8 +452,7 @@
 
 void TimeStretchFilter::setFilterEnabled(bool b){
 	filterEnabled=b;
-	emit filterEnableChanged(b);
-
+	
 	if (filterEnabled)
 	{
 		if (!m_bypass)
@@ -465,8 +464,7 @@
 
 void TimeStretchFilter::setFilterEnabled(int b){
 	filterEnabled=b;
-	emit filterEnableChanged(b);
-
+	
 	if (filterEnabled)
 	{
 		if (!m_bypass)
@@ -475,3 +473,5 @@
 	else 
 		emit playSpeedChanged(1);
 }
+
+
--- a/sv/main/MainWindow.cpp	Tue Jan 29 12:46:03 2008 +0000
+++ b/sv/main/MainWindow.cpp	Tue Jan 29 17:21:42 2008 +0000
@@ -3117,7 +3117,8 @@
 	createMultiPaneLayerContainer();
     PaneCallback callback(this);
     m_viewManager->clearSelections();
-	
+	setupFiltersMenu();
+
     SVFileReader reader(m_document, callback, location);
     QXmlInputSource inputSource(&bzFile);
     reader.parse(inputSource);
@@ -3157,8 +3158,6 @@
 
 	m_EasaierManager->newSession();
 
-	setupFiltersMenu();
-
 	return ok ? FileOpenSucceeded : FileOpenFailed;
 }
 
@@ -3393,8 +3392,6 @@
 
     s += "</display>\n";
 
-//    s += m_viewManager->getSelection().toXmlString();
-
     s += m_document->toEasaierXmlString(indent, "");
 
     s += "</easaierSession>\n";
@@ -5233,6 +5230,7 @@
 	createMultiPaneLayerContainer();
     PaneCallback callback(this);
     m_viewManager->clearSelections();
+	setupFiltersMenu();
 
 	ESFileReader reader(m_document, callback);
     QXmlInputSource inputSource(&file);
@@ -5261,8 +5259,6 @@
 
 	m_EasaierManager->openSession(m_document);
 
-	setupFiltersMenu();
-
     return ok;
 }
 
--- a/widgets/ItemAudioFilterList.cpp	Tue Jan 29 12:46:03 2008 +0000
+++ b/widgets/ItemAudioFilterList.cpp	Tue Jan 29 17:21:42 2008 +0000
@@ -62,6 +62,7 @@
 	this->setLayout(m_layoutMain);
 
 	connect(this, SIGNAL(doubleClicked()), this, SLOT(openPropertyBox()));
+
 }
 
 ItemAudioFilterList::~ItemAudioFilterList(){
@@ -91,7 +92,8 @@
 		m_container = (Filter *) m_propertyBox->container();
 		updateCheckboxs();
 		connect(m_propertyBox, SIGNAL(showLayer(bool)), this, SLOT(showLayer(bool)));
-
+		connect(m_checkBoxPlay, SIGNAL(stateChanged(int)),m_container, SLOT(setFilterEnabled(int)));
+		connect(m_container, SIGNAL(filterEnableChange(bool)),this, SLOT(updateCheckboxs()));
 	}
 }
 
@@ -109,11 +111,7 @@
 
 void ItemAudioFilterList::updateCheckboxs(){
 
-		m_checkBoxPlay->setEnabled(true);
 		m_checkBoxPlay->setChecked(m_container->isFilterEnabled());
-		
-		connect(m_container, SIGNAL(filterEnableChanged(bool)),m_checkBoxPlay, SLOT(setState(bool)));
-		connect(m_checkBoxPlay, SIGNAL(stateChanged(int)),m_container, SLOT(setFilterEnabled(int)));
 }
 
 
--- a/widgets/PropertyBox.cpp	Tue Jan 29 12:46:03 2008 +0000
+++ b/widgets/PropertyBox.cpp	Tue Jan 29 17:21:42 2008 +0000
@@ -447,9 +447,9 @@
 		}
 
 		if (slider->value() != value) {
-			slider->blockSignals(true);
+			//slider->blockSignals(true);
 			slider->setValue(value);
-			slider->blockSignals(false);
+			//slider->blockSignals(false);
 		}
 		break;
 	}
--- a/widgets/RealTimeFilterPropertyStack.cpp	Tue Jan 29 12:46:03 2008 +0000
+++ b/widgets/RealTimeFilterPropertyStack.cpp	Tue Jan 29 17:21:42 2008 +0000
@@ -24,6 +24,9 @@
 {
 	PropertyBox *box = new PropertyBox(filter);
 
+	connect(filter, SIGNAL(propertiesChanged(PropertyContainer *)),
+	    box, SLOT(propertyContainerPropertyChanged(PropertyContainer *)));
+
 	ItemAudioFilterList *itAudio = new ItemAudioFilterList;
 	QString name(filter->objectName());
 	itAudio->setName(name);