comparison layer/SpectrumLayer.cpp @ 374:64e84e5efb76 spectrogram-cache-rejig

* Merge from trunk
author Chris Cannam
date Wed, 27 Feb 2008 11:59:42 +0000
parents 29fcf125f98b
children
comparison
equal deleted inserted replaced
332:6440e280122e 374:64e84e5efb76
45 setBinScale(LogBins); 45 setBinScale(LogBins);
46 } 46 }
47 47
48 SpectrumLayer::~SpectrumLayer() 48 SpectrumLayer::~SpectrumLayer()
49 { 49 {
50 //!!! delete parent's model 50 Model *m = const_cast<Model *>
51 // for (size_t i = 0; i < m_fft.size(); ++i) delete m_fft[i]; 51 (static_cast<const Model *>(m_sliceableModel));
52 m->aboutToDelete();
53 m_sliceableModel = 0;
54 delete m;
52 } 55 }
53 56
54 void 57 void
55 SpectrumLayer::setModel(DenseTimeValueModel *model) 58 SpectrumLayer::setModel(DenseTimeValueModel *model)
56 { 59 {
60 std::cerr << "SpectrumLayer::setModel(" << model << ") from " << m_originModel << std::endl;
61
57 if (m_originModel == model) return; 62 if (m_originModel == model) return;
63
58 m_originModel = model; 64 m_originModel = model;
59 65
60 if (m_sliceableModel) { 66 if (m_sliceableModel) {
61 const Model *oldModel = m_sliceableModel; 67 Model *m = const_cast<Model *>
68 (static_cast<const Model *>(m_sliceableModel));
69 m->aboutToDelete();
62 setSliceableModel(0); 70 setSliceableModel(0);
63 // surprised I'm allowed to delete a const pointer -- may be a 71 delete m;
64 // source of future compiler rejection? 72 }
65 delete oldModel; 73
66 } 74 m_newFFTNeeded = true;
67 //!!! setupFFT(); 75
76 emit layerParametersChanged();
77 }
78
79 void
80 SpectrumLayer::setChannel(int channel)
81 {
82 std::cerr << "SpectrumLayer::setChannel(" << channel << ") from " << m_channel << std::endl;
83
84 m_channelSet = true;
85
86 if (m_channel == channel) return;
87
88 m_channel = channel;
89
90 m_newFFTNeeded = true;
91
92 emit layerParametersChanged();
68 } 93 }
69 94
70 void 95 void
71 SpectrumLayer::setupFFT() 96 SpectrumLayer::setupFFT()
72 { 97 {
73 FFTModel *oldFFT = dynamic_cast<FFTModel *> 98 if (m_sliceableModel) {
74 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); 99 Model *m = const_cast<Model *>
75 100 (static_cast<const Model *>(m_sliceableModel));
76 if (oldFFT) { 101 m->aboutToDelete();
77 setSliceableModel(0); 102 setSliceableModel(0);
78 delete oldFFT; 103 delete m;
104 }
105
106 if (!m_originModel) {
107 return;
79 } 108 }
80 109
81 FFTModel *newFFT = new FFTModel(m_originModel, 110 FFTModel *newFFT = new FFTModel(m_originModel,
82 m_channel, 111 m_channel,
83 m_windowType, 112 m_windowType,
95 for (size_t i = 0; i < m_windowSize; ++i) { 124 for (size_t i = 0; i < m_windowSize; ++i) {
96 m_biasCurve.push_back(1.f / (float(m_windowSize)/2.f)); 125 m_biasCurve.push_back(1.f / (float(m_windowSize)/2.f));
97 } 126 }
98 127
99 newFFT->resume(); 128 newFFT->resume();
100 } 129
101 130 m_newFFTNeeded = false;
102 void
103 SpectrumLayer::setChannel(int channel)
104 {
105 m_channelSet = true;
106
107 FFTModel *fft = dynamic_cast<FFTModel *>
108 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel));
109
110 if (m_channel == channel) {
111 if (fft) fft->resume();
112 return;
113 }
114
115 m_channel = channel;
116
117 emit layerParametersChanged();
118 } 131 }
119 132
120 Layer::PropertyList 133 Layer::PropertyList
121 SpectrumLayer::getProperties() const 134 SpectrumLayer::getProperties() const
122 { 135 {
132 { 145 {
133 if (name == "Window Size") return tr("Window Size"); 146 if (name == "Window Size") return tr("Window Size");
134 if (name == "Window Increment") return tr("Window Overlap"); 147 if (name == "Window Increment") return tr("Window Overlap");
135 if (name == "Show Peak Frequencies") return tr("Show Peak Frequencies"); 148 if (name == "Show Peak Frequencies") return tr("Show Peak Frequencies");
136 return SliceLayer::getPropertyLabel(name); 149 return SliceLayer::getPropertyLabel(name);
150 }
151
152 QString
153 SpectrumLayer::getPropertyIconName(const PropertyName &name) const
154 {
155 if (name == "Show Peak Frequencies") return "show-peaks";
156 return SliceLayer::getPropertyIconName(name);
137 } 157 }
138 158
139 Layer::PropertyType 159 Layer::PropertyType
140 SpectrumLayer::getPropertyType(const PropertyName &name) const 160 SpectrumLayer::getPropertyType(const PropertyName &name) const
141 { 161 {
631 651
632 void 652 void
633 SpectrumLayer::paint(View *v, QPainter &paint, QRect rect) const 653 SpectrumLayer::paint(View *v, QPainter &paint, QRect rect) const
634 { 654 {
635 if (!m_originModel || !m_originModel->isOK() || 655 if (!m_originModel || !m_originModel->isOK() ||
636 !m_originModel->isReady()) return; 656 !m_originModel->isReady()) {
657 std::cerr << "SpectrumLayer::paint: no origin model, or origin model not OK or not ready" << std::endl;
658 return;
659 }
637 660
638 if (m_newFFTNeeded) { 661 if (m_newFFTNeeded) {
662 std::cerr << "SpectrumLayer::paint: new FFT needed, calling setupFFT" << std::endl;
639 const_cast<SpectrumLayer *>(this)->setupFFT(); //ugh 663 const_cast<SpectrumLayer *>(this)->setupFFT(); //ugh
640 m_newFFTNeeded = false;
641 } 664 }
642 665
643 FFTModel *fft = dynamic_cast<FFTModel *> 666 FFTModel *fft = dynamic_cast<FFTModel *>
644 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); 667 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel));
645 668
650 673
651 int pkh = 0; 674 int pkh = 0;
652 //!!! if (m_binScale == LogBins) { 675 //!!! if (m_binScale == LogBins) {
653 pkh = 10; 676 pkh = 10;
654 //!!! } 677 //!!! }
678
679 paint.save();
655 680
656 if (fft && m_showPeaks) { 681 if (fft && m_showPeaks) {
657 682
658 // draw peak lines 683 // draw peak lines
659 684
790 815
791 ppx = px; 816 ppx = px;
792 px = x; 817 px = x;
793 } 818 }
794 // } 819 // }
820
821 paint.restore();
795 } 822 }
796 823
797 void 824 void
798 SpectrumLayer::getBiasCurve(BiasCurve &curve) const 825 SpectrumLayer::getBiasCurve(BiasCurve &curve) const
799 { 826 {