~mixxxdevelopers/mixxx/features_library_scanner

« back to all changes in this revision

Viewing changes to mixxx/mixxx/controlpotmeter.cpp

  • Committer: tuehaste
  • Date: 2002-02-26 11:12:07 UTC
  • Revision ID: vcs-imports@canonical.com-20020226111207-5rly26cj9gdd19ba
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          controlpotmeter.cpp  -  description
 
3
                             -------------------
 
4
    begin                : Wed Feb 20 2002
 
5
    copyright            : (C) 2002 by Tue and Ken Haste Andersen
 
6
    email                : 
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#include "controlpotmeter.h"
 
19
 
 
20
/* -------- ------------------------------------------------------
 
21
   Purpose: Creates a new potmeter
 
22
   Input:   n - name
 
23
            midino - number of the midi controller.
 
24
            master - pointer to the control to which the potmeter is
 
25
                    attached. This control is acknowledged when the
 
26
                    potmeter is changed.
 
27
            midicontroller - pointer to the midi controller.
 
28
   -------- ------------------------------------------------------ */
 
29
//ControlPotmeter::ControlPotmeter() {}
 
30
ControlPotmeter::ControlPotmeter(char* n, short int _midino, MidiObject *_midi,
 
31
                                 FLOAT _minvalue=0.0, FLOAT _maxvalue=1.0)
 
32
{
 
33
  name = n;
 
34
  position = middlePosition;
 
35
  minvalue = _minvalue;
 
36
  maxvalue = _maxvalue;
 
37
  valuerange = maxvalue-minvalue;
 
38
  value = minvalue + 0.5*(maxvalue-minvalue);
 
39
 
 
40
  midi = _midi;
 
41
  midino = _midino;
 
42
  midi->addpotmeter(this);
 
43
}
 
44
 
 
45
ControlPotmeter::~ControlPotmeter() {
 
46
  midi->removepotmeter(this);
 
47
}
 
48
 
 
49
char* ControlPotmeter::print()
 
50
{
 
51
  return name;
 
52
}
 
53
 
 
54
/* -------- ------------------------------------------------------
 
55
   Purpose: Set the position of the potmeter, and change the
 
56
            value correspondingly.
 
57
   Input:   The (new) position.
 
58
   Output:  The value is updated.
 
59
   -------- ------------------------------------------------------ */
 
60
void ControlPotmeter::slotSetPosition(int _newpos)
 
61
{
 
62
  char newpos =(char)_newpos;
 
63
 
 
64
  char static const maxPosition = 127;
 
65
  char static const minPosition  = 0;
 
66
 
 
67
  // Ensure that the position is within bounds:
 
68
  position = std::max(minPosition,std::min(newpos, maxPosition));
 
69
  // Calculate the value linearly:
 
70
  value = (valuerange/positionrange)*
 
71
    ((maxPosition-newpos)-minPosition)+minvalue;
 
72
 
 
73
  emit valueChanged(value);
 
74
}
 
75
 
 
76
char ControlPotmeter::getPosition()
 
77
{
 
78
  return position;
 
79
}
 
80
 
 
81
void ControlPotmeter::setValue(FLOAT newvalue)
 
82
{
 
83
  value = newvalue;
 
84
  emit valueChanged(value);
 
85
}
 
86
 
 
87
FLOAT ControlPotmeter::getValue()
 
88
{
 
89
  return value;
 
90
}
 
91
 
 
92
char ControlPotmeter::getmidino()
 
93
{ return midino; }