# HG changeset patch # User Chris Cannam # Date 1139593896 0 # Node ID 090c22aa726aa65856909ee2df5d0a7ca922a939 # Parent 7dad8a310963970c570a7e41552c14f81fa7354f * 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 diff -r 7dad8a310963 -r 090c22aa726a base/Layer.h --- 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" diff -r 7dad8a310963 -r 090c22aa726a base/Pitch.cpp --- 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, ¢sOffset, concertA); - return getPitchLabel(midiPitch, centsOffset); + return getPitchLabel(midiPitch, centsOffset, useFlats); } diff -r 7dad8a310963 -r 090c22aa726a base/Pitch.h --- 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); }; diff -r 7dad8a310963 -r 090c22aa726a base/Profiler.cpp --- 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); diff -r 7dad8a310963 -r 090c22aa726a base/RealTime.cpp --- 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) { diff -r 7dad8a310963 -r 090c22aa726a base/RealTime.h --- 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 #include +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; }