1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Rosegarden
5 A MIDI and audio sequencer and musical notation editor.
6 Copyright 2000-2021 the Rosegarden development team.
7
8 Other copyrights also apply to some parts of this work. Please
9 see the AUTHORS file and individual file headers for details.
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18
19 #include "MidiPitchLabel.h"
20 #include "misc/ConfigGroups.h"
21
22 #include <QApplication>
23 #include <QSettings>
24 #include <QString>
25
26
27 namespace Rosegarden
28 {
29
MidiPitchLabel(int pitch)30 MidiPitchLabel::MidiPitchLabel(int pitch)
31 {
32 // this was refactored to take advantage of these translations being
33 // available in other contexts, and to avoid extra work for translators
34 static QString notes[] = {
35 QObject::tr("C", "note name"), QObject::tr("C#", "note name"),
36 QObject::tr("D", "note name"), QObject::tr("D#", "note name"),
37 QObject::tr("E", "note name"), QObject::tr("F", "note name"),
38 QObject::tr("F#", "note name"), QObject::tr("G", "note name"),
39 QObject::tr("G#", "note name"), QObject::tr("A", "note name"),
40 QObject::tr("A#", "note name"), QObject::tr("B", "note name")
41 };
42
43 if (pitch < 0 || pitch > 127) {
44
45 m_midiNote = "";
46
47 } else {
48
49 QSettings settings;
50 settings.beginGroup( GeneralOptionsConfigGroup );
51
52 int baseOctave = settings.value("midipitchoctave", -2).toInt() ;
53
54 int octave = (int)(((float)pitch) / 12.0) + baseOctave;
55 m_midiNote = QString("%1 %2").arg(notes[pitch % 12]).arg(octave);
56
57 settings.endGroup();
58 }
59 }
60
61 std::string
getString() const62 MidiPitchLabel::getString() const
63 {
64 return std::string(m_midiNote.toUtf8().data());
65 }
66
67 QString
getQString() const68 MidiPitchLabel::getQString() const
69 {
70 return m_midiNote;
71 }
72
73 }
74