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

« back to all changes in this revision

Viewing changes to muse/widgets/wtscale.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:
3
3
//  Linux Music Editor
4
4
//    $Id: wtscale.cpp,v 1.3 2004/04/11 13:03:32 wschweer Exp $
5
5
//  (C) Copyright 2000 Werner Schweer (ws@seh.de)
 
6
//
 
7
//  This program is free software; you can redistribute it and/or
 
8
//  modify it under the terms of the GNU General Public License
 
9
//  as published by the Free Software Foundation; version 2 of
 
10
//  the License, or (at your option) any later version.
 
11
//
 
12
//  This program is distributed in the hope that it will be useful,
 
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
//  GNU General Public License for more details.
 
16
//
 
17
//  You should have received a copy of the GNU General Public License
 
18
//  along with this program; if not, write to the Free Software
 
19
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
20
//
6
21
//=========================================================
7
22
 
8
23
#include <values.h>
14
29
#include "wtscale.h"
15
30
#include "midieditor.h"
16
31
#include "globals.h"
 
32
#include "gconfig.h"
17
33
#include "song.h"
18
34
#include "../marker/marker.h"
19
35
#include "icons.h"
20
36
 
 
37
namespace MusEGui {
 
38
 
21
39
//---------------------------------------------------------
22
40
//   WTScale
23
41
//    Wave Time Scale
29
47
      QToolTip::add(this, tr("bar scale"));
30
48
      barLocator = false;
31
49
      raster = r;
32
 
      pos[0] = int(song->tempomap()->tick2time(song->cpos()) * sampleRate);
33
 
      pos[1] = int(song->tempomap()->tick2time(song->lpos()) * sampleRate);
34
 
      pos[2] = int(song->tempomap()->tick2time(song->rpos()) * sampleRate);
 
50
      pos[0] = int(MusEGlobal::song->tempomap()->tick2time(MusEGlobal::song->cpos()) * sampleRate);
 
51
      pos[1] = int(MusEGlobal::song->tempomap()->tick2time(MusEGlobal::song->lpos()) * sampleRate);
 
52
      pos[2] = int(MusEGlobal::song->tempomap()->tick2time(MusEGlobal::song->rpos()) * sampleRate);
35
53
      pos[3] = -1;            // do not show
36
54
      button = Qt::NoButton;
37
55
      setMouseTracking(true);
38
 
      connect(song, SIGNAL(posChanged(int, unsigned, bool)), SLOT(setPos(int, unsigned, bool)));
39
 
      connect(song, SIGNAL(songChanged(int)), SLOT(songChanged(int)));
40
 
      connect(song, SIGNAL(markerChanged(int)), SLOT(redraw()));
 
56
      connect(MusEGlobal::song, SIGNAL(posChanged(int, unsigned, bool)), SLOT(setPos(int, unsigned, bool)));
 
57
      connect(MusEGlobal::song, SIGNAL(songChanged(int)), SLOT(songChanged(int)));
 
58
      connect(MusEGlobal::song, SIGNAL(markerChanged(int)), SLOT(redraw()));
41
59
      setFixedHeight(28);
42
60
      setBg(QColor(0xe0, 0xe0, 0xe0));
43
61
      }
56
74
 
57
75
void WTScale::setPos(int idx, unsigned val, bool adjustScrollbar)
58
76
      {
59
 
      val = int(song->tempomap()->tick2time(val) * sampleRate);
 
77
      val = int(MusEGlobal::song->tempomap()->tick2time(val) * sampleRate);
60
78
      if (val == pos[idx])
61
79
            return;
62
80
      int opos = mapx(pos[idx] == -1 ? val : pos[idx]);
102
120
 
103
121
void WTScale::viewMouseMoveEvent(QMouseEvent* event)
104
122
      {
105
 
      int x= song->tempomap()->time2tick(double(event->x())/double(sampleRate));
106
 
      x = song->raster(x, *raster);
 
123
      int x= MusEGlobal::song->tempomap()->time2tick(double(event->x())/double(sampleRate));
 
124
      x = MusEGlobal::song->raster(x, *raster);
107
125
      if (x < 0)
108
126
            x = 0;
109
127
      emit timeChanged(x);
116
134
                  i = 1;
117
135
                  break;
118
136
            case Qt::RightButton:
119
 
                  i = 2;
 
137
                  if ((MusEGlobal::config.rangeMarkerWithoutMMB) && (event->modifiers() & Qt::ControlModifier))
 
138
                      i = 1;
 
139
                  else
 
140
                      i = 2;
120
141
                  break;
121
142
            default:
122
143
                  return;
123
144
            }
124
 
      song->setPos(i, x);
 
145
      MusEGlobal::song->setPos(i, x);
125
146
      }
126
147
 
127
148
//---------------------------------------------------------
154
175
      p.drawLine(r.x(), y+1, r.x() + r.width(), y+1);
155
176
      QRect tr(r);
156
177
      tr.setHeight(12);
157
 
      MarkerList* marker = song->marker();
 
178
      MarkerList* marker = MusEGlobal::song->marker();
158
179
      for (iMarker m = marker->begin(); m != marker->end(); ++m) {
159
180
            int xp = mapx(int(m->second.time() * sampleRate));
160
181
            if (xp > x+w)
218
239
                  p.drawLine(xp, 0, xp, height());
219
240
            }
220
241
 
221
 
      int ctick = song->samples2tick(mapxDev(x));
 
242
      int ctick = MusEGlobal::song->samples2tick(mapxDev(x));
222
243
      int bar1, bar2, beat, tick;
223
 
      song->tickValues(ctick, &bar1, &beat, &tick);
224
 
      song->tickValues(song->samples2tick(mapxDev(x+w)), &bar2, &beat, &tick);
 
244
      MusEGlobal::song->tickValues(ctick, &bar1, &beat, &tick);
 
245
      MusEGlobal::song->tickValues(MusEGlobal::song->samples2tick(mapxDev(x+w)), &bar2, &beat, &tick);
225
246
 
226
247
//printf("bar %d  %d-%d=%d\n", bar, ntick, stick, ntick-stick);
227
248
 
228
 
      int stick = song->bar2tick(bar1, 0, 0);
 
249
      int stick = MusEGlobal::song->bar2tick(bar1, 0, 0);
229
250
      int ntick;
230
251
      for (int bar = bar1; bar <= bar2; bar++, stick = ntick) {
231
 
            ntick     = song->bar2tick(bar+1, 0, 0);
232
 
            int a = song->tick2samples(ntick);
233
 
            int b = song->tick2samples(stick);
 
252
            ntick     = MusEGlobal::song->bar2tick(bar+1, 0, 0);
 
253
            int a = MusEGlobal::song->tick2samples(ntick);
 
254
            int b = MusEGlobal::song->tick2samples(stick);
234
255
            int tpix  = rmapx(a - b);
235
256
            if (tpix < 64) {
236
257
                  // don�t show beats if measure is this small
257
278
                  }
258
279
            else {
259
280
                  int z, n;
260
 
                  song->timesig(stick, z, n);
 
281
                  MusEGlobal::song->timesig(stick, z, n);
261
282
                  for (int beat = 0; beat < z; beat++) {
262
 
                        int xx = song->tick2samples(song->bar2tick(bar, beat, 0));
 
283
                        int xx = MusEGlobal::song->tick2samples(MusEGlobal::song->bar2tick(bar, beat, 0));
263
284
                        int xp = mapx(xx);
264
285
                        QString s;
265
286
                        QRect r(xp+2, y, 0, h);
284
305
            }
285
306
      }
286
307
 
 
308
} // namespace MusEGui
 
309