comparison layer/WaveformLayer.cpp @ 261:11021509c4eb

* some more work on measurement tool, and refactor Pane::paintEvent
author Chris Cannam
date Thu, 14 Jun 2007 16:28:27 +0000
parents 28c8e8e3c537
children dae479593572
comparison
equal deleted inserted replaced
260:6d113226bb4c 261:11021509c4eb
386 } 386 }
387 387
388 int 388 int
389 WaveformLayer::dBscale(float sample, int m) const 389 WaveformLayer::dBscale(float sample, int m) const
390 { 390 {
391 //!!! if (sample < 0.0) return -dBscale(-sample, m);
392 if (sample < 0.0) return dBscale(-sample, m); 391 if (sample < 0.0) return dBscale(-sample, m);
393 float dB = AudioLevel::multiplier_to_dB(sample); 392 float dB = AudioLevel::multiplier_to_dB(sample);
394 if (dB < -50.0) return 0; 393 if (dB < -50.0) return 0;
395 if (dB > 0.0) return m; 394 if (dB > 0.0) return m;
396 return int(((dB + 50.0) * m) / 50.0 + 0.1); 395 return int(((dB + 50.0) * m) / 50.0 + 0.1);
1031 } 1030 }
1032 1031
1033 return my - vy; 1032 return my - vy;
1034 } 1033 }
1035 1034
1035 float
1036 WaveformLayer::getValueForY(View *v, Scale scale, int y,
1037 size_t minChannel, size_t maxChannel) const
1038 {
1039 if (maxChannel < minChannel) return 0;
1040
1041 int h = v->height();
1042
1043 int channels = maxChannel - minChannel + 1;
1044 int m = (h / channels) / 2;
1045
1046 if ((m_scale == dBScale || m_scale == MeterScale) &&
1047 m_channelMode != MergeChannels) {
1048 m = (h / channels);
1049 }
1050
1051 int channel = minChannel;
1052 int mind = 0;
1053
1054 for (int c = minChannel; c <= maxChannel; ++c) {
1055 int my = m + (((c - minChannel) * h) / channels);
1056 int d = y - my;
1057 if (d < 0) d = -d;
1058 if (c == minChannel || d < mind) {
1059 mind = d;
1060 channel = c;
1061 }
1062 }
1063
1064 int my = m + (((channel - minChannel) * h) / channels);
1065
1066 int vy = y - my;
1067 float value = 0;
1068
1069 switch (scale) {
1070
1071 case LinearScale:
1072 value = float(vy) / m;
1073 break;
1074
1075 case MeterScale:
1076 value = AudioLevel::preview_to_multiplier(vy, m);
1077 break;
1078
1079 case dBScale:
1080 value = AudioLevel::dB_to_multiplier((50 * float(vy)) / m - 50);
1081 break;
1082 }
1083
1084 return value;
1085 }
1086
1087 bool
1088 WaveformLayer::getYScaleValue(View *v, int y,
1089 float &value, QString &unit) const
1090 {
1091 size_t channels = 0, minChannel = 0, maxChannel = 0;
1092 bool mergingChannels = false, mixingChannels = false;
1093
1094 channels = getChannelArrangement(minChannel, maxChannel,
1095 mergingChannels, mixingChannels);
1096
1097 if (channels == 0) return false;
1098
1099 value = getValueForY(v, m_scale, y, minChannel, maxChannel);
1100 unit = "V";
1101 return true;
1102 }
1103
1036 int 1104 int
1037 WaveformLayer::getVerticalScaleWidth(View *, QPainter &paint) const 1105 WaveformLayer::getVerticalScaleWidth(View *, QPainter &paint) const
1038 { 1106 {
1039 if (m_scale == LinearScale) { 1107 if (m_scale == LinearScale) {
1040 return paint.fontMetrics().width("0.0") + 13; 1108 return paint.fontMetrics().width("0.0") + 13;