annotate Source/Mappings/KeyDivision/TouchkeyKeyDivisionMappingFactory.h @ 56:b4a2d2ae43cf tip

merge
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 23 Nov 2018 15:48:14 +0000
parents 003236a1e29b
children
rev   line source
andrewm@0 1 /*
andrewm@0 2 TouchKeys: multi-touch musical keyboard control software
andrewm@0 3 Copyright (c) 2013 Andrew McPherson
andrewm@0 4
andrewm@0 5 This program is free software: you can redistribute it and/or modify
andrewm@0 6 it under the terms of the GNU General Public License as published by
andrewm@0 7 the Free Software Foundation, either version 3 of the License, or
andrewm@0 8 (at your option) any later version.
andrewm@0 9
andrewm@0 10 This program is distributed in the hope that it will be useful,
andrewm@0 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
andrewm@0 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrewm@0 13 GNU General Public License for more details.
andrewm@0 14
andrewm@0 15 You should have received a copy of the GNU General Public License
andrewm@0 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
andrewm@0 17
andrewm@0 18 =====================================================================
andrewm@0 19
andrewm@0 20 TouchkeyKeyDivisionMappingFactory.h: factory for the split-key mapping
andrewm@0 21 which triggers different actions or pitches depending on where the key
andrewm@0 22 was struck.
andrewm@0 23 */
andrewm@0 24
andrewm@0 25 #ifndef __TouchKeys__TouchkeyKeyDivisionMappingFactory__
andrewm@0 26 #define __TouchKeys__TouchkeyKeyDivisionMappingFactory__
andrewm@0 27
andrewm@0 28 #include "../TouchkeyBaseMappingFactory.h"
andrewm@0 29 #include "TouchkeyKeyDivisionMapping.h"
andrewm@0 30
andrewm@0 31 class TouchkeyKeyDivisionMappingFactory : public TouchkeyBaseMappingFactory<TouchkeyKeyDivisionMapping> {
andrewm@0 32 private:
andrewm@51 33 static const float kTuningsYarman24c[];
andrewm@51 34 static const int kMaxSegmentsPerKey;
andrewm@0 35
andrewm@0 36 public:
andrewm@51 37 enum {
andrewm@51 38 kTuningPreset19TET = 0,
andrewm@51 39 kTuningPreset24TET,
andrewm@51 40 kTuningPreset31TET,
andrewm@51 41 kTuningPreset36TET,
andrewm@51 42 kTuningPresetYarman24c,
andrewm@51 43 kTuningPresetMaxValue
andrewm@51 44 };
andrewm@51 45
andrewm@0 46 // ***** Constructor *****
andrewm@0 47
andrewm@0 48 // Default constructor, containing a reference to the PianoKeyboard class.
andrewm@0 49 TouchkeyKeyDivisionMappingFactory(PianoKeyboard &keyboard, MidiKeyboardSegment& segment);
andrewm@0 50
andrewm@0 51 // ***** Destructor *****
andrewm@0 52
andrewm@44 53 ~TouchkeyKeyDivisionMappingFactory();
andrewm@0 54
andrewm@0 55 // ***** Accessors / Modifiers *****
andrewm@0 56
andrewm@0 57 virtual const std::string factoryTypeName() { return "Split\nKeys"; }
andrewm@0 58
andrewm@0 59 void setName(const string& name);
andrewm@0 60
andrewm@51 61 // ***** Split-Key Specific Methods *****
andrewm@51 62
andrewm@51 63 int getNumberOfSegments() { return numSegmentsPerKey_; }
andrewm@51 64 timestamp_diff_type getTimeout() { return timeout_; }
andrewm@51 65 int getDetectionParameter() { return detectionParameter_; }
andrewm@51 66 bool getRetriggerable() { return retriggerable_; }
andrewm@51 67 int getRetriggerNumFrames() { return retriggerNumFrames_; }
andrewm@51 68 bool getRetriggerKeepsVelocity() { return retriggerKeepsVelocity_; }
andrewm@51 69 int getReferenceNote() { return referenceNote_; }
andrewm@51 70 float getGlobalOffset() { return globalOffsetCents_; }
andrewm@51 71 int getTuningPreset() { return tuningPreset_; }
andrewm@0 72
andrewm@0 73 void setNumberOfSegments(int segments) {
andrewm@51 74 if(segments > 0 && segments <= kMaxSegmentsPerKey)
andrewm@0 75 numSegmentsPerKey_ = segments;
andrewm@0 76 }
andrewm@0 77
andrewm@0 78 // Set the detection timeout value (how long from MIDI note on to touch)
andrewm@0 79 void setTimeout(timestamp_diff_type timeout) {
andrewm@0 80 timeout_ = timeout;
andrewm@0 81 }
andrewm@0 82
andrewm@0 83 // Set the detection parameter for choosing a segment
andrewm@0 84 void setDetectionParameter(int detectionParameter) {
andrewm@51 85 if(detectionParameter >= 1 && detectionParameter < TouchkeyKeyDivisionMapping::kDetectionParameterMaxValue)
andrewm@51 86 detectionParameter_ = detectionParameter;
andrewm@0 87 }
andrewm@0 88
andrewm@0 89 // Set whether placing a second finger in the other segment triggers a
andrewm@51 90 // new note with that segment. Two forms of this...
andrewm@0 91 void setRetriggerable(bool retrigger, int numFrames, bool keepOriginalVelocity) {
andrewm@0 92 retriggerable_ = retrigger;
andrewm@0 93 retriggerNumFrames_ = numFrames;
andrewm@0 94 retriggerKeepsVelocity_ = keepOriginalVelocity;
andrewm@0 95 }
andrewm@0 96
andrewm@51 97 void setRetriggerable(bool retrigger) {
andrewm@51 98 retriggerable_ = retrigger;
andrewm@51 99 }
andrewm@51 100
andrewm@0 101 // Set the note that acts as the reference point in a microtonal scale
andrewm@0 102 void setReferenceNote(int note) {
andrewm@0 103 if(note >= 0)
andrewm@0 104 referenceNote_ = note % 12;
andrewm@0 105 }
andrewm@0 106
andrewm@0 107 void setGlobalOffset(float offsetCents) {
andrewm@0 108 globalOffsetCents_ = offsetCents;
andrewm@0 109 }
andrewm@0 110
andrewm@51 111 void setTuningPreset(int preset);
andrewm@51 112
andrewm@51 113 #ifndef TOUCHKEYS_NO_GUI
andrewm@51 114 // ***** GUI Support *****
andrewm@51 115 bool hasBasicEditor() { return true; }
andrewm@51 116 MappingEditorComponent* createBasicEditor();
andrewm@51 117 bool hasExtendedEditor() { return false; }
andrewm@51 118 MappingEditorComponent* createExtendedEditor() { return nullptr; }
andrewm@51 119 #endif
andrewm@51 120
andrewm@36 121 // ****** Preset Save/Load ******
andrewm@36 122 XmlElement* getPreset();
andrewm@36 123 bool loadPreset(XmlElement const* preset);
andrewm@36 124
andrewm@0 125 private:
andrewm@0 126 // ***** Private Methods *****
andrewm@0 127 void initializeMappingParameters(int noteNumber, TouchkeyKeyDivisionMapping *mapping);
andrewm@0 128 void setBendParameters();
andrewm@0 129
andrewm@51 130 int tuningPreset_; // Number of the preset tuning, if active
andrewm@51 131 float *tunings_; // Array of tuning values, set by preset
andrewm@0 132 int numSegmentsPerKey_; // How many segments per key
andrewm@0 133 timestamp_diff_type timeout_; // How long before timeout activates default segment
andrewm@0 134 int detectionParameter_; // Which parameter separates it into segments
andrewm@0 135 bool retriggerable_; // Whether a second touch can retrigger this note
andrewm@0 136 int retriggerNumFrames_; // How many frames a new touch must be present to retrigger
andrewm@0 137 bool retriggerKeepsVelocity_; // Whether a retriggered note keeps the original velocity or a default
andrewm@0 138 int referenceNote_; // Which note acts as the reference point
andrewm@0 139 float globalOffsetCents_; // Offset of every note in cents
andrewm@51 140
andrewm@51 141 CriticalSection tuningMutex_; // Mutex to avoid triggers during tuning changes
andrewm@0 142 };
andrewm@0 143
andrewm@0 144 #endif /* defined(__TouchKeys__TouchkeyKeyDivisionMappingFactory__) */