diff layer/NoteLayer.cpp @ 42:1bdf285c4eac

* Add "Export Audio File" option * Make note layer align in frequency with any spectrogram layer on the same view (if it's set to frequency mode) * Start to implement mouse editing for ranges of points by dragging the selection * First scrappy attempt at a vertical scale for time value layer
author Chris Cannam
date Mon, 27 Feb 2006 17:34:41 +0000
parents ea6fe8cfcdd5
children 78515b1e29eb
line wrap: on
line diff
--- a/layer/NoteLayer.cpp	Fri Feb 24 17:26:11 2006 +0000
+++ b/layer/NoteLayer.cpp	Mon Feb 27 17:34:41 2006 +0000
@@ -17,6 +17,8 @@
 
 #include "model/NoteModel.h"
 
+#include "SpectrogramLayer.h" // for optional frequency alignment
+
 #include <QPainter>
 #include <QPainterPath>
 #include <QMouseEvent>
@@ -353,7 +355,7 @@
 NoteLayer::getYForValue(float value) const
 {
     float min, max, h = m_view->height();
-    
+
     switch (m_verticalScale) {
 
     case MIDIRangeScale:
@@ -367,12 +369,26 @@
 	break;
 
     case FrequencyScale:
+    
+	value = Pitch::getFrequencyForPitch(lrintf(value),
+					    value - lrintf(value));
+
+	// If we have a spectrogram layer on the same view as us, align
+	// ourselves with it...
+	for (int i = 0; i < m_view->getLayerCount(); ++i) {
+	    SpectrogramLayer *spectrogram = dynamic_cast<SpectrogramLayer *>
+		(m_view->getLayer(i));
+	    if (spectrogram) {
+		return spectrogram->getYForFrequency(value);
+	    }
+	}
+
+	// ...otherwise just interpolate
 	std::cerr << "FrequencyScale: value in = " << value << std::endl;
 	min = m_model->getValueMinimum();
 	min = Pitch::getFrequencyForPitch(lrintf(min), min - lrintf(min));
 	max = m_model->getValueMaximum();
 	max = Pitch::getFrequencyForPitch(lrintf(max), max - lrintf(max));
-	value = Pitch::getFrequencyForPitch(lrintf(value), value - lrintf(value));
 	std::cerr << "FrequencyScale: min = " << min << ", max = " << max << ", value = " << value << std::endl;
 	break;
     }