annotate base/UnitDatabase.h @ 1541:71207822a7e0 zoom

Provide fromMicroseconds (and test it)
author Chris Cannam
date Thu, 27 Sep 2018 15:53:34 +0100
parents 1d789d688f59
children ad5f892c0c4d
rev   line source
Chris@116 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@116 2
Chris@116 3 /*
Chris@116 4 Sonic Visualiser
Chris@116 5 An audio file viewer and annotation editor.
Chris@116 6 Centre for Digital Music, Queen Mary, University of London.
Chris@116 7 This file copyright 2006 Chris Cannam.
Chris@116 8
Chris@116 9 This program is free software; you can redistribute it and/or
Chris@116 10 modify it under the terms of the GNU General Public License as
Chris@116 11 published by the Free Software Foundation; either version 2 of the
Chris@116 12 License, or (at your option) any later version. See the file
Chris@116 13 COPYING included with this distribution for more information.
Chris@116 14 */
Chris@116 15
Chris@116 16 #ifndef _UNIT_DATABASE_H_
Chris@116 17 #define _UNIT_DATABASE_H_
Chris@116 18
Chris@116 19 #include <QObject>
Chris@116 20 #include <QString>
Chris@116 21 #include <QStringList>
Chris@116 22 #include <map>
Chris@116 23
Chris@116 24 // This grandly named class is just a list of the names of known scale
Chris@116 25 // units for the various models, for use as the set of fixed values in
Chris@116 26 // unit dropdown menus etc. Of course, the user should be allowed to
Chris@116 27 // enter their own as well.
Chris@116 28
Chris@116 29 class UnitDatabase : public QObject
Chris@116 30 {
Chris@116 31 Q_OBJECT
Chris@116 32
Chris@116 33 public:
Chris@116 34 static UnitDatabase *getInstance();
Chris@116 35
Chris@116 36 QStringList getKnownUnits() const;
Chris@116 37 void registerUnit(QString unit);
Chris@199 38
Chris@199 39 /**
Chris@199 40 * Return the reference id for a given unit name. If registerNew is
Chris@199 41 * true and the unit is not known, register it and return its new
Chris@199 42 * id. If register is false and the unit is not known, return -1.
Chris@199 43 */
Chris@199 44 int getUnitId(QString unit, bool registerNew = true);
Chris@199 45
Chris@116 46 QString getUnitById(int id);
Chris@116 47
Chris@116 48 signals:
Chris@116 49 void unitDatabaseChanged();
Chris@116 50
Chris@116 51 protected:
Chris@116 52 UnitDatabase();
Chris@116 53
Chris@116 54 typedef std::map<QString, int> UnitMap;
Chris@116 55 UnitMap m_units;
Chris@116 56 int m_nextId;
Chris@116 57
Chris@116 58 static UnitDatabase m_instance;
Chris@116 59 };
Chris@116 60
Chris@116 61 #endif
Chris@116 62