andrewm@9: /* andrewm@9: TouchKeys: multi-touch musical keyboard control software andrewm@9: Copyright (c) 2013 Andrew McPherson andrewm@9: andrewm@9: This program is free software: you can redistribute it and/or modify andrewm@9: it under the terms of the GNU General Public License as published by andrewm@9: the Free Software Foundation, either version 3 of the License, or andrewm@9: (at your option) any later version. andrewm@9: andrewm@9: This program is distributed in the hope that it will be useful, andrewm@9: but WITHOUT ANY WARRANTY; without even the implied warranty of andrewm@9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrewm@9: GNU General Public License for more details. andrewm@9: andrewm@9: You should have received a copy of the GNU General Public License andrewm@9: along with this program. If not, see . andrewm@9: andrewm@9: ===================================================================== andrewm@9: andrewm@9: TouchkeyOscEmulator.h: emulates a TouchKeys source using OSC messages andrewm@9: */ andrewm@9: andrewm@9: #ifndef TOUCHKEYOSCEMULATOR_H_INCLUDED andrewm@9: #define TOUCHKEYOSCEMULATOR_H_INCLUDED andrewm@9: andrewm@9: #include "Osc.h" andrewm@9: #include "PianoKeyboard.h" andrewm@9: andrewm@9: class TouchkeyOscEmulator : public OscHandler { andrewm@9: public: andrewm@9: // *** Constructor *** andrewm@9: TouchkeyOscEmulator(PianoKeyboard& keyboard, OscMessageSource& messageSource); andrewm@9: andrewm@9: // *** Destructor *** andrewm@9: ~TouchkeyOscEmulator(); andrewm@9: andrewm@9: // *** TouchKeys emulation methods *** andrewm@9: int lowestMidiNote() { return lowestMidiNote_; } andrewm@9: void setLowestMidiNote(int note) { lowestMidiNote_ = note; } andrewm@9: andrewm@9: void allTouchesOff(bool send = true); andrewm@9: andrewm@9: // *** OSC handler method *** andrewm@9: bool oscHandlerMethod(const char *path, const char *types, int numValues, lo_arg **values, void *data); andrewm@9: andrewm@9: // *** Data processing methods *** andrewm@9: // New touch data point received andrewm@9: void touchReceived(int key, int touch, float x, float y); andrewm@9: andrewm@9: // Touch removed andrewm@9: void touchOffReceived(int key, int touch); andrewm@9: andrewm@9: private: andrewm@9: void clearTouchData(int i); // Clear touch data for a particular key andrewm@9: void removeTouchFromFrame(int note, int index); // Remove a particular touch from the frame andrewm@9: void addTouchToFrame(int note, int touchId, float x, float y); // Add a touch with a particular ID andrewm@9: void updateTouchInFrame(int note, int index, float x, float y); // Update the touch at the given index andrewm@9: andrewm@9: private: andrewm@9: PianoKeyboard& keyboard_; // Main keyboard controller andrewm@9: OscMessageSource& source_; // Source of OSC messages andrewm@9: andrewm@9: int lowestMidiNote_; // Lowest MIDI note andrewm@9: andrewm@9: KeyTouchFrame touchFrames_[127]; // Current state of each virtual TouchKey andrewm@9: int touchIdAssignments_[127][3]; // Assignments between OSC touch IDs and TouchKeys touch IDs andrewm@9: }; andrewm@9: andrewm@9: #endif // TOUCHKEYOSCEMULATOR_H_INCLUDED