1 //=============================================================================
2 //  MusE Score
3 //  Linux Music Score Editor
4 //
5 //  Copyright (C) 2002-2016 Werner Schweer and others
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License version 2.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #include "editpitch.h"
21 #include "musescore.h"
22 
23 namespace Ms {
24 
25 //---------------------------------------------------------
26 //   EditPitch
27 //    To select a MIDI pitch code using human-readable note names
28 //---------------------------------------------------------
29 
EditPitch(QWidget * parent)30 EditPitch::EditPitch(QWidget *parent)
31    : QDialog(parent)
32       {
33       setObjectName("EditPitchNew");
34       setupUi(this);
35       setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
36       tableWidget->setCurrentCell(tableWidget->rowCount()-1-5, 0);                    // select centre C by default
37       MuseScore::restoreGeometry(this);
38       }
39 
EditPitch(QWidget * parent,int midiCode)40 EditPitch::EditPitch(QWidget *parent, int midiCode)
41    : QDialog(parent)
42       {
43       setObjectName("EditPitchEdit");
44       setupUi(this);
45       setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
46       tableWidget->setCurrentCell(tableWidget->rowCount()-1-(midiCode/12), midiCode%12);
47       MuseScore::restoreGeometry(this);
48       }
49 
50 //---------------------------------------------------------
51 //   hideEvent
52 //---------------------------------------------------------
53 
hideEvent(QHideEvent * ev)54 void EditPitch::hideEvent(QHideEvent* ev)
55       {
56       MuseScore::saveGeometry(this);
57       QWidget::hideEvent(ev);
58       }
59 
accept()60 void EditPitch::accept()
61       {
62       on_tableWidget_cellDoubleClicked(tableWidget->currentRow(), tableWidget->currentColumn());
63       }
64 
on_tableWidget_cellDoubleClicked(int row,int col)65 void EditPitch::on_tableWidget_cellDoubleClicked(int row, int col)
66       {
67       // topmost row contains notes for 10-th MIDI octave (numbered as '9')
68       int pitch = (tableWidget->rowCount()-1 - row) * 12 + col;
69       done((pitch > 127)? 127: pitch);
70       }
71 }
72 
73