Updated to modern Qt
authorJames Bunton <jamesbunton@delx.net.au>
Sun, 12 Mar 2017 12:37:59 +0000 (23:37 +1100)
committerJames Bunton <jamesbunton@delx.net.au>
Mon, 13 Mar 2017 01:48:35 +0000 (12:48 +1100)
14 files changed:
.editorconfig [new file with mode: 0644]
.gitignore [new file with mode: 0644]
instrument.cpp
main.cpp
mainwin.cpp
mainwin.h
midiengine.cpp
midiengine.h
pianoinstrument.cpp
pianoinstrument.h
resources.qrc [new file with mode: 0644]
stringinstrument.cpp
stringinstrument.h
vtones.pro

diff --git a/.editorconfig b/.editorconfig
new file mode 100644 (file)
index 0000000..08bb77c
--- /dev/null
@@ -0,0 +1,12 @@
+# EditorConfig is awesome: http://EditorConfig.org
+
+# top-most EditorConfig file
+root = true
+
+[**]
+end_of_line = lf
+insert_final_newline = true
+charset = utf-8
+indent_style = tab
+trim_trailing_whitespace = true
+indent_size = 8
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..db9d875
--- /dev/null
@@ -0,0 +1,3 @@
+build
+.qmake.*
+Makefile
index b4e7296..0ebf341 100644 (file)
@@ -5,6 +5,8 @@
 
 #include "instrument.h"
 
+using namespace Qt;
+
 
 Instrument::Instrument(QWidget *parent)
 : QWidget(parent, 0)
@@ -112,5 +114,3 @@ bool Instrument::checkSharp(int note)
 
        return false;
 }
-
-
index f4f9bcf..29a3829 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -2,15 +2,13 @@
 // Written by James Bunton <james@delx.cjb.net>
 // Licensed under the GPL, see COPYING.txt for more details
 
-#include <qapplication.h>
+#include <QApplication>
 #include "mainwin.h"
 
 int main(int argc, char **argv)
 {
        QApplication a(argc, argv);
        MainWin w;
-       a.setMainWidget(&w);
+       QObject::connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
        return a.exec();
 }
-
-
index d7796c9..243d9b0 100644 (file)
@@ -5,11 +5,13 @@
 
 #include "mainwin.h"
 
+using namespace Qt;
+
 
 MainWin::MainWin()
 : QWidget(0,0)
 {
-       setCaption("Virtual Tones");
+       setWindowTitle("Virtual Tones");
 
        // Setup the MIDI output
        midi = new MidiReal();
@@ -21,29 +23,29 @@ MainWin::MainWin()
        midiFile = 0;
 
        // Create the sound selector
-       soundSelection = new QComboBox(false, this);
-       QToolTip::add(soundSelection, "Select the MIDI instrument to play with");
+       soundSelection = new QComboBox(this);
+       soundSelection->setToolTip("Select the MIDI instrument to play with");
        fillSounds();
        connect(soundSelection, SIGNAL(activated(int)), midi, SLOT(setInstrument(int)));
        soundSelectionLabel = new QLabel("Sound:", this);
 
        // Setup the interface selector
-       interfaceSelection = new QComboBox(false, this);
-       QToolTip::add(interfaceSelection, "Select the interface to play with");
-       interfaceSelection->insertItem("Piano", 0);
-       interfaceSelection->insertItem("Violin", 1);
-       interfaceSelection->insertItem("Viola", 2);
-       interfaceSelection->insertItem("Cello", 3);
-       interfaceSelection->insertItem("Contrabass", 4);
+       interfaceSelection = new QComboBox(this);
+       interfaceSelection->setToolTip("Select the interface to play with");
+       interfaceSelection->insertItem(0, "Piano");
+       interfaceSelection->insertItem(1, "Violin");
+       interfaceSelection->insertItem(2, "Viola");
+       interfaceSelection->insertItem(3, "Cello");
+       interfaceSelection->insertItem(4, "Contrabass");
        connect(interfaceSelection, SIGNAL(activated(int)), this, SLOT(interfaceSelectionSlot(int)));
        instrument = 0;
        interfaceSelectionLabel = new QLabel("Interface:", this);
 
        // Setup the octave selector
-       octaveSelection = new QComboBox(false, this);
-       QToolTip::add(octaveSelection, "Select the starting octave");
+       octaveSelection = new QComboBox(this);
+       octaveSelection->setToolTip("Select the starting octave");
        for(int i = 0; i < 11; i++) {
-               octaveSelection->insertItem("Octave " + QString::number(i - 2), i);
+               octaveSelection->insertItem(i, "Octave " + QString::number(i - 2));
        }
        octaveSelectionLabel = new QLabel("Base Octave:", this);
 
@@ -54,11 +56,11 @@ MainWin::MainWin()
 
        // MIDI recording buttons
        recordBtn = new QPushButton("Record", this);
-       QToolTip::add(recordBtn, "Starts a MIDI recording of the notes played");
+       recordBtn->setToolTip("Starts a MIDI recording of the notes played");
        recordBtn->setEnabled(true);
        connect(recordBtn, SIGNAL(clicked()), SLOT(setupRecord()));
        stopBtn = new QPushButton("Stop", this);
-       QToolTip::add(stopBtn, "Stops the MIDI recording");
+       stopBtn->setToolTip("Stops the MIDI recording");
        stopBtn->setEnabled(false);
        connect(stopBtn, SIGNAL(clicked()), SLOT(finishRecord()));
 
@@ -125,7 +127,7 @@ MainWin::~MainWin()
 
 void MainWin::setupRecord() {
        if(midiFile == 0) {
-               QString filename = QFileDialog::getSaveFileName(QString::null, "MIDI files (*.mid *.midi)", this);
+               QString filename = QFileDialog::getSaveFileName(NULL, "MIDI files (*.mid *.midi)");
                if(filename.isNull() || filename.isEmpty())
                        return;
                midiFile = new MidiFile(filename);
@@ -173,7 +175,7 @@ void MainWin::interfaceSelectionSlot(int num)
                PianoInstrument *p = new PianoInstrument(this);
                instrument = p;
                // Select piano as the default
-               soundSelection->setCurrentItem(0);
+               soundSelection->setCurrentIndex(0);
                midi->setInstrument(0);
                if(midiFile != 0)
                        midiFile->setInstrument(0);
@@ -183,7 +185,7 @@ void MainWin::interfaceSelectionSlot(int num)
                ViolinInstrument *p = new ViolinInstrument(this);
                instrument = p;
                // Select violin as the default
-               soundSelection->setCurrentItem(40);
+               soundSelection->setCurrentIndex(40);
                midi->setInstrument(40);
                if(midiFile != 0)
                        midiFile->setInstrument(40);
@@ -193,7 +195,7 @@ void MainWin::interfaceSelectionSlot(int num)
                ViolaInstrument *p = new ViolaInstrument(this);
                instrument = p;
                // Select violin as the default
-               soundSelection->setCurrentItem(41);
+               soundSelection->setCurrentIndex(41);
                midi->setInstrument(41);
                if(midiFile != 0)
                        midiFile->setInstrument(41);
@@ -203,7 +205,7 @@ void MainWin::interfaceSelectionSlot(int num)
                CelloInstrument *p = new CelloInstrument(this);
                instrument = p;
                // Select violin as the default
-               soundSelection->setCurrentItem(42);
+               soundSelection->setCurrentIndex(42);
                midi->setInstrument(42);
                if(midiFile != 0)
                        midiFile->setInstrument(42);
@@ -213,7 +215,7 @@ void MainWin::interfaceSelectionSlot(int num)
                ContrabassInstrument *p = new ContrabassInstrument(this);
                instrument = p;
                // Select violin as the default
-               soundSelection->setCurrentItem(43);
+               soundSelection->setCurrentIndex(43);
                midi->setInstrument(43);
                if(midiFile != 0)
                        midiFile->setInstrument(43);
@@ -223,6 +225,7 @@ void MainWin::interfaceSelectionSlot(int num)
 
        // Relayout
        vLayout->insertWidget(3, instrument);
+       setFixedSize(640, 640);
        instrument->show();
 
        // Connect signals
@@ -236,139 +239,138 @@ void MainWin::interfaceSelectionSlot(int num)
        connect(octaveSelection, SIGNAL(activated(int)), instrument, SLOT(setStartOctave(int)));
 
        // Set the octave widget
-       octaveSelection->setCurrentItem(instrument->getNoteStart() / 12);
+       octaveSelection->setCurrentIndex(instrument->getNoteStart() / 12);
 }
 
 void MainWin::fillSounds()
 {
-       soundSelection->insertItem("Acoustic Grand Piano", 0);
-       soundSelection->insertItem("Bright Acoustic Piano", 1);
-       soundSelection->insertItem("Electric Grand Piano", 2);
-       soundSelection->insertItem("Honky-tonk Piano", 3);
-       soundSelection->insertItem("Rhodes Piano", 4);
-       soundSelection->insertItem("Chorused Piano", 5);
-       soundSelection->insertItem("Harpsichord", 6);
-       soundSelection->insertItem("Clavinet", 7);
-       soundSelection->insertItem("Celesta", 8);
-       soundSelection->insertItem("Glockenspiel", 9);
-       soundSelection->insertItem("Music Box", 10);
-       soundSelection->insertItem("Vibraphone", 11);
-       soundSelection->insertItem("Marimba", 12);
-       soundSelection->insertItem("Xylophone", 13);
-       soundSelection->insertItem("Tubular bells", 14);
-       soundSelection->insertItem("Dulcimer", 15);
-       soundSelection->insertItem("Draw Organ", 16);
-       soundSelection->insertItem("Percussive Organ", 17);
-       soundSelection->insertItem("Rock Organ", 18);
-       soundSelection->insertItem("Church Organ", 19);
-       soundSelection->insertItem("Reed Organ", 20);
-       soundSelection->insertItem("Accordion", 21);
-       soundSelection->insertItem("Harmonica", 22);
-       soundSelection->insertItem("Tango Accordion", 23);
-       soundSelection->insertItem("Acoustic Nylon Guitar", 24);
-       soundSelection->insertItem("Acoustic Steel Guitar", 25);
-       soundSelection->insertItem("Electric Jazz Guitar", 26);
-       soundSelection->insertItem("Electric clean Guitar", 27);
-       soundSelection->insertItem("Electric Guitar muted", 28);
-       soundSelection->insertItem("Overdriven Guitar", 29);
-       soundSelection->insertItem("Distortion Guitar", 30);
-       soundSelection->insertItem("Guitar Harmonics", 31);
-       soundSelection->insertItem("Wood Bass", 32);
-       soundSelection->insertItem("Electric Bass Fingered", 33);
-       soundSelection->insertItem("Electric Bass Picked", 34);
-       soundSelection->insertItem("Fretless Bass", 35);
-       soundSelection->insertItem("Slap Bass 1", 36);
-       soundSelection->insertItem("Slap Bass 2", 37);
-       soundSelection->insertItem("Synth Bass 1", 38);
-       soundSelection->insertItem("Synth Bass 2", 39);
-       soundSelection->insertItem("Violin", 40);
-       soundSelection->insertItem("Viola", 41);
-       soundSelection->insertItem("Cello", 42);
-       soundSelection->insertItem("Contrabass", 43);
-       soundSelection->insertItem("Tremolo Strings", 44);
-       soundSelection->insertItem("Pizzicato Strings", 45);
-       soundSelection->insertItem("Orchestral Harp", 46);
-       soundSelection->insertItem("Timpani", 47);
-       soundSelection->insertItem("Acoustic String Ensemble 1", 48);
-       soundSelection->insertItem("Acoustic String Ensemble 2", 49);
-       soundSelection->insertItem("Synth Strings 1", 50);
-       soundSelection->insertItem("Synth Strings 2", 51);
-       soundSelection->insertItem("Aah Choir", 52);
-       soundSelection->insertItem("Ooh Choir", 53);
-       soundSelection->insertItem("Synvox", 54);
-       soundSelection->insertItem("Orchestra Hit", 55);
-       soundSelection->insertItem("Trumpet", 56);
-       soundSelection->insertItem("Trombone", 57);
-       soundSelection->insertItem("Tuba", 58);
-       soundSelection->insertItem("Muted Trumpet", 59);
-       soundSelection->insertItem("French Horn", 60);
-       soundSelection->insertItem("Brass Section", 61);
-       soundSelection->insertItem("Synth Brass 1", 62);
-       soundSelection->insertItem("Synth Brass 2", 63);
-       soundSelection->insertItem("Soprano Sax", 64);
-       soundSelection->insertItem("Alto Sax", 65);
-       soundSelection->insertItem("Tenor Sax", 66);
-       soundSelection->insertItem("Baritone Sax", 67);
-       soundSelection->insertItem("Oboe", 68);
-       soundSelection->insertItem("English Horn", 69);
-       soundSelection->insertItem("Bassoon", 70);
-       soundSelection->insertItem("Clarinet", 71);
-       soundSelection->insertItem("Piccolo", 72);
-       soundSelection->insertItem("Flute", 73);
-       soundSelection->insertItem("Recorder", 74);
-       soundSelection->insertItem("Pan Flute", 75);
-       soundSelection->insertItem("Bottle blow", 76);
-       soundSelection->insertItem("Shakuhachi", 77);
-       soundSelection->insertItem("Whistle", 78);
-       soundSelection->insertItem("Ocarina", 79);
-       soundSelection->insertItem("Square Lead", 80);
-       soundSelection->insertItem("Saw Lead", 81);
-       soundSelection->insertItem("Calliope", 82);
-       soundSelection->insertItem("Chiffer", 83);
-       soundSelection->insertItem("Synth Lead 5", 84);
-       soundSelection->insertItem("Synth Lead 6", 85);
-       soundSelection->insertItem("Synth Lead 7", 86);
-       soundSelection->insertItem("Synth Lead 8", 87);
-       soundSelection->insertItem("Synth Pad 1", 88);
-       soundSelection->insertItem("Synth Pad 2", 89);
-       soundSelection->insertItem("Synth Pad 3", 90);
-       soundSelection->insertItem("Synth Pad 4", 91);
-       soundSelection->insertItem("Synth Pad 5", 92);
-       soundSelection->insertItem("Synth Pad 6", 93);
-       soundSelection->insertItem("Synth Pad 7", 94);
-       soundSelection->insertItem("Synth Pad 8", 95);
-       soundSelection->insertItem("Ice Rain", 96);
-       soundSelection->insertItem("Soundtracks", 97);
-       soundSelection->insertItem("Crystal", 98);
-       soundSelection->insertItem("Atmosphere", 99);
-       soundSelection->insertItem("Bright", 100);
-       soundSelection->insertItem("Goblin", 101);
-       soundSelection->insertItem("Echoes", 102);
-       soundSelection->insertItem("Space", 103);
-       soundSelection->insertItem("Sitar", 104);
-       soundSelection->insertItem("Banjo", 105);
-       soundSelection->insertItem("Shamisen", 106);
-       soundSelection->insertItem("Koto", 107);
-       soundSelection->insertItem("Kalimba", 108);
-       soundSelection->insertItem("Bagpipe", 109);
-       soundSelection->insertItem("Fiddle", 110);
-       soundSelection->insertItem("Shanai", 111);
-       soundSelection->insertItem("Tinkle bell", 112);
-       soundSelection->insertItem("Agogo", 113);
-       soundSelection->insertItem("Steel Drums", 114);
-       soundSelection->insertItem("Woodblock", 115);
-       soundSelection->insertItem("Taiko Drum", 116);
-       soundSelection->insertItem("Melodic Tom", 117);
-       soundSelection->insertItem("Synth Tom", 118);
-       soundSelection->insertItem("Reverse Cymbal", 119);
-       soundSelection->insertItem("Guitar Fret Noise", 120);
-       soundSelection->insertItem("Breath Noise", 121);
-       soundSelection->insertItem("Seashore", 122);
-       soundSelection->insertItem("Bird Tweet", 123);
-       soundSelection->insertItem("Telephone Ring", 124);
-       soundSelection->insertItem("Helicopter", 125);
-       soundSelection->insertItem("Applause", 126);
-       soundSelection->insertItem("Gunshot", 127);
+       soundSelection->insertItem(0, "Acoustic Grand Piano");
+       soundSelection->insertItem(1, "Bright Acoustic Piano");
+       soundSelection->insertItem(2, "Electric Grand Piano");
+       soundSelection->insertItem(3, "Honky-tonk Piano");
+       soundSelection->insertItem(4, "Rhodes Piano");
+       soundSelection->insertItem(5, "Chorused Piano");
+       soundSelection->insertItem(6, "Harpsichord");
+       soundSelection->insertItem(7, "Clavinet");
+       soundSelection->insertItem(8, "Celesta");
+       soundSelection->insertItem(9, "Glockenspiel");
+       soundSelection->insertItem(10, "Music Box");
+       soundSelection->insertItem(11, "Vibraphone");
+       soundSelection->insertItem(12, "Marimba");
+       soundSelection->insertItem(13, "Xylophone");
+       soundSelection->insertItem(14, "Tubular bells");
+       soundSelection->insertItem(15, "Dulcimer");
+       soundSelection->insertItem(16, "Draw Organ");
+       soundSelection->insertItem(17, "Percussive Organ");
+       soundSelection->insertItem(18, "Rock Organ");
+       soundSelection->insertItem(19, "Church Organ");
+       soundSelection->insertItem(20, "Reed Organ");
+       soundSelection->insertItem(21, "Accordion");
+       soundSelection->insertItem(22, "Harmonica");
+       soundSelection->insertItem(23, "Tango Accordion");
+       soundSelection->insertItem(24, "Acoustic Nylon Guitar");
+       soundSelection->insertItem(25, "Acoustic Steel Guitar");
+       soundSelection->insertItem(26, "Electric Jazz Guitar");
+       soundSelection->insertItem(27, "Electric clean Guitar");
+       soundSelection->insertItem(28, "Electric Guitar muted");
+       soundSelection->insertItem(29, "Overdriven Guitar");
+       soundSelection->insertItem(30, "Distortion Guitar");
+       soundSelection->insertItem(31, "Guitar Harmonics");
+       soundSelection->insertItem(32, "Wood Bass");
+       soundSelection->insertItem(33, "Electric Bass Fingered");
+       soundSelection->insertItem(34, "Electric Bass Picked");
+       soundSelection->insertItem(35, "Fretless Bass");
+       soundSelection->insertItem(36, "Slap Bass 1");
+       soundSelection->insertItem(37, "Slap Bass 2");
+       soundSelection->insertItem(38, "Synth Bass 1");
+       soundSelection->insertItem(39, "Synth Bass 2");
+       soundSelection->insertItem(40, "Violin");
+       soundSelection->insertItem(41, "Viola");
+       soundSelection->insertItem(42, "Cello");
+       soundSelection->insertItem(43, "Contrabass");
+       soundSelection->insertItem(44, "Tremolo Strings");
+       soundSelection->insertItem(45, "Pizzicato Strings");
+       soundSelection->insertItem(46, "Orchestral Harp");
+       soundSelection->insertItem(47, "Timpani");
+       soundSelection->insertItem(48, "Acoustic String Ensemble 1");
+       soundSelection->insertItem(49, "Acoustic String Ensemble 2");
+       soundSelection->insertItem(50, "Synth Strings 1");
+       soundSelection->insertItem(51, "Synth Strings 2");
+       soundSelection->insertItem(52, "Aah Choir");
+       soundSelection->insertItem(53, "Ooh Choir");
+       soundSelection->insertItem(54, "Synvox");
+       soundSelection->insertItem(55, "Orchestra Hit");
+       soundSelection->insertItem(56, "Trumpet");
+       soundSelection->insertItem(57, "Trombone");
+       soundSelection->insertItem(58, "Tuba");
+       soundSelection->insertItem(59, "Muted Trumpet");
+       soundSelection->insertItem(60, "French Horn");
+       soundSelection->insertItem(61, "Brass Section");
+       soundSelection->insertItem(62, "Synth Brass 1");
+       soundSelection->insertItem(63, "Synth Brass 2");
+       soundSelection->insertItem(64, "Soprano Sax");
+       soundSelection->insertItem(65, "Alto Sax");
+       soundSelection->insertItem(66, "Tenor Sax");
+       soundSelection->insertItem(67, "Baritone Sax");
+       soundSelection->insertItem(68, "Oboe");
+       soundSelection->insertItem(69, "English Horn");
+       soundSelection->insertItem(70, "Bassoon");
+       soundSelection->insertItem(71, "Clarinet");
+       soundSelection->insertItem(72, "Piccolo");
+       soundSelection->insertItem(73, "Flute");
+       soundSelection->insertItem(74, "Recorder");
+       soundSelection->insertItem(75, "Pan Flute");
+       soundSelection->insertItem(76, "Bottle blow");
+       soundSelection->insertItem(77, "Shakuhachi");
+       soundSelection->insertItem(78, "Whistle");
+       soundSelection->insertItem(79, "Ocarina");
+       soundSelection->insertItem(80, "Square Lead");
+       soundSelection->insertItem(81, "Saw Lead");
+       soundSelection->insertItem(82, "Calliope");
+       soundSelection->insertItem(83, "Chiffer");
+       soundSelection->insertItem(84, "Synth Lead 5");
+       soundSelection->insertItem(85, "Synth Lead 6");
+       soundSelection->insertItem(86, "Synth Lead 7");
+       soundSelection->insertItem(87, "Synth Lead 8");
+       soundSelection->insertItem(88, "Synth Pad 1");
+       soundSelection->insertItem(89, "Synth Pad 2");
+       soundSelection->insertItem(90, "Synth Pad 3");
+       soundSelection->insertItem(91, "Synth Pad 4");
+       soundSelection->insertItem(92, "Synth Pad 5");
+       soundSelection->insertItem(93, "Synth Pad 6");
+       soundSelection->insertItem(94, "Synth Pad 7");
+       soundSelection->insertItem(95, "Synth Pad 8");
+       soundSelection->insertItem(96, "Ice Rain");
+       soundSelection->insertItem(97, "Soundtracks");
+       soundSelection->insertItem(98, "Crystal");
+       soundSelection->insertItem(99, "Atmosphere");
+       soundSelection->insertItem(100, "Bright");
+       soundSelection->insertItem(101, "Goblin");
+       soundSelection->insertItem(102, "Echoes");
+       soundSelection->insertItem(103, "Space");
+       soundSelection->insertItem(104, "Sitar");
+       soundSelection->insertItem(105, "Banjo");
+       soundSelection->insertItem(106, "Shamisen");
+       soundSelection->insertItem(107, "Koto");
+       soundSelection->insertItem(108, "Kalimba");
+       soundSelection->insertItem(109, "Bagpipe");
+       soundSelection->insertItem(110, "Fiddle");
+       soundSelection->insertItem(111, "Shanai");
+       soundSelection->insertItem(112, "Tinkle bell");
+       soundSelection->insertItem(113, "Agogo");
+       soundSelection->insertItem(114, "Steel Drums");
+       soundSelection->insertItem(115, "Woodblock");
+       soundSelection->insertItem(116, "Taiko Drum");
+       soundSelection->insertItem(117, "Melodic Tom");
+       soundSelection->insertItem(118, "Synth Tom");
+       soundSelection->insertItem(119, "Reverse Cymbal");
+       soundSelection->insertItem(120, "Guitar Fret Noise");
+       soundSelection->insertItem(121, "Breath Noise");
+       soundSelection->insertItem(122, "Seashore");
+       soundSelection->insertItem(123, "Bird Tweet");
+       soundSelection->insertItem(124, "Telephone Ring");
+       soundSelection->insertItem(125, "Helicopter");
+       soundSelection->insertItem(126, "Applause");
+       soundSelection->insertItem(127, "Gunshot");
 
 }
-
index d1ee828..5a16e51 100644 (file)
--- a/mainwin.h
+++ b/mainwin.h
@@ -7,16 +7,16 @@
 #ifndef MAINWIN_H
 #define MAINWIN_H
 
-#include <qapplication.h>
-#include <qmessagebox.h>
-#include <qcombobox.h>
-#include <qlabel.h>
-#include <qpushbutton.h>
-#include <qlayout.h>
-#include <qfiledialog.h>
-#include <qtooltip.h>
-
-#include <stdlib.h>
+#include <QApplication>
+#include <QMessageBox>
+#include <QComboBox>
+#include <QLabel>
+#include <QPushButton>
+#include <QLayout>
+#include <QFileDialog>
+#include <QToolTip>
+
+#include <cstdlib>
 
 #include "instrument.h"
 #include "stringinstrument.h"
index 1ba3299..5972527 100644 (file)
@@ -5,6 +5,13 @@
 
 #include "midiengine.h"
 
+#include <cstdio>
+
+#include <QList>
+
+
+using namespace Qt;
+
 
 /* |---------------------------| */
 /* | Code for class MidiEngine | */
@@ -60,7 +67,7 @@ void MidiEngine::timerEvent(QTimerEvent *)
 
 /* Linux code */
 
-#ifdef Q_WS_X11
+#ifdef Q_OS_LINUX
 
 #include <linux/soundcard.h>
 #include <sys/ioctl.h>
@@ -82,7 +89,7 @@ MidiReal::MidiReal()
 {
        // Use to set the sequencer and device
        QString dev = "/dev/sequencer";
-       int devicenum = 0;
+       int devicenum = 1;
 
        d = new Private();
 
@@ -93,7 +100,7 @@ MidiReal::MidiReal()
        timer = 0;
 
        // Open the sequencer file
-       d->seqfd = open(d->seqDevice.latin1(), O_WRONLY, 0);
+       d->seqfd = open(d->seqDevice.toLatin1(), O_WRONLY, 0);
        if (d->seqfd < 0) {
                errorMessage = "Cannot open sequencer: " + d->seqDevice;
                return;
@@ -208,7 +215,7 @@ bool MidiReal::playNote(int num, int vel, int len)
 
 /* Windows code */
 
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
 
 #include <windows.h>
 #include <mmsystem.h>
@@ -323,10 +330,6 @@ bool MidiReal::playNote(int num, int vel, int len)
 /* |-------------------------| */
 
 
-#include <stdio.h>
-
-#include <qvaluelist.h>
-
 
 
 
@@ -368,7 +371,7 @@ public:
 
 
        /* A place to store the MTrk_Packets as we wait for them */
-       QValueList<struct MTrk_Packet> packets;
+       QList<struct MTrk_Packet> packets;
 
        /* The time the last note was played, relative to MidiEngine::timer */
        long int prevNoteTime;
@@ -476,7 +479,7 @@ void MidiFile::Private::writeMIDI()
 
 
        // Store the MIDI packets in the MTrk chunk
-       QValueList<struct MTrk_Packet>::Iterator it;
+       QList<struct MTrk_Packet>::Iterator it;
        int pos = 0;
        for(it = packets.begin(); it != packets.end(); ++it) {
                // Twist the deltaTime, then copy it
@@ -544,7 +547,7 @@ MidiFile::MidiFile(QString file)
        d->prevNoteTime = -1;
 
        // Open the MIDI file to send output to
-       d->file = fopen(d->filename.latin1(), "wb");
+       d->file = fopen(d->filename.toLatin1(), "wb");
        if (d->file == 0) {
                errorMessage = "Cannot open output MIDI file: " + d->filename;
                return;
@@ -649,5 +652,3 @@ bool MidiFile::playNote(int num, int vel, int len)
 
        return true;
 }
-
-
index ea5931e..9045a96 100644 (file)
@@ -7,9 +7,9 @@
 #define MIDIENGINE_H
 
 
-#include <qobject.h>
-#include <qevent.h>
-#include <qstring.h>
+#include <QObject>
+#include <QEvent>
+#include <QString>
 
 
 class MidiEngine : public QObject
@@ -98,4 +98,3 @@ Q_OBJECT
 
 
 #endif
-
index 127d9e1..0fea76f 100644 (file)
@@ -5,21 +5,16 @@
 
 #include "pianoinstrument.h"
 
-
+using namespace Qt;
 
 
 PianoInstrument::PianoInstrument(QWidget *parent)
 : Instrument(parent)
 {
-       // Set us up to look pretty
-       setPaletteBackgroundPixmap(QPixmap("piano.png"));
-       setFixedSize(184, 220);
-       parentWidget()->setFixedSize(184, 220);
+       background.load("piano.png");
 
-       for(int i = 0; i < 26; i++) {
-               oldNotes[i] = false;
-               notes[i] = false;
-       }
+       memset(oldNotes, 0, sizeof(oldNotes));
+       memset(notes, 0, sizeof(notes));
 
        noteStart = 48;
 
@@ -57,6 +52,9 @@ QString PianoInstrument::generateHelp()
 void PianoInstrument::paintEvent(QPaintEvent *)
 {
        QPainter paint(this);
+
+       paint.drawPixmap(0, 0, background);
+
        paint.setPen(Qt::red);
 
        const int topBlackY = 38;
@@ -385,4 +383,3 @@ void PianoInstrument::emitSounds()
 
        repaint();
 }
-
index 53f823b..6ece085 100644 (file)
@@ -6,9 +6,9 @@
 #ifndef PIANOINSTRUMENT_H
 #define PIANOINSTRUMENT_H
 
-#include <qwidget.h>
-#include <qpixmap.h>
-#include <qpainter.h>
+#include <QWidget>
+#include <QPixmap>
+#include <QPainter>
 
 #include "instrument.h"
 
@@ -31,6 +31,8 @@ Q_OBJECT
                void copyArray(bool source[26], bool dest[26]);
                void emitSounds();
 
+               QPixmap background;
+
                bool oldNotes[26];
                bool notes[26];
 };
diff --git a/resources.qrc b/resources.qrc
new file mode 100644 (file)
index 0000000..291b75e
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC>
+<RCC version="1.0">
+<qresource prefix="/">
+          <file>piano.png</file>
+          <file>violin.png</file>
+          <file>viola.png</file>
+          <file>cello.png</file>
+          <file>contrabass.png</file>
+</qresource>
+</RCC>
index 8d369a1..c047520 100644 (file)
@@ -5,6 +5,8 @@
 
 #include "stringinstrument.h"
 
+using namespace Qt;
+
 // Images from http://www.asinari.it/bassoeng.htm
 
 ViolinInstrument::ViolinInstrument(QWidget *parent)
@@ -12,10 +14,7 @@ ViolinInstrument::ViolinInstrument(QWidget *parent)
 {
        noteStart = 48;
 
-       // Set us up to look pretty
-       setPaletteBackgroundPixmap(QPixmap("violin.png"));
-       setFixedSize(637, 384);
-       parentWidget()->setFixedSize(637,384);
+       background.load("violin.png");
 
        setNotes(stringnote);
 }
@@ -35,10 +34,7 @@ ViolaInstrument::ViolaInstrument(QWidget *parent)
 {
        noteStart = 48;
 
-       // Set us up to look pretty
-       setPaletteBackgroundPixmap(QPixmap("viola.png"));
-       setFixedSize(638, 392);
-       parentWidget()->setFixedSize(638,392);
+       background.load("viola.png");
 
        setNotes(stringnote);
 }
@@ -58,10 +54,7 @@ CelloInstrument::CelloInstrument(QWidget *parent)
 {
        noteStart = 36;
 
-       // Set us up to look pretty
-       setPaletteBackgroundPixmap(QPixmap("cello.png"));
-       setFixedSize(639, 391);
-       parentWidget()->setFixedSize(639,391);
+       background.load("cello.png");
 
        setNotes(stringnote);
 }
@@ -81,10 +74,7 @@ ContrabassInstrument::ContrabassInstrument(QWidget *parent)
 {
        noteStart = 24;
 
-       // Set us up to look pretty
-       setPaletteBackgroundPixmap(QPixmap("contrabass.png"));
-       setFixedSize(638, 388);
-       parentWidget()->setFixedSize(637,384);
+       background.load("contrabass.png");
 
        setNotes(stringnote);
 }
@@ -128,15 +118,15 @@ StringInstrument::StringInstrument(QWidget *parent)
 : Instrument(parent)
 {
        // Set all the keys to false
-       zeroArray(down);
-       zeroArray(downFudge);
-       zeroArray(bow);
-       zeroArray(oldVolume);
-       zeroArray(oldNote);
-       zeroArray(note);
-       zeroArray(volume);
-
-       emitSounds();
+       memset(down, 0, sizeof(down));
+       memset(downFudge, 0, sizeof(downFudge));
+       memset(bow, 0, sizeof(bow));
+       memset(oldVolume, 0, sizeof(oldVolume));
+       memset(oldNote, 0, sizeof(oldNote));
+       memset(note, 0, sizeof(note));
+       memset(volume, 0, sizeof(volume));
+
+       QTimer::singleShot(50, this, SLOT(emitSounds()));
 }
 
 StringInstrument::~StringInstrument()
@@ -176,6 +166,9 @@ QString StringInstrument::generateHelp()
 
 void StringInstrument::paintEvent(QPaintEvent *) {
        QPainter paint(this);
+
+       paint.drawPixmap(0, 0, background);
+
        paint.setPen(Qt::black);
 
        for(int i = 0; i < 4; i++) {
@@ -323,9 +316,9 @@ void StringInstrument::keyPressEvent(QKeyEvent *e)
                break;
 
        case Key_F12:
-               zeroArray(down);
-               zeroArray(bow);
-                break;
+               memset(down, 0, sizeof(down));
+               memset(bow, 0, sizeof(bow));
+               break;
 
        default:
                e->ignore();
@@ -471,9 +464,9 @@ void StringInstrument::keyReleaseEvent(QKeyEvent *e)
                break;
 
        case Key_F12:
-               zeroArray(down);
-               zeroArray(bow);
-                break;
+               memset(down, 0, sizeof(down));
+               memset(bow, 0, sizeof(bow));
+               break;
 
        default:
                e->ignore();
@@ -483,44 +476,13 @@ void StringInstrument::keyReleaseEvent(QKeyEvent *e)
        QTimer::singleShot(50, this, SLOT(emitSounds()));
 }
 
-void StringInstrument::zeroArray(bool array[4][4])
-{
-       for(int i = 0; i < 4; i++) {
-               for(int j = 0; j < 4; j++) {
-                       array[i][j] = false;
-               }
-       }
-}
-
-void StringInstrument::zeroArray(bool array[4])
-{
-       for(int i = 0; i < 4; i++) {
-               array[i] = false;
-       }
-
-}
-
-void StringInstrument::zeroArray(int array[4])
-{
-       for(int i = 0; i < 4; i++) {
-               array[i] = 0;
-       }
-}
-
-void StringInstrument::copyArray(int source[4], int dest[4])
-{
-       for(int i = 0; i < 4; i++) {
-               dest[i] = source[i];
-       }
-}
-
 void StringInstrument::emitSounds()
 {
-       copyArray(volume, oldVolume);
-       copyArray(note, oldNote);
+       memcpy(oldVolume, volume, sizeof(oldVolume));
+       memcpy(oldNote, note, sizeof(oldNote));
 
-       zeroArray(volume);
-       copyArray(stringnote, note); // Fudge for setNotes(note);
+       memset(volume, 0, sizeof(volume));
+       memcpy(note, stringnote, sizeof(note)); // Fudge for setNotes(note);
 
        // Need to find the differences in oldVolume, volume and oldNote, note
        // Then stop changed notes, and start new ones
index 8e5b485..b3497b4 100644 (file)
 #include <qpixmap.h>
 #include <qpainter.h>
 #include <qtimer.h>
+#include <QWidget>
+#include <QPixmap>
+#include <QPainter>
+#include <QTimer>
 
 #include "instrument.h"
 
@@ -21,7 +25,7 @@ Q_OBJECT
        public:
                StringInstrument(QWidget *parent);
                ~StringInstrument();
-       
+
        private slots:
                void emitSounds();
 
@@ -32,11 +36,9 @@ Q_OBJECT
                void keyReleaseEvent(QKeyEvent *);
 
 
-               void zeroArray(bool array[4][4]);
-               void zeroArray(bool array[4]);
-               void zeroArray(int array[4]);
                virtual void setNotes(int array[4])=0; // Set the base string notes
-               void copyArray(int source[4], int dest[4]);
+
+               QPixmap background;
 
                // Keys
                bool down[4][4];
index bf5a28b..3d509c6 100644 (file)
@@ -1,6 +1,7 @@
+CONFIG += debug
 TEMPLATE = app
 INCLUDEPATH += .
-DEFINES += QT_DLL
+QT += widgets
 
 HEADERS += \
        pianoinstrument.h \
@@ -17,8 +18,10 @@ SOURCES += \
        midiengine.cpp \
        main.cpp \
 
+RESOURCES += \
+        resources.qrc
 
-MOC_DIR = tmp
-OBJECTS_DIR = tmp
-
-
+MOC_DIR = build
+OBJECTS_DIR = build
+RCC_DIR = build
+DESTDIR = build