annotate Source/Mappings/OnsetAngle/TouchkeyOnsetAngleMappingFactory.cpp @ 56:b4a2d2ae43cf tip

merge
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 23 Nov 2018 15:48:14 +0000
parents 0deac2806a7b
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 TouchkeyOnsetAngleMappingFactory.cpp: factory for the onset angle mapping,
andrewm@0 21 which measures the speed of finger motion along the key surface at the
andrewm@0 22 time of MIDI note onset.
andrewm@0 23 */
andrewm@0 24
andrewm@0 25 #include "TouchkeyOnsetAngleMappingFactory.h"
andrewm@0 26
andrewm@0 27 // Class constants
andrewm@0 28 const timestamp_diff_type TouchkeyOnsetAngleMappingFactory::kDefaultMaxLookbackTime = milliseconds_to_timestamp(100);
andrewm@0 29
andrewm@0 30
andrewm@0 31 TouchkeyOnsetAngleMappingFactory::TouchkeyOnsetAngleMappingFactory(PianoKeyboard &keyboard, MidiKeyboardSegment& segment)
andrewm@0 32 : TouchkeyBaseMappingFactory<TouchkeyOnsetAngleMapping>(keyboard, segment) {
andrewm@0 33 //setName("/touchkeys/scoop");
andrewm@0 34 setMidiParameters(MidiKeyboardSegment::kControlPitchWheel, -2.0, 2.0, 0.0);
andrewm@0 35 }
andrewm@0 36
andrewm@36 37 // ****** Preset Save/Load ******
andrewm@36 38 XmlElement* TouchkeyOnsetAngleMappingFactory::getPreset() {
andrewm@36 39 PropertySet properties;
andrewm@36 40
andrewm@36 41 storeCommonProperties(properties);
andrewm@36 42
andrewm@36 43 // No properties for now
andrewm@36 44
andrewm@36 45 XmlElement* preset = properties.createXml("MappingFactory");
andrewm@36 46 preset->setAttribute("type", "OnsetAngle");
andrewm@36 47
andrewm@36 48 return preset;
andrewm@36 49 }
andrewm@36 50
andrewm@36 51 bool TouchkeyOnsetAngleMappingFactory::loadPreset(XmlElement const* preset) {
andrewm@36 52 if(preset == 0)
andrewm@36 53 return false;
andrewm@36 54
andrewm@36 55 PropertySet properties;
andrewm@36 56 properties.restoreFromXml(*preset);
andrewm@36 57
andrewm@36 58 if(!loadCommonProperties(properties))
andrewm@36 59 return false;
andrewm@36 60
andrewm@36 61 // Nothing specific to do for now
andrewm@36 62
andrewm@36 63 return true;
andrewm@36 64 }
andrewm@36 65
andrewm@0 66 // MIDI note ended: see whether the mapping was suspended and if not, execute the angle calculation
andrewm@0 67 void TouchkeyOnsetAngleMappingFactory::midiNoteOn(int noteNumber, bool touchIsOn, bool keyMotionActive,
andrewm@0 68 Node<KeyTouchFrame>* touchBuffer,
andrewm@0 69 Node<key_position>* positionBuffer,
andrewm@0 70 KeyPositionTracker* positionTracker) {
andrewm@0 71 // Call base class method
andrewm@0 72 TouchkeyBaseMappingFactory<TouchkeyOnsetAngleMapping>::midiNoteOn(noteNumber, touchIsOn, keyMotionActive, touchBuffer, positionBuffer, positionTracker);
andrewm@0 73
andrewm@0 74 if(mappings_.count(noteNumber) != 0) {
andrewm@0 75 mappings_[noteNumber]->processOnset(keyboard_.schedulerCurrentTimestamp());
andrewm@0 76 }
andrewm@0 77 }