File: effect.cpp

package info (click to toggle)
musescore2 2.3.2%2Bdfsg3-11~bpo9%2B1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports-sloppy
  • size: 192,432 kB
  • sloc: cpp: 262,278; xml: 176,707; sh: 3,376; ansic: 1,384; python: 356; makefile: 229; perl: 82; pascal: 78
file content (81 lines) | stat: -rw-r--r-- 2,093 bytes parent folder | download | duplicates (13)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//=============================================================================
//  MuseSynth
//  Music Software Synthesizer
//
//  Copyright (C) 2013 Werner Schweer
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2
//  as published by the Free Software Foundation and appearing in
//  the file LICENCE.GPL
//=============================================================================

#include "effect.h"

namespace Ms {

//---------------------------------------------------------
//   parameter
//---------------------------------------------------------

const ParDescr* Effect::parameter(int idx) const
      {
      return &parDescr()[idx];
      }

const ParDescr* Effect::parameter(const QString& name) const
      {
      for (const ParDescr& pd : parDescr()) {
            if (name == pd.name)
                  return &pd;
            }
      return 0;
      }

void Effect::setValue(const QString& name, double value)
      {
      const ParDescr* p = parameter(name);
      if (p == 0)
            return;
      setValue(p->id, value);
      }

void Effect::setValue(int id, double value)
      {
      const ParDescr* p = parameter(id);
      if (p == 0)
            return;
      double v;
      if (p->log)
            v = exp(p->min + value * (p->max - p->min));
      else
            v = p->min + value * (p->max - p->min);

      setNValue(p->id, v);
      }

//---------------------------------------------------------
//   value
//    return normalized value 0-1.0
//---------------------------------------------------------

double Effect::value(const QString& name) const
      {
      const ParDescr* p = parameter(name);
      if (p == 0)
            return 0.0;
      return value(p->id);
      }

double Effect::value(int idx) const
      {
      double v = nvalue(idx);
      const ParDescr* p = parameter(idx);
      if (p->log)
            v = (log(v) - p->min)/(p->max - p->min);
      else
            v = (v - p->min)/(p->max - p->min);
      return v;
      }
}