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
8namespace Midi
9{
11{
12 static const MidiStyle& instance() noexcept
13 {
14 static MidiStyle s;
15 return s;
16 }
17
18 MidiStyle()
19 {
20 reload();
21 QObject::connect(
22 &score::Skin::instance(), &score::Skin::changed, qApp, [this] { reload(); });
23 }
24
25 void reload()
26 {
27 auto& skin = score::Skin::instance();
28
29 noteBaseBrush = skin.Base4.main.brush;
30 noteSelectedBasePen = QPen{skin.Base2.main.brush, 2};
31 noteBasePen = QPen{skin.Base4.darker300.brush, 1};
32
33 lightBrush = skin.Transparent3.main.brush;
34 darkerBrush = skin.LightGray.main.brush;
35
36 darkPen = QPen{skin.Transparent2.main.brush, 1};
37 darkPen.setCosmetic(true);
38
39 selectionPen
40 = QPen{skin.Transparent1.main.brush, 2, Qt::DashLine, Qt::SquareCap,
41 Qt::BevelJoin};
42 selectionPen.setCosmetic(true);
43
44 // The velocity ramp: the note colour at a saturation that follows the
45 // velocity, so a quiet note is washed out and a loud one is the full
46 // accent.
47 const QColor base = noteBaseBrush.color();
48 const double hue = base.hslHueF();
49 const double lightness = base.lightnessF();
50 for(std::size_t i = 0; i < std::size(paintedNoteBrush); i++)
51 {
52 QColor c = base;
53 c.setHslF(hue, 0.2 + 1.5 * i / 256., lightness);
54 paintedNoteBrush[i].setColor(c);
55 paintedNoteBrush[i].setStyle(Qt::SolidPattern);
56 }
57 }
58
59 QBrush lightBrush;
60 QBrush darkerBrush;
61 const QBrush transparentBrush{Qt::transparent};
62 QPen darkPen;
63 QPen selectionPen;
64
65 QBrush noteBaseBrush;
66 QPen noteSelectedBasePen;
67 QPen noteBasePen;
68
69 QBrush paintedNoteBrush[128];
70};
71}
Definition MidiStyle.hpp:11