summaryrefslogtreecommitdiffstats
path: root/src/controllers/softtakeover.h
blob: f43251780920d4fa31d28746385b60a20de5434c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/***************************************************************************
                           softtakeover.h  -  description
                           --------------
    begin                : Thu Mar 17 2011
    copyright            : (C) 2011 by Sean M. Pappalardo
    email                : spappalardo@mixxx.org
 ***************************************************************************/

#ifndef SOFTTAKEOVER_H
#define SOFTTAKEOVER_H

#include <QHash>

class ControlObject;

// 3/128 units away from the current is enough to catch fast non-sequential moves
//  but not cause an audibly noticeable jump.


class SoftTakeover {
  public:
    static const double kDefaultTakeoverThreshold;

    SoftTakeover();
    bool ignore(ControlObject* control, double newParameter);
    void ignoreNext();
    void setThreshold(double threshold);
    
    struct TestAccess;

  private:
    // If a new value is received within this amount of time, jump to it
    // regardless. This allows quickly whipping controls to work while retaining
    // the benefits of soft-takeover for slower movements.  Setting this too
    // high will defeat the purpose of soft-takeover.
    static const qint64 SUBSEQUENT_VALUE_OVERRIDE_TIME_MILLIS = 50;

    qint64 m_time;
    double m_prevParameter;
    double m_dThreshold;
};

struct SoftTakeover::TestAccess {
    static qint64 getTimeThreshold() {
        return SUBSEQUENT_VALUE_OVERRIDE_TIME_MILLIS;
    }
};

class SoftTakeoverCtrl {
  public:
    SoftTakeoverCtrl();
    ~SoftTakeoverCtrl();

    // Enable soft-takeover for the given Control.
    // This does nothing on a control that already has soft-takeover enabled.
    void enable(ControlObject* control);
    // Disable soft-takeover for the given Control
    void disable(ControlObject* control);
    // Check to see if the new value for the Control should be ignored
    bool ignore(ControlObject* control, double newMidiParameter);

  private:
    QHash<ControlObject*, SoftTakeover*> m_softTakeoverHash;
};

#endif