]>
code.delx.au - virtualtones/blob - instrument.cpp
1 // instrument.cpp - An instrument widget
2 // Written by James Bunton <james@delx.net.au>
3 // Licensed under the GPL, see COPYING.txt for more details
6 #include "instrument.h"
11 Instrument::Instrument(QWidget
*parent
)
16 setFocusPolicy(StrongFocus
);
21 // Initialise the base midi notes array
22 midnotes
[0] = QString("C");
23 midnotes
[1] = QString("C#");
24 midnotes
[2] = QString("D");
25 midnotes
[3] = QString("D#");
26 midnotes
[4] = QString("E");
27 midnotes
[5] = QString("F");
28 midnotes
[6] = QString("F#");
29 midnotes
[7] = QString("G");
30 midnotes
[8] = QString("G#");
31 midnotes
[9] = QString("A");
32 midnotes
[10] = QString("A#");
33 midnotes
[11] = QString("B");
36 Instrument::~Instrument()
41 void Instrument::displayHelp()
43 QMessageBox::information(this, "Help", generateHelp());
46 bool Instrument::setNoteStart(int note
)
48 if(note
% 12 == 0 && noteStart
>= 0 && noteStart
<= 127) {
53 // printf("noteStart=%d is invalid\n", note);
58 int Instrument::getNoteStart()
63 void Instrument::setStartOctave(int octave
)
65 if(setNoteStart((octave
) * 12) == false) {
66 QMessageBox::warning(parentWidget(), "Error", "Could not set octave. This shouldn't happen!");
70 void Instrument::focusOutEvent(QFocusEvent
*)
75 bool Instrument::event(QEvent
*e
)
77 if(e
->type() == QEvent::KeyPress
) {
78 QKeyEvent
*k
= (QKeyEvent
*)e
;
80 if(k
->isAccepted() == true) {
84 else if(e
->type() == QEvent::KeyRelease
) {
85 QKeyEvent
*k
= (QKeyEvent
*)e
;
87 if(k
->isAccepted() == true) {
92 return QWidget::event(e
);
95 QString
Instrument::midi2string(int num
)
98 for(octave
= 0; num
>= 12; octave
++) {
101 return QString(midnotes
[num
] + " - Octave: " + QString::number(octave
- 2)); // Middle C is then "C - Octave: 3"
104 bool Instrument::checkSharp(int note
)
106 // This misnamed function checks to see if we are of the the following notes. Useful for string instruments
107 // These are the notes with only a half-tone gap between them
108 //1 13 25 37 49 61 73 85 97 109 121
109 //6 18 30 42 54 66 78 90 102 114 126
110 if((note
- 1) % 12 == 0 || note
- 1 == 0)
112 if((note
- 6) % 12 == 0 || note
- 6 == 0)