view Source/TouchKeys/TouchkeyOscEmulator.h @ 20:dfff66c07936

Lots of minor changes to support building on Visual Studio. A few MSVC-specific #ifdefs to eliminate things Visual Studio doesn't like. This version now compiles on Windows (provided liblo, Juce and pthread are present) but the TouchKeys device support is not yet enabled. Also, the code now needs to be re-checked on Mac and Linux.
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Sun, 09 Feb 2014 18:40:51 +0000
parents f943785252fc
children
line wrap: on
line source
/*
  TouchKeys: multi-touch musical keyboard control software
  Copyright (c) 2013 Andrew McPherson

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
 
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
  =====================================================================
 
  TouchkeyOscEmulator.h: emulates a TouchKeys source using OSC messages
*/

#ifndef TOUCHKEYOSCEMULATOR_H_INCLUDED
#define TOUCHKEYOSCEMULATOR_H_INCLUDED

#include "Osc.h"
#include "PianoKeyboard.h"

class TouchkeyOscEmulator : public OscHandler {
public:
    // *** Constructor ***
    TouchkeyOscEmulator(PianoKeyboard& keyboard, OscMessageSource& messageSource);
    
    // *** Destructor ***
    ~TouchkeyOscEmulator();
    
    // *** TouchKeys emulation methods ***
    int lowestMidiNote() { return lowestMidiNote_; }
	void setLowestMidiNote(int note) { lowestMidiNote_ = note; }
    
    void allTouchesOff(bool send = true);
    
    // *** OSC handler method ***
	bool oscHandlerMethod(const char *path, const char *types, int numValues, lo_arg **values, void *data);

    // *** Data processing methods ***
    // New touch data point received
    void touchReceived(int key, int touch, float x, float y);
    
    // Touch removed
    void touchOffReceived(int key, int touch);
    
private:
    void clearTouchData(int i);                     // Clear touch data for a particular key
    void removeTouchFromFrame(int note, int index); // Remove a particular touch from the frame
    void addTouchToFrame(int note, int touchId, float x, float y);       // Add a touch with a particular ID
    void updateTouchInFrame(int note, int index, float x, float y);      // Update the touch at the given index
    
private:
	PianoKeyboard& keyboard_;           // Main keyboard controller
    OscMessageSource& source_;          // Source of OSC messages
    
    int lowestMidiNote_;                // Lowest MIDI note
    
    KeyTouchFrame touchFrames_[127];    // Current state of each virtual TouchKey
    int touchIdAssignments_[127][3];    // Assignments between OSC touch IDs and TouchKeys touch IDs
};

#endif  // TOUCHKEYOSCEMULATOR_H_INCLUDED