|
From: Lasse Kärkkäi. <tr...@us...> - 2011-02-23 11:44:02
|
Author: Lasse Kärkkäinen <tronic+ndrm at trn.iki.fi> Date: Wed Feb 23 12:43:49 2011 +0100 Fixes to piano rendering --- editorapp.cc | 11 ++++++----- notes.cc | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/editorapp.cc b/editorapp.cc index a8ce3f8..44196cf 100644 --- a/editorapp.cc +++ b/editorapp.cc @@ -949,20 +949,21 @@ void Piano::updatePixmap(int noteHeight) painter.setPen(pen); int y; int w = image.width(); - for (int i = 0; i < notes; ++i) { + // Render only the white keys first + for (int i = -1; i < notes; ++i) { if (scale.isSharp(i)) continue; int y2 = image.height() - i * noteHeight; // Note center y y2 -= (scale.isSharp(i + 1) ? 1.0 : 0.5) * noteHeight; // Key top y // Skip the first key because y hasn't been calculated yet - if (i > 0) { - bool sh = false; + if (i > -1) { painter.fillRect(0, y2, w, y - y2, QColor("#ffffff")); painter.drawRect(0, y2, w, y - y2); } y = y2; // The next key bottom y } - w /= 2; // Half length black keys - for (int i = 1; i < notes; ++i) { + // Now render the black keys + w *= 0.6; + for (int i = 0; i < notes; ++i) { if (!scale.isSharp(i)) continue; y = image.height() - i*noteHeight - noteHeight / 2; painter.fillRect(0, y, w, noteHeight, QColor("#000000")); diff --git a/notes.cc b/notes.cc index 94a9ba2..51b5cf6 100644 --- a/notes.cc +++ b/notes.cc @@ -25,9 +25,10 @@ unsigned int MusicalScale::getNoteNum(int id) const { } bool MusicalScale::isSharp(int id) const { - if (id < 0) throw std::logic_error("MusicalScale::isSharp: Invalid note ID"); + id %= 12; + if (id < 0) id += 12; // Fix the modulus of a negative value // C major scale - switch (id % 12) { + switch (id) { case 1: case 3: case 6: case 8: case 10: return true; } return false; |