changeset 293:15b8a4bfe855

* continue to pick "new" colours for coloured layers even when all colours have been used at least once, rather than sticking on the last one * some messing about with application palette settings * when replacing an audio file, retain the previous playback settings for any layers that depended on the old file * re-check plugin program setting when a parameter changes -- so a plugin can decide to reset the program if the parameters no longer match those for the current program * fix failure to update check-boxes for toggled plugin parameters when their parameters are changed by program changes
author Chris Cannam
date Thu, 09 Aug 2007 14:40:03 +0000
parents 24fc90078754
children 919740b20cc9
files layer/SingleColourLayer.cpp layer/SingleColourLayer.h view/ViewManager.cpp widgets/PluginParameterBox.cpp widgets/PluginParameterBox.h
diffstat 5 files changed, 144 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/layer/SingleColourLayer.cpp	Mon Aug 06 14:37:59 2007 +0000
+++ b/layer/SingleColourLayer.cpp	Thu Aug 09 14:40:03 2007 +0000
@@ -21,8 +21,8 @@
 
 #include <QApplication>
 
-SingleColourLayer::ColourIndexPool 
-SingleColourLayer::m_usedColourIndices;
+SingleColourLayer::ColourRefCount 
+SingleColourLayer::m_colourRefCount;
 
 SingleColourLayer::SingleColourLayer() :
     m_colour(0)
@@ -119,56 +119,87 @@
 {
     bool dark = false;
     if (v) {
-        ColourIndexPool::iterator i = m_usedColourIndices.find(m_colour);
-        if (i != m_usedColourIndices.end()) m_usedColourIndices.erase(i);
         dark = !v->hasLightBackground();
     } else {
         QColor bg = QApplication::palette().color(QPalette::Window);
         if (bg.red() + bg.green() + bg.blue() < 384) dark = true;
     }
 
-    m_colour = -1;
     ColourDatabase *cdb = ColourDatabase::getInstance();
 
     int hint = -1;
     bool impose = false;
     if (v) {
+        if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() &&
+            m_colourRefCount[m_colour] > 0) {
+            m_colourRefCount[m_colour]--;
+        }
         // We don't want to call this if !v because that probably
         // means we're being called from the constructor, and this is
         // a virtual function
         hint = getDefaultColourHint(dark, impose);
-        std::cerr << "hint = " << hint << ", impose = " << impose << std::endl;
+//        std::cerr << "hint = " << hint << ", impose = " << impose << std::endl;
+    } else {
+//        std::cerr << "(from ctor)" << std::endl;
     }
 
     if (hint >= 0 && impose) {
-        m_colour = hint;
-        m_usedColourIndices.insert(m_colour);
+        setBaseColour(hint);
         return;
     }
 
+    int bestCount = 0, bestColour = -1;
+    
     for (int i = 0; i < cdb->getColourCount(); ++i) {
+
         int index = i;
         if (hint > 0) index = (index + hint) % cdb->getColourCount();
         if (cdb->useDarkBackground(index) != dark) continue;
-        if (m_colour < 0) m_colour = index;
-        if (m_usedColourIndices.find(index) == m_usedColourIndices.end()) {
-            m_colour = index;
-            break;
+
+        int count = 0;
+        if (m_colourRefCount.find(index) != m_colourRefCount.end()) {
+            count = m_colourRefCount[index];
         }
+
+//        std::cerr << "index = " << index << ", count = " << count;
+
+        if (bestColour < 0 || count < bestCount) {
+            bestColour = index;
+            bestCount = count;
+//            std::cerr << " *";
+        }
+
+//        std::cerr << std::endl;
     }
+    
+    if (bestColour < 0) m_colour = 0;
+    else m_colour = bestColour;
 
-    if (m_colour < 0) m_colour = 0;
-    m_usedColourIndices.insert(m_colour);
+    if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) {
+        m_colourRefCount[m_colour] = 1;
+    } else {
+        m_colourRefCount[m_colour]++;
+    }
 }
 
 void
 SingleColourLayer::setBaseColour(int colour)
 {
     if (m_colour == colour) return;
-    ColourIndexPool::iterator i = m_usedColourIndices.find(m_colour);
-    if (i != m_usedColourIndices.end()) m_usedColourIndices.erase(i);
+
+    if (m_colourRefCount.find(m_colour) != m_colourRefCount.end() &&
+        m_colourRefCount[m_colour] > 0) {
+        m_colourRefCount[m_colour]--;
+    }
+
     m_colour = colour;
-    m_usedColourIndices.insert(m_colour);
+
+    if (m_colourRefCount.find(m_colour) == m_colourRefCount.end()) {
+        m_colourRefCount[m_colour] = 1;
+    } else {
+        m_colourRefCount[m_colour]++;
+    }
+
     flagBaseColourChanged();
     emit layerParametersChanged();
 }
--- a/layer/SingleColourLayer.h	Mon Aug 06 14:37:59 2007 +0000
+++ b/layer/SingleColourLayer.h	Thu Aug 09 14:40:03 2007 +0000
@@ -19,6 +19,7 @@
 #include "Layer.h"
 #include <QColor>
 #include <vector>
+#include <map>
 
 class SingleColourLayer : public Layer
 {
@@ -62,8 +63,8 @@
     virtual int getDefaultColourHint(bool /* darkBackground */,
                                      bool & /* impose */) { return -1; }
 
-    typedef std::multiset<int> ColourIndexPool;
-    static ColourIndexPool m_usedColourIndices;
+    typedef std::map<int, int> ColourRefCount;
+    static ColourRefCount m_colourRefCount;
 
     int m_colour;
 };
--- a/view/ViewManager.cpp	Mon Aug 06 14:37:59 2007 +0000
+++ b/view/ViewManager.cpp	Thu Aug 09 14:40:03 2007 +0000
@@ -52,9 +52,54 @@
     settings.endGroup();
 
     if (getGlobalDarkBackground()) {
-        m_lightPalette = QPalette(QColor(240, 240, 240));
+
+        std::cerr << "dark palette:" << std::endl;
+        std::cerr << "window = " << QApplication::palette().color(QPalette::Window).name().toStdString() << std::endl;
+        std::cerr << "windowtext = " << QApplication::palette().color(QPalette::WindowText).name().toStdString() << std::endl;
+        std::cerr << "base = " << QApplication::palette().color(QPalette::Base).name().toStdString() << std::endl;
+        std::cerr << "alternatebase = " << QApplication::palette().color(QPalette::AlternateBase).name().toStdString() << std::endl;
+        std::cerr << "text = " << QApplication::palette().color(QPalette::Text).name().toStdString() << std::endl;
+        std::cerr << "button = " << QApplication::palette().color(QPalette::Button).name().toStdString() << std::endl;
+        std::cerr << "buttontext = " << QApplication::palette().color(QPalette::ButtonText).name().toStdString() << std::endl;
+        std::cerr << "brighttext = " << QApplication::palette().color(QPalette::BrightText).name().toStdString() << std::endl;
+        std::cerr << "light = " << QApplication::palette().color(QPalette::Light).name().toStdString() << std::endl;
+        std::cerr << "dark = " << QApplication::palette().color(QPalette::Dark).name().toStdString() << std::endl;
+        std::cerr << "mid = " << QApplication::palette().color(QPalette::Mid).name().toStdString() << std::endl;
+
+        m_lightPalette = QPalette(QColor("#000000"),  // WindowText
+                                  QColor("#dddfe4"),  // Button
+                                  QColor("#ffffff"),  // Light
+                                  QColor("#555555"),  // Dark
+                                  QColor("#c7c7c7"),  // Mid
+                                  QColor("#000000"),  // Text
+                                  QColor("#ffffff"),  // BrightText
+                                  QColor("#ffffff"),  // Base
+                                  QColor("#efefef")); // Window
+                                  
+
     } else {
-        m_darkPalette = QPalette(QColor(16, 16, 16));
+        std::cerr << "light palette:" << std::endl;
+        std::cerr << "window = " << QApplication::palette().color(QPalette::Window).name().toStdString() << std::endl;
+        std::cerr << "windowtext = " << QApplication::palette().color(QPalette::WindowText).name().toStdString() << std::endl;
+        std::cerr << "base = " << QApplication::palette().color(QPalette::Base).name().toStdString() << std::endl;
+        std::cerr << "alternatebase = " << QApplication::palette().color(QPalette::AlternateBase).name().toStdString() << std::endl;
+        std::cerr << "text = " << QApplication::palette().color(QPalette::Text).name().toStdString() << std::endl;
+        std::cerr << "button = " << QApplication::palette().color(QPalette::Button).name().toStdString() << std::endl;
+        std::cerr << "buttontext = " << QApplication::palette().color(QPalette::ButtonText).name().toStdString() << std::endl;
+        std::cerr << "brighttext = " << QApplication::palette().color(QPalette::BrightText).name().toStdString() << std::endl;
+        std::cerr << "light = " << QApplication::palette().color(QPalette::Light).name().toStdString() << std::endl;
+        std::cerr << "dark = " << QApplication::palette().color(QPalette::Dark).name().toStdString() << std::endl;
+        std::cerr << "mid = " << QApplication::palette().color(QPalette::Mid).name().toStdString() << std::endl;
+
+        m_darkPalette = QPalette(QColor("#ffffff"),  // WindowText
+                                 QColor("#3e3e3e"),  // Button
+                                 QColor("#808080"),  // Light
+                                 QColor("#1e1e1e"),  // Dark
+                                 QColor("#404040"),  // Mid
+                                 QColor("#ffffff"),  // Text
+                                 QColor("#ffffff"),  // BrightText
+                                 QColor("#000000"),  // Base
+                                 QColor("#202020")); // Window
     }
 }
 
--- a/widgets/PluginParameterBox.cpp	Mon Aug 06 14:37:59 2007 +0000
+++ b/widgets/PluginParameterBox.cpp	Thu Aug 09 14:40:03 2007 +0000
@@ -35,7 +35,8 @@
 
 PluginParameterBox::PluginParameterBox(Vamp::PluginBase *plugin, QWidget *parent) :
     QFrame(parent),
-    m_plugin(plugin)
+    m_plugin(plugin),
+    m_programCombo(0)
 {
     m_layout = new QGridLayout;
     setLayout(m_layout);
@@ -50,11 +51,11 @@
 PluginParameterBox::populate()
 {
     Vamp::PluginBase::ParameterList params = m_plugin->getParameterDescriptors();
-    Vamp::PluginBase::ProgramList programs = m_plugin->getPrograms();
+    m_programs = m_plugin->getPrograms();
 
     m_params.clear();
 
-    if (params.empty() && programs.empty()) {
+    if (params.empty() && m_programs.empty()) {
         m_layout->addWidget
             (new QLabel(tr("This plugin has no adjustable parameters.")),
              0, 0);
@@ -62,24 +63,25 @@
 
     int offset = 0;
 
-    if (!programs.empty()) {
+    if (!m_programs.empty()) {
 
         std::string currentProgram = m_plugin->getCurrentProgram();
 
-        QComboBox *programCombo = new QComboBox;
-        programCombo->setMaxVisibleItems(20);
+        m_programCombo = new QComboBox;
+        m_programCombo->setMaxVisibleItems
+            (m_programs.size() < 25 ? m_programs.size() : 20);
 
-        for (size_t i = 0; i < programs.size(); ++i) {
-            programCombo->addItem(programs[i].c_str());
-            if (programs[i] == currentProgram) {
-                programCombo->setCurrentIndex(i);
+        for (size_t i = 0; i < m_programs.size(); ++i) {
+            m_programCombo->addItem(m_programs[i].c_str());
+            if (m_programs[i] == currentProgram) {
+                m_programCombo->setCurrentIndex(i);
             }
         }
 
         m_layout->addWidget(new QLabel(tr("Program")), 0, 0);
-        m_layout->addWidget(programCombo, 0, 1, 1, 2);
+        m_layout->addWidget(m_programCombo, 0, 1, 1, 2);
 
-        connect(programCombo, SIGNAL(currentIndexChanged(const QString &)),
+        connect(m_programCombo, SIGNAL(currentIndexChanged(const QString &)),
                 this, SLOT(programComboChanged(const QString &)));
 
         offset = 1;
@@ -146,7 +148,7 @@
             
             QCheckBox *checkbox = new QCheckBox;
             checkbox->setObjectName(identifier);
-            checkbox->setCheckState(value == 0.0 ? Qt::Unchecked : Qt::Checked);
+            checkbox->setCheckState(value < 0.5 ? Qt::Unchecked : Qt::Checked);
             connect(checkbox, SIGNAL(stateChanged(int)),
                     this, SLOT(checkBoxChanged(int)));
             m_layout->addWidget(checkbox, i + offset, 2);
@@ -245,6 +247,8 @@
 
     m_plugin->setParameter(identifier.toStdString(), newValue);
 
+    updateProgramCombo();
+
     emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString());
 }
 
@@ -269,6 +273,8 @@
     if (state) m_plugin->setParameter(identifier.toStdString(), 1.0);
     else m_plugin->setParameter(identifier.toStdString(), 0.0);
 
+    updateProgramCombo();
+
     emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString());
 }
 
@@ -320,6 +326,8 @@
 
     m_plugin->setParameter(identifier.toStdString(), value);
 
+    updateProgramCombo();
+
     emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString());
 }
 
@@ -362,8 +370,29 @@
             i->second.combo->setCurrentIndex(lrintf(value));
             i->second.combo->blockSignals(false);
         }
+
+        if (i->second.check) {
+            i->second.check->blockSignals(true);
+            i->second.check->setCheckState(value < 0.5 ? Qt::Unchecked : Qt::Checked);
+            i->second.check->blockSignals(false);
+        }            
     }
 
     emit pluginConfigurationChanged(PluginXml(m_plugin).toXmlString());
 }
 
+void
+PluginParameterBox::updateProgramCombo()
+{
+    if (!m_programCombo || m_programs.empty()) return;
+
+    std::string currentProgram = m_plugin->getCurrentProgram();
+
+    for (size_t i = 0; i < m_programs.size(); ++i) {
+        if (m_programs[i] == currentProgram) {
+            m_programCombo->setCurrentIndex(i);
+        }
+    }
+}
+
+
--- a/widgets/PluginParameterBox.h	Mon Aug 06 14:37:59 2007 +0000
+++ b/widgets/PluginParameterBox.h	Thu Aug 09 14:40:03 2007 +0000
@@ -48,6 +48,7 @@
 
 protected:
     void populate();
+    void updateProgramCombo();
 
     QGridLayout *m_layout;
     Vamp::PluginBase *m_plugin;
@@ -60,8 +61,11 @@
         Vamp::PluginBase::ParameterDescriptor param;
     };
 
+    QComboBox *m_programCombo;
+
     std::map<QString, ParamRec> m_params;
     std::map<QString, QString> m_nameMap;
+    Vamp::PluginBase::ProgramList m_programs;
 };
 
 #endif