Loading...
Searching...
No Matches
MidiStyle.hpp
1#pragma once
2#include <score/model/Skin.hpp>
3
4#include <QBrush>
5#include <QGuiApplication>
6#include <QPen>
7
8#include <utility>
9
10namespace Midi
11{
13{
14 static const MidiStyle& instance() noexcept
15 {
16 static MidiStyle s;
17 return s;
18 }
19
20 MidiStyle()
21 {
22 reload();
23 QObject::connect(
24 &score::Skin::instance(), &score::Skin::changed, qApp, [this] { reload(); });
25 }
26
27 void reload()
28 {
29 auto& skin = score::Skin::instance();
30
31 noteBaseBrush = skin.Base4.main.brush;
32 noteSelectedBasePen = QPen{skin.Base2.main.brush, 2};
33 noteBasePen = QPen{skin.Base4.darker300.brush, 1};
34
35 // The rows are tints over whatever is behind the layer, not fills: the
36 // interval's bar lines in musical mode are drawn behind its processes and
37 // must show through. White keys are lighter and black keys darker than
38 // the ground, as on a keyboard: light skins swap Light and Dark (Light is
39 // the foreground), so the two are ordered by lightness.
40 QColor lighter = skin.Light.main.brush.color();
41 QColor darker = skin.Dark.main.brush.color();
42 if(lighter.lightness() < darker.lightness())
43 std::swap(lighter, darker);
44 lighter.setAlpha(14);
45 darker.setAlpha(64);
46 whiteKeyBrush = QBrush{lighter};
47 blackKeyBrush = QBrush{darker};
48 darkerBrush = skin.LightGray.main.brush;
49
50 // Row separations: faint, in the skin's foreground; stronger between B
51 // and C so the octaves read at a glance.
52 QColor fg = skin.Light.main.brush.color();
53 fg.setAlpha(16);
54 semitonePen = QPen{fg, 1};
55 semitonePen.setCosmetic(true);
56 fg.setAlpha(48);
57 octavePen = QPen{fg, 1};
58 octavePen.setCosmetic(true);
59
60 selectionPen
61 = QPen{skin.Transparent1.main.brush, 2, Qt::DashLine, Qt::SquareCap,
62 Qt::BevelJoin};
63 selectionPen.setCosmetic(true);
64
65 // The velocity ramp: the note colour at a saturation that follows the
66 // velocity, so a quiet note is washed out and a loud one is the full
67 // accent.
68 const QColor base = noteBaseBrush.color();
69 const double hue = base.hslHueF();
70 const double lightness = base.lightnessF();
71 for(std::size_t i = 0; i < std::size(paintedNoteBrush); i++)
72 {
73 QColor c = base;
74 c.setHslF(hue, 0.2 + 1.5 * i / 256., lightness);
75 paintedNoteBrush[i].setColor(c);
76 paintedNoteBrush[i].setStyle(Qt::SolidPattern);
77 }
78 }
79
80 QBrush whiteKeyBrush;
81 QBrush blackKeyBrush;
82 QBrush darkerBrush;
83 const QBrush transparentBrush{Qt::transparent};
84 QPen semitonePen;
85 QPen octavePen;
86 QPen selectionPen;
87
88 QBrush noteBaseBrush;
89 QPen noteSelectedBasePen;
90 QPen noteBasePen;
91
92 QBrush paintedNoteBrush[128];
93};
94}
Definition MidiStyle.hpp:13