# HG changeset patch # User Chris Cannam # Date 1425316894 0 # Node ID 682d64f05e72d0d83ae0c75a7a4962c0eb3bbeee # Parent d74ebd2d2c4906096870cf49ac0b4f37dabeda29# Parent 780959a4fe23619a2efdfaaa2414e9f3ec18045f Merge diff -r d74ebd2d2c49 -r 682d64f05e72 base/Preferences.cpp --- a/base/Preferences.cpp Mon Mar 02 17:17:59 2015 +0000 +++ b/base/Preferences.cpp Mon Mar 02 17:21:34 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) { diff -r d74ebd2d2c49 -r 682d64f05e72 base/Preferences.h --- a/base/Preferences.h Mon Mar 02 17:17:59 2015 +0000 +++ b/base/Preferences.h Mon Mar 02 17:21:34 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; }; diff -r d74ebd2d2c49 -r 682d64f05e72 base/RealTime.cpp --- a/base/RealTime.cpp Mon Mar 02 17:17:59 2015 +0000 +++ b/base/RealTime.cpp Mon Mar 02 17:21:34 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); diff -r d74ebd2d2c49 -r 682d64f05e72 base/test/TestRealTime.h --- a/base/test/TestRealTime.h Mon Mar 02 17:17:59 2015 +0000 +++ b/base/test/TestRealTime.h Mon Mar 02 17:21:34 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 diff -r d74ebd2d2c49 -r 682d64f05e72 data/fileio/CSVFileReader.cpp --- a/data/fileio/CSVFileReader.cpp Mon Mar 02 17:17:59 2015 +0000 +++ b/data/fileio/CSVFileReader.cpp Mon Mar 02 17:21:34 2015 +0000 @@ -26,6 +26,7 @@ #include "DataFileReaderFactory.h" #include +#include #include #include #include @@ -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; diff -r d74ebd2d2c49 -r 682d64f05e72 data/fileio/CSVFileReader.h --- a/data/fileio/CSVFileReader.h Mon Mar 02 17:17:59 2015 +0000 +++ b/data/fileio/CSVFileReader.h Mon Mar 02 17:21:34 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; diff -r d74ebd2d2c49 -r 682d64f05e72 data/fileio/FileSource.cpp --- a/data/fileio/FileSource.cpp Mon Mar 02 17:17:59 2015 +0000 +++ b/data/fileio/FileSource.cpp Mon Mar 02 17:21:34 2015 +0000 @@ -32,7 +32,7 @@ #include -//#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 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::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 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()), diff -r d74ebd2d2c49 -r 682d64f05e72 data/fileio/FileSource.h --- a/data/fileio/FileSource.h Mon Mar 02 17:17:59 2015 +0000 +++ b/data/fileio/FileSource.h Mon Mar 02 17:21:34 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 diff -r d74ebd2d2c49 -r 682d64f05e72 data/fileio/MIDIFileReader.cpp --- a/data/fileio/MIDIFileReader.cpp Mon Mar 02 17:17:59 2015 +0000 +++ b/data/fileio/MIDIFileReader.cpp Mon Mar 02 17:21:34 2015 +0000 @@ -36,6 +36,7 @@ #include "model/NoteModel.h" #include +#include #include @@ -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; diff -r d74ebd2d2c49 -r 682d64f05e72 data/fileio/OggVorbisFileReader.cpp --- a/data/fileio/OggVorbisFileReader.cpp Mon Mar 02 17:17:59 2015 +0000 +++ b/data/fileio/OggVorbisFileReader.cpp Mon Mar 02 17:21:34 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); }