comparison Source/Mappings/KeyDivision/TouchkeyKeyDivisionMappingFactory.cpp @ 0:3580ffe87dc8

First commit of TouchKeys public pre-release.
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Mon, 11 Nov 2013 18:19:35 +0000
parents
children 353276611036
comparison
equal deleted inserted replaced
-1:000000000000 0:3580ffe87dc8
1 /*
2 TouchKeys: multi-touch musical keyboard control software
3 Copyright (c) 2013 Andrew McPherson
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 =====================================================================
19
20 TouchkeyKeyDivisionMappingFactory.cpp: factory for the split-key mapping
21 which triggers different actions or pitches depending on where the key
22 was struck.
23 */
24
25 #include "TouchkeyKeyDivisionMappingFactory.h"
26
27 const float TouchkeyKeyDivisionMappingFactory::kDefaultPitchWheelRangeSemitones = 2.0;
28
29 // Yarman-24 Turkish microtonal tuning:
30 /* 1/1 RAST C
31 84.360 Nim Zengule C#/Db
32 145.112 Zengule Cᵻ/Dƀ
33 192.180 Dik Zengule Dd
34 9/8 DUGAH D
35 292.180 Kurdi D#/Eb
36 60/49 Dik Kurdi Dᵻ/Eƀ
37 364.735 Nerm Segah Ed
38 5/4 SEGAH E
39 415.677 Buselik E‡
40 4/3 CHARGAH F
41 584.359 Nim Hijaz F#/Gb
42 635.300 Hijaz/Saba Fᵻ/Gƀ
43 696.090 Dik Hijaz/Saba Gd
44 3/2 NEVA G
45 788.270 Nim Hisar G#/Ab
46 854.924 Hisar Gᵻ/Aƀ
47 888.270 Dik Hisar Ad
48 27/16 HUSEYNI A 440hz
49 16/9 Ajem A#/Bb
50 11/6 Dik Ajem Aᵻ/Bƀ
51 1074.547 Nerm Evdj Bd
52 15/8 EVDJ B
53 1125.488 Mahur B‡
54 2/1 GERDANIYE C */
55 /*const float TouchkeyKeyDivisionMappingFactory::kDefaultTuningsCents[24] = {
56 0, 84.36, 145.112, 192.18, 203.9, 292.18, 350.62, 364.74, 386.31, 415.677, 498.04, 584.359,
57 635.3, 696.09, 701.95, 788.27, 854.92, 888.27, 905.87, 996.1, 1049.36, 1074.55, 1088.27, 1125.488
58 };*/
59
60 // Yarman-24c Turkish microtonal tuning:
61 /* 0: 1/1 C Dbb unison, perfect prime RAST ♥
62 1: 83.059 cents C# Db nim zengule
63 2: 143.623 cents zengule
64 3: 191.771 cents C## Dd dik zengule
65 4: 9/8 D Ebb major whole tone DÜGAH ♥
66 5: 292.413 cents D# Eb kürdi
67 6: 348.343 cents D#| Eb- dik kürdi
68 7: 362.503 cents nerm segah
69 8: 156/125 cents E SEGAH ♥
70 9: 415.305 cents E| Buselik
71 10: 4/3 F Gbb perfect fourth ÇARGAH ♥
72 11: 581.382 cents F# Gb nim hicaz
73 12: 634.184 cents hicaz
74 13: 695.885 cents F## Gd dik hicaz
75 14: 3/2 G Abb perfect fifth NEVA ♥
76 15: 788.736 cents G# Ab nim hisar
77 16: 853.063 cents hisar
78 17: 887.656 cents G## Ad dik hisar
79 18: 27/16 A Bbb Pyth. major sixth HÜSEYNİ ♥
80 19: 16/9 A# Bb Pyth. minor seventh acem
81 20: 1043.623 cents A#| Bb- dik acem
82 21: 1071.942 cents nerm eviç
83 22: 234/125 cents B EVİÇ ♥
84 23: 1124.744 cents B| mahur
85 24: 2/1 C Dbb octave GERDANİYE ♥
86 */
87
88 /*const float TouchkeyKeyDivisionMappingFactory::kDefaultTuningsCents[24] = {
89 0, 83.059, 143.623, 191.771, 203.9, 292.413, 348.343, 362.503, 383.54, 415.305, 498.04, 581.382,
90 634.184, 695.885, 701.95, 788.736, 853.063, 887.656, 905.87, 996.1, 1043.623, 1071.942, 1085.49, 1124.744
91 };*/
92
93 /* Yarman-24c as above but arranged for performance */
94 const float TouchkeyKeyDivisionMappingFactory::kDefaultTuningsCents[24] = {
95 0, (1124.744 - 1200.0), 83.059, 143.623, 203.9, 191.771, 292.413, 348.343,
96 383.54, 362.503, 498.04, 415.305, 581.382, 634.184, 695.885, 648.682,
97 788.736, 853.063, 905.87, 887.656, 996.1, 1043.623, 1085.49, 1071.942,
98 };
99
100 /*const float TouchkeyKeyDivisionMappingFactory::kDefaultTuningsCents[24] = {
101 0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700,
102 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150
103 };*/
104
105 /*const float TouchkeyKeyDivisionMappingFactory::kDefaultTuningsCents[36] = {
106 0, 33.3, 66.6, 100, 133.3, 166.6, 200, 233.3, 266.6, 300, 333.3, 366.6,
107 400, 433.3, 466.6, 500, 533.3, 566.6, 600, 633.3, 666.6, 700, 733.3, 766.6,
108 800, 833.3, 866.6, 900, 933.3, 966.6, 1000, 1033.3, 1066.6, 1100, 1133.3, 1166.6
109 };*/
110
111 /* As arranged:
112 *
113 * B| Db/ Dd Eb/ Ed E| Gb/ Gd Ab/ Ad Bb/ Bd
114 * C C# D D# E F F# G G# A A# B
115 */
116
117 TouchkeyKeyDivisionMappingFactory::TouchkeyKeyDivisionMappingFactory(PianoKeyboard &keyboard, MidiKeyboardSegment& segment)
118 : TouchkeyBaseMappingFactory<TouchkeyKeyDivisionMapping>(keyboard, segment),
119 pitchWheelRangeSemitones_(kDefaultPitchWheelRangeSemitones),
120 numSegmentsPerKey_(TouchkeyKeyDivisionMapping::kDefaultNumberOfSegments),
121 timeout_(TouchkeyKeyDivisionMapping::kDefaultDetectionTimeout),
122 detectionParameter_(TouchkeyKeyDivisionMapping::kDefaultDetectionParameter),
123 retriggerable_(false),
124 retriggerNumFrames_(TouchkeyKeyDivisionMapping::kDefaultRetriggerNumFrames),
125 retriggerKeepsVelocity_(true),
126 referenceNote_(0), globalOffsetCents_(0)
127 {
128 //setName("/touchkeys/segmentpitch");
129 setBendParameters();
130 }
131
132 void TouchkeyKeyDivisionMappingFactory::setMIDIPitchWheelRange(float maxBendSemitones) {
133 if(maxBendSemitones <= 0)
134 return;
135 pitchWheelRangeSemitones_ = maxBendSemitones;
136
137 setBendParameters();
138 }
139
140 void TouchkeyKeyDivisionMappingFactory::setName(const string& name) {
141 TouchkeyBaseMappingFactory<TouchkeyKeyDivisionMapping>::setName(name);
142 setBendParameters();
143 }
144
145 // Set the initial parameters for a new mapping
146 void TouchkeyKeyDivisionMappingFactory::initializeMappingParameters(int noteNumber, TouchkeyKeyDivisionMapping *mapping) {
147 // KLUDGE: testing Maqam tunings. Go from absolute tunings in cents to pitch bends in semitones
148 float tunings[2];
149 int index = (noteNumber + 12 - referenceNote_) % 12;
150 float standardTuning = (float)index * 100.0;
151 tunings[0] = (kDefaultTuningsCents[index*2] - standardTuning + globalOffsetCents_) * .01;
152 tunings[1] = (kDefaultTuningsCents[index*2 + 1] - standardTuning + globalOffsetCents_) * .01;
153 mapping->setSegmentPitchBends(tunings, 2);
154 /*float tunings[3];
155 int index = (noteNumber + 12 - referenceNote_) % 12;
156 float standardTuning = (float)index * 100.0;
157 tunings[0] = (kDefaultTuningsCents[index*3] - standardTuning + globalOffsetCents_) * .01;
158 tunings[1] = (kDefaultTuningsCents[index*3 + 1] - standardTuning + globalOffsetCents_) * .01;
159 tunings[2] = (kDefaultTuningsCents[index*3 + 2] - standardTuning + globalOffsetCents_) * .01;
160 mapping->setSegmentPitchBends(tunings, 3);*/
161
162
163 mapping->setNumberOfSegments(numSegmentsPerKey_);
164 mapping->setTimeout(timeout_);
165 mapping->setDetectionParameter(detectionParameter_);
166 mapping->setRetriggerable(retriggerable_, retriggerNumFrames_, retriggerKeepsVelocity_);
167 }
168
169 void TouchkeyKeyDivisionMappingFactory::setBendParameters() {
170 setMidiParameters(MidiKeyboardSegment::kControlPitchWheel, -pitchWheelRangeSemitones_, pitchWheelRangeSemitones_, 0.0);
171
172 if(midiConverter_ != 0) {
173 midiConverter_->setMidiPitchWheelRange(pitchWheelRangeSemitones_);
174 midiConverter_->listenToIncomingControl(MidiKeyboardSegment::kControlPitchWheel);
175 }
176 }