annotate Source/Mappings/TouchkeyBaseMapping.h @ 56:b4a2d2ae43cf tip

merge
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 23 Nov 2018 15:48:14 +0000
parents 3580ffe87dc8
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 TouchkeyBaseMapping.h: base class from which all TouchKeys-specific
andrewm@0 21 mappings derive. Like its Mapping parent class, it handles a mapping
andrewm@0 22 for one specific note.
andrewm@0 23 */
andrewm@0 24
andrewm@0 25 #ifndef TouchKeys_TouchkeyBaseMapping_h
andrewm@0 26 #define TouchKeys_TouchkeyBaseMapping_h
andrewm@0 27
andrewm@0 28
andrewm@0 29 #include <map>
andrewm@0 30 #include <boost/bind.hpp>
andrewm@0 31 #include "../TouchKeys/KeyTouchFrame.h"
andrewm@0 32 #include "../TouchKeys/KeyPositionTracker.h"
andrewm@0 33 #include "../TouchKeys/PianoKeyboard.h"
andrewm@0 34 #include "Mapping.h"
andrewm@0 35
andrewm@0 36 // This class is a virtual base class for mappings which work specifically with TouchKeys
andrewm@0 37 // and MIDI data (not continuous key angle), designed to work with TouchkeyBaseMappingFactory.
andrewm@0 38 // Specific behaviors will be implemented in subclasses.
andrewm@0 39
andrewm@0 40 class TouchkeyBaseMapping : public Mapping, public OscHandler {
andrewm@0 41 friend class MappingFactory;
andrewm@0 42
andrewm@0 43 public:
andrewm@0 44 // ***** Constructors *****
andrewm@0 45
andrewm@0 46 // Default constructor, passing the buffer on which to trigger
andrewm@0 47 TouchkeyBaseMapping(PianoKeyboard &keyboard, MappingFactory *factory, int noteNumber, Node<KeyTouchFrame>* touchBuffer,
andrewm@0 48 Node<key_position>* positionBuffer, KeyPositionTracker* positionTracker, bool finishesAutomatically = true);
andrewm@0 49
andrewm@0 50 // ***** Destructor *****
andrewm@0 51
andrewm@0 52 virtual ~TouchkeyBaseMapping();
andrewm@0 53
andrewm@0 54 // ***** Modifiers *****
andrewm@0 55
andrewm@0 56 // Enable mappings to be sent
andrewm@0 57 virtual void engage();
andrewm@0 58
andrewm@0 59 // Disable mappings from being sent
andrewm@0 60 virtual void disengage(bool shouldDelete = false);
andrewm@0 61
andrewm@0 62 // Reset the state back initial values
andrewm@0 63 virtual void reset();
andrewm@0 64
andrewm@0 65 // Resend the current state of all parameters
andrewm@0 66 virtual void resend() = 0;
andrewm@0 67
andrewm@0 68 // ***** Parameters *****
andrewm@0 69
andrewm@0 70 // Name for this control, used in the OSC path
andrewm@0 71 virtual void setName(const std::string& name);
andrewm@0 72
andrewm@0 73 // ***** Evaluators *****
andrewm@0 74
andrewm@0 75 // OSC Handler Method: called by PianoKeyboard (or other OSC source)
andrewm@0 76 virtual bool oscHandlerMethod(const char *path, const char *types, int numValues, lo_arg **values, void *data);
andrewm@0 77
andrewm@0 78 // This method receives triggers whenever events occur in the touch data or the
andrewm@0 79 // continuous key position (state changes only). It alters the behavior and scheduling
andrewm@0 80 // of the mapping but does not itself send OSC messages
andrewm@0 81 virtual void triggerReceived(TriggerSource* who, timestamp_type timestamp) = 0;
andrewm@0 82
andrewm@0 83 // This method handles the OSC message transmission. It should be run in the Scheduler
andrewm@0 84 // thread provided by PianoKeyboard.
andrewm@0 85 virtual timestamp_type performMapping() = 0;
andrewm@0 86
andrewm@0 87 // Override the finished() method to give the note time for a post-release action.
andrewm@0 88 virtual bool requestFinish();
andrewm@0 89
andrewm@0 90 // Acknowledge the finish when the mapping is done, removing the mapping
andrewm@0 91 virtual void acknowledgeFinish();
andrewm@0 92
andrewm@0 93 protected:
andrewm@0 94 // ***** Internal Methods for MIDI *****
andrewm@0 95
andrewm@0 96 // These methods are called when an OSC message is received indicating
andrewm@0 97 // a MIDI note on/off message took place. They let the subclass insert
andrewm@0 98 // its own code right before the main MIDI processing.
andrewm@0 99
andrewm@0 100 virtual void midiNoteOnReceived(int channel, int velocity) {}
andrewm@0 101 virtual void midiNoteOffReceived(int channel) {}
andrewm@0 102
andrewm@0 103 // ***** Member Variables *****
andrewm@0 104
andrewm@0 105 std::string controlName_; // Name of this control, used in the OSC message
andrewm@0 106 bool noteIsOn_; // Whether the MIDI note is active or not
andrewm@0 107 bool finished_; // Whether the note is finished
andrewm@0 108 bool finishRequested_; // Whether the factory has requested a finish
andrewm@0 109 bool finishesAutomatically_; // Whether the mapping finishes automatically when requested
andrewm@0 110
andrewm@0 111 private:
andrewm@0 112 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TouchkeyBaseMapping)
andrewm@0 113 };
andrewm@0 114
andrewm@0 115
andrewm@0 116
andrewm@0 117
andrewm@0 118 #endif