Chris@690: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@690: Chris@690: /* Chris@690: Sonic Visualiser Chris@690: An audio file viewer and annotation editor. Chris@690: Centre for Digital Music, Queen Mary, University of London. Chris@690: This file copyright 2006-2013 Chris Cannam and QMUL. Chris@690: Chris@690: This program is free software; you can redistribute it and/or Chris@690: modify it under the terms of the GNU General Public License as Chris@690: published by the Free Software Foundation; either version 2 of the Chris@690: License, or (at your option) any later version. See the file Chris@690: COPYING included with this distribution for more information. Chris@690: */ Chris@690: Chris@690: #include "PianoScale.h" Chris@690: Chris@690: #include Chris@690: Chris@690: #include Chris@690: Chris@690: #include "base/Pitch.h" Chris@690: Chris@1077: #include "LayerGeometryProvider.h" Chris@690: Chris@690: void Chris@918: PianoScale::paintPianoVertical(LayerGeometryProvider *v, Chris@690: QPainter &paint, Chris@690: QRect r, Chris@904: double minf, Chris@904: double maxf) Chris@690: { Chris@690: int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height(); Chris@690: Chris@690: paint.drawLine(x0, y0, x0, y1); Chris@690: Chris@690: int py = y1, ppy = y1; Chris@690: paint.setBrush(paint.pen().color()); Chris@690: Chris@690: for (int i = 0; i < 128; ++i) { Chris@690: Chris@904: double f = Pitch::getFrequencyForPitch(i); Chris@905: int y = int(lrint(v->getYForFrequency(f, minf, maxf, true))); Chris@690: Chris@690: if (y < y0 - 2) break; Chris@690: if (y > y1 + 2) { Chris@690: continue; Chris@690: } Chris@690: Chris@690: int n = (i % 12); Chris@690: Chris@690: if (n == 1) { Chris@690: // C# -- fill the C from here Chris@690: QColor col = Qt::gray; Chris@690: if (i == 61) { // filling middle C Chris@690: col = Qt::blue; Chris@690: col = col.light(150); Chris@690: } Chris@690: if (ppy - y > 2) { Chris@690: paint.fillRect(x0 + 1, Chris@690: y, Chris@690: x1 - x0, Chris@690: (py + ppy) / 2 - y, Chris@690: col); Chris@690: } Chris@690: } Chris@690: Chris@690: if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { Chris@690: // black notes Chris@690: paint.drawLine(x0 + 1, y, x1, y); Chris@690: int rh = ((py - y) / 4) * 2; Chris@690: if (rh < 2) rh = 2; Chris@690: paint.drawRect(x0 + 1, y - (py-y)/4, (x1 - x0) / 2, rh); Chris@690: } else if (n == 0 || n == 5) { Chris@690: // C, F Chris@690: if (py < y1) { Chris@690: paint.drawLine(x0 + 1, (y + py) / 2, x1, (y + py) / 2); Chris@690: } Chris@690: } Chris@690: Chris@690: ppy = py; Chris@690: py = y; Chris@690: } Chris@690: } Chris@690: