On 10/05/2009 07:33 PM, Nikos Chantziaras wrote:
I wrapped up my patch that enables additional keyboard keys to be used
for playing notes. Please consider it for inclusion in LMMS.

Yes, I'm still using that patch 2 years later. If anyone else does, I rebased it so it applies against current Git (stable-0.4 branch). I'm attaching it to this post.

(What this patch does is fit more notes on your PC keyboard.)
commit ace092fa991f18380eea21542a076a425c13b0f3
Author: Nikos Chantziaras <rea...@gmail.com>
Date:   Mon Sep 12 19:33:36 2011 +0300

    Recognize additional keyboard scancodes for playing notes in a PianoView
    
    The following additional keys are now recognized by PianoView:
    
       Left Shift = 'B
       Right Shift = f
       Enter = f#
       ` = A#
       TAB = B
       [ = f'
       = = f'#
       ] = g'
       BACKSPACE = g'#
       \ = a''
    
    To handle TAB, we override QWidget::event().

diff --git a/include/PianoView.h b/include/PianoView.h
index 3f99fbc..c14072a 100644
--- a/include/PianoView.h
+++ b/include/PianoView.h
@@ -50,6 +50,7 @@ public:
 
 protected:
 	virtual void modelChanged();
+	virtual bool event( QEvent * e );
 	virtual void contextMenuEvent( QContextMenuEvent * _me );
 	virtual void paintEvent( QPaintEvent * );
 	virtual void mousePressEvent( QMouseEvent * me );
diff --git a/src/gui/PianoView.cpp b/src/gui/PianoView.cpp
index a0c5dea..4f45c43 100644
--- a/src/gui/PianoView.cpp
+++ b/src/gui/PianoView.cpp
@@ -221,6 +221,7 @@ int PianoView::getKeyFromKeyEvent( QKeyEvent * _ke )
 #ifdef LMMS_BUILD_LINUX
 	switch( k )
 	{
+		case 50: return -1; // Left Shift = 'B
 		case 52: return 0; // Z  = C
 		case 39: return 1; // S  = C#
 		case 53: return 2; // X  = D
@@ -238,6 +239,10 @@ int PianoView::getKeyFromKeyEvent( QKeyEvent * _ke )
 		case 60: return 14; // . = d
 		case 47: return 15; // ; = d#
 		case 61: return 16; // / = e
+		case 62: return 17; // Right Shift = f
+		case 36: return 18; // Enter = f#
+		case 49: return 10; // ` = A#
+		case 23: return 11; // TAB = B
 		case 24: return 12; // Q = c
 		case 11: return 13; // 2 = c#
 		case 25: return 14; // W = d
@@ -255,6 +260,11 @@ int PianoView::getKeyFromKeyEvent( QKeyEvent * _ke )
 		case 32: return 26; // O = d'
 		case 19: return 27; // 0 = d'#
 		case 33: return 28; // P = e'
+		case 34: return 29; // [ = f'
+		case 21: return 30; // = = f'#
+		case 35: return 31; // ] = g'
+		case 22: return 32; // BACKSPACE = g'#
+		case 51: return 33; // \ = a''
 	}
 #endif
 #ifdef LMMS_BUILD_APPLE
@@ -320,6 +330,38 @@ void PianoView::modelChanged()
 
 
 
+/*! \brief Our own version of the main event handler.
+ *
+ *  We use our own handler to intercept events that wouldn't propagate
+ *  to us otherwise (like a TAB keypress, for example.)
+ *
+ *  \param event The event.
+ */
+// This #undef is needed; some X.Org header seems to define a KeyPress
+// macro, resulting in a compilation error.  Since this is not a header
+// file, it's safe to undef it.
+#ifdef KeyPress
+#undef KeyPress
+#endif
+bool PianoView::event( QEvent * event )
+{
+	if (event->type() == QEvent::KeyPress) {
+		QKeyEvent *ke = static_cast<QKeyEvent *>(event);
+		// On virtually all keyboards, TAB is always in the same
+		// position, so we save us the trouble of extracting its
+		// scancode (23) here.
+		if (ke->key() == Qt::Key_Tab) {
+			keyPressEvent(ke);
+			return true;
+		}
+	}
+	// Use the default handler for everything else.
+	return QWidget::event(event);
+}
+
+
+
+
 // gets the key from the given mouse-position
 /*! \brief Get the key from the mouse position in the piano display
  *
------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop 
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops?   How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
_______________________________________________
LMMS-devel mailing list
LMMS-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lmms-devel

Reply via email to