changeset 26:090c22aa726a

* Add the Note layer for pianoroll-type display of note-type data * Complete the MIDI file importer (well, nearly -- it would be nice to be able to import the non-note data as other sorts of models, and that's not done yet). * Minor refactoring in RealTime etc
author Chris Cannam
date Fri, 10 Feb 2006 17:51:36 +0000
parents 7dad8a310963
children 070e9e1e40ea
files base/Layer.h base/Pitch.cpp base/Pitch.h base/Profiler.cpp base/RealTime.cpp base/RealTime.h
diffstat 6 files changed, 46 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/base/Layer.h	Thu Feb 09 18:01:52 2006 +0000
+++ b/base/Layer.h	Fri Feb 10 17:51:36 2006 +0000
@@ -8,8 +8,8 @@
     This is experimental software.  Not for distribution.
 */
 
-#ifndef _VIEWER_H_
-#define _VIEWER_H_
+#ifndef _LAYER_H_
+#define _LAYER_H_
 
 #include "PropertyContainer.h"
 #include "XmlExportable.h"
--- a/base/Pitch.cpp	Thu Feb 09 18:01:52 2006 +0000
+++ b/base/Pitch.cpp	Fri Feb 10 17:51:36 2006 +0000
@@ -45,9 +45,16 @@
     "G#%1", "A%1",  "A#%1", "B%1"
 };
 
+static QString flatNotes[] = {
+    "C%1",  "Db%1", "D%1",  "Eb%1",
+    "E%1",  "F%1",  "Gb%1", "G%1",
+    "Ab%1", "A%1",  "Bb%1", "B%1"
+};
+
 QString
 Pitch::getPitchLabel(int midiPitch,
-		     float centsOffset)
+		     float centsOffset,
+		     bool useFlats)
 {
     int octave = -2;
 
@@ -60,7 +67,7 @@
 	octave = midiPitch / 12 - 2;
     }
 
-    QString plain = notes[midiPitch % 12].arg(octave);
+    QString plain = (useFlats ? flatNotes : notes)[midiPitch % 12].arg(octave);
 
     int ic = lrintf(centsOffset);
     if (ic == 0) return plain;
@@ -70,10 +77,11 @@
 
 QString
 Pitch::getPitchLabelForFrequency(float frequency,
-				 float concertA)
+				 float concertA,
+				 bool useFlats)
 {
     float centsOffset = 0.0;
     int midiPitch = getPitchForFrequency(frequency, &centsOffset, concertA);
-    return getPitchLabel(midiPitch, centsOffset);
+    return getPitchLabel(midiPitch, centsOffset, useFlats);
 }
 
--- a/base/Pitch.h	Thu Feb 09 18:01:52 2006 +0000
+++ b/base/Pitch.h	Fri Feb 10 17:51:36 2006 +0000
@@ -24,10 +24,12 @@
 				    float concertA = 440.0);
 
     static QString getPitchLabel(int midiPitch,
-				 float centsOffset = 0);
+				 float centsOffset = 0,
+				 bool useFlats = false);
 
     static QString getPitchLabelForFrequency(float frequency,
-					     float concertA = 440.0);
+					     float concertA = 440.0,
+					     bool useFlats = false);
 };
 
 
--- a/base/Profiler.cpp	Thu Feb 09 18:01:52 2006 +0000
+++ b/base/Profiler.cpp	Fri Feb 10 17:51:36 2006 +0000
@@ -112,7 +112,7 @@
 
     struct timeval tv;
     (void)gettimeofday(&tv, 0);
-    m_startTime = RealTime(tv.tv_sec, tv.tv_usec * 1000);
+    m_startTime = RealTime::fromTimeval(tv);
 #endif
 }
 
@@ -124,7 +124,7 @@
 
     struct timeval tv;
     (void)gettimeofday(&tv, 0);
-    RealTime elapsedTime = RealTime(tv.tv_sec, tv.tv_usec * 1000) - m_startTime;
+    RealTime elapsedTime = RealTime::fromTimeval(tv) - m_startTime;
 
     cerr << "Profiler : id = " << m_c
 	 << " - elapsed so far = " << ((elapsedCPU * 1000) / CLOCKS_PER_SEC)
@@ -139,7 +139,7 @@
 
     struct timeval tv;
     (void)gettimeofday(&tv, 0);
-    RealTime elapsedTime = RealTime(tv.tv_sec, tv.tv_usec * 1000) - m_startTime;
+    RealTime elapsedTime = RealTime::fromTimeval(tv) - m_startTime;
 
     Profiles::getInstance()->accumulate(m_c, elapsedCPU, elapsedTime);
 
--- a/base/RealTime.cpp	Thu Feb 09 18:01:52 2006 +0000
+++ b/base/RealTime.cpp	Fri Feb 10 17:51:36 2006 +0000
@@ -26,6 +26,7 @@
 using std::endl;
 
 #include "base/RealTime.h"
+#include "sys/time.h"
 
 // A RealTime consists of two ints that must be at least 32 bits each.
 // A signed 32-bit int can store values exceeding +/- 2 billion.  This
@@ -53,6 +54,23 @@
     }
 }
 
+RealTime
+RealTime::fromSeconds(double sec)
+{
+    return RealTime(int(sec), int((sec - int(sec)) * ONE_BILLION));
+}
+
+RealTime
+RealTime::fromMilliseconds(int msec)
+{
+    return RealTime(msec / 1000, (msec % 1000) * 1000000);
+}
+
+RealTime
+RealTime::fromTimeval(const struct timeval &tv)
+{
+    return RealTime(tv.tv_sec, tv.tv_usec * 1000);
+}
 
 std::ostream &operator<<(std::ostream &out, const RealTime &rt)
 {
--- a/base/RealTime.h	Thu Feb 09 18:01:52 2006 +0000
+++ b/base/RealTime.h	Fri Feb 10 17:51:36 2006 +0000
@@ -19,6 +19,9 @@
 #include <iostream>
 #include <string>
 
+struct timeval;
+
+
 /**
  * RealTime represents time values to nanosecond precision
  * with accurate arithmetic and frame-rate conversion functions.
@@ -38,6 +41,10 @@
     RealTime(const RealTime &r) :
 	sec(r.sec), nsec(r.nsec) { }
 
+    static RealTime fromSeconds(double sec);
+    static RealTime fromMilliseconds(int msec);
+    static RealTime fromTimeval(const struct timeval &);
+
     RealTime &operator=(const RealTime &r) {
 	sec = r.sec; nsec = r.nsec; return *this;
     }