andrewm@11
|
1 /*
|
andrewm@11
|
2 TouchKeys: multi-touch musical keyboard control software
|
andrewm@11
|
3 Copyright (c) 2013 Andrew McPherson
|
andrewm@11
|
4
|
andrewm@11
|
5 This program is free software: you can redistribute it and/or modify
|
andrewm@11
|
6 it under the terms of the GNU General Public License as published by
|
andrewm@11
|
7 the Free Software Foundation, either version 3 of the License, or
|
andrewm@11
|
8 (at your option) any later version.
|
andrewm@11
|
9
|
andrewm@11
|
10 This program is distributed in the hope that it will be useful,
|
andrewm@11
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
andrewm@11
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
andrewm@11
|
13 GNU General Public License for more details.
|
andrewm@11
|
14
|
andrewm@11
|
15 You should have received a copy of the GNU General Public License
|
andrewm@11
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
andrewm@11
|
17
|
andrewm@11
|
18 =====================================================================
|
andrewm@11
|
19
|
andrewm@11
|
20 TouchkeyEntropyGenerator.h: generate random TouchKeys data for testing
|
andrewm@11
|
21 */
|
andrewm@11
|
22
|
andrewm@11
|
23 #ifndef TOUCHKEYENTROPYGENERATOR_H_INCLUDED
|
andrewm@11
|
24 #define TOUCHKEYENTROPYGENERATOR_H_INCLUDED
|
andrewm@11
|
25
|
andrewm@11
|
26 #include "../../JuceLibraryCode/JuceHeader.h"
|
andrewm@11
|
27 #include "PianoKeyboard.h"
|
andrewm@11
|
28
|
andrewm@11
|
29 class TouchkeyEntropyGenerator : public Thread {
|
andrewm@11
|
30 public:
|
andrewm@11
|
31 // *** Constructor ***
|
andrewm@11
|
32 TouchkeyEntropyGenerator(PianoKeyboard& keyboard);
|
andrewm@11
|
33
|
andrewm@11
|
34 // *** Destructor ***
|
andrewm@11
|
35 ~TouchkeyEntropyGenerator() {
|
andrewm@11
|
36 stop();
|
andrewm@11
|
37 }
|
andrewm@11
|
38
|
andrewm@11
|
39 // *** Control methods ***
|
andrewm@11
|
40 // Start running the generator
|
andrewm@11
|
41 void start();
|
andrewm@11
|
42
|
andrewm@11
|
43 // Stop running the generator
|
andrewm@11
|
44 void stop();
|
andrewm@11
|
45
|
andrewm@11
|
46 // Check if the generator is running
|
andrewm@11
|
47 bool isRunning() { return isRunning_; }
|
andrewm@11
|
48
|
andrewm@11
|
49 // *** Data generation ***
|
andrewm@11
|
50
|
andrewm@11
|
51 // Set the range of keys for which touch data will be generated
|
andrewm@11
|
52 void setKeyboardRange(int lowest, int highest) {
|
andrewm@11
|
53 keyboardRangeLow_ = lowest;
|
andrewm@11
|
54 keyboardRangeHigh_ = highest;
|
andrewm@11
|
55 }
|
andrewm@11
|
56
|
andrewm@11
|
57 // Set the interval at which data should be generated
|
andrewm@11
|
58 void setDataInterval(timestamp_diff_type interval) {
|
andrewm@11
|
59 dataInterval_ = interval;
|
andrewm@11
|
60 }
|
andrewm@11
|
61
|
andrewm@11
|
62 // *** Juce Thread method ***
|
andrewm@11
|
63 void run();
|
andrewm@11
|
64
|
andrewm@11
|
65 private:
|
andrewm@11
|
66 void clearTouchData(int i); // Clear touch data for a particular key
|
andrewm@11
|
67
|
andrewm@11
|
68 void generateRandomFrame(int key); // Generate a random touch frame on this key
|
andrewm@11
|
69
|
andrewm@11
|
70 private:
|
andrewm@11
|
71 PianoKeyboard& keyboard_; // Main keyboard controller
|
andrewm@11
|
72
|
andrewm@11
|
73 WaitableEvent waitableEvent_; // For thread timing
|
andrewm@11
|
74 bool isRunning_;
|
andrewm@11
|
75 int keyboardRangeLow_; // Range of keys to generate data for
|
andrewm@11
|
76 int keyboardRangeHigh_;
|
andrewm@11
|
77 timestamp_diff_type dataInterval_; // Interval between frames of data
|
andrewm@11
|
78
|
andrewm@11
|
79 KeyTouchFrame touchFrames_[127]; // Current state of each virtual TouchKey
|
andrewm@11
|
80 int nextOnOffFrameCount_[127]; // How long until the next note goes on or off
|
andrewm@11
|
81 };
|
andrewm@11
|
82
|
andrewm@11
|
83
|
andrewm@11
|
84 #endif // TOUCHKEYENTROPYGENERATOR_H_INCLUDED
|