Mercurial > hg > svgui
diff layer/SpectrogramLayer.cpp @ 589:7ebd5a21d74f sonification
Branch to handle audio feedback and metadata sonification interactively with the UI.
Piano keyboard audio feedback:
The midi pitch of a piano keyboard note is retrieved in SpectrogramLayer::processMouseEvent when a left click is made on the note in the Select tool mode (SpectrogramLayer with a log frequency scale). The same process should be applied to the Spectrum layer (log frequency scale) as well.
author | mathieub <mathieu.barthet@eecs.qmul.ac.uk> |
---|---|
date | Wed, 22 Jun 2011 00:04:21 +0100 |
parents | 4806715f7a19 |
children | 241929c5d57c |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Tue Jun 14 15:27:05 2011 +0100 +++ b/layer/SpectrogramLayer.cpp Wed Jun 22 00:04:21 2011 +0100 @@ -3781,3 +3781,36 @@ setNormalizeVisibleArea(normalizeVisibleArea); } +void +SpectrogramLayer::processMouseEvent(const View *v, QMouseEvent *e, int w) +{ + + std::cerr<< "Mouse click detected in the layer: (" << e->x() << "," << e->y() << ")" << std::endl; + + //is there a way to declare pkw and w may as class private variables? + + int pkw = (m_frequencyScale == LogFrequencyScale ? 10 : 0); + + int pianoKeyboardXLeft = w - pkw - 1; + int pianoKeyboardXRight = w; + + float freq; + QString unit; + float *centsOffsetReturn = 0; + float concertA = 0.0; + int midipitch; + + if ((e->x() >= pianoKeyboardXLeft)&&(e->x() <= pianoKeyboardXRight)) + { + std::cerr << "Piano keyboard left border: " << pianoKeyboardXLeft<<std::endl; + std::cerr << "Piano keyboard right border: " << pianoKeyboardXRight<<std::endl; + std::cerr<< "Mouse click detected within the piano keyboard: (" << e->x() << "," << e->y() << ")" << std::endl; + + if (getYScaleValue(v, e->y(),freq, unit)) { + + midipitch = Pitch::getPitchForFrequency(freq,centsOffsetReturn,concertA); + + std::cerr<< "Frequency: " << freq << " " << unit.toStdString() << " (midi pitch = " << midipitch << ")" << std::endl; + } + } +}