comparison layer/SpectrogramLayer.cpp @ 590:241929c5d57c sonification

Check the scale width in the View (which has access to it); ask the layer to do something when the user clicks in the scale regardless of the edit mode, and continue with normal processing if the layer has nothing interesting to do
author Chris Cannam
date Fri, 24 Jun 2011 14:27:32 +0100
parents 7ebd5a21d74f
children 0946feb81b79
comparison
equal deleted inserted replaced
589:7ebd5a21d74f 590:241929c5d57c
3779 bool normalizeVisibleArea = 3779 bool normalizeVisibleArea =
3780 (attributes.value("normalizeVisibleArea").trimmed() == "true"); 3780 (attributes.value("normalizeVisibleArea").trimmed() == "true");
3781 setNormalizeVisibleArea(normalizeVisibleArea); 3781 setNormalizeVisibleArea(normalizeVisibleArea);
3782 } 3782 }
3783 3783
3784 void 3784 bool
3785 SpectrogramLayer::processMouseEvent(const View *v, QMouseEvent *e, int w) 3785 SpectrogramLayer::scaleClicked(const View *v, QMouseEvent *e)
3786 { 3786 {
3787 3787 std::cerr<< "Mouse click detected in the spectrogram scale area: (" << e->x() << "," << e->y() << ")" << std::endl;
3788 std::cerr<< "Mouse click detected in the layer: (" << e->x() << "," << e->y() << ")" << std::endl;
3789
3790 //is there a way to declare pkw and w may as class private variables?
3791
3792 int pkw = (m_frequencyScale == LogFrequencyScale ? 10 : 0);
3793
3794 int pianoKeyboardXLeft = w - pkw - 1;
3795 int pianoKeyboardXRight = w;
3796 3788
3797 float freq; 3789 float freq;
3798 QString unit; 3790 QString unit;
3799 float *centsOffsetReturn = 0; 3791 float *centsOffsetReturn = 0;
3800 float concertA = 0.0; 3792 float concertA = 0.0;
3801 int midipitch; 3793 int midipitch;
3802 3794
3803 if ((e->x() >= pianoKeyboardXLeft)&&(e->x() <= pianoKeyboardXRight)) 3795 if (getYScaleValue(v, e->y(), freq, unit)) {
3804 { 3796
3805 std::cerr << "Piano keyboard left border: " << pianoKeyboardXLeft<<std::endl; 3797 midipitch = Pitch::getPitchForFrequency(freq,centsOffsetReturn,concertA);
3806 std::cerr << "Piano keyboard right border: " << pianoKeyboardXRight<<std::endl; 3798
3807 std::cerr<< "Mouse click detected within the piano keyboard: (" << e->x() << "," << e->y() << ")" << std::endl; 3799 std::cerr<< "Frequency: " << freq << " " << unit.toStdString() << " (midi pitch = " << midipitch << ")" << std::endl;
3808 3800
3809 if (getYScaleValue(v, e->y(),freq, unit)) { 3801 return true;
3810 3802 } else {
3811 midipitch = Pitch::getPitchForFrequency(freq,centsOffsetReturn,concertA); 3803 return false;
3812 3804 }
3813 std::cerr<< "Frequency: " << freq << " " << unit.toStdString() << " (midi pitch = " << midipitch << ")" << std::endl; 3805 }
3814 } 3806
3815 }
3816 }