summaryrefslogtreecommitdiff
path: root/muse2/awl/midimslider.cpp
blob: 6aad7ab7c4e6e48b54f60b960763f143c5a64082 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//=============================================================================
//  Awl
//  Audio Widget Library
//  $Id:$
//
//  Copyright (C) 1999-2011 by Werner Schweer and others
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; version 2 of
//  the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//=============================================================================

#include "fastlog.h"
#include "midimslider.h"

#include <QPainter>
#include <QPaintEvent>

namespace Awl {

//---------------------------------------------------------
//   MidiMeterSlider
//---------------------------------------------------------

MidiMeterSlider::MidiMeterSlider(QWidget* parent)
   : Slider(parent)
      {
      setRange(0.0f, 127.0f);
      setLineStep(2);
      setPageStep(4);

      setScaleWidth(7);
      _meterWidth = _scaleWidth * 3;
      meterval = 0.0f;
      }

//---------------------------------------------------------
//   setMeterVal
//    v -  0.0 < 1.0
//---------------------------------------------------------

void MidiMeterSlider::setMeterVal(double v)
      {
      if (v < 0.001)
            v = .0f;
      if (meterval != v) {
            meterval = v;
            update();
            }
      }

//---------------------------------------------------------
//   mouseDoubleClickEvent
//---------------------------------------------------------

void MidiMeterSlider::mouseDoubleClickEvent(QMouseEvent*)
      {
      _value = _minValue;
      valueChange();
      update();
      }

//---------------------------------------------------------
//   drawScale
//---------------------------------------------------------

void MidiMeterSlider::paintEvent(QPaintEvent* ev)
      {
      int pixel = height() - sliderSize().height();
      double range = maxValue() - minValue();
      int ppos = int(pixel * (_value - minValue()) / range);
      if (_invert)
            ppos = pixel - ppos;

      QRect rr(ev->rect());
      QPainter p(this);

      QColor sc(isEnabled() ? _scaleColor : Qt::gray);
      QColor svc(isEnabled() ? _scaleValueColor : Qt::gray);
      p.setBrush(svc);

      int h  = height();
//      int kw = sliderSize().width();
      int kh = sliderSize().height();

      //---------------------------------------------------
      //    draw meter
      //---------------------------------------------------

      int mw = _meterWidth;
      int x  = 0;

      int y1 = kh / 2;
      int y2 = h - (ppos + y1);
      int y3 = h - y1;

      int mh  = h - kh;

      p.setPen(Qt::white);
      h = lrint(meterval * mh);
      if (h < 0)
            h = 0;
      else if (h > mh)
            h = mh;
      //QColor qc;
      //float v = 5.0/6.0 + 1.0/6.0 * meterval;
      //qc.setHsvF(1.0/3.0, 1.0, (v<=1.0?v:1.0));
      p.fillRect(x, y3-h, mw, h,    QBrush(0x00ff00)); // green
      //p.fillRect(x, y3-h, mw, h,    QBrush(qc)); // green get a bit darker
      p.fillRect(x, y1,   mw, mh-h, QBrush(0x007000)); // dark green
      x += mw;

      //---------------------------------------------------
      //    draw scale
      //---------------------------------------------------

//      x  += _scaleWidth/2;

//      p.setPen(QPen(sc, _scaleWidth));
//      p.drawLine(x, y1, x, y2);
//      p.setPen(QPen(svc, _scaleWidth));
//      p.drawLine(x, y2, x, y3);

      p.fillRect(x, y1, _scaleWidth, y2-y1, sc);
      p.fillRect(x, y2, _scaleWidth, y3-y2, svc);

      //---------------------------------------------------
      //    draw slider
      //---------------------------------------------------

      x  += _scaleWidth/2;
      p.setPen(QPen(svc, 0));
      p.translate(QPointF(x, y2));
      p.setRenderHint(QPainter::Antialiasing, true);
      p.drawPath(*points);
      }
}