]> code.delx.au - virtualtones/blobdiff - stringinstrument.cpp
Updated to modern Qt
[virtualtones] / stringinstrument.cpp
index 8d369a1b1d9f106a3fe0083d81ef635d642b154d..c047520f10e02a2ad82eccc489d5a4b4dfe1a980 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