comparison data/model/WaveFileModel.cpp @ 411:52303ec15cd2

* Permit holding Shift while dragging an instant or other edited thing, to override the initial drag resistance (for #1928943 sticky time instants) * better handling of updates during progressive decode load * ready() signal from model (used by vect)
author Chris Cannam
date Mon, 19 May 2008 17:23:11 +0000
parents 9c7ebf2cd956
children 6036b38177e2
comparison
equal deleted inserted replaced
410:9c7ebf2cd956 411:52303ec15cd2
630 m_mutex.unlock(); 630 m_mutex.unlock();
631 if (getEndFrame() > m_lastFillExtent) { 631 if (getEndFrame() > m_lastFillExtent) {
632 emit modelChanged(m_lastFillExtent, getEndFrame()); 632 emit modelChanged(m_lastFillExtent, getEndFrame());
633 } 633 }
634 emit modelChanged(); 634 emit modelChanged();
635 emit ready();
635 #ifdef DEBUG_WAVE_FILE_MODEL 636 #ifdef DEBUG_WAVE_FILE_MODEL
636 cerr << "WaveFileModel::cacheFilled" << endl; 637 cerr << "WaveFileModel::cacheFilled" << endl;
637 #endif 638 #endif
638 } 639 }
639 640
644 cacheBlockSize[0] = (1 << m_model.m_zoomConstraint.getMinCachePower()); 645 cacheBlockSize[0] = (1 << m_model.m_zoomConstraint.getMinCachePower());
645 cacheBlockSize[1] = ((unsigned int)((1 << m_model.m_zoomConstraint.getMinCachePower()) * 646 cacheBlockSize[1] = ((unsigned int)((1 << m_model.m_zoomConstraint.getMinCachePower()) *
646 sqrt(2) + 0.01)); 647 sqrt(2) + 0.01));
647 648
648 size_t frame = 0; 649 size_t frame = 0;
649 size_t readBlockSize = 16384; 650 int readBlockSize = 16384;
650 SampleBlock block; 651 SampleBlock block;
651 652
652 if (!m_model.isOK()) return; 653 if (!m_model.isOK()) return;
653 654
654 size_t channels = m_model.getChannelCount(); 655 size_t channels = m_model.getChannelCount();
664 665
665 Range *range = new Range[2 * channels]; 666 Range *range = new Range[2 * channels];
666 float *means = new float[2 * channels]; 667 float *means = new float[2 * channels];
667 size_t count[2]; 668 size_t count[2];
668 count[0] = count[1] = 0; 669 count[0] = count[1] = 0;
670 for (int i = 0; i < 2 * channels; ++i) {
671 means[i] = 0.f;
672 }
669 673
670 bool first = true; 674 bool first = true;
671 675
672 while (first || updating) { 676 while (first || updating) {
673 677
684 688
685 m_model.m_reader->getInterleavedFrames(frame, readBlockSize, block); 689 m_model.m_reader->getInterleavedFrames(frame, readBlockSize, block);
686 690
687 // std::cerr << "block is " << block.size() << std::endl; 691 // std::cerr << "block is " << block.size() << std::endl;
688 692
689 for (size_t i = 0; i < readBlockSize; ++i) { 693 for (int i = 0; i < readBlockSize; ++i) {
690 694
691 if (channels * i + channels > block.size()) break; 695 if (channels * i + channels > block.size()) break;
692 696
693 for (size_t ch = 0; ch < size_t(channels); ++ch) { 697 for (int ch = 0; ch < channels; ++ch) {
694 698
695 size_t index = channels * i + ch; 699 int index = channels * i + ch;
696 float sample = block[index]; 700 float sample = block[index];
697 701
698 for (size_t ct = 0; ct < 2; ++ct) { // cache type 702 for (int ct = 0; ct < 2; ++ct) { // cache type
699 703
700 size_t rangeIndex = ch * 2 + ct; 704 int rangeIndex = ch * 2 + ct;
701 705
702 if (sample > range[rangeIndex].max() || count[ct] == 0) { 706 if (sample > range[rangeIndex].max() || count[ct] == 0) {
703 range[rangeIndex].setMax(sample); 707 range[rangeIndex].setMax(sample);
704 } 708 }
705 if (sample < range[rangeIndex].min() || count[ct] == 0) { 709 if (sample < range[rangeIndex].min() || count[ct] == 0) {
720 size_t rangeIndex = ch * 2 + ct; 724 size_t rangeIndex = ch * 2 + ct;
721 means[rangeIndex] /= count[ct]; 725 means[rangeIndex] /= count[ct];
722 range[rangeIndex].setAbsmean(means[rangeIndex]); 726 range[rangeIndex].setAbsmean(means[rangeIndex]);
723 m_model.m_cache[ct].push_back(range[rangeIndex]); 727 m_model.m_cache[ct].push_back(range[rangeIndex]);
724 range[rangeIndex] = Range(); 728 range[rangeIndex] = Range();
729 means[rangeIndex] = 0.f;
725 } 730 }
726 731
727 count[ct] = 0; 732 count[ct] = 0;
728 } 733 }
729 } 734 }
758 size_t rangeIndex = ch * 2 + ct; 763 size_t rangeIndex = ch * 2 + ct;
759 means[rangeIndex] /= count[ct]; 764 means[rangeIndex] /= count[ct];
760 range[rangeIndex].setAbsmean(means[rangeIndex]); 765 range[rangeIndex].setAbsmean(means[rangeIndex]);
761 m_model.m_cache[ct].push_back(range[rangeIndex]); 766 m_model.m_cache[ct].push_back(range[rangeIndex]);
762 range[rangeIndex] = Range(); 767 range[rangeIndex] = Range();
768 means[rangeIndex] = 0.f;
763 } 769 }
764 770
765 count[ct] = 0; 771 count[ct] = 0;
766 } 772 }
767 773