# HG changeset patch
# User Chris Cannam
# Date 1154016392 0
# Node ID 82f529a08cf344c3ddab737160f66d4f69b5d939
# Parent a9c3ba1777e1fdf60d882b596f6e726af1aa883f
* Change preferences dialog to ok/apply/cancel model
* Make preferences persist in a config file
* Change instance() to getInstance() for all singleton types
* Make pasting to time-value layer with no values in clipboard ask you how to
generate the values
* Fix bad behaviour caused by importing "data"-type (i.e. 3d dense) model from
annotation file without a fixed window size available
diff -r a9c3ba1777e1 -r 82f529a08cf3 base/Layer.cpp
--- a/base/Layer.cpp Wed Jul 26 16:48:07 2006 +0000
+++ b/base/Layer.cpp Thu Jul 27 16:06:32 2006 +0000
@@ -34,8 +34,8 @@
QString
Layer::getPropertyContainerIconName() const
{
- return LayerFactory::instance()->getLayerIconName
- (LayerFactory::instance()->getLayerType(this));
+ return LayerFactory::getInstance()->getLayerIconName
+ (LayerFactory::getInstance()->getLayerType(this));
}
QString
@@ -70,8 +70,8 @@
s += indent;
s += QString("\n")
- .arg(encodeEntities(LayerFactory::instance()->getLayerTypeName
- (LayerFactory::instance()->getLayerType(this))))
+ .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName
+ (LayerFactory::getInstance()->getLayerType(this))))
.arg(getObjectExportId(this))
.arg(encodeEntities(objectName()))
.arg(getObjectExportId(getModel()))
@@ -86,7 +86,7 @@
// std::cerr << "Layer (" << this << ", " << objectName().toStdString() << ")::getPlayParameters: model is "<< getModel() << std::endl;
const Model *model = getModel();
if (model) {
- return PlayParameterRepository::instance()->getPlayParameters(model);
+ return PlayParameterRepository::getInstance()->getPlayParameters(model);
}
return 0;
}
diff -r a9c3ba1777e1 -r 82f529a08cf3 base/Layer.h
--- a/base/Layer.h Wed Jul 26 16:48:07 2006 +0000
+++ b/base/Layer.h Thu Jul 27 16:06:32 2006 +0000
@@ -78,8 +78,10 @@
virtual int getVerticalScaleWidth(View *, QPainter &) const { return 0; }
virtual void paintVerticalScale(View *, QPainter &, QRect) const { }
- virtual bool getCrosshairExtents(View *, QPainter &, QPoint cursorPos,
- std::vector &) const { return false; }
+ virtual bool getCrosshairExtents(View *, QPainter &, QPoint /* cursorPos */,
+ std::vector &) const {
+ return false;
+ }
virtual void paintCrosshairs(View *, QPainter &, QPoint) const { }
virtual QString getFeatureDescription(View *, QPoint &) const {
@@ -112,10 +114,10 @@
* available. Also return the resolution of the model in this
* layer in sample frames.
*/
- virtual bool snapToFeatureFrame(View *v,
- int &frame,
+ virtual bool snapToFeatureFrame(View * /* v */,
+ int & /* frame */,
size_t &resolution,
- SnapType snap) const {
+ SnapType /* snap */) const {
resolution = 1;
return false;
}
@@ -135,12 +137,22 @@
virtual void editOpen(View *, QMouseEvent *) { } // on double-click
- virtual void moveSelection(Selection s, size_t newStartFrame) { }
- virtual void resizeSelection(Selection s, Selection newSize) { }
- virtual void deleteSelection(Selection s) { }
+ virtual void moveSelection(Selection, size_t /* newStartFrame */) { }
+ virtual void resizeSelection(Selection, Selection /* newSize */) { }
+ virtual void deleteSelection(Selection) { }
- virtual void copy(Selection s, Clipboard &to) { }
- virtual void paste(const Clipboard &from, int frameOffset) { }
+ virtual void copy(Selection, Clipboard & /* to */) { }
+
+ /**
+ * Paste from the given clipboard onto the layer at the given
+ * frame offset. If interactive is true, the layer may ask the
+ * user about paste options through a dialog if desired, and may
+ * return false if the user cancelled the paste operation. This
+ * function should return true if a paste actually occurred.
+ */
+ virtual bool paste(const Clipboard & /* from */,
+ int /* frameOffset */,
+ bool /* interactive */) { return false; }
// Text mode:
//
@@ -252,7 +264,8 @@
* extent (using the normal layer extents or deferring to whatever
* is in use for the same units elsewhere in the view).
*/
- virtual bool getDisplayExtents(float &min, float &max) const {
+ virtual bool getDisplayExtents(float & /* min */,
+ float & /* max */) const {
return false;
}
@@ -263,7 +276,8 @@
* return false for getDisplayExtents should also return false for
* this function.
*/
- virtual bool setDisplayExtents(float min, float max) {
+ virtual bool setDisplayExtents(float /* min */,
+ float /* max */) {
return false;
}
diff -r a9c3ba1777e1 -r 82f529a08cf3 base/Model.cpp
--- a/base/Model.cpp Wed Jul 26 16:48:07 2006 +0000
+++ b/base/Model.cpp Thu Jul 27 16:06:32 2006 +0000
@@ -28,7 +28,7 @@
// 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);
+ PlayParameterRepository::getInstance()->removeModel(this);
}
QString
diff -r a9c3ba1777e1 -r 82f529a08cf3 base/PlayParameterRepository.cpp
--- a/base/PlayParameterRepository.cpp Wed Jul 26 16:48:07 2006 +0000
+++ b/base/PlayParameterRepository.cpp Thu Jul 27 16:06:32 2006 +0000
@@ -27,7 +27,7 @@
PlayParameterRepository::m_instance = new PlayParameterRepository;
PlayParameterRepository *
-PlayParameterRepository::instance()
+PlayParameterRepository::getInstance()
{
return m_instance;
}
diff -r a9c3ba1777e1 -r 82f529a08cf3 base/PlayParameterRepository.h
--- a/base/PlayParameterRepository.h Wed Jul 26 16:48:07 2006 +0000
+++ b/base/PlayParameterRepository.h Thu Jul 27 16:06:32 2006 +0000
@@ -28,7 +28,7 @@
Q_OBJECT
public:
- static PlayParameterRepository *instance();
+ static PlayParameterRepository *getInstance();
virtual ~PlayParameterRepository();
diff -r a9c3ba1777e1 -r 82f529a08cf3 base/Preferences.cpp
--- a/base/Preferences.cpp Wed Jul 26 16:48:07 2006 +0000
+++ b/base/Preferences.cpp Thu Jul 27 16:06:32 2006 +0000
@@ -15,6 +15,15 @@
#include "Preferences.h"
+#include "Exceptions.h"
+
+#include "TempDirectory.h"
+
+#include "fileio/ConfigFile.h" //!!! reorg
+
+#include
+#include
+
Preferences *
Preferences::m_instance = new Preferences();
@@ -22,8 +31,41 @@
m_smoothSpectrogram(true),
m_tuningFrequency(440),
m_propertyBoxLayout(VerticallyStacked),
- m_windowType(HanningWindow)
+ m_windowType(HanningWindow),
+ m_configFile(0)
{
+ // Let TempDirectory do its thing first, so as to avoid any race
+ // condition if it happens that we both want to use the same directory
+ TempDirectory::getInstance();
+
+ QString svDirBase = ".sv1";
+ QString svDir = QDir::home().filePath(svDirBase);
+ if (!QFileInfo(svDir).exists()) {
+ if (!QDir::home().mkdir(svDirBase)) {
+ throw DirectoryCreationFailed(QString("%1 directory in $HOME")
+ .arg(svDirBase));
+ }
+ } else if (!QFileInfo(svDir).isDir()) {
+ throw DirectoryCreationFailed(QString("$HOME/%1 is not a directory")
+ .arg(svDirBase));
+ }
+
+ m_configFile = new ConfigFile(QDir(svDir).filePath("preferences.cfg"));
+
+ m_smoothSpectrogram =
+ m_configFile->getBool("preferences-smooth-spectrogram", true);
+ m_tuningFrequency =
+ m_configFile->getFloat("preferences-tuning-frequency", 440.f);
+ m_propertyBoxLayout = PropertyBoxLayout
+ (m_configFile->getInt("preferences-property-box-layout",
+ int(VerticallyStacked)));
+ m_windowType = WindowType
+ (m_configFile->getInt("preferences-window-type", int(HanningWindow)));
+}
+
+Preferences::~Preferences()
+{
+ delete m_configFile;
}
Preferences::PropertyList
@@ -155,6 +197,7 @@
{
if (m_smoothSpectrogram != smooth) {
m_smoothSpectrogram = smooth;
+ m_configFile->set("preferences-smooth-spectrogram", smooth);
emit propertyChanged("Smooth Spectrogram");
}
}
@@ -164,6 +207,7 @@
{
if (m_tuningFrequency != freq) {
m_tuningFrequency = freq;
+ m_configFile->set("preferences-tuning-frequency", freq);
emit propertyChanged("Tuning Frequency");
}
}
@@ -173,6 +217,7 @@
{
if (m_propertyBoxLayout != layout) {
m_propertyBoxLayout = layout;
+ m_configFile->set("preferences-property-box-layout", int(layout));
emit propertyChanged("Property Box Layout");
}
}
@@ -182,6 +227,7 @@
{
if (m_windowType != type) {
m_windowType = type;
+ m_configFile->set("preferences-window-type", int(type));
emit propertyChanged("Window Type");
}
}
diff -r a9c3ba1777e1 -r 82f529a08cf3 base/Preferences.h
--- a/base/Preferences.h Wed Jul 26 16:48:07 2006 +0000
+++ b/base/Preferences.h Thu Jul 27 16:06:32 2006 +0000
@@ -20,6 +20,8 @@
#include "Window.h"
+class ConfigFile;
+
class Preferences : public PropertyContainer
{
Q_OBJECT
@@ -39,6 +41,8 @@
float getTuningFrequency() const { return m_tuningFrequency; }
WindowType getWindowType() const { return m_windowType; }
+ ConfigFile *getConfigFile() { return m_configFile; }
+
//!!! harmonise with PaneStack
enum PropertyBoxLayout {
VerticallyStacked,
@@ -55,8 +59,8 @@
void setWindowType(WindowType type);
private:
- Preferences();
- virtual ~Preferences() { }
+ Preferences(); // may throw DirectoryCreationFailed
+ virtual ~Preferences();
static Preferences *m_instance;
@@ -64,6 +68,7 @@
float m_tuningFrequency;
PropertyBoxLayout m_propertyBoxLayout;
WindowType m_windowType;
+ ConfigFile *m_configFile;
};
#endif
diff -r a9c3ba1777e1 -r 82f529a08cf3 base/TempDirectory.cpp
--- a/base/TempDirectory.cpp Wed Jul 26 16:48:07 2006 +0000
+++ b/base/TempDirectory.cpp Thu Jul 27 16:06:32 2006 +0000
@@ -28,7 +28,7 @@
TempDirectory::m_instance = new TempDirectory;
TempDirectory *
-TempDirectory::instance()
+TempDirectory::getInstance()
{
return m_instance;
}
diff -r a9c3ba1777e1 -r 82f529a08cf3 base/TempDirectory.h
--- a/base/TempDirectory.h Wed Jul 26 16:48:07 2006 +0000
+++ b/base/TempDirectory.h Thu Jul 27 16:06:32 2006 +0000
@@ -33,7 +33,7 @@
class TempDirectory
{
public:
- static TempDirectory *instance();
+ static TempDirectory *getInstance();
virtual ~TempDirectory();
diff -r a9c3ba1777e1 -r 82f529a08cf3 plugin/LADSPAPluginFactory.cpp
--- a/plugin/LADSPAPluginFactory.cpp Wed Jul 26 16:48:07 2006 +0000
+++ b/plugin/LADSPAPluginFactory.cpp Thu Jul 27 16:06:32 2006 +0000
@@ -31,6 +31,7 @@
#include "PluginIdentifier.h"
#include "base/System.h"
+#include "base/Preferences.h"
#ifdef HAVE_LRDF
#include "lrdf.h"
@@ -261,7 +262,8 @@
} else if (LADSPA_IS_HINT_DEFAULT_440(d)) {
- deft = 440.0;
+// deft = 440.0;
+ deft = Preferences::getInstance()->getTuningFrequency();
} else {
diff -r a9c3ba1777e1 -r 82f529a08cf3 transform/FeatureExtractionPluginTransform.cpp
--- a/transform/FeatureExtractionPluginTransform.cpp Wed Jul 26 16:48:07 2006 +0000
+++ b/transform/FeatureExtractionPluginTransform.cpp Thu Jul 27 16:06:32 2006 +0000
@@ -288,7 +288,7 @@
fftAdapters[ch]->getValuesAt
(column, i, buffers[ch][i*2], buffers[ch][i*2+1]);
}
- //!!!
+/*!!!
float sum = 0.0;
for (size_t i = 0; i < m_blockSize/2; ++i) {
sum += buffers[ch][i*2];
@@ -296,6 +296,7 @@
if (fabs(sum) < 0.0001) {
std::cerr << "WARNING: small sum for column " << column << " (sum is " << sum << ")" << std::endl;
}
+*/
} else {
getFrames(ch, channelCount,
blockFrame, m_blockSize, buffers[ch]);
diff -r a9c3ba1777e1 -r 82f529a08cf3 transform/TransformFactory.cpp
--- a/transform/TransformFactory.cpp Wed Jul 26 16:48:07 2006 +0000
+++ b/transform/TransformFactory.cpp Thu Jul 27 16:06:32 2006 +0000
@@ -35,7 +35,7 @@
TransformFactory::m_instance = new TransformFactory;
TransformFactory *
-TransformFactory::instance()
+TransformFactory::getInstance()
{
return m_instance;
}
diff -r a9c3ba1777e1 -r 82f529a08cf3 transform/TransformFactory.h
--- a/transform/TransformFactory.h Wed Jul 26 16:48:07 2006 +0000
+++ b/transform/TransformFactory.h Thu Jul 27 16:06:32 2006 +0000
@@ -29,7 +29,7 @@
public:
virtual ~TransformFactory();
- static TransformFactory *instance();
+ static TransformFactory *getInstance();
// The name is intended to be computer-referenceable, and unique
// within the application. The description is intended to be