andrewm@0: /* andrewm@0: TouchKeys: multi-touch musical keyboard control software andrewm@0: Copyright (c) 2013 Andrew McPherson andrewm@0: andrewm@0: This program is free software: you can redistribute it and/or modify andrewm@0: it under the terms of the GNU General Public License as published by andrewm@0: the Free Software Foundation, either version 3 of the License, or andrewm@0: (at your option) any later version. andrewm@0: andrewm@0: This program is distributed in the hope that it will be useful, andrewm@0: but WITHOUT ANY WARRANTY; without even the implied warranty of andrewm@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrewm@0: GNU General Public License for more details. andrewm@0: andrewm@0: You should have received a copy of the GNU General Public License andrewm@0: along with this program. If not, see . andrewm@0: andrewm@0: ===================================================================== andrewm@0: andrewm@0: TouchkeyBaseMapping.h: base class from which all TouchKeys-specific andrewm@0: mappings derive. Like its Mapping parent class, it handles a mapping andrewm@0: for one specific note. andrewm@0: */ andrewm@0: andrewm@0: #ifndef TouchKeys_TouchkeyBaseMapping_h andrewm@0: #define TouchKeys_TouchkeyBaseMapping_h andrewm@0: andrewm@0: andrewm@0: #include andrewm@0: #include andrewm@0: #include "../TouchKeys/KeyTouchFrame.h" andrewm@0: #include "../TouchKeys/KeyPositionTracker.h" andrewm@0: #include "../TouchKeys/PianoKeyboard.h" andrewm@0: #include "Mapping.h" andrewm@0: andrewm@0: // This class is a virtual base class for mappings which work specifically with TouchKeys andrewm@0: // and MIDI data (not continuous key angle), designed to work with TouchkeyBaseMappingFactory. andrewm@0: // Specific behaviors will be implemented in subclasses. andrewm@0: andrewm@0: class TouchkeyBaseMapping : public Mapping, public OscHandler { andrewm@0: friend class MappingFactory; andrewm@0: andrewm@0: public: andrewm@0: // ***** Constructors ***** andrewm@0: andrewm@0: // Default constructor, passing the buffer on which to trigger andrewm@0: TouchkeyBaseMapping(PianoKeyboard &keyboard, MappingFactory *factory, int noteNumber, Node* touchBuffer, andrewm@0: Node* positionBuffer, KeyPositionTracker* positionTracker, bool finishesAutomatically = true); andrewm@0: andrewm@0: // ***** Destructor ***** andrewm@0: andrewm@0: virtual ~TouchkeyBaseMapping(); andrewm@0: andrewm@0: // ***** Modifiers ***** andrewm@0: andrewm@0: // Enable mappings to be sent andrewm@0: virtual void engage(); andrewm@0: andrewm@0: // Disable mappings from being sent andrewm@0: virtual void disengage(bool shouldDelete = false); andrewm@0: andrewm@0: // Reset the state back initial values andrewm@0: virtual void reset(); andrewm@0: andrewm@0: // Resend the current state of all parameters andrewm@0: virtual void resend() = 0; andrewm@0: andrewm@0: // ***** Parameters ***** andrewm@0: andrewm@0: // Name for this control, used in the OSC path andrewm@0: virtual void setName(const std::string& name); andrewm@0: andrewm@0: // ***** Evaluators ***** andrewm@0: andrewm@0: // OSC Handler Method: called by PianoKeyboard (or other OSC source) andrewm@0: virtual bool oscHandlerMethod(const char *path, const char *types, int numValues, lo_arg **values, void *data); andrewm@0: andrewm@0: // This method receives triggers whenever events occur in the touch data or the andrewm@0: // continuous key position (state changes only). It alters the behavior and scheduling andrewm@0: // of the mapping but does not itself send OSC messages andrewm@0: virtual void triggerReceived(TriggerSource* who, timestamp_type timestamp) = 0; andrewm@0: andrewm@0: // This method handles the OSC message transmission. It should be run in the Scheduler andrewm@0: // thread provided by PianoKeyboard. andrewm@0: virtual timestamp_type performMapping() = 0; andrewm@0: andrewm@0: // Override the finished() method to give the note time for a post-release action. andrewm@0: virtual bool requestFinish(); andrewm@0: andrewm@0: // Acknowledge the finish when the mapping is done, removing the mapping andrewm@0: virtual void acknowledgeFinish(); andrewm@0: andrewm@0: protected: andrewm@0: // ***** Internal Methods for MIDI ***** andrewm@0: andrewm@0: // These methods are called when an OSC message is received indicating andrewm@0: // a MIDI note on/off message took place. They let the subclass insert andrewm@0: // its own code right before the main MIDI processing. andrewm@0: andrewm@0: virtual void midiNoteOnReceived(int channel, int velocity) {} andrewm@0: virtual void midiNoteOffReceived(int channel) {} andrewm@0: andrewm@0: // ***** Member Variables ***** andrewm@0: andrewm@0: std::string controlName_; // Name of this control, used in the OSC message andrewm@0: bool noteIsOn_; // Whether the MIDI note is active or not andrewm@0: bool finished_; // Whether the note is finished andrewm@0: bool finishRequested_; // Whether the factory has requested a finish andrewm@0: bool finishesAutomatically_; // Whether the mapping finishes automatically when requested andrewm@0: andrewm@0: private: andrewm@0: JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TouchkeyBaseMapping) andrewm@0: }; andrewm@0: andrewm@0: andrewm@0: andrewm@0: andrewm@0: #endif