diff layer/FlexiNoteLayer.cpp @ 922:26da827e8fb5 tonioni

Merge from cxx11 branch
author Chris Cannam
date Mon, 23 Mar 2015 11:26:28 +0000
parents b62c2785ed83 b66fb15de477
children bb80983c9e61
line wrap: on
line diff
--- a/layer/FlexiNoteLayer.cpp	Mon Mar 23 10:04:51 2015 +0000
+++ b/layer/FlexiNoteLayer.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -222,7 +222,7 @@
 }
 
 bool
-FlexiNoteLayer::getValueExtents(float &min, float &max,
+FlexiNoteLayer::getValueExtents(double &min, double &max,
                                 bool &logarithmic, QString &unit) const
 {
     if (!m_model) return false;
@@ -231,8 +231,8 @@
 
     if (shouldConvertMIDIToHz()) {
         unit = "Hz";
-        min = Pitch::getFrequencyForPitch(lrintf(min));
-        max = Pitch::getFrequencyForPitch(lrintf(max + 1));
+        min = Pitch::getFrequencyForPitch(int(lrint(min)));
+        max = Pitch::getFrequencyForPitch(int(lrint(max + 1)));
     } else unit = getScaleUnits();
 
     if (m_verticalScale == MIDIRangeScale ||
@@ -242,7 +242,7 @@
 }
 
 bool
-FlexiNoteLayer::getDisplayExtents(float &min, float &max) const
+FlexiNoteLayer::getDisplayExtents(double &min, double &max) const
 {
     if (!m_model || shouldAutoAlign()) {
 //        std::cerr << "No model or shouldAutoAlign()" << std::endl;
@@ -264,8 +264,8 @@
     }
 
     if (shouldConvertMIDIToHz()) {
-        min = Pitch::getFrequencyForPitch(lrintf(min));
-        max = Pitch::getFrequencyForPitch(lrintf(max + 1));
+        min = Pitch::getFrequencyForPitch(int(lrint(min)));
+        max = Pitch::getFrequencyForPitch(int(lrint(max + 1)));
     }
 
 #ifdef DEBUG_NOTE_LAYER
@@ -276,7 +276,7 @@
 }
 
 bool
-FlexiNoteLayer::setDisplayExtents(float min, float max)
+FlexiNoteLayer::setDisplayExtents(double min, double max)
 {
     if (!m_model) return false;
 
@@ -284,7 +284,7 @@
         if (min == 0.f) {
             max = 1.f;
         } else {
-            max = min * 1.0001;
+            max = min * 1.0001f;
         }
     }
 
@@ -318,7 +318,7 @@
     RangeMapper *mapper = getNewVerticalZoomRangeMapper();
     if (!mapper) return 0;
 
-    float dmin, dmax;
+    double dmin, dmax;
     getDisplayExtents(dmin, dmax);
 
     int nr = mapper->getPositionForValue(dmax - dmin);
@@ -339,29 +339,29 @@
     RangeMapper *mapper = getNewVerticalZoomRangeMapper();
     if (!mapper) return;
     
-    float min, max;
+    double min, max;
     bool logarithmic;
     QString unit;
     getValueExtents(min, max, logarithmic, unit);
     
-    float dmin, dmax;
+    double dmin, dmax;
     getDisplayExtents(dmin, dmax);
 
-    float newdist = mapper->getValueForPosition(100 - step);
+    double newdist = mapper->getValueForPosition(100 - step);
 
-    float newmin, newmax;
+    double newmin, newmax;
 
     if (logarithmic) {
 
         // see SpectrogramLayer::setVerticalZoomStep
 
-        newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2;
+        newmax = (newdist + sqrt(newdist*newdist + 4*dmin*dmax)) / 2;
         newmin = newmax - newdist;
 
 //        cerr << "newmin = " << newmin << ", newmax = " << newmax << endl;
 
     } else {
-        float dmid = (dmax + dmin) / 2;
+        double dmid = (dmax + dmin) / 2;
         newmin = dmid - newdist / 2;
         newmax = dmid + newdist / 2;
     }
@@ -388,7 +388,7 @@
     
     RangeMapper *mapper;
 
-    float min, max;
+    double min, max;
     bool logarithmic;
     QString unit;
     getValueExtents(min, max, logarithmic, unit);
@@ -409,7 +409,7 @@
 {
     if (!m_model) return FlexiNoteModel::PointList();
 
-    int frame = v->getFrameForX(x);
+    sv_frame_t frame = v->getFrameForX(x);
 
     FlexiNoteModel::PointList onPoints =
         m_model->getPoints(frame);
@@ -452,7 +452,7 @@
 {
     if (!m_model) return false;
 
-    int frame = v->getFrameForX(x);
+    sv_frame_t frame = v->getFrameForX(x);
 
     FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
     if (onPoints.empty()) return false;
@@ -481,7 +481,7 @@
     // GF: find the note that is closest to the cursor
     if (!m_model) return false;
 
-    int frame = v->getFrameForX(x);
+    sv_frame_t frame = v->getFrameForX(x);
 
     FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
     if (onPoints.empty()) return false;
@@ -552,9 +552,9 @@
 
     if (shouldConvertMIDIToHz()) {
 
-        int mnote = lrintf(note.value);
-        int cents = lrintf((note.value - mnote) * 100);
-        float freq = Pitch::getFrequencyForPitch(mnote, cents);
+        int mnote = int(lrint(note.value));
+        int cents = int(lrint((note.value - double(mnote)) * 100));
+        double freq = Pitch::getFrequencyForPitch(mnote, cents);
         pitchText = tr("%1 (%2, %3 Hz)")
             .arg(Pitch::getPitchLabel(mnote, cents))
             .arg(mnote)
@@ -593,7 +593,7 @@
 }
 
 bool
-FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame,
+FlexiNoteLayer::snapToFeatureFrame(View *v, sv_frame_t &frame,
                                    int &resolution,
                                    SnapType snap) const
 {
@@ -613,7 +613,7 @@
     }    
 
     points = m_model->getPoints(frame, frame);
-    int snapped = frame;
+    sv_frame_t snapped = frame;
     bool found = false;
 
     for (FlexiNoteModel::PointList::const_iterator i = points.begin();
@@ -673,7 +673,7 @@
 }
 
 void
-FlexiNoteLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const
+FlexiNoteLayer::getScaleExtents(View *v, double &min, double &max, bool &log) const
 {
     min = 0.0;
     max = 0.0;
@@ -691,8 +691,8 @@
             max = m_model->getValueMaximum();
 
             if (shouldConvertMIDIToHz()) {
-                min = Pitch::getFrequencyForPitch(lrintf(min));
-                max = Pitch::getFrequencyForPitch(lrintf(max + 1));
+                min = Pitch::getFrequencyForPitch(int(lrint(min)));
+                max = Pitch::getFrequencyForPitch(int(lrint(max + 1)));
             }
 
 #ifdef DEBUG_NOTE_LAYER
@@ -716,8 +716,8 @@
             min = Pitch::getFrequencyForPitch(0);
             max = Pitch::getFrequencyForPitch(70);
         } else if (shouldConvertMIDIToHz()) {
-            min = Pitch::getFrequencyForPitch(lrintf(min));
-            max = Pitch::getFrequencyForPitch(lrintf(max + 1));
+            min = Pitch::getFrequencyForPitch(int(lrint(min)));
+            max = Pitch::getFrequencyForPitch(int(lrint(max + 1)));
         }
 
         if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) {
@@ -730,9 +730,9 @@
 }
 
 int
-FlexiNoteLayer::getYForValue(View *v, float val) const
+FlexiNoteLayer::getYForValue(View *v, double val) const
 {
-    float min = 0.0, max = 0.0;
+    double min = 0.0, max = 0.0;
     bool logarithmic = false;
     int h = v->height();
 
@@ -743,8 +743,8 @@
 #endif
 
     if (shouldConvertMIDIToHz()) {
-        val = Pitch::getFrequencyForPitch(lrintf(val),
-                                          lrintf((val - lrintf(val)) * 100));
+        val = Pitch::getFrequencyForPitch(int(lrint(val)),
+                                          int(lrint((val - floor(val)) * 100.0)));
 #ifdef DEBUG_NOTE_LAYER
         cerr << "shouldConvertMIDIToHz true, val now = " << val << endl;
 #endif
@@ -764,19 +764,19 @@
     return y;
 }
 
-float
+double
 FlexiNoteLayer::getValueForY(View *v, int y) const
 {
-    float min = 0.0, max = 0.0;
+    double min = 0.0, max = 0.0;
     bool logarithmic = false;
     int h = v->height();
 
     getScaleExtents(v, min, max, logarithmic);
 
-    float val = min + (float(h - y) * float(max - min)) / h;
+    double val = min + (double(h - y) * double(max - min)) / h;
 
     if (logarithmic) {
-        val = powf(10.f, val);
+        val = pow(10.f, val);
     }
 
     if (shouldConvertMIDIToHz()) {
@@ -798,13 +798,13 @@
 {
     if (!m_model || !m_model->isOK()) return;
 
-    int sampleRate = m_model->getSampleRate();
+    sv_samplerate_t sampleRate = m_model->getSampleRate();
     if (!sampleRate) return;
 
 //    Profiler profiler("FlexiNoteLayer::paint", true);
 
     int x1 = rect.right();
-    int frame1 = v->getFrameForX(x1);
+    sv_frame_t frame1 = v->getFrameForX(x1);
 
     FlexiNoteModel::PointList points(m_model->getPoints(0, frame1));
     if (points.empty()) return;
@@ -817,8 +817,8 @@
 //    SVDEBUG << "FlexiNoteLayer::paint: resolution is "
 //        << m_model->getResolution() << " frames" << endl;
 
-    float min = m_model->getValueMinimum();
-    float max = m_model->getValueMaximum();
+    double min = m_model->getValueMinimum();
+    double max = m_model->getValueMaximum();
     if (max == min) max = min + 1.0;
 
     QPoint localPos;
@@ -923,7 +923,7 @@
     if (!m_model || m_model->getPoints().empty()) return;
 
     QString unit;
-    float min, max;
+    double min, max;
     bool logarithmic;
 
     int w = getVerticalScaleWidth(v, false, paint);
@@ -962,13 +962,13 @@
 
     if (!m_model) return;
 
-    int frame = v->getFrameForX(e->x());
+    sv_frame_t frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
 
-    float value = getValueForY(v, e->y());
+    double value = getValueForY(v, e->y());
 
-    m_editingPoint = FlexiNoteModel::Point(frame, value, 0, 0.8, tr("New Point"));
+    m_editingPoint = FlexiNoteModel::Point(frame, float(value), 0, 0.8f, tr("New Point"));
     m_originalPoint = m_editingPoint;
 
     if (m_editingCommand) finish(m_editingCommand);
@@ -986,14 +986,14 @@
 
     if (!m_model || !m_editing) return;
 
-    int frame = v->getFrameForX(e->x());
+    sv_frame_t frame = v->getFrameForX(e->x());
     if (frame < 0) frame = 0;
     frame = frame / m_model->getResolution() * m_model->getResolution();
 
-    float newValue = getValueForY(v, e->y());
+    double newValue = getValueForY(v, e->y());
 
-    int newFrame = m_editingPoint.frame;
-    int newDuration = frame - newFrame;
+    sv_frame_t newFrame = m_editingPoint.frame;
+    sv_frame_t newDuration = frame - newFrame;
     if (newDuration < 0) {
         newFrame = frame;
         newDuration = -newDuration;
@@ -1003,7 +1003,7 @@
 
     m_editingCommand->deletePoint(m_editingPoint);
     m_editingPoint.frame = newFrame;
-    m_editingPoint.value = newValue;
+    m_editingPoint.value = float(newValue);
     m_editingPoint.duration = newDuration;
     m_editingCommand->addPoint(m_editingPoint);
 }
@@ -1085,8 +1085,8 @@
     m_dragStartX = e->x();
     m_dragStartY = e->y();
     
-    int onset = m_originalPoint.frame;
-    int offset = m_originalPoint.frame + m_originalPoint.duration - 1;
+    sv_frame_t onset = m_originalPoint.frame;
+    sv_frame_t offset = m_originalPoint.frame + m_originalPoint.duration - 1;
     
     m_greatestLeftNeighbourFrame = -1;
     m_smallestRightNeighbourFrame = std::numeric_limits<int>::max();
@@ -1122,11 +1122,11 @@
     int newx = m_dragPointX + xdist;
     int newy = m_dragPointY + ydist;
 
-    int dragFrame = v->getFrameForX(newx);
+    sv_frame_t dragFrame = v->getFrameForX(newx);
     if (dragFrame < 0) dragFrame = 0;
     dragFrame = dragFrame / m_model->getResolution() * m_model->getResolution();
     
-    float value = getValueForY(v, newy);
+    double value = getValueForY(v, newy);
 
     if (!m_editingCommand) {
         m_editingCommand = new FlexiNoteModel::EditCommand(m_model,
@@ -1165,17 +1165,18 @@
             dragFrame = m_smallestRightNeighbourFrame - m_originalPoint.duration;
         }
         m_editingPoint.frame = dragFrame;
-        m_editingPoint.value = value;
+
+        m_editingPoint.value = float(value);
 
         // Re-analyse region within +/- 1 semitone of the dragged value
         float cents = 0;
         int midiPitch = Pitch::getPitchForFrequency(m_editingPoint.value, &cents);
-        float lower = Pitch::getFrequencyForPitch(midiPitch - 1, cents);
-        float higher = Pitch::getFrequencyForPitch(midiPitch + 1, cents);
+        double lower = Pitch::getFrequencyForPitch(midiPitch - 1, cents);
+        double higher = Pitch::getFrequencyForPitch(midiPitch + 1, cents);
         
         emit reAnalyseRegion(m_editingPoint.frame,
                              m_editingPoint.frame + m_editingPoint.duration,
-                             lower, higher);
+                             float(lower), float(higher));
         break;
     }
     case SplitNote: // nothing
@@ -1264,19 +1265,19 @@
         return; 
     }
 
-    int frame = v->getFrameForX(e->x());
+    sv_frame_t frame = v->getFrameForX(e->x());
 
     splitNotesAt(v, frame, e);
 }
 
 void
-FlexiNoteLayer::splitNotesAt(View *v, int frame)
+FlexiNoteLayer::splitNotesAt(View *v, sv_frame_t frame)
 {
     splitNotesAt(v, frame, 0);
 }
 
 void
-FlexiNoteLayer::splitNotesAt(View *v, int frame, QMouseEvent *e)
+FlexiNoteLayer::splitNotesAt(View *v, sv_frame_t frame, QMouseEvent *e)
 {
     FlexiNoteModel::PointList onPoints = m_model->getPoints(frame);
     if (onPoints.empty()) return;
@@ -1321,15 +1322,15 @@
     std::cerr << "addNote" << std::endl;
     if (!m_model) return;
 
-    int duration = 10000;
+    sv_frame_t duration = 10000;
     
-    int frame = v->getFrameForX(e->x());
-    float value = getValueForY(v, e->y());
+    sv_frame_t frame = v->getFrameForX(e->x());
+    double value = getValueForY(v, e->y());
     
     FlexiNoteModel::PointList noteList = m_model->getPoints();
 
     if (m_intelligentActions) {
-        int smallestRightNeighbourFrame = 0;
+        sv_frame_t smallestRightNeighbourFrame = 0;
         for (FlexiNoteModel::PointList::const_iterator i = noteList.begin();
              i != noteList.end(); ++i) {
             FlexiNote currentNote = *i;
@@ -1346,7 +1347,7 @@
 
     if (!m_intelligentActions || 
         (m_model->getPoints(frame).empty() && duration > 0)) {
-        FlexiNote newNote(frame, value, duration, 100, "new note");
+        FlexiNote newNote(frame, float(value), duration, 100.f, "new note");
         FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand
             (m_model, tr("Add Point"));
         command->addPoint(newNote);
@@ -1476,7 +1477,7 @@
    
     if (dataPoints.empty()) return false;
 
-    std::vector<float> pitchValues;
+    std::vector<double> pitchValues;
    
     for (SparseModel<TimeValuePoint>::PointList::const_iterator i =
              dataPoints.begin(); i != dataPoints.end(); ++i) {
@@ -1489,7 +1490,7 @@
     if (pitchValues.empty()) return false;
 
     sort(pitchValues.begin(), pitchValues.end());
-    int size = pitchValues.size();
+    int size = int(pitchValues.size());
     double median;
 
     if (size % 2 == 0) {
@@ -1500,7 +1501,7 @@
 
     std::cerr << "updateNoteValueFromPitchCurve: corrected from " << note.value << " to median " << median << std::endl;
     
-    note.value = median;
+    note.value = float(median);
 
     return true;
 }
@@ -1616,7 +1617,7 @@
 }
 
 void
-FlexiNoteLayer::moveSelection(Selection s, int newStartFrame)
+FlexiNoteLayer::moveSelection(Selection s, sv_frame_t newStartFrame)
 {
     if (!m_model) return;
 
@@ -1660,13 +1661,13 @@
 
         if (s.contains(i->frame)) {
 
-            double targetStart = i->frame;
-            targetStart = newSize.getStartFrame() + 
-                double(targetStart - s.getStartFrame()) * ratio;
+            double targetStart = double(i->frame);
+            targetStart = double(newSize.getStartFrame()) +
+                targetStart - double(s.getStartFrame()) * ratio;
 
-            double targetEnd = i->frame + i->duration;
-            targetEnd = newSize.getStartFrame() +
-                double(targetEnd - s.getStartFrame()) * ratio;
+            double targetEnd = double(i->frame + i->duration);
+            targetEnd = double(newSize.getStartFrame()) +
+                targetEnd - double(s.getStartFrame()) * ratio;
 
             FlexiNoteModel::Point newPoint(*i);
             newPoint.frame = lrint(targetStart);
@@ -1745,7 +1746,7 @@
 }
 
 bool
-FlexiNoteLayer::paste(View *v, const Clipboard &from, int /*frameOffset */, bool /* interactive */)
+FlexiNoteLayer::paste(View *v, const Clipboard &from, sv_frame_t /*frameOffset */, bool /* interactive */)
 {
     if (!m_model) return false;
 
@@ -1777,7 +1778,7 @@
          i != points.end(); ++i) {
         
         if (!i->haveFrame()) continue;
-        int frame = 0;
+        sv_frame_t frame = 0;
 
         if (!realign) {
             
@@ -1802,7 +1803,7 @@
         if (i->haveLevel()) newPoint.level = i->getLevel();
         if (i->haveDuration()) newPoint.duration = i->getDuration();
         else {
-            int nextFrame = frame;
+            sv_frame_t nextFrame = frame;
             Clipboard::PointList::const_iterator j = i;
             for (; j != points.end(); ++j) {
                 if (!j->haveFrame()) continue;
@@ -1826,17 +1827,17 @@
 }
 
 void
-FlexiNoteLayer::addNoteOn(int frame, int pitch, int velocity)
+FlexiNoteLayer::addNoteOn(sv_frame_t frame, int pitch, int velocity)
 {
-    m_pendingNoteOns.insert(FlexiNote(frame, pitch, 0, float(velocity) / 127.0, ""));
+    m_pendingNoteOns.insert(FlexiNote(frame, float(pitch), 0, float(velocity / 127.0), ""));
 }
 
 void
-FlexiNoteLayer::addNoteOff(int frame, int pitch)
+FlexiNoteLayer::addNoteOff(sv_frame_t frame, int pitch)
 {
     for (FlexiNoteSet::iterator i = m_pendingNoteOns.begin();
          i != m_pendingNoteOns.end(); ++i) {
-        if (lrintf((*i).value) == pitch) {
+        if (lrint((*i).value) == pitch) {
             FlexiNote note(*i);
             m_pendingNoteOns.erase(i);
             note.duration = frame - note.frame;
@@ -1887,16 +1888,16 @@
     if (ok) setVerticalScale(scale);
 
 //    bool alsoOk;
-//    float min = attributes.value("scaleMinimum").toFloat(&ok);
-//    float max = attributes.value("scaleMaximum").toFloat(&alsoOk);
+//    double min = attributes.value("scaleMinimum").toDouble(&ok);
+//    double max = attributes.value("scaleMaximum").toDouble(&alsoOk);
 //    if (ok && alsoOk && min != max) setDisplayExtents(min, max);
 }
 
 void
 FlexiNoteLayer::setVerticalRangeToNoteRange(View *v)
 {
-    float minf = std::numeric_limits<float>::max();
-    float maxf = 0;
+    double minf = std::numeric_limits<double>::max();
+    double maxf = 0;
     bool hasNotes = 0;
     for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin();
          i != m_model->getPoints().end(); ++i) {