]>
code.delx.au - virtualtones/blob - mainwin.cpp
243d9b07b49bbbc3e0d623330aa8209d42f7cf5d
1 // mainwin.cpp - Displays the MIDI keyboard and instrument selector
2 // Written by James Bunton <james@delx.cjb.net>
3 // Licensed under the GPL, see COPYING.txt for more details
14 setWindowTitle("Virtual Tones");
16 // Setup the MIDI output
17 midi
= new MidiReal();
18 if(midi
->initSuccess() == false) {
19 QMessageBox::critical(this, "MIDI Error", midi
->getError());
25 // Create the sound selector
26 soundSelection
= new QComboBox(this);
27 soundSelection
->setToolTip("Select the MIDI instrument to play with");
29 connect(soundSelection
, SIGNAL(activated(int)), midi
, SLOT(setInstrument(int)));
30 soundSelectionLabel
= new QLabel("Sound:", this);
32 // Setup the interface selector
33 interfaceSelection
= new QComboBox(this);
34 interfaceSelection
->setToolTip("Select the interface to play with");
35 interfaceSelection
->insertItem(0, "Piano");
36 interfaceSelection
->insertItem(1, "Violin");
37 interfaceSelection
->insertItem(2, "Viola");
38 interfaceSelection
->insertItem(3, "Cello");
39 interfaceSelection
->insertItem(4, "Contrabass");
40 connect(interfaceSelection
, SIGNAL(activated(int)), this, SLOT(interfaceSelectionSlot(int)));
42 interfaceSelectionLabel
= new QLabel("Interface:", this);
44 // Setup the octave selector
45 octaveSelection
= new QComboBox(this);
46 octaveSelection
->setToolTip("Select the starting octave");
47 for(int i
= 0; i
< 11; i
++) {
48 octaveSelection
->insertItem(i
, "Octave " + QString::number(i
- 2));
50 octaveSelectionLabel
= new QLabel("Base Octave:", this);
52 // Create the help & quit button
53 helpBtn
= new QPushButton("Help", this);
54 quitBtn
= new QPushButton("Quit", this);
55 connect(quitBtn
, SIGNAL(clicked()), qApp
, SLOT(quit()));
57 // MIDI recording buttons
58 recordBtn
= new QPushButton("Record", this);
59 recordBtn
->setToolTip("Starts a MIDI recording of the notes played");
60 recordBtn
->setEnabled(true);
61 connect(recordBtn
, SIGNAL(clicked()), SLOT(setupRecord()));
62 stopBtn
= new QPushButton("Stop", this);
63 stopBtn
->setToolTip("Stops the MIDI recording");
64 stopBtn
->setEnabled(false);
65 connect(stopBtn
, SIGNAL(clicked()), SLOT(finishRecord()));
69 aboutLabel
= new QLabel("Written for Julieanne...", this);
72 soundSelectionLayout
= new QVBoxLayout();
73 soundSelectionLayout
->addWidget(soundSelectionLabel
);
74 soundSelectionLayout
->addWidget(soundSelection
);
76 interfaceSelectionLayout
= new QVBoxLayout();
77 interfaceSelectionLayout
->addWidget(interfaceSelectionLabel
);
78 interfaceSelectionLayout
->addWidget(interfaceSelection
);
80 octaveSelectionLayout
= new QVBoxLayout();
81 octaveSelectionLayout
->addWidget(octaveSelectionLabel
);
82 octaveSelectionLayout
->addWidget(octaveSelection
);
84 midiBtnLayout
= new QVBoxLayout();
85 midiBtnLayout
->addWidget(recordBtn
);
86 midiBtnLayout
->addSpacing(5);
87 midiBtnLayout
->addWidget(stopBtn
);
89 buttonsLayout
= new QVBoxLayout();
90 buttonsLayout
->addWidget(helpBtn
);
91 buttonsLayout
->addSpacing(5);
92 buttonsLayout
->addWidget(quitBtn
);
94 optionsLayout
= new QHBoxLayout();
95 optionsLayout
->addSpacing(5);
96 optionsLayout
->addLayout(interfaceSelectionLayout
);
97 optionsLayout
->addSpacing(5);
98 optionsLayout
->addLayout(soundSelectionLayout
);
99 optionsLayout
->addSpacing(5);
100 optionsLayout
->addLayout(octaveSelectionLayout
);
101 optionsLayout
->addSpacing(5);
102 optionsLayout
->addLayout(midiBtnLayout
);
103 optionsLayout
->addSpacing(5);
104 optionsLayout
->addLayout(buttonsLayout
);
105 optionsLayout
->addSpacing(5);
107 vLayout
= new QVBoxLayout(this);
108 vLayout
->insertSpacing(0, 5);
109 vLayout
->insertLayout(1, optionsLayout
);
110 vLayout
->insertSpacing(2, 5);
111 vLayout
->insertSpacing(3, 1);// instrument goes here
112 vLayout
->insertSpacing(4, 5);
113 vLayout
->insertWidget(5, aboutLabel
);
114 vLayout
->insertSpacing(6, 5);
116 interfaceSelectionSlot(0);
128 void MainWin::setupRecord() {
130 QString filename
= QFileDialog::getSaveFileName(NULL
, "MIDI files (*.mid *.midi)");
131 if(filename
.isNull() || filename
.isEmpty())
133 midiFile
= new MidiFile(filename
);
134 if(midiFile
->initSuccess() == false) {
135 QMessageBox::warning(this, "MIDI recording error", midiFile
->getError());
139 connect(soundSelection
, SIGNAL(activated(int)), midiFile
, SLOT(setInstrument(int)));
140 connect(instrument
, SIGNAL(playNote(int, int, int)), midiFile
, SLOT(playNote(int, int, int)));
141 connect(instrument
, SIGNAL(stopNote(int)), midiFile
, SLOT(stopNote(int)));
144 recordBtn
->setEnabled(false);
145 stopBtn
->setEnabled(true);
148 void MainWin::finishRecord() {
154 recordBtn
->setEnabled(true);
155 stopBtn
->setEnabled(false);
158 void MainWin::interfaceSelectionSlot(int num
)
160 // Right now interfaces 0-4 exist
162 if(instrument
!= 0) {
163 // if(vLayout->findWidget(instrument)) {
164 // vLayout->remove(instrument);
171 // Create the instrument
175 PianoInstrument
*p
= new PianoInstrument(this);
177 // Select piano as the default
178 soundSelection
->setCurrentIndex(0);
179 midi
->setInstrument(0);
181 midiFile
->setInstrument(0);
185 ViolinInstrument
*p
= new ViolinInstrument(this);
187 // Select violin as the default
188 soundSelection
->setCurrentIndex(40);
189 midi
->setInstrument(40);
191 midiFile
->setInstrument(40);
195 ViolaInstrument
*p
= new ViolaInstrument(this);
197 // Select violin as the default
198 soundSelection
->setCurrentIndex(41);
199 midi
->setInstrument(41);
201 midiFile
->setInstrument(41);
205 CelloInstrument
*p
= new CelloInstrument(this);
207 // Select violin as the default
208 soundSelection
->setCurrentIndex(42);
209 midi
->setInstrument(42);
211 midiFile
->setInstrument(42);
215 ContrabassInstrument
*p
= new ContrabassInstrument(this);
217 // Select violin as the default
218 soundSelection
->setCurrentIndex(43);
219 midi
->setInstrument(43);
221 midiFile
->setInstrument(43);
227 vLayout
->insertWidget(3, instrument
);
228 setFixedSize(640, 640);
232 connect(instrument
, SIGNAL(playNote(int, int, int)), midi
, SLOT(playNote(int, int, int)));
233 connect(instrument
, SIGNAL(stopNote(int)), midi
, SLOT(stopNote(int)));
235 connect(instrument
, SIGNAL(playNote(int, int, int)), midiFile
, SLOT(playNote(int, int, int)));
236 connect(instrument
, SIGNAL(stopNote(int)), midiFile
, SLOT(stopNote(int)));
238 connect(helpBtn
, SIGNAL(clicked()), instrument
, SLOT(displayHelp()));
239 connect(octaveSelection
, SIGNAL(activated(int)), instrument
, SLOT(setStartOctave(int)));
241 // Set the octave widget
242 octaveSelection
->setCurrentIndex(instrument
->getNoteStart() / 12);
245 void MainWin::fillSounds()
247 soundSelection
->insertItem(0, "Acoustic Grand Piano");
248 soundSelection
->insertItem(1, "Bright Acoustic Piano");
249 soundSelection
->insertItem(2, "Electric Grand Piano");
250 soundSelection
->insertItem(3, "Honky-tonk Piano");
251 soundSelection
->insertItem(4, "Rhodes Piano");
252 soundSelection
->insertItem(5, "Chorused Piano");
253 soundSelection
->insertItem(6, "Harpsichord");
254 soundSelection
->insertItem(7, "Clavinet");
255 soundSelection
->insertItem(8, "Celesta");
256 soundSelection
->insertItem(9, "Glockenspiel");
257 soundSelection
->insertItem(10, "Music Box");
258 soundSelection
->insertItem(11, "Vibraphone");
259 soundSelection
->insertItem(12, "Marimba");
260 soundSelection
->insertItem(13, "Xylophone");
261 soundSelection
->insertItem(14, "Tubular bells");
262 soundSelection
->insertItem(15, "Dulcimer");
263 soundSelection
->insertItem(16, "Draw Organ");
264 soundSelection
->insertItem(17, "Percussive Organ");
265 soundSelection
->insertItem(18, "Rock Organ");
266 soundSelection
->insertItem(19, "Church Organ");
267 soundSelection
->insertItem(20, "Reed Organ");
268 soundSelection
->insertItem(21, "Accordion");
269 soundSelection
->insertItem(22, "Harmonica");
270 soundSelection
->insertItem(23, "Tango Accordion");
271 soundSelection
->insertItem(24, "Acoustic Nylon Guitar");
272 soundSelection
->insertItem(25, "Acoustic Steel Guitar");
273 soundSelection
->insertItem(26, "Electric Jazz Guitar");
274 soundSelection
->insertItem(27, "Electric clean Guitar");
275 soundSelection
->insertItem(28, "Electric Guitar muted");
276 soundSelection
->insertItem(29, "Overdriven Guitar");
277 soundSelection
->insertItem(30, "Distortion Guitar");
278 soundSelection
->insertItem(31, "Guitar Harmonics");
279 soundSelection
->insertItem(32, "Wood Bass");
280 soundSelection
->insertItem(33, "Electric Bass Fingered");
281 soundSelection
->insertItem(34, "Electric Bass Picked");
282 soundSelection
->insertItem(35, "Fretless Bass");
283 soundSelection
->insertItem(36, "Slap Bass 1");
284 soundSelection
->insertItem(37, "Slap Bass 2");
285 soundSelection
->insertItem(38, "Synth Bass 1");
286 soundSelection
->insertItem(39, "Synth Bass 2");
287 soundSelection
->insertItem(40, "Violin");
288 soundSelection
->insertItem(41, "Viola");
289 soundSelection
->insertItem(42, "Cello");
290 soundSelection
->insertItem(43, "Contrabass");
291 soundSelection
->insertItem(44, "Tremolo Strings");
292 soundSelection
->insertItem(45, "Pizzicato Strings");
293 soundSelection
->insertItem(46, "Orchestral Harp");
294 soundSelection
->insertItem(47, "Timpani");
295 soundSelection
->insertItem(48, "Acoustic String Ensemble 1");
296 soundSelection
->insertItem(49, "Acoustic String Ensemble 2");
297 soundSelection
->insertItem(50, "Synth Strings 1");
298 soundSelection
->insertItem(51, "Synth Strings 2");
299 soundSelection
->insertItem(52, "Aah Choir");
300 soundSelection
->insertItem(53, "Ooh Choir");
301 soundSelection
->insertItem(54, "Synvox");
302 soundSelection
->insertItem(55, "Orchestra Hit");
303 soundSelection
->insertItem(56, "Trumpet");
304 soundSelection
->insertItem(57, "Trombone");
305 soundSelection
->insertItem(58, "Tuba");
306 soundSelection
->insertItem(59, "Muted Trumpet");
307 soundSelection
->insertItem(60, "French Horn");
308 soundSelection
->insertItem(61, "Brass Section");
309 soundSelection
->insertItem(62, "Synth Brass 1");
310 soundSelection
->insertItem(63, "Synth Brass 2");
311 soundSelection
->insertItem(64, "Soprano Sax");
312 soundSelection
->insertItem(65, "Alto Sax");
313 soundSelection
->insertItem(66, "Tenor Sax");
314 soundSelection
->insertItem(67, "Baritone Sax");
315 soundSelection
->insertItem(68, "Oboe");
316 soundSelection
->insertItem(69, "English Horn");
317 soundSelection
->insertItem(70, "Bassoon");
318 soundSelection
->insertItem(71, "Clarinet");
319 soundSelection
->insertItem(72, "Piccolo");
320 soundSelection
->insertItem(73, "Flute");
321 soundSelection
->insertItem(74, "Recorder");
322 soundSelection
->insertItem(75, "Pan Flute");
323 soundSelection
->insertItem(76, "Bottle blow");
324 soundSelection
->insertItem(77, "Shakuhachi");
325 soundSelection
->insertItem(78, "Whistle");
326 soundSelection
->insertItem(79, "Ocarina");
327 soundSelection
->insertItem(80, "Square Lead");
328 soundSelection
->insertItem(81, "Saw Lead");
329 soundSelection
->insertItem(82, "Calliope");
330 soundSelection
->insertItem(83, "Chiffer");
331 soundSelection
->insertItem(84, "Synth Lead 5");
332 soundSelection
->insertItem(85, "Synth Lead 6");
333 soundSelection
->insertItem(86, "Synth Lead 7");
334 soundSelection
->insertItem(87, "Synth Lead 8");
335 soundSelection
->insertItem(88, "Synth Pad 1");
336 soundSelection
->insertItem(89, "Synth Pad 2");
337 soundSelection
->insertItem(90, "Synth Pad 3");
338 soundSelection
->insertItem(91, "Synth Pad 4");
339 soundSelection
->insertItem(92, "Synth Pad 5");
340 soundSelection
->insertItem(93, "Synth Pad 6");
341 soundSelection
->insertItem(94, "Synth Pad 7");
342 soundSelection
->insertItem(95, "Synth Pad 8");
343 soundSelection
->insertItem(96, "Ice Rain");
344 soundSelection
->insertItem(97, "Soundtracks");
345 soundSelection
->insertItem(98, "Crystal");
346 soundSelection
->insertItem(99, "Atmosphere");
347 soundSelection
->insertItem(100, "Bright");
348 soundSelection
->insertItem(101, "Goblin");
349 soundSelection
->insertItem(102, "Echoes");
350 soundSelection
->insertItem(103, "Space");
351 soundSelection
->insertItem(104, "Sitar");
352 soundSelection
->insertItem(105, "Banjo");
353 soundSelection
->insertItem(106, "Shamisen");
354 soundSelection
->insertItem(107, "Koto");
355 soundSelection
->insertItem(108, "Kalimba");
356 soundSelection
->insertItem(109, "Bagpipe");
357 soundSelection
->insertItem(110, "Fiddle");
358 soundSelection
->insertItem(111, "Shanai");
359 soundSelection
->insertItem(112, "Tinkle bell");
360 soundSelection
->insertItem(113, "Agogo");
361 soundSelection
->insertItem(114, "Steel Drums");
362 soundSelection
->insertItem(115, "Woodblock");
363 soundSelection
->insertItem(116, "Taiko Drum");
364 soundSelection
->insertItem(117, "Melodic Tom");
365 soundSelection
->insertItem(118, "Synth Tom");
366 soundSelection
->insertItem(119, "Reverse Cymbal");
367 soundSelection
->insertItem(120, "Guitar Fret Noise");
368 soundSelection
->insertItem(121, "Breath Noise");
369 soundSelection
->insertItem(122, "Seashore");
370 soundSelection
->insertItem(123, "Bird Tweet");
371 soundSelection
->insertItem(124, "Telephone Ring");
372 soundSelection
->insertItem(125, "Helicopter");
373 soundSelection
->insertItem(126, "Applause");
374 soundSelection
->insertItem(127, "Gunshot");