comparison layer/SpectrogramLayer.cpp @ 34:c43f2c4f66f2

* As previous commit
author Chris Cannam
date Fri, 17 Feb 2006 18:11:08 +0000
parents 651e4e868bcc
children 10ba9276a315
comparison
equal deleted inserted replaced
33:651e4e868bcc 34:c43f2c4f66f2
77 } 77 }
78 78
79 void 79 void
80 SpectrogramLayer::setModel(const DenseTimeValueModel *model) 80 SpectrogramLayer::setModel(const DenseTimeValueModel *model)
81 { 81 {
82 std::cerr << "SpectrogramLayer(" << this << "): setModel(" << model << ")" << std::endl;
83
82 m_mutex.lock(); 84 m_mutex.lock();
83 m_model = model; 85 m_model = model;
84 delete m_cache; 86 delete m_cache; //!!! hang on, this isn't safe to do here is it?
87 // we need some sort of guard against the fill
88 // thread trying to read the defunct model too.
89 // should we use a scavenger?
85 m_cache = 0; 90 m_cache = 0;
86 m_mutex.unlock(); 91 m_mutex.unlock();
87 92
88 if (!m_model || !m_model->isOK()) return; 93 if (!m_model || !m_model->isOK()) return;
89 94
603 if (dormant) { 608 if (dormant) {
604 609
605 m_mutex.lock(); 610 m_mutex.lock();
606 m_dormant = true; 611 m_dormant = true;
607 612
608 delete m_cache; 613 // delete m_cache;
609 m_cache = 0; 614 // m_cache = 0;
610 615
616 m_cacheInvalid = true;
611 m_pixmapCacheInvalid = true; 617 m_pixmapCacheInvalid = true;
618 m_cachedInitialVisibleArea = false;
612 delete m_pixmapCache; 619 delete m_pixmapCache;
613 m_pixmapCache = 0; 620 m_pixmapCache = 0;
614 621
615 m_mutex.unlock(); 622 m_mutex.unlock();
616 623
826 833
827 windower.cut(input); 834 windower.cut(input);
828 835
829 fftw_execute(plan); 836 fftw_execute(plan);
830 837
831 if (lock) m_mutex.lock(); 838 // if (lock) m_mutex.lock();
832 bool interrupted = false; 839 bool interrupted = false;
833 840
834 for (size_t i = 0; i < windowSize / 2; ++i) { 841 for (size_t i = 0; i < windowSize / 2; ++i) {
835 842
836 int value = 0; 843 int value = 0;
875 } 882 }
876 883
877 m_cache->setValueAt(column, i, value + 1); 884 m_cache->setValueAt(column, i, value + 1);
878 } 885 }
879 886
880 if (lock) m_mutex.unlock(); 887 // if (lock) m_mutex.unlock();
881 return !interrupted; 888 return !interrupted;
882 } 889 }
883 890
884 SpectrogramLayer::Cache::Cache(size_t width, size_t height) : 891 SpectrogramLayer::Cache::Cache(size_t width, size_t height) :
885 m_width(width), 892 m_width(width),
951 958
952 bool interrupted = false; 959 bool interrupted = false;
953 960
954 // std::cerr << "SpectrogramLayer::CacheFillThread::run in loop" << std::endl; 961 // std::cerr << "SpectrogramLayer::CacheFillThread::run in loop" << std::endl;
955 962
956 if (m_layer.m_model && m_layer.m_cacheInvalid && !m_layer.m_dormant) { 963 if (m_layer.m_dormant) {
964
965 if (m_layer.m_cacheInvalid) {
966 delete m_layer.m_cache;
967 m_layer.m_cache = 0;
968 }
969
970 } else if (m_layer.m_model && m_layer.m_cacheInvalid) {
957 971
958 // std::cerr << "SpectrogramLayer::CacheFillThread::run: something to do" << std::endl; 972 // std::cerr << "SpectrogramLayer::CacheFillThread::run: something to do" << std::endl;
959 973
960 while (!m_layer.m_model->isReady()) { 974 while (!m_layer.m_model->isReady()) {
961 m_layer.m_condition.wait(&m_layer.m_mutex, 100); 975 m_layer.m_condition.wait(&m_layer.m_mutex, 100);