From e0efeea407809897396731f760ff60e361351d83 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Thu, 1 Jan 2004 21:46:33 +0000 Subject: [PATCH] Few polish fixes It's now easier to play stringed instruments (less accidental notes) --- instrument.cpp | 9 +++++---- pianoinstrument.cpp | 3 ++- stringinstrument.cpp | 6 +++--- stringinstrument.h | 5 ++++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/instrument.cpp b/instrument.cpp index f8d7083..b4e7296 100644 --- a/instrument.cpp +++ b/instrument.cpp @@ -92,16 +92,17 @@ bool Instrument::event(QEvent *e) QString Instrument::midi2string(int num) { - int i; - for(i = 9; num > 11; i--) { + int octave; + for(octave = 0; num >= 12; octave++) { num -= 12; } - - return QString(midnotes[num] + " - Octave:" + QString::number(i - 6)); // Middle C is then "C - Octave: 3" + return QString(midnotes[num] + " - Octave: " + QString::number(octave - 6)); // Middle C is then "C - Octave: 3" } bool Instrument::checkSharp(int note) { + // This misnamed function checks to see if we are of the the following notes. Useful for string instruments + // These are the notes with only a half-tone gap between them //1 13 25 37 49 61 73 85 97 109 121 //6 18 30 42 54 66 78 90 102 114 126 if((note - 1) % 12 == 0 || note - 1 == 0) diff --git a/pianoinstrument.cpp b/pianoinstrument.cpp index 67ebc13..127d9e1 100644 --- a/pianoinstrument.cpp +++ b/pianoinstrument.cpp @@ -40,11 +40,12 @@ QString PianoInstrument::generateHelp() "Playing the keyboard:" "" "" diff --git a/stringinstrument.cpp b/stringinstrument.cpp index b9ba392..8d369a1 100644 --- a/stringinstrument.cpp +++ b/stringinstrument.cpp @@ -156,7 +156,7 @@ QString StringInstrument::generateHelp() "
  • The row 'q' 'w' 'e' 'r' is the A string
  • " "
  • The row 'a' 's' 'd' 'f' is the D string
  • " "
  • The row 'z' 'x' 'c' 'v' is the G string
  • " -"
  • The further right the key is, the higher the note
  • " +"
  • The further to the right the key is, the higher the note
  • " "
  • Try pressing multiple keys on the same string to get sharp notes. On the A,D,G strings try the Tab, Caps and Shift keys for sharp notes
  • " "" @@ -332,7 +332,7 @@ void StringInstrument::keyPressEvent(QKeyEvent *e) return; } e->accept(); - emitSounds(); + QTimer::singleShot(50, this, SLOT(emitSounds())); } void StringInstrument::keyReleaseEvent(QKeyEvent *e) @@ -480,7 +480,7 @@ void StringInstrument::keyReleaseEvent(QKeyEvent *e) return; } e->accept(); - emitSounds(); + QTimer::singleShot(50, this, SLOT(emitSounds())); } void StringInstrument::zeroArray(bool array[4][4]) diff --git a/stringinstrument.h b/stringinstrument.h index e88d29f..8e5b485 100644 --- a/stringinstrument.h +++ b/stringinstrument.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "instrument.h" @@ -20,6 +21,9 @@ Q_OBJECT public: StringInstrument(QWidget *parent); ~StringInstrument(); + + private slots: + void emitSounds(); protected: QString generateHelp(); @@ -33,7 +37,6 @@ Q_OBJECT 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]); - void emitSounds(); // Keys bool down[4][4]; -- 2.39.2