svgui
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006-2013 Chris Cannam and QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #include "PianoScale.h" 00017 00018 #include <QPainter> 00019 00020 #include <cmath> 00021 00022 #include "base/Pitch.h" 00023 00024 #include "view/View.h" 00025 00026 void 00027 PianoScale::paintPianoVertical(View *v, 00028 QPainter &paint, 00029 QRect r, 00030 float minf, 00031 float maxf) 00032 { 00033 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height(); 00034 00035 paint.drawLine(x0, y0, x0, y1); 00036 00037 int py = y1, ppy = y1; 00038 paint.setBrush(paint.pen().color()); 00039 00040 for (int i = 0; i < 128; ++i) { 00041 00042 float f = Pitch::getFrequencyForPitch(i); 00043 int y = lrintf(v->getYForFrequency(f, minf, maxf, true)); 00044 00045 if (y < y0 - 2) break; 00046 if (y > y1 + 2) { 00047 continue; 00048 } 00049 00050 int n = (i % 12); 00051 00052 if (n == 1) { 00053 // C# -- fill the C from here 00054 QColor col = Qt::gray; 00055 if (i == 61) { // filling middle C 00056 col = Qt::blue; 00057 col = col.light(150); 00058 } 00059 if (ppy - y > 2) { 00060 paint.fillRect(x0 + 1, 00061 y, 00062 x1 - x0, 00063 (py + ppy) / 2 - y, 00064 col); 00065 } 00066 } 00067 00068 if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { 00069 // black notes 00070 paint.drawLine(x0 + 1, y, x1, y); 00071 int rh = ((py - y) / 4) * 2; 00072 if (rh < 2) rh = 2; 00073 paint.drawRect(x0 + 1, y - (py-y)/4, (x1 - x0) / 2, rh); 00074 } else if (n == 0 || n == 5) { 00075 // C, F 00076 if (py < y1) { 00077 paint.drawLine(x0 + 1, (y + py) / 2, x1, (y + py) / 2); 00078 } 00079 } 00080 00081 ppy = py; 00082 py = y; 00083 } 00084 } 00085