~ubuntu-branches/ubuntu/wily/muse/wily-proposed

« back to all changes in this revision

Viewing changes to muse/ctrl.cpp

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2011-12-03 17:12:54 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20111203171254-28b1j4lpb46r5jtl
Tags: 2.0~rc1-1
* New upstream RC release.
* Refresh patches, remove those patches not needed anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
//    controller handling for mixer automation
7
7
//
8
8
//  (C) Copyright 2003 Werner Schweer (ws@seh.de)
 
9
//  (C) Copyright 2011 Time E. Real (terminator356 on users dot sourceforge dot net)
 
10
//
 
11
//  This program is free software; you can redistribute it and/or
 
12
//  modify it under the terms of the GNU General Public License
 
13
//  as published by the Free Software Foundation; version 2 of
 
14
//  the License, or (at your option) any later version.
 
15
//
 
16
//  This program is distributed in the hope that it will be useful,
 
17
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
//  GNU General Public License for more details.
 
20
//
 
21
//  You should have received a copy of the GNU General Public License
 
22
//  along with this program; if not, write to the Free Software
 
23
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
24
//
9
25
//=========================================================
10
26
 
11
27
 
19
35
#include "globals.h"
20
36
#include "ctrl.h"
21
37
#include "xml.h"
22
 
// #include "audio.h"
 
38
#include "audio.h"
 
39
 
 
40
namespace MusECore {
23
41
 
24
42
void CtrlList::initColor(int i)
25
43
{
81
99
//   value
82
100
//---------------------------------------------------------
83
101
 
84
 
double CtrlList::value(int frame)
 
102
double CtrlList::value(int frame) const
85
103
{
86
 
      if (!automation || empty()) {
87
 
            return _curVal;
88
 
            }
 
104
      // Changed by Tim. p4.0.32...
 
105
      
 
106
      ///if (!automation || empty()) 
 
107
      ///      return _curVal;
 
108
      if(empty()) 
 
109
        return _curVal;
89
110
 
 
111
      double rv;
90
112
      ciCtrl i = upper_bound(frame); // get the index after current frame
91
113
 
92
114
      if (i == end()) { // if we are past all items just return the last value
93
 
            ciCtrl i = end();
 
115
            ///ciCtrl i = end();
94
116
            --i;
95
 
            const CtrlVal& val = i->second;
96
 
            _curVal = val.val;
 
117
            ///const CtrlVal& val = i->second;
 
118
            ///_curVal = val.val;
 
119
            rv = i->second.val;
97
120
            }
98
121
      else if(_mode == DISCRETE)
99
122
      {
100
123
        if(i == begin())
101
 
          _curVal = _default;
 
124
        {
 
125
          ///_curVal = _default;
 
126
          //if(i->second.frame == frame)
 
127
            rv = i->second.val;
 
128
          //else  
 
129
          //  rv = _default;
 
130
        }  
102
131
        else
103
132
        {  
104
133
          --i;
105
 
          const CtrlVal& val = i->second;
106
 
          _curVal = val.val;
 
134
          ///const CtrlVal& val = i->second;
 
135
          ///_curVal = val.val;
 
136
          rv = i->second.val;
107
137
        }  
108
138
      }
109
139
      else {
110
 
        int frame2 = i->second.frame;
111
 
        double val2 = i->second.val;
112
 
        int frame1;
113
 
        double val1;
 
140
        ///int frame2 = i->second.frame;
 
141
        ///double val2 = i->second.val;
 
142
        ///int frame1;
 
143
        ///double val1;
114
144
        if (i == begin()) {
115
 
            frame1 = 0;
116
 
            val1   = _default;
 
145
            ///frame1 = 0;
 
146
            ///val1   = _default;
 
147
            rv = i->second.val;
117
148
        }
118
149
        else {
 
150
            int frame2 = i->second.frame;
 
151
            double val2 = i->second.val;
119
152
            --i;
120
 
            frame1 = i->second.frame;
121
 
            val1   = i->second.val;
122
 
        }
123
 
        //printf("before val1=%f val2=%f\n", val1,val2);
124
 
        if (_valueType == VAL_LOG) {
125
 
          val1 = 20.0*fast_log10(val1);
126
 
          if (val1 < config.minSlider)
127
 
            val1=config.minSlider;
128
 
          val2 = 20.0*fast_log10(val2);
129
 
          if (val2 < config.minSlider)
130
 
            val2=config.minSlider;
131
 
        }
132
 
        //printf("after val1=%f val2=%f\n", val1,val2);
133
 
        frame -= frame1;
134
 
        val2  -= val1;
135
 
        frame2 -= frame1;
136
 
        val1 += (double(frame) * val2)/double(frame2);
137
 
 
138
 
        if (_valueType == VAL_LOG) {
139
 
          val1 = exp10(val1/20.0);
140
 
        }
141
 
        //printf("after val1=%f\n", val1);
142
 
        _curVal = val1;
 
153
            ///frame1 = i->second.frame;
 
154
            ///val1   = i->second.val;
 
155
            int frame1 = i->second.frame;
 
156
            double val1   = i->second.val;
 
157
        ///}
 
158
            //printf("before val1=%f val2=%f\n", val1,val2);
 
159
            if (_valueType == VAL_LOG) {
 
160
              val1 = 20.0*fast_log10(val1);
 
161
              if (val1 < MusEGlobal::config.minSlider)
 
162
                val1=MusEGlobal::config.minSlider;
 
163
              val2 = 20.0*fast_log10(val2);
 
164
              if (val2 < MusEGlobal::config.minSlider)
 
165
                val2=MusEGlobal::config.minSlider;
 
166
            }
 
167
            //printf("after val1=%f val2=%f\n", val1,val2);
 
168
            frame -= frame1;
 
169
            val2  -= val1;
 
170
            frame2 -= frame1;
 
171
            val1 += (double(frame) * val2)/double(frame2);
 
172
    
 
173
            if (_valueType == VAL_LOG) {
 
174
              val1 = exp10(val1/20.0);
 
175
            }
 
176
            //printf("after val1=%f\n", val1);
 
177
            ///_curVal = val1;
 
178
            rv = val1;
 
179
          }
143
180
      }
144
181
// printf("autoVal %d %f\n", frame, _curVal);
145
 
      return _curVal;
 
182
      ///return _curVal;
 
183
      return rv;
146
184
}
147
185
 
 
186
//---------------------------------------------------------
 
187
//   curVal
 
188
//   returns the value at the current audio position 
 
189
//---------------------------------------------------------
 
190
double CtrlList::curVal() const
 
191
 
192
  //double v = value(Pos(audio->tickPos()).frame());      // p4.0.33
 
193
  //double v = value(audio->pos().frame());                 // Try this.
 
194
  //return v;
 
195
  return _curVal;
 
196
}
148
197
 
149
198
//---------------------------------------------------------
150
199
//   setCurVal
152
201
void CtrlList::setCurVal(double val)
153
202
{
154
203
  _curVal = val;
155
 
  if (size() < 2) {
156
 
    add(0,val);
157
 
  }
 
204
  //if (size() < 2)   // Removed p4.0.32
 
205
  //  add(0,val);
158
206
}
159
207
 
160
208
//---------------------------------------------------------
175
223
//   del
176
224
//---------------------------------------------------------
177
225
 
178
 
void CtrlList::del(int /* frame*/)
 
226
void CtrlList::del(int frame)
179
227
      {
180
 
      /*
181
228
      iCtrl e = find(frame);
182
229
      if (e == end()) {
183
 
            printf("CtrlList::del(%d): not found\n", frame);
 
230
            //printf("CtrlList::del(%d): not found\n", frame);
184
231
            return;
185
232
            }
186
233
      erase(e);
187
 
      */
188
234
      }
189
235
 
190
236
//---------------------------------------------------------
264
310
                              }
265
311
                           */   
266
312
                          
267
 
                          // Added by Tim. p3.3.6
268
313
                          //printf("CtrlList::read tag:%s\n", tag.toLatin1().constData());
269
314
                          
270
315
                          int len = tag.length();
320
365
                                  break;
321
366
                                }
322
367
                                  
323
 
                                // Added by Tim. p3.3.6
324
368
                                //printf("CtrlList::read i:%d len:%d fs:%s frame %d: vs:%s val %f \n", i, len, fs.toLatin1().constData(), frame, vs.toLatin1().constData(), val);
325
369
                                
326
370
                                add(frame, val);
333
377
                  case Xml::TagEnd:
334
378
                        if (xml.s1() == "controller")
335
379
                        {
336
 
                              // Added by Tim. p3.3.6
337
380
                              //printf("CtrlList::read _id:%d _curVal:%f\n", _id, _curVal);
338
381
                              
339
382
                              return;
354
397
      insert(std::pair<const int, CtrlList*>(vl->id(), vl));
355
398
      }
356
399
 
 
400
} // namespace MusECore