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: TouchkeyMultiFingerTriggerMapping.h: per-note mapping for the multiple-
andrewm@0: finger trigger mapping, which performs actions when two or more fingers
andrewm@0: are added or removed from the key.
andrewm@0: */
andrewm@0:
andrewm@0: #ifndef __TouchKeys__TouchkeyMultiFingerTriggerMapping__
andrewm@0: #define __TouchKeys__TouchkeyMultiFingerTriggerMapping__
andrewm@0:
andrewm@0: #include "../TouchkeyBaseMapping.h"
andrewm@42: #include
andrewm@42:
andrewm@42: class TouchkeyMultiFingerTriggerMappingFactory;
andrewm@0:
andrewm@0: // This class handles the detection of finger motion specifically at
andrewm@0: // note release, which can be used to trigger specific release effects.
andrewm@0:
andrewm@0: class TouchkeyMultiFingerTriggerMapping : public TouchkeyBaseMapping {
andrewm@42: friend class TouchkeyMultiFingerTriggerMappingFactory;
andrewm@42: public:
andrewm@42: enum {
andrewm@42: kActionNone = 1,
andrewm@42: kActionNoteOn,
andrewm@42: kActionNoteOff,
andrewm@42: kActionMax
andrewm@42: };
andrewm@42:
andrewm@0: private:
andrewm@0: // Default values
andrewm@0: /*constexpr static const int kDefaultFilterBufferLength = 30;
andrewm@0: constexpr static const int kDefaultNumTouchesForTrigger = 2;
andrewm@0: constexpr static const int kDefaultNumFramesForTrigger = 2;
andrewm@0: constexpr static const int kDefaultNumConsecutiveTapsForTrigger = 1;
andrewm@0: constexpr static const timestamp_diff_type kDefaultMaxTapSpacing = milliseconds_to_timestamp(500.0);*/
andrewm@0: static const int kDefaultFilterBufferLength;
andrewm@0: static const int kDefaultNumTouchesForTrigger;
andrewm@0: static const int kDefaultNumFramesForTrigger;
andrewm@0: static const int kDefaultNumConsecutiveTapsForTrigger;
andrewm@0: static const timestamp_diff_type kDefaultMaxTapSpacing;
andrewm@42: static const int kDefaultTriggerOnAction;
andrewm@42: static const int kDefaultTriggerOffAction;
andrewm@42: static const int kDefaultTriggerOnNoteNum;
andrewm@42: static const int kDefaultTriggerOffNoteNum;
andrewm@42: static const int kDefaultTriggerOnNoteVel;
andrewm@42: static const int kDefaultTriggerOffNoteVel;
andrewm@42:
andrewm@0: public:
andrewm@0: // ***** Constructors *****
andrewm@0:
andrewm@0: // Default constructor, passing the buffer on which to trigger
andrewm@0: TouchkeyMultiFingerTriggerMapping(PianoKeyboard &keyboard, MappingFactory *factory, int noteNumber, Node* touchBuffer,
andrewm@0: Node* positionBuffer, KeyPositionTracker* positionTracker);
andrewm@0:
andrewm@0: // ***** Modifiers *****
andrewm@0:
andrewm@42: // Disable mappings from being sent
andrewm@42: void disengage(bool shouldDelete = false);
andrewm@42:
andrewm@0: // Reset the state back initial values
andrewm@0: void reset();
andrewm@0:
andrewm@0: // Resend the current state of all parameters
andrewm@0: void resend();
andrewm@0:
andrewm@42: // Parameters for multi-finger trigger
andrewm@42: void setTouchesForTrigger(int touches);
andrewm@42: void setFramesForTrigger(int frames);
andrewm@42: void setConsecutiveTapsForTrigger(int taps);
andrewm@42: void setMaxTimeBetweenTapsForTrigger(timestamp_diff_type timeDiff);
andrewm@42: void setNeedsMidiNoteOn(bool needsMidi);
andrewm@42: void setTriggerOnAction(int action);
andrewm@42: void setTriggerOffAction(int action);
andrewm@42: void setTriggerOnNoteNumber(int note);
andrewm@42: void setTriggerOffNoteNumber(int note);
andrewm@42: void setTriggerOnNoteVelocity(int velocity);
andrewm@42: void setTriggerOffNoteVelocity(int velocity);
andrewm@42:
andrewm@0: // ***** Evaluators *****
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: void triggerReceived(TriggerSource* who, timestamp_type timestamp);
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: timestamp_type performMapping();
andrewm@0:
andrewm@0: // ***** Specific Methods *****
andrewm@0:
andrewm@0:
andrewm@0: private:
andrewm@0: // ***** Private Methods *****
andrewm@0: // Generate the multi-finger trigger
andrewm@0: void generateTriggerOn(timestamp_type timestamp, timestamp_diff_type timeBetweenTaps, float distanceBetweenPoints);
andrewm@0: void generateTriggerOff(timestamp_type timestamp);
andrewm@0:
andrewm@0: void midiNoteOffReceived(int channel);
andrewm@0:
andrewm@0: // ***** Member Variables *****
andrewm@0:
andrewm@0: // Parameters
andrewm@0: int numTouchesForTrigger_; // How many touches are needed for a trigger
andrewm@0: int numFramesForTrigger_; // How many consecutive frames with these touches are needed to trigger
andrewm@0: int numConsecutiveTapsForTrigger_; // How many taps with this number of touches are needed to trigger
andrewm@0: timestamp_diff_type maxTapSpacing_; // How far apart the taps can come and be considered a multi-tap gesture
andrewm@0: bool needsMidiNoteOn_; // Whether the MIDI note has to be on for this gesture to trigger
andrewm@42: int triggerOnAction_, triggerOffAction_; // Actions to take on trigger on/off
andrewm@42: int triggerOnNoteNum_, triggerOffNoteNum_; // Which notes to send if a note is being sent
andrewm@42: int triggerOnNoteVel_, triggerOffNoteVel_; // Velocity to send if a note is being sent
andrewm@0:
andrewm@0: int lastNumActiveTouches_; // How many touches were active before
andrewm@0: float lastActiveTouchLocations_[3]; // Where (Y coord.) the active touches were last frame
andrewm@0: int framesCount_; // How many frames have met the current number of active touches
andrewm@0: int tapsCount_; // How many taps we've registered so far
andrewm@0: bool hasGeneratedTap_; // Whether we've generated a tap with this number of touches yet
andrewm@0: timestamp_type lastTapStartTimestamp_; // When the last tap ended
andrewm@0: bool hasTriggered_; // Whether we've generated a trigger
andrewm@0:
andrewm@42: std::set > otherNotesOn_; // Which other notes are on as a result of triggers?
andrewm@42:
andrewm@0: Node pastSamples_; // Locations of touch
andrewm@0: CriticalSection sampleBufferMutex_; // Mutex to protect threaded access to sample buffer
andrewm@0: };
andrewm@0:
andrewm@0:
andrewm@0: #endif /* defined(__TouchKeys__TouchkeyMultiFingerTriggerMapping__) */