changeset 1037:bf0e5944289b cxx11

Merge from default branch
author Chris Cannam
date Tue, 03 Mar 2015 09:33:59 +0000
parents ce1077bd663a (current diff) 682d64f05e72 (diff)
children cc27f35aa75c
files
diffstat 14 files changed, 168 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/base/Preferences.cpp	Mon Feb 09 10:31:07 2015 +0000
+++ b/base/Preferences.cpp	Tue Mar 03 09:33:59 2015 +0000
@@ -49,6 +49,7 @@
     m_viewFontSize(10),
     m_backgroundMode(BackgroundFromTheme),
     m_timeToTextMode(TimeToTextMs),
+    m_showHMS(true),
     m_octave(4),
     m_showSplash(true)
 {
@@ -71,6 +72,7 @@
         (settings.value("background-mode", int(BackgroundFromTheme)).toInt());
     m_timeToTextMode = TimeToTextMode
         (settings.value("time-to-text-mode", int(TimeToTextMs)).toInt());
+    m_showHMS = (settings.value("show-hours-minutes-seconds", true)).toBool(); 
     m_octave = (settings.value("octave-of-middle-c", 4)).toInt();
     m_viewFontSize = settings.value("view-font-size", 10).toInt();
     m_showSplash = settings.value("show-splash", true).toBool();
@@ -102,6 +104,7 @@
     props.push_back("Temporary Directory Root");
     props.push_back("Background Mode");
     props.push_back("Time To Text Mode");
+    props.push_back("Show Hours And Minutes");
     props.push_back("Octave Numbering System");
     props.push_back("View Font Size");
     props.push_back("Show Splash Screen");
@@ -148,7 +151,10 @@
         return tr("Background colour preference");
     }
     if (name == "Time To Text Mode") {
-        return tr("Time display format");
+        return tr("Time display precision");
+    }
+    if (name == "Show Hours And Minutes") {
+        return tr("Use hours:minutes:seconds format");
     }
     if (name == "Octave Numbering System") {
         return tr("Label middle C as");
@@ -205,6 +211,9 @@
     if (name == "Time To Text Mode") {
         return ValueProperty;
     }
+    if (name == "Show Hours And Minutes") {
+        return ToggleProperty;
+    }
     if (name == "Octave Numbering System") {
         return ValueProperty;
     }
@@ -259,6 +268,7 @@
 
     if (name == "Omit Temporaries from Recent Files") {
         if (deflt) *deflt = 1;
+        return m_omitRecentTemps ? 1 : 0;
     }
 
     if (name == "Background Mode") {
@@ -275,6 +285,11 @@
         return int(m_timeToTextMode);
     }        
 
+    if (name == "Show Hours And Minutes") {
+        if (deflt) *deflt = 1;
+        return m_showHMS ? 1 : 0;
+    }
+    
     if (name == "Octave Numbering System") {
         // we don't support arbitrary octaves in the gui, because we
         // want to be able to label what the octave system comes
@@ -294,6 +309,7 @@
 
     if (name == "Show Splash Screen") {
         if (deflt) *deflt = 1;
+        return m_showSplash ? 1 : 0;
     }
 
     return 0;
@@ -404,6 +420,8 @@
         setBackgroundMode(BackgroundMode(value));
     } else if (name == "Time To Text Mode") {
         setTimeToTextMode(TimeToTextMode(value));
+    } else if (name == "Show Hours And Minutes") {
+        setShowHMS(value ? true : false);
     } else if (name == "Octave Numbering System") {
         setOctaveOfMiddleC(getOctaveOfMiddleCInSystem
                            (OctaveNumberingSystem(value)));
@@ -599,6 +617,21 @@
 }
 
 void
+Preferences::setShowHMS(bool show)
+{
+    if (m_showHMS != show) {
+
+        m_showHMS = show;
+
+        QSettings settings;
+        settings.beginGroup("Preferences");
+        settings.setValue("show-hours-minutes-seconds", show);
+        settings.endGroup();
+        emit propertyChanged("Show Hours And Minutes");
+    }
+}
+
+void
 Preferences::setOctaveOfMiddleC(int oct)
 {
     if (m_octave != oct) {
--- a/base/Preferences.h	Mon Feb 09 10:31:07 2015 +0000
+++ b/base/Preferences.h	Tue Mar 03 09:33:59 2015 +0000
@@ -93,6 +93,8 @@
     };
     TimeToTextMode getTimeToTextMode() const { return m_timeToTextMode; }
 
+    bool getShowHMS() const { return m_showHMS; }
+    
     int getOctaveOfMiddleC() const {
         // weed out unsupported octaves
         return getOctaveOfMiddleCInSystem(getSystemWithMiddleCInOctave(m_octave));
@@ -119,6 +121,7 @@
     void setNormaliseAudio(bool);
     void setBackgroundMode(BackgroundMode mode);
     void setTimeToTextMode(TimeToTextMode mode);
+    void setShowHMS(bool show);
     void setOctaveOfMiddleC(int oct);
     void setViewFontSize(int size);
     void setShowSplash(bool);
@@ -156,6 +159,7 @@
     int m_viewFontSize;
     BackgroundMode m_backgroundMode;
     TimeToTextMode m_timeToTextMode;
+    bool m_showHMS;
     int m_octave;
     bool m_showSplash;
 };
--- a/base/RealTime.cpp	Mon Feb 09 10:31:07 2015 +0000
+++ b/base/RealTime.cpp	Tue Mar 03 09:33:59 2015 +0000
@@ -274,19 +274,25 @@
 
     std::stringstream out;
 
-    if (sec >= 3600) {
-	out << (sec / 3600) << ":";
+    if (p->getShowHMS()) {
+    
+        if (sec >= 3600) {
+            out << (sec / 3600) << ":";
+        }
+
+        if (sec >= 60) {
+            out << (sec % 3600) / 60 << ":";
+        }
+
+        if (sec >= 10) {
+            out << ((sec % 60) / 10);
+        }
+
+        out << (sec % 10);
+
+    } else {
+        out << sec;
     }
-
-    if (sec >= 60) {
-	out << (sec % 3600) / 60 << ":";
-    }
-
-    if (sec >= 10) {
-	out << ((sec % 60) / 10);
-    }
-
-    out << (sec % 10);
     
     int ms = msec();
 
@@ -319,21 +325,29 @@
 {
     if (*this < RealTime::zeroTime) return "-" + (-*this).toFrameText(fps);
 
+    Preferences *p = Preferences::getInstance();
+
     std::stringstream out;
 
-    if (sec >= 3600) {
-	out << (sec / 3600) << ":";
+    if (p->getShowHMS()) {
+    
+        if (sec >= 3600) {
+            out << (sec / 3600) << ":";
+        }
+
+        if (sec >= 60) {
+            out << (sec % 3600) / 60 << ":";
+        }
+
+        if (sec >= 10) {
+            out << ((sec % 60) / 10);
+        }
+
+        out << (sec % 10);
+
+    } else {
+        out << sec;
     }
-
-    if (sec >= 60) {
-	out << (sec % 3600) / 60 << ":";
-    }
-
-    if (sec >= 10) {
-	out << ((sec % 60) / 10);
-    }
-
-    out << (sec % 10);
     
     int f = nsec / (ONE_BILLION / fps);
 
--- a/base/test/TestRealTime.h	Mon Feb 09 10:31:07 2015 +0000
+++ b/base/test/TestRealTime.h	Tue Mar 03 09:33:59 2015 +0000
@@ -269,8 +269,33 @@
 	}
     }
 
-	
-	
+    void frame()
+    {
+        int frames[] = {
+            0, 1, 2047, 2048, 6656, 32767, 32768, 44100, 44101, 999999999
+        };
+        int n = sizeof(frames)/sizeof(frames[0]);
+
+        int rates[] = {
+            1, 2, 8000, 22050, 44100, 44101, 192000
+        };
+        int m = sizeof(rates)/sizeof(rates[0]);
+
+        for (int i = 0; i < n; ++i) {
+            int frame = frames[i];
+            for (int j = 0; j < m; ++j) {
+                int rate = rates[j];
+
+                RealTime rt = RealTime::frame2RealTime(frame, rate);
+                int conv = RealTime::realTime2Frame(rt, rate);
+                QCOMPARE(frame, conv);
+
+                rt = RealTime::frame2RealTime(-frame, rate);
+                conv = RealTime::realTime2Frame(rt, rate);
+                QCOMPARE(-frame, conv);
+            }
+        }
+    }
 };
 
 #endif
--- a/data/fileio/CSVFileReader.cpp	Mon Feb 09 10:31:07 2015 +0000
+++ b/data/fileio/CSVFileReader.cpp	Tue Mar 03 09:33:59 2015 +0000
@@ -26,6 +26,7 @@
 #include "DataFileReaderFactory.h"
 
 #include <QFile>
+#include <QFileInfo>
 #include <QString>
 #include <QRegExp>
 #include <QStringList>
@@ -55,6 +56,7 @@
 
     if (good) {
         m_device = file;
+        m_filename = QFileInfo(path).fileName();
     } else {
 	delete file;
     }
@@ -263,6 +265,12 @@
                     model = model3;
                     break;
                 }
+
+                if (model) {
+                    if (m_filename != "") {
+                        model->setObjectName(m_filename);
+                    }
+                }
             }
 
             float value = 0.f;
--- a/data/fileio/CSVFileReader.h	Mon Feb 09 10:31:07 2015 +0000
+++ b/data/fileio/CSVFileReader.h	Tue Mar 03 09:33:59 2015 +0000
@@ -53,6 +53,7 @@
     CSVFormat m_format;
     QIODevice *m_device;
     bool m_ownDevice;
+    QString m_filename;
     QString m_error;
     mutable int m_warnings;
     int m_mainModelSampleRate;
--- a/data/fileio/FileSource.cpp	Mon Feb 09 10:31:07 2015 +0000
+++ b/data/fileio/FileSource.cpp	Tue Mar 03 09:33:59 2015 +0000
@@ -32,7 +32,7 @@
 
 #include <unistd.h>
 
-//#define DEBUG_FILE_SOURCE 1
+#define DEBUG_FILE_SOURCE 1
 
 int
 FileSource::m_count = 0;
@@ -51,8 +51,11 @@
 
 #ifdef DEBUG_FILE_SOURCE
 static int extantCount = 0;
+static int threadCount = 0;
 static std::map<QString, int> urlExtantCountMap;
+static QMutex countMutex;
 static void incCount(QString url) {
+    QMutexLocker locker(&countMutex);
     ++extantCount;
     if (urlExtantCountMap.find(url) == urlExtantCountMap.end()) {
         urlExtantCountMap[url] = 1;
@@ -62,10 +65,26 @@
     cerr << "FileSource: Now " << urlExtantCountMap[url] << " for this url, " << extantCount << " total" << endl;
 }
 static void decCount(QString url) {
+    QMutexLocker locker(&countMutex);
     --extantCount;
     --urlExtantCountMap[url];
     cerr << "FileSource: Now " << urlExtantCountMap[url] << " for this url, " << extantCount << " total" << endl;
 }
+void
+FileSource::debugReport()
+{
+    QMutexLocker locker(&countMutex);
+    cerr << "\nFileSource::debugReport: Have " << extantCount << " FileSource object(s) extant across " << threadCount << " thread(s)" << endl;
+    cerr << "URLs by extant count:" << endl;
+    cerr << "Count | URL" << endl;
+    for (std::map<QString, int>::const_iterator i = urlExtantCountMap.begin();
+         i != urlExtantCountMap.end(); ++i) {
+        cerr << i->second << " | " << i->first << endl;
+    }
+    cerr << "FileSource::debugReport done\n" << endl;
+}
+#else
+void FileSource::debugReport() { }
 #endif
 
 static QThreadStorage<QNetworkAccessManager *> nms;
@@ -268,13 +287,6 @@
 void
 FileSource::init()
 {
-    { // check we have a QNetworkAccessManager
-        QMutexLocker locker(&m_mapMutex);
-        if (!nms.hasLocalData()) {
-            nms.setLocalData(new QNetworkAccessManager());
-        }
-    }
-
     if (isResource()) {
 #ifdef DEBUG_FILE_SOURCE
         cerr << "FileSource::init: Is a resource" << endl;
@@ -463,6 +475,16 @@
              QString("%1, */*").arg(m_preferredContentType).toLatin1());
     }
 
+    { // check we have a QNetworkAccessManager
+        QMutexLocker locker(&m_mapMutex);
+        if (!nms.hasLocalData()) {
+#ifdef DEBUG_FILE_SOURCE
+            ++threadCount;
+#endif
+            nms.setLocalData(new QNetworkAccessManager());
+        }
+    }
+
     m_reply = nms.localData()->get(req);
 
     connect(m_reply, SIGNAL(readyRead()),
--- a/data/fileio/FileSource.h	Mon Feb 09 10:31:07 2015 +0000
+++ b/data/fileio/FileSource.h	Tue Mar 03 09:33:59 2015 +0000
@@ -195,6 +195,13 @@
      */
     static bool canHandleScheme(QUrl url);
 
+    /**
+     * Print some stats, if FileSource was compiled with debugging.
+     * It's safe to leave a call to this function in release code, as
+     * long as FileSource itself is compiled with release flags.
+     */
+    static void debugReport();
+    
 signals:
     /**
      * Emitted during URL retrieval, when the retrieval progress
--- a/data/fileio/MIDIFileReader.cpp	Mon Feb 09 10:31:07 2015 +0000
+++ b/data/fileio/MIDIFileReader.cpp	Tue Mar 03 09:33:59 2015 +0000
@@ -36,6 +36,7 @@
 #include "model/NoteModel.h"
 
 #include <QString>
+#include <QFileInfo>
 
 #include <sstream>
 
@@ -932,6 +933,7 @@
     if (!model) {
 	model = new NoteModel(m_mainModelSampleRate, 1, 0.0, 0.0, false);
 	model->setValueQuantization(1.0);
+        model->setObjectName(QFileInfo(m_path).fileName());
     }
 
     const MIDITrack &track = m_midiComposition.find(trackToLoad)->second;
--- a/data/fileio/OggVorbisFileReader.cpp	Mon Feb 09 10:31:07 2015 +0000
+++ b/data/fileio/OggVorbisFileReader.cpp	Tue Mar 03 09:33:59 2015 +0000
@@ -173,11 +173,11 @@
 
     if (!reader->m_commentsRead) {
         const FishSoundComment *comment;
-        comment = fish_sound_comment_first_byname(fs, "TITLE");
+        comment = fish_sound_comment_first_byname(fs, (char *)"TITLE");
         if (comment && comment->value) {
             reader->m_title = QString::fromUtf8(comment->value);
         }
-        comment = fish_sound_comment_first_byname(fs, "ARTIST");
+        comment = fish_sound_comment_first_byname(fs, (char *)"ARTIST");
         if (comment && comment->value) {
             reader->m_maker = QString::fromUtf8(comment->value);
         }
--- a/rdf/RDFFeatureWriter.cpp	Mon Feb 09 10:31:07 2015 +0000
+++ b/rdf/RDFFeatureWriter.cpp	Tue Mar 03 09:33:59 2015 +0000
@@ -22,6 +22,7 @@
 #include "PluginRDFIndexer.h"
 
 #include <QTextStream>
+#include <QTextCodec>
 #include <QUrl>
 #include <QFileInfo>
 #include <QRegExp>
@@ -160,7 +161,8 @@
     // Need to select appropriate output file for our track/transform
     // combination
 
-    QTextStream *stream = getOutputStream(trackId, transform.getIdentifier());
+    QTextStream *stream = getOutputStream(trackId, transform.getIdentifier(),
+                                          QTextCodec::codecForName("UTF-8"));
     if (!stream) {
         throw FailedToOpenOutputStream(trackId, transform.getIdentifier());
     }
--- a/transform/CSVFeatureWriter.cpp	Mon Feb 09 10:31:07 2015 +0000
+++ b/transform/CSVFeatureWriter.cpp	Tue Mar 03 09:33:59 2015 +0000
@@ -23,6 +23,7 @@
 
 #include <QRegExp>
 #include <QTextStream>
+#include <QTextCodec>
 
 using namespace std;
 using namespace Vamp;
@@ -123,7 +124,9 @@
     // Select appropriate output file for our track/transform
     // combination
 
-    QTextStream *sptr = getOutputStream(trackId, transformId);
+    QTextStream *sptr = getOutputStream(trackId,
+                                        transformId,
+                                        QTextCodec::codecForName("UTF-8"));
     if (!sptr) {
         throw FailedToOpenOutputStream(trackId, transformId);
     }
@@ -169,7 +172,9 @@
          i != m_pending.end(); ++i) {
         DataId tt = i->first;
         Plugin::Feature f = i->second;
-        QTextStream *sptr = getOutputStream(tt.first, tt.second.getIdentifier());
+        QTextStream *sptr = getOutputStream(tt.first,
+                                            tt.second.getIdentifier(),
+                                            QTextCodec::codecForName("UTF-8"));
         if (!sptr) {
             throw FailedToOpenOutputStream(tt.first, tt.second.getIdentifier());
         }
--- a/transform/FileFeatureWriter.cpp	Mon Feb 09 10:31:07 2015 +0000
+++ b/transform/FileFeatureWriter.cpp	Tue Mar 03 09:33:59 2015 +0000
@@ -315,7 +315,8 @@
 
 
 QTextStream *FileFeatureWriter::getOutputStream(QString trackId,
-                                               TransformId transformId)
+                                                TransformId transformId,
+                                                QTextCodec *codec)
 {
     QFile *file = getOutputFile(trackId, transformId);
     if (!file && !m_stdout) {
@@ -328,6 +329,7 @@
         } else {
             m_streams[file] = new QTextStream(file);
         }
+        m_streams[file]->setCodec(codec);
     }
 
     QTextStream *stream = m_streams[file];
--- a/transform/FileFeatureWriter.h	Mon Feb 09 10:31:07 2015 +0000
+++ b/transform/FileFeatureWriter.h	Tue Mar 03 09:33:59 2015 +0000
@@ -32,6 +32,7 @@
 using std::pair;
 
 class QTextStream;
+class QTextCodec;
 class QFile;
 
 class FileFeatureWriter : public FeatureWriter
@@ -55,7 +56,7 @@
     };
 
     FileFeatureWriter(int support, QString extension);
-    QTextStream *getOutputStream(QString, TransformId);
+    QTextStream *getOutputStream(QString, TransformId, QTextCodec *);
 
     typedef pair<QString, TransformId> TrackTransformPair;
     typedef map<TrackTransformPair, QString> FileNameMap;