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