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: TouchkeyOnsetAngleMapping.h: per-note mapping for the onset angle mapping,
andrewm@0: which measures the speed of finger motion along the key surface at the
andrewm@0: time of MIDI note onset.
andrewm@0: */
andrewm@0:
andrewm@0:
andrewm@0: #ifndef __TouchKeys__TouchkeyOnsetAngleMapping__
andrewm@0: #define __TouchKeys__TouchkeyOnsetAngleMapping__
andrewm@0:
andrewm@0: #include "../TouchkeyBaseMapping.h"
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 TouchkeyOnsetAngleMapping : public TouchkeyBaseMapping {
andrewm@0: private:
andrewm@0: // Default values
andrewm@0: /*constexpr static const int kDefaultFilterBufferLength = 30;
andrewm@0: constexpr static const timestamp_diff_type kDefaultMaxLookbackTime = milliseconds_to_timestamp(100);*/
andrewm@0:
andrewm@0: static const int kDefaultFilterBufferLength;
andrewm@0: static const timestamp_diff_type kDefaultMaxLookbackTime;
andrewm@0: static const int kDefaultMaxLookbackSamples;
andrewm@0:
andrewm@0: public:
andrewm@0: // ***** Constructors *****
andrewm@0:
andrewm@0: // Default constructor, passing the buffer on which to trigger
andrewm@0: TouchkeyOnsetAngleMapping(PianoKeyboard &keyboard, MappingFactory *factory, int noteNumber, Node* touchBuffer,
andrewm@0: Node* positionBuffer, KeyPositionTracker* positionTracker);
andrewm@0:
andrewm@0: // ***** Modifiers *****
andrewm@0:
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@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: // Process the release by calculating the angle
andrewm@0: void processOnset(timestamp_type timestamp);
andrewm@0:
andrewm@0: private:
andrewm@0: // ***** Private Methods *****
andrewm@0:
andrewm@0: void sendOnsetAngleMessage(float onsetAngle, bool force = false);
andrewm@0: void sendPitchBendMessage(float pitchBendSemitones, bool force = false);
andrewm@0:
andrewm@0: // ***** Member Variables *****
andrewm@0:
andrewm@0: Node pastSamples_; // Locations of touch
andrewm@0: timestamp_diff_type maxLookbackTime_; // How long to look backwards to find release velocity
andrewm@0: CriticalSection sampleBufferMutex_; // Mutex to protect threaded access to sample buffer
andrewm@0:
andrewm@0: float startingPitchBendSemitones_; // The value of pitch bend to start with
andrewm@0: float lastPitchBendSemitones_; // The last pitch value we sent out
andrewm@0: timestamp_type rampBeginTime_; // When did the pitch bend ramp begin?
andrewm@0: timestamp_diff_type rampLength_; // How long should the ramp be?
andrewm@0: };
andrewm@0:
andrewm@0: #endif /* defined(__TouchKeys__TouchkeyOnsetAngleMapping__) */