Just Intonation  Version 1.3.0 (18)
Explore scale-independent dynamically adapting tuning in just intonation
touchscreenkeyboard.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2016-2017 Karolin Stange, Christoph Wick, and Haye Hinrichsen
3  *
4  * This file is part of JustIntonation.
5  *
6  * JustIntonation is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * JustIntonation is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with JustIntonation. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 #include "touchscreenkeyboard.h"
21 
22 //-----------------------------------------------------------------------------
23 // Constructor
24 //-----------------------------------------------------------------------------
28 
30  : mPressedKeys()
31  , mSoundActive(128,false)
32  , mToggleMode(false)
33  , mActive(false)
34 {
35 }
36 
37 
38 //-----------------------------------------------------------------------------
39 // SLOT: Receive an event from the touchscreen keyboard
40 //-----------------------------------------------------------------------------
48 
50 {
51  QList<QVariant> list = keys.toList();
52  QSet<int> actualKeys;
53  for (QVariant var : list) actualKeys.insert(var.toInt());
54 
55  // Find released keys (take care of the loop over a shrinking set)
56  bool entriesToDelete;
57  do
58  {
59  entriesToDelete = false;
60  for (int key : mPressedKeys) if (not actualKeys.contains(key))
61  {
62  if (not mToggleMode) switchNote(key,false);
63  mPressedKeys.remove(key);
64  entriesToDelete=true;
65  break;
66  }
67  }
68  while (entriesToDelete);
69 
70  // Find newly pressed keys
71  for (int key : actualKeys) if (not mPressedKeys.contains(key))
72  {
73  if (mToggleMode) switchNote(key,not mSoundActive[key]);
74  else switchNote(key,true);
75  mPressedKeys.insert(key);
76  }
77 }
78 
79 
80 //-----------------------------------------------------------------------------
81 // Switch note on or off
82 //-----------------------------------------------------------------------------
88 
89 void TouchscreenKeyboard::switchNote(int key, bool on)
90 {
91  // Remember that the key is pressed or released
92  mSoundActive[key] = on;
93 
94  // Send a signal to the Qml layer for highlighting pressed keys
95  highlightKey(key,on);
96 
97  // Send a Midi event (note on / off) at constant value;
98  const qint8 volume = 90;
100  QMidiMessage((on ? 0x90 : 0x80), (key&0x7f), volume, 0.0));
101 }
102 
103 
104 //-----------------------------------------------------------------------------
105 // Clear
106 //-----------------------------------------------------------------------------
110 
112 {
113  // Erase memory
114  mSoundActive.fill(false);
115 
116  // Turn all notes off
117  for (quint8 command = 0xB0U; command < 0xC0U; command++)
118  sendTouchpadMidiEvent (QMidiMessage(command, 123, 0, 0.0));
119  for (int i=0; i<128; ++i) highlightKey(i,false);
120 }
void highlightKey(QVariant key, QVariant on)
Signal: Tells the Qml layer to highlight pressed keys.
QVector< bool > mSoundActive
Flag wether the sound is turned on.
bool mActive
Flag that allows to send data.
bool mToggleMode
Flag for desktop toggling mode.
void sendTouchpadMidiEvent(QMidiMessage event)
Signal: On keypress send the corresponding Midi event to a different module.
void receiveTouchpadKeyboardEvent(QVariant keys)
SLOT: Receive an event from the touchscreen keyboard.
QSet< int > mPressedKeys
Keeps track of pressed keys.
void switchNote(int key, bool on)
Switch note on or off.
void clear()
Clear the keyboard memory and turn all notes off.
TouchscreenKeyboard()
Constructor.