1 //=========================================================
2 // MusE
3 // Linux Music Editor
4 // $Id: pitchedit.cpp,v 1.2 2004/01/09 17:12:54 wschweer Exp $
5 // (C) Copyright 2001 Werner Schweer (ws@seh.de)
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; version 2 of
10 // the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 //
21 //=========================================================
22
23 #include <stdio.h>
24 #include "pitchedit.h"
25 #include "helper.h"
26
27 namespace MusEGui {
28
29 //---------------------------------------------------------
30 // PitchEdit
31 //---------------------------------------------------------
32
PitchEdit(QWidget * parent)33 PitchEdit::PitchEdit(QWidget* parent)
34 : SpinBox(parent)
35 {
36 setMinimum(0);
37 setMaximum(127);
38 setSingleStep(1);
39 deltaMode = false;
40 }
41
42 //---------------------------------------------------------
43 // mapValueToText
44 //---------------------------------------------------------
45
textFromValue(int v) const46 QString PitchEdit::textFromValue(int v) const
47 {
48 if (deltaMode) {
49 QString s;
50 s.setNum(v);
51 return s;
52 }
53 else
54 return MusECore::pitch2string(v);
55 }
56
validate(QString & input,int &) const57 QValidator::State PitchEdit::validate(QString &input, int &) const
58 {
59 if (input.isEmpty())
60 return QValidator::Intermediate;
61
62 return MusECore::validatePitch(input);
63 }
64
65 //---------------------------------------------------------
66 // mapTextToValue
67 //---------------------------------------------------------
68
valueFromText(const QString & s) const69 int PitchEdit::valueFromText(const QString &s) const
70 {
71 // printf("PitchEdit: valueFromText: not impl.\n");
72 // //if (text)
73 // //*text = false;
74 // return 0;
75
76 if (deltaMode)
77 return s.toInt();
78 else
79 return MusECore::string2pitch(s);
80
81 }
82
83 //---------------------------------------------------------
84 // setDeltaMode
85 //---------------------------------------------------------
86
setDeltaMode(bool val)87 void PitchEdit::setDeltaMode(bool val)
88 {
89 if(deltaMode == val)
90 return;
91
92 deltaMode = val;
93 if (deltaMode)
94 setRange(-127, 127);
95 else
96 setRange(0, 127);
97 }
98
midiNote(int pitch,int velo)99 void PitchEdit::midiNote(int pitch, int velo)
100 {
101 if (hasFocus() && velo)
102 setValue(pitch);
103 }
104
105 } // namespace MusEGui
106