comparison view/View.cpp @ 362:a9dfa2d6d5ac

* Add pitch range in octaves, semitones and cents to the measurement rect as well as in Hz * Avoid crash when adding time ruler This commit contains a lot of debug output (will be slow)
author Chris Cannam
date Wed, 06 Feb 2008 16:21:29 +0000
parents 020c485aa7e0
children 6167a28d25fc
comparison
equal deleted inserted replaced
361:67834ac56f2b 362:a9dfa2d6d5ac
1908 int axx, axy, bxx, bxy, dxx, dxy; 1908 int axx, axy, bxx, bxy, dxx, dxy;
1909 int aw = 0, bw = 0, dw = 0; 1909 int aw = 0, bw = 0, dw = 0;
1910 1910
1911 int labelCount = 0; 1911 int labelCount = 0;
1912 1912
1913 // top-left point, x-coord
1914
1913 if ((b0 = topLayer->getXScaleValue(this, r.x(), v0, u0))) { 1915 if ((b0 = topLayer->getXScaleValue(this, r.x(), v0, u0))) {
1914 axs = QString("%1 %2").arg(v0).arg(u0); 1916 axs = QString("%1 %2").arg(v0).arg(u0);
1915 if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) { 1917 if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) {
1916 axs = QString("%1 (%2)").arg(axs) 1918 axs = QString("%1 (%2)").arg(axs)
1917 .arg(Pitch::getPitchLabelForFrequency(v0)); 1919 .arg(Pitch::getPitchLabelForFrequency(v0));
1918 } 1920 }
1919 aw = paint.fontMetrics().width(axs); 1921 aw = paint.fontMetrics().width(axs);
1920 ++labelCount; 1922 ++labelCount;
1921 } 1923 }
1924
1925 // bottom-right point, x-coord
1922 1926
1923 if (r.width() > 0) { 1927 if (r.width() > 0) {
1924 if ((b1 = topLayer->getXScaleValue(this, r.x() + r.width(), v1, u1))) { 1928 if ((b1 = topLayer->getXScaleValue(this, r.x() + r.width(), v1, u1))) {
1925 bxs = QString("%1 %2").arg(v1).arg(u1); 1929 bxs = QString("%1 %2").arg(v1).arg(u1);
1926 if (u1 == "Hz" && Pitch::isFrequencyInMidiRange(v1)) { 1930 if (u1 == "Hz" && Pitch::isFrequencyInMidiRange(v1)) {
1928 .arg(Pitch::getPitchLabelForFrequency(v1)); 1932 .arg(Pitch::getPitchLabelForFrequency(v1));
1929 } 1933 }
1930 bw = paint.fontMetrics().width(bxs); 1934 bw = paint.fontMetrics().width(bxs);
1931 } 1935 }
1932 } 1936 }
1937
1938 // dimension, width
1933 1939
1934 if (b0 && b1 && v1 != v0 && u0 == u1) { 1940 if (b0 && b1 && v1 != v0 && u0 == u1) {
1935 dxs = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); 1941 dxs = QString("[%1 %2]").arg(fabs(v1 - v0)).arg(u1);
1936 dw = paint.fontMetrics().width(dxs); 1942 dw = paint.fontMetrics().width(dxs);
1937 } 1943 }
1938 1944
1939 b0 = false; 1945 b0 = false;
1940 b1 = false; 1946 b1 = false;
1947
1948 // top-left point, y-coord
1941 1949
1942 if ((b0 = topLayer->getYScaleValue(this, r.y(), v0, u0))) { 1950 if ((b0 = topLayer->getYScaleValue(this, r.y(), v0, u0))) {
1943 ays = QString("%1 %2").arg(v0).arg(u0); 1951 ays = QString("%1 %2").arg(v0).arg(u0);
1944 if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) { 1952 if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) {
1945 ays = QString("%1 (%2)").arg(ays) 1953 ays = QString("%1 (%2)").arg(ays)
1946 .arg(Pitch::getPitchLabelForFrequency(v0)); 1954 .arg(Pitch::getPitchLabelForFrequency(v0));
1947 } 1955 }
1948 aw = std::max(aw, paint.fontMetrics().width(ays)); 1956 aw = std::max(aw, paint.fontMetrics().width(ays));
1949 ++labelCount; 1957 ++labelCount;
1950 } 1958 }
1959
1960 // bottom-right point, y-coord
1951 1961
1952 if (r.height() > 0) { 1962 if (r.height() > 0) {
1953 if ((b1 = topLayer->getYScaleValue(this, r.y() + r.height(), v1, u1))) { 1963 if ((b1 = topLayer->getYScaleValue(this, r.y() + r.height(), v1, u1))) {
1954 bys = QString("%1 %2").arg(v1).arg(u1); 1964 bys = QString("%1 %2").arg(v1).arg(u1);
1955 if (u1 == "Hz" && Pitch::isFrequencyInMidiRange(v1)) { 1965 if (u1 == "Hz" && Pitch::isFrequencyInMidiRange(v1)) {
1962 1972
1963 bool bd = false; 1973 bool bd = false;
1964 float dy = 0.f; 1974 float dy = 0.f;
1965 QString du; 1975 QString du;
1966 1976
1977 // dimension, height
1978
1967 if ((bd = topLayer->getYScaleDifference(this, r.y(), r.y() + r.height(), 1979 if ((bd = topLayer->getYScaleDifference(this, r.y(), r.y() + r.height(),
1968 dy, du)) && 1980 dy, du)) &&
1969 dy != 0) { 1981 dy != 0) {
1970 if (du != "") { 1982 if (du != "") {
1971 dys = QString("(%1 %2)").arg(dy).arg(du); 1983 if (du == "Hz") {
1984 int semis;
1985 float cents;
1986 semis = Pitch::getPitchForFrequencyDifference(v0, v1, &cents);
1987 dys = QString("[%1 %2 (%3)]")
1988 .arg(dy).arg(du)
1989 .arg(Pitch::getLabelForPitchRange(semis, cents));
1990 } else {
1991 dys = QString("[%1 %2]").arg(dy).arg(du);
1992 }
1972 } else { 1993 } else {
1973 dys = QString("(%1)").arg(dy); 1994 dys = QString("[%1]").arg(dy);
1974 } 1995 }
1975 dw = std::max(dw, paint.fontMetrics().width(dys)); 1996 dw = std::max(dw, paint.fontMetrics().width(dys));
1976 } 1997 }
1977 1998
1978 int mw = r.width(); 1999 int mw = r.width();