~ubuntu-branches/ubuntu/quantal/muse/quantal

« back to all changes in this revision

Viewing changes to awl/tcanvas.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2011-08-12 11:16:41 UTC
  • mto: (1.1.9) (10.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: james.westby@ubuntu.com-20110812111641-72iatqb9jomjejko
ImportĀ upstreamĀ versionĀ 2.0~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//  Awl
 
3
//  Audio Widget Library
 
4
//  $Id:$
 
5
//
 
6
//  Copyright (C) 2002-2006 by Werner Schweer and others
 
7
//
 
8
//  This program is free software; you can redistribute it and/or modify
 
9
//  it under the terms of the GNU General Public License version 2.
 
10
//
 
11
//  This program is distributed in the hope that it will be useful,
 
12
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
//  GNU General Public License for more details.
 
15
//
 
16
//  You should have received a copy of the GNU General Public License
 
17
//  along with this program; if not, write to the Free Software
 
18
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
//=============================================================================
 
20
 
 
21
#include "tcanvas.h"
 
22
#include "al/al.h"
 
23
#include "al/sig.h"
 
24
#include "al/tempo.h"
 
25
#include "../muse/gconfig.h"
 
26
#include "../muse/icons.h"
 
27
 
 
28
#include "metronom.xpm"
 
29
#include "clock.xpm"
 
30
 
 
31
#ifdef __APPLE__
 
32
  inline double exp10(double a) { return pow(10.0, a); }
 
33
#endif
 
34
 
 
35
static QIcon* clockIcon;
 
36
static QIcon* metronomIcon;
 
37
 
 
38
FollowMode TimeCanvas::followMode = FOLLOW_JUMP;
 
39
QPixmap* TimeCanvas::octave;
 
40
QPixmap* TimeCanvas::mk1;
 
41
QPixmap* TimeCanvas::mk2;
 
42
QPixmap* TimeCanvas::mk3;
 
43
QPixmap* TimeCanvas::mk4;
 
44
 
 
45
enum DragType {
 
46
      DRAG_RULER,
 
47
      DRAG_CANVASA, DRAG_CANVAS_B,
 
48
      DRAG_PANELA, DRAG_PANELB,
 
49
      DRAG_OTHER
 
50
      };
 
51
 
 
52
//---------------------------------------------------------
 
53
//   TimeCanvas
 
54
//---------------------------------------------------------
 
55
 
 
56
TimeCanvas::TimeCanvas(TimeCanvasType t)
 
57
   : QFrame()
 
58
      {
 
59
      setAttribute(Qt::WA_NoSystemBackground, true);
 
60
 
 
61
      _yFit      = false;
 
62
      _tool      = PointerTool;
 
63
      type       = t;
 
64
      _timeType  = AL::TICKS;
 
65
      marker     = 0;
 
66
      showCursor = false;
 
67
      ctrlHeight = 0;
 
68
      curPitch   = -1;
 
69
      mouseInB   = false;
 
70
      dragType   = DRAG_OTHER;
 
71
      followPos  = true;
 
72
 
 
73
      // set default color
 
74
      canvasBackgroundColor = QColor(0x71, 0x8d, 0xbe);
 
75
 
 
76
      if (clockIcon == 0) {
 
77
            clockIcon = new QIcon(QPixmap(clock_xpm));
 
78
            metronomIcon = new QIcon(QPixmap(metronom_xpm));
 
79
            }
 
80
      button = Qt::NoButton;
 
81
      grid   = new QGridLayout;
 
82
      grid->setMargin(0);
 
83
      grid->setSpacing(1);
 
84
      setLayout(grid);
 
85
 
 
86
      _widget = new QWidget;
 
87
      _widget->setAttribute(Qt::WA_NoSystemBackground);
 
88
      _widget->setAttribute(Qt::WA_StaticContents);
 
89
      _widget->installEventFilter(this);
 
90
      _widget->setMouseTracking(true);
 
91
      _widget->setAcceptDrops(true);
 
92
 
 
93
      // allow to set slider position before slider range
 
94
      // is known:
 
95
 
 
96
      pos1.setTick(0);
 
97
      pos2.setTick(INT_MAX);
 
98
 
 
99
      hmag = new QSlider(Qt::Horizontal);
 
100
      hmag->setRange(0, 100);
 
101
      _xmagMin = 0.001;
 
102
      _xmagMax = 0.3;
 
103
      _xmag    = 0.04;
 
104
      hmag->setValue(xmag2s(_xmag));
 
105
 
 
106
      vmag = 0;
 
107
      if (type != TIME_CANVAS_DRUMEDIT) {
 
108
            vmag = new QSlider(Qt::Vertical);
 
109
            vmag->setRange(0, 100);
 
110
            vmag->setPageStep(1);
 
111
            }
 
112
      _ymag = 1.0;
 
113
 
 
114
      hbar = new QScrollBar(Qt::Horizontal);
 
115
      hbar->setRange(0, INT_MAX);
 
116
      vbar = new QScrollBar(Qt::Vertical);
 
117
      timeTypeButton = new QToolButton;
 
118
      timeTypeButton->setFixedSize(20, rulerHeight);
 
119
      setTimeType1(AL::TICKS);
 
120
      yRange = 0;
 
121
 
 
122
      switch(type) {
 
123
            case TIME_CANVAS_PIANOROLL:
 
124
                  _ymagMin = 0.5;
 
125
                  _ymagMax = 3.0;
 
126
                  vmag->setValue(lrint((_ymag-_ymagMin)*100.0/(_ymagMax-_ymagMin)));
 
127
                  initPianoroll();
 
128
                  break;
 
129
            case TIME_CANVAS_DRUMEDIT:
 
130
                  _ymagMin = 1.0;
 
131
                  _ymagMax = 1.0;
 
132
                  yRange   = drumHeight * 128;
 
133
                  break;
 
134
            case TIME_CANVAS_WAVEEDIT:
 
135
                  _xmagMin = 0.001;
 
136
                  _xmagMax = 100.0;
 
137
                  _xmag    = 0.04;
 
138
                  _ymagMin = 1.0;
 
139
                  _ymagMax = 10.0;
 
140
                  _ymag    = 1.0;
 
141
                  break;
 
142
            default:
 
143
                  _ymagMin = 1.0;
 
144
                  _ymagMax = 1.0;
 
145
                  break;
 
146
            }
 
147
      updateGeometry();
 
148
      if (type == TIME_CANVAS_PIANOROLL || type == TIME_CANVAS_DRUMEDIT
 
149
         || type == TIME_CANVAS_WAVEEDIT) {
 
150
            addCtrlButton = new QPushButton(tr("Ctrl"), _widget);
 
151
            addCtrlButton->setGeometry(1, 1, rPanelA.width()-4, rulerHeight-4);
 
152
            addCtrlButton->setToolTip(tr("Add Controller View"));
 
153
            connect(addCtrlButton, SIGNAL(clicked()), SLOT(addCtrlClicked()));
 
154
            }
 
155
 
 
156
      grid->addWidget(_widget,  0, 0, 3, 2);
 
157
      grid->addWidget(hbar,     3, 0, Qt::AlignVCenter);
 
158
      grid->addWidget(hmag,     3, 1, Qt::AlignVCenter);
 
159
      grid->addWidget(timeTypeButton, 0, 2);
 
160
      grid->addWidget(vbar,     1, 2, Qt::AlignHCenter);
 
161
      if (vmag)
 
162
            grid->addWidget(vmag,     2, 2, Qt::AlignHCenter);
 
163
 
 
164
      grid->setColumnStretch(0, 100);
 
165
      grid->setRowStretch(1, 100);
 
166
 
 
167
      _raster = 0;
 
168
      updateScrollBars();
 
169
      connect(hbar, SIGNAL(valueChanged(int)), SLOT(moveX(int)));
 
170
      connect(vbar, SIGNAL(valueChanged(int)), SLOT(moveY(int)));
 
171
      connect(hmag, SIGNAL(valueChanged(int)), SLOT(scaleX(int)));
 
172
      if (vmag)
 
173
            connect(vmag, SIGNAL(valueChanged(int)), SLOT(scaleY(int)));
 
174
      connect(timeTypeButton, SIGNAL(clicked()), SLOT(toggleTimeType()));
 
175
      }
 
176
 
 
177
//---------------------------------------------------------
 
178
//   resizeController
 
179
//---------------------------------------------------------
 
180
 
 
181
void TimeCanvas::resizeController(int h)
 
182
      {
 
183
      if (h == ctrlHeight)
 
184
            return;
 
185
      int updateH = h > ctrlHeight ? h : ctrlHeight;
 
186
      ctrlHeight = h;
 
187
      updateGeometry();
 
188
      updateScrollBars();
 
189
      widget()->update(0, widget()->height() - updateH, widget()->width(), updateH);
 
190
      }
 
191
 
 
192
//---------------------------------------------------------
 
193
//   eventFilter
 
194
//---------------------------------------------------------
 
195
 
 
196
bool TimeCanvas::eventFilter(QObject* obj, QEvent* event)
 
197
      {
 
198
      if (obj != _widget)
 
199
            return QFrame::eventFilter(obj, event);
 
200
 
 
201
      switch(event->type()) {
 
202
            case QEvent::Paint:
 
203
                  {
 
204
                  QPainter p(_widget);
 
205
                  canvasPaintEvent(((QPaintEvent*)event)->rect(), p);
 
206
                  }
 
207
                  return true;
 
208
 
 
209
            case QEvent::Resize:
 
210
                  updateGeometry();
 
211
                  updateScrollBars();
 
212
                  layout();
 
213
                  return false;
 
214
 
 
215
            case QEvent::MouseButtonDblClick:
 
216
                  {
 
217
                  QMouseEvent* me = (QMouseEvent*)event;
 
218
                  QPoint p(me->pos());
 
219
                  button   = me->button();
 
220
                  keyState = me->modifiers();
 
221
                  mouseDoubleClick(me);
 
222
                  }
 
223
                  return true;
 
224
 
 
225
            case QEvent::MouseButtonPress:
 
226
                  {
 
227
                  QMouseEvent* me = (QMouseEvent*)event;
 
228
                  keyState = me->modifiers();
 
229
                  button   = me->button();
 
230
                  QPoint p(me->pos());
 
231
                  int x = p.x() - rRuler.x();
 
232
                  bool shift = keyState & Qt::ShiftModifier;
 
233
 
 
234
                  if (rRuler.contains(p)) {
 
235
                        dragType = DRAG_RULER;
 
236
                        if (shift) {
 
237
                              AL::Pos pos(pix2pos(x));
 
238
                              if (button == Qt::LeftButton)
 
239
                                    emit addMarker(pos);
 
240
                              else if (button == Qt::RightButton)
 
241
                                    emit removeMarker(pos);
 
242
                              return true;
 
243
                              }
 
244
                        }
 
245
                  else {
 
246
                        dragType = DRAG_OTHER;
 
247
                        mousePress(me);
 
248
                        }
 
249
                  }
 
250
                  // go on with MouseMove
 
251
 
 
252
            case QEvent::MouseMove:
 
253
                  {
 
254
                  QMouseEvent* me = (QMouseEvent*)event;
 
255
                  keyState        = me->modifiers();
 
256
                  button          = me->buttons();
 
257
                  QPoint p(me->pos());
 
258
                  AL::Pos pos(pix2pos(p.x()-rCanvasA.x()));
 
259
 
 
260
                  if (dragType == DRAG_OTHER) {
 
261
                        if (button == 0 && (rPanelB.contains(p) || rCanvasB.contains(p))) {
 
262
                              if (!mouseInB) {
 
263
                                    mouseInB = true;
 
264
                                    enterB();
 
265
                                    }
 
266
                              }
 
267
                        else {
 
268
                              if (button == 0 && mouseInB) {
 
269
                                    mouseInB = false;
 
270
                                    leaveB();
 
271
                                    }
 
272
                              }
 
273
 
 
274
                        if (showCursor && p.x() < rCanvasA.x()) {
 
275
                              showCursor = false;
 
276
                              widget()->update(rRuler);
 
277
                              emit cursorPos(cursor, showCursor);
 
278
                              }
 
279
 
 
280
                        if (p.x() >= rCanvasA.x() && (cursor != pos)) {
 
281
                                        int x1 = pos2pix(cursor) + rCanvasA.x();
 
282
                              int x2 = pos2pix(pos)    + rCanvasA.x();
 
283
                              QRect r1(x1-1, 0, 2, rRuler.height());
 
284
                              QRect r2(x2-1, 0, 2, rRuler.height());
 
285
                              widget()->update(rRuler & (r1 | r2));
 
286
                              cursor     = pos;
 
287
                              showCursor = true;
 
288
                              emit cursorPos(cursor, showCursor);
 
289
                              }
 
290
 
 
291
                        if (rRuler.contains(p)) {
 
292
                              int b = me->buttons();
 
293
                              if (b == 0)
 
294
                                    return true;
 
295
                              int i = 0;
 
296
                              if (b & Qt::MidButton)
 
297
                                    i = 1;
 
298
                              else if (b & Qt::RightButton)
 
299
                                    i = 2;
 
300
                              if (keyState & Qt::ShiftModifier)
 
301
                                    emit addMarker(i);
 
302
                              emit posChanged(i, pos);
 
303
                              }
 
304
                        else {
 
305
                              mouseMove(p);
 
306
                              }
 
307
                        }
 
308
                  else if (dragType == DRAG_RULER) {
 
309
                        int b = me->buttons();
 
310
                        if (b == 0)
 
311
                              return true;
 
312
                        int i = 0;
 
313
                        if (b & Qt::MidButton)
 
314
                              i = 1;
 
315
                        else if (b & Qt::RightButton)
 
316
                              i = 2;
 
317
                        if (keyState & Qt::ShiftModifier)
 
318
                              emit addMarker(i);
 
319
                        emit posChanged(i, pos);
 
320
                        }
 
321
                  }
 
322
                  return true;
 
323
 
 
324
            case QEvent::MouseButtonRelease:
 
325
                  {
 
326
                  QMouseEvent* me = (QMouseEvent*)event;
 
327
                  button   = Qt::NoButton;
 
328
                  keyState = me->modifiers();
 
329
                  mouseRelease(me);
 
330
                dragType = DRAG_OTHER;
 
331
                  }
 
332
                  return true;
 
333
 
 
334
            case QEvent::DragEnter:
 
335
                  dragEnter((QDragEnterEvent*)event);
 
336
                  return true;
 
337
 
 
338
            case QEvent::Drop:
 
339
                  drop((QDropEvent*)event);
 
340
                  return true;
 
341
 
 
342
            case QEvent::DragMove:
 
343
                  dragMove((QDragMoveEvent*)event);
 
344
                  return true;
 
345
 
 
346
            case QEvent::DragLeave:
 
347
                  dragLeave((QDragLeaveEvent*)event);
 
348
                  return true;
 
349
 
 
350
            case QEvent::Leave:
 
351
                {
 
352
                  emit cursorPos(cursor, false);
 
353
                  showCursor = false;
 
354
                  emit pitchChanged(-1);
 
355
                  curPitch = -1;
 
356
                QRect r(rRuler);
 
357
                if (!rPanelA.isEmpty())
 
358
                        r |= rPanelA;
 
359
                  widget()->update(r);
 
360
 
 
361
                  if (mouseInB) {
 
362
                        mouseInB = false;
 
363
                        // button = ((QMouseEvent*)event)->buttons();
 
364
                        leaveB();
 
365
                        }
 
366
                  }
 
367
                  return false;
 
368
 
 
369
            case QEvent::Wheel:
 
370
                {
 
371
                  QWheelEvent* e = (QWheelEvent*)event;
 
372
                  if (e->orientation() != Qt::Vertical)
 
373
                        return true;
 
374
                if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) {
 
375
                        //
 
376
                        // xmag
 
377
                        //
 
378
                        int oldx = e->x() - rCanvasA.x();
 
379
                        AL::Pos pos(pix2pos(oldx));
 
380
                        int step = e->delta() / 120;
 
381
                        if (step > 0) {
 
382
                              for (int i = 0; i< step; ++i)
 
383
                                    _xmag *= 1.1;
 
384
                              }
 
385
                        else {
 
386
                              for (int i = 0; i < -step; ++i)
 
387
                                    _xmag *= 0.9;
 
388
                              }
 
389
                        if (_xmag < _xmagMin)
 
390
                              _xmag = _xmagMin;
 
391
                        else if (_xmag > _xmagMax)
 
392
                              _xmag = _xmagMax;
 
393
                        hmag->setValue(xmag2s(_xmag));
 
394
                        int newx = pos2pix(pos);
 
395
                        updateScrollBars();
 
396
                        hbar->setValue(wpos.x() + (newx - oldx));
 
397
                        updateRulerMag();
 
398
                        magChanged();
 
399
                        _widget->update();
 
400
                        }
 
401
                  else {
 
402
                        //
 
403
                        //   scroll
 
404
                        //
 
405
                        int step = qMin(QApplication::wheelScrollLines() * vbar->singleStep(), vbar->pageStep());
 
406
                        int offset = e->delta() * step / 120;
 
407
                        if (vbar->invertedControls())
 
408
                                offset = -offset;
 
409
                        if (qAbs(offset) < 1)
 
410
                                return true;
 
411
                vbar->setValue(vbar->value() + offset);
 
412
                        }
 
413
                  }
 
414
                return true;
 
415
            default:
 
416
// printf("event %d missed\n", event->type());
 
417
                  break;
 
418
            }
 
419
      return false;
 
420
      }
 
421
 
 
422
 
 
423
 
 
424
void TimeCanvas::keyPressEvent(QKeyEvent *e)
 
425
{
 
426
    if (e->key() == Qt::Key_Up   || e->key() == Qt::Key_Down ||
 
427
        e->key() == Qt::Key_Left || e->key() == Qt::Key_Right)
 
428
        keyboardNavigate(e);
 
429
}
 
430
 
 
431
//---------------------------------------------------------
 
432
//   moveX
 
433
//---------------------------------------------------------
 
434
 
 
435
void TimeCanvas::moveX(int x)
 
436
      {
 
437
      int dx = wpos.x() - x;
 
438
      wpos.setX(x);
 
439
 
 
440
      int wh = _widget->height();
 
441
 
 
442
      if (type == TIME_CANVAS_PIANOROLL || type == TIME_CANVAS_DRUMEDIT
 
443
         || TIME_CANVAS_WAVEEDIT) {
 
444
            _widget->scroll(dx, 0, QRect(rCanvasA.x(), 0, rCanvasA.width(), wh));
 
445
 
 
446
            //HACK:
 
447
            // update controller names
 
448
            int w = 100 + ((dx > 0) ? dx : 0);
 
449
            _widget->update(rCanvasB.x(), rCanvasB.y(), w, rCanvasB.height());
 
450
 
 
451
            //HACK:
 
452
            // repaint rounded line end (splitter handle for controller
 
453
            // canvas)
 
454
            int x = rCanvasB.x() + rCanvasB.width() - 1;
 
455
            w = 1;
 
456
            if (dx < 0) {
 
457
                  x += dx;
 
458
                  w -= dx;
 
459
                  }
 
460
            _widget->update(x, rCanvasB.y(), w, rCanvasB.height());
 
461
            }
 
462
      else
 
463
            _widget->scroll(dx, 0);
 
464
      emit contentsMoving(wpos.x(), wpos.y());
 
465
      }
 
466
 
 
467
//---------------------------------------------------------
 
468
//   moveY
 
469
//---------------------------------------------------------
 
470
 
 
471
void TimeCanvas::moveY(int y)
 
472
      {
 
473
      int dy = wpos.y() - y;
 
474
      if (dy == 0)
 
475
            return;
 
476
      wpos.setY(y);
 
477
 
 
478
      // dont move ruler:
 
479
 
 
480
      int ww = _widget->width();
 
481
      int wh = _widget->height();
 
482
 
 
483
      QRect r(0, rulerHeight, ww, wh - rulerHeight - ctrlHeight);
 
484
 
 
485
      _widget->scroll(0, dy, r);
 
486
      emit contentsMoving(wpos.x(), wpos.y());
 
487
      }
 
488
 
 
489
//---------------------------------------------------------
 
490
//   setYPos
 
491
//---------------------------------------------------------
 
492
 
 
493
void TimeCanvas::setYPos(int y)
 
494
      {
 
495
      setWPos(QPoint(wpos.x(), y));
 
496
      }
 
497
 
 
498
//---------------------------------------------------------
 
499
//   setWPos
 
500
//---------------------------------------------------------
 
501
 
 
502
void TimeCanvas::setWPos(const QPoint& p)
 
503
      {
 
504
      if (wpos != p) {
 
505
            wpos = p;
 
506
            hbar->setValue(wpos.x());
 
507
            vbar->setValue(wpos.y());
 
508
            _widget->update();
 
509
//            QCoreApplication::flush();
 
510
            }
 
511
      }
 
512
 
 
513
//---------------------------------------------------------
 
514
//   paintClockRuler
 
515
//---------------------------------------------------------
 
516
 
 
517
void TimeCanvas::paintClockRuler(QPainter& p, const QRect& r)
 
518
      {
 
519
      int x1 = r.x();
 
520
      int x2 = x1 + r.width();
 
521
 
 
522
      int y1 = r.y();
 
523
      int rh = r.height();
 
524
      if (y1 < rulerHeight) {
 
525
            rh -= rulerHeight - y1;
 
526
            y1 = rulerHeight;
 
527
            }
 
528
      int y2 = y1 + rh;
 
529
 
 
530
      //---------------------------------------------------
 
531
      //    draw Marker
 
532
      //---------------------------------------------------
 
533
 
 
534
      int y = rulerHeight - 16;
 
535
      p.setPen(Qt::black);
 
536
      p.setFont(_font3);
 
537
      QRect tr(r);
 
538
      tr.setHeight(12);
 
539
 
 
540
      if (marker) {
 
541
            for (AL::iMarker m = marker->begin(); m != marker->end(); ++m) {
 
542
                  int xp = mapx(int(m->second.frame()));
 
543
                  if (xp > x2)
 
544
                        break;
 
545
                  AL::iMarker mm = m;
 
546
                  ++mm;
 
547
                  int xe = x2;
 
548
                  if (mm != marker->end()) {
 
549
                        xe = mapx(mm->first);
 
550
                        }
 
551
                  QRect tr(xp, 0, x2 - xp, 11);
 
552
                  if (m->second.current()) {
 
553
                        p.fillRect(tr, Qt::white);
 
554
                        }
 
555
                  if (r.intersects(tr)) {
 
556
                        int x2;
 
557
                        AL::iMarker mm = m;
 
558
                        ++mm;
 
559
                        if (mm != marker->end())
 
560
                              x2 = mapx(mm->first);
 
561
                        else
 
562
                              x2 = xp+200;
 
563
                        QRect r  = QRect(xp+10, 0, x2-xp, 12);
 
564
                        p.drawPixmap(xp, 0, *flagIconS);
 
565
                        p.drawText(r, Qt::AlignLeft|Qt::AlignVCenter, m->second.name());
 
566
                        }
 
567
                  }
 
568
            }
 
569
 
 
570
      p.setPen(Qt::black);
 
571
      if (showCursor) {
 
572
            int xp = pos2pix(cursor);
 
573
            if (xp >= x1 && xp < x2)
 
574
                  p.drawLine(xp, 0, xp, rulerHeight);
 
575
            }
 
576
 
 
577
      AL::Pos p1(pix2pos(x1));
 
578
      AL::Pos p2(pix2pos(x2));
 
579
 
 
580
      int sec1 = p1.frame() / AL::sampleRate;
 
581
      int sec2 = (p2.frame() + AL::sampleRate - 1) / AL::sampleRate;
 
582
 
 
583
      int sw = lrint(AL::sampleRate * _xmag);
 
584
 
 
585
      if (sw > 20) {
 
586
            for (int sec = sec1; sec < sec2; ++sec) {
 
587
                  int min = sec / 60;
 
588
                  int sr  = sec % 60;
 
589
 
 
590
                  int yy;
 
591
                  QString s;
 
592
                  if (sr == 0) {
 
593
                        p.setFont(_font2);
 
594
                        s.sprintf("%d:00", min);
 
595
                        yy = y;
 
596
                        }
 
597
                  else {
 
598
                        p.setFont(_font1);
 
599
                        s.sprintf("%02d", sr);
 
600
                        yy = y + 7;
 
601
                        }
 
602
                  int xp = pos2pix(AL::Pos(sec * AL::sampleRate, AL::FRAMES));
 
603
// printf("  sec %d min %d sr %d  xp %d\n", sec, min, sr, xp);
 
604
                  p.setPen(Qt::black);
 
605
                  p.drawLine(xp, yy, xp, rulerHeight);
 
606
                  p.drawText(xp + 2, rulerHeight - 4, s);
 
607
                  p.setPen(sr == 0 ? Qt::lightGray : Qt::gray);
 
608
                  p.drawLine(xp, y1, xp, y2);
 
609
                  }
 
610
            }
 
611
      else {
 
612
            int min1 = sec1/60;
 
613
            int min2 = (sec2+59)/60;
 
614
            for (int min = min1; min < min2; ++min) {
 
615
                  QString s;
 
616
                  p.setFont(_font2);
 
617
                  s.sprintf("%d", min);
 
618
                  int xp = pos2pix(AL::Pos(min * AL::sampleRate * 60, AL::FRAMES));
 
619
                  p.setPen(Qt::black);
 
620
                  p.drawLine(xp, y, xp, rulerHeight);
 
621
                  p.drawText(xp + 2, rulerHeight - 4, s);
 
622
                  p.setPen(Qt::lightGray);
 
623
                  p.drawLine(xp, y1, xp, y2);
 
624
                  }
 
625
            }
 
626
      }
 
627
 
 
628
//---------------------------------------------------------
 
629
//   updateRulerMag
 
630
//---------------------------------------------------------
 
631
 
 
632
void TimeCanvas::updateRulerMag()
 
633
      {
 
634
      int bar1, beat, tick;
 
635
      pos1.mbt(&bar1, &beat, &tick);
 
636
      AL::Pos stick(bar1, 0, 0);
 
637
      AL::Pos ntick = AL::Pos(bar1 + 1, 0, 0);
 
638
      int tpix  = pos2pix(ntick) - pos2pix(stick);
 
639
      metronomeRulerMag = 0;
 
640
      if (tpix < 64)
 
641
        metronomeRulerMag = 1;
 
642
      if (tpix < 32)
 
643
        metronomeRulerMag = 2;
 
644
        if (tpix <= 16)
 
645
        metronomeRulerMag = 3;
 
646
        if (tpix < 8)
 
647
        metronomeRulerMag = 4;
 
648
      if (tpix <= 4)
 
649
        metronomeRulerMag = 5;
 
650
      if (tpix <= 2)
 
651
        metronomeRulerMag = 6;
 
652
      }
 
653
 
 
654
//---------------------------------------------------------
 
655
//   paintMetronomRuler
 
656
//---------------------------------------------------------
 
657
 
 
658
void TimeCanvas::paintMetronomRuler(QPainter& p, const QRect& r)
 
659
      {
 
660
      static const int mag[7] = {
 
661
            1, 1, 2, 5, 10, 20, 50
 
662
            };
 
663
 
 
664
      int x = r.x();
 
665
      int w = r.width();
 
666
      int y = rulerHeight - 16;
 
667
 
 
668
      p.setFont(_font3);
 
669
 
 
670
      int h  = 14;
 
671
      int y1 = r.y();
 
672
      int rh = r.height();
 
673
      if (y1 < rulerHeight) {
 
674
            rh -= rulerHeight - y1;
 
675
            y1 = rulerHeight;
 
676
            }
 
677
      int y2 = y1 + rh;
 
678
 
 
679
      if (x < (MAP_OFFSET - wpos.x()))
 
680
            x = MAP_OFFSET - wpos.x();
 
681
      AL::Pos pos1 = pix2pos(x);
 
682
      AL::Pos pos2 = pix2pos(x+w);
 
683
 
 
684
      if (marker) {
 
685
            AL::iMarker start = marker->lower_bound(pos1.tick());
 
686
            if (start != marker->begin())
 
687
                  --start;
 
688
            AL::iMarker end = marker->lower_bound(pos2.tick());
 
689
            for (AL::iMarker m = start; m != end; ++m) {
 
690
                  AL::Pos pm1(m->second);
 
691
                  AL::iMarker m2 = m;
 
692
                  ++m2;
 
693
                  AL::Pos pm2(pos2);
 
694
                  if (m2 != marker->end())
 
695
                        pm2 = m2->second;
 
696
 
 
697
                  int x1 = pos2pix(pm1);
 
698
                  int x2 = pos2pix(pm2);
 
699
 
 
700
                  if (pos[0] >= pm1 && (m2 == marker->end() || pos[0] < pm2))
 
701
                        p.fillRect(x1, 0, x2 - x1, 11, Qt::white);
 
702
 
 
703
                  QRect r  = QRect(x1 + 10, 0, x2 - x1, 12);
 
704
                  p.drawPixmap(x1, 0, *flagIconS);
 
705
                  p.drawText(r, Qt::AlignLeft|Qt::AlignVCenter, m->second.name());
 
706
                  }
 
707
            }
 
708
 
 
709
      //---------------------------------------------------
 
710
      //    draw raster
 
711
      //---------------------------------------------------
 
712
 
 
713
      int bar1, bar2, beat, tick;
 
714
      pos1.mbt(&bar1, &beat, &tick);
 
715
      pos2.mbt(&bar2, &beat, &tick);
 
716
 
 
717
      int n = mag[metronomeRulerMag];
 
718
 
 
719
        bar1 = (bar1 / n) * n;          // round down
 
720
      if (bar1 && n >= 2)
 
721
            bar1 -= 1;
 
722
        bar2 = ((bar2 + n - 1) / n) * n; // round up
 
723
 
 
724
      for (int bar = bar1; bar <= bar2;) {
 
725
        AL::Pos stick(bar, 0, 0);
 
726
            if (metronomeRulerMag) {
 
727
                        p.setFont(_font2);
 
728
                  int x = pos2pix(stick);
 
729
                  QString s;
 
730
                  s.setNum(bar + 1);
 
731
 
 
732
                  p.setPen(Qt::black);
 
733
                  p.drawLine(x, y, x, y + h);
 
734
                  QRect r = QRect(x+2, y, 1000, h);
 
735
                  p.drawText(r, Qt::AlignLeft | Qt::AlignVCenter, s);
 
736
                  p.setPen(Qt::lightGray);
 
737
                  if (x > 0)
 
738
                        p.drawLine(x, y1, x, y2);
 
739
                  }
 
740
            else {
 
741
                  AL::TimeSignature sig = stick.timesig();
 
742
                  int z = sig.z;
 
743
                  for (int beat = 0; beat < z; beat++) {
 
744
                        AL::Pos xx(bar, beat, 0);
 
745
                        int xp = pos2pix(xx);
 
746
                        if (xp < 0)
 
747
                              continue;
 
748
                        QString s;
 
749
                        QRect r(xp+2, y + 1, 1000, h);
 
750
                        int y3;
 
751
                        int num;
 
752
                        if (beat == 0) {
 
753
                              num = bar + 1;
 
754
                              y3  = y + 2;
 
755
                              p.setFont(_font2);
 
756
                              }
 
757
                        else {
 
758
                              num = beat + 1;
 
759
                              y3  = y + 8;
 
760
                              p.setFont(_font1);
 
761
                              r.moveTop(r.top() + 1);
 
762
                              }
 
763
                        s.setNum(num);
 
764
                        p.setPen(Qt::black);
 
765
                        p.drawLine(xp, y3, xp, y+h);
 
766
                        p.drawText(r, Qt::AlignLeft | Qt::AlignVCenter, s);
 
767
                        p.setPen(beat == 0 ? Qt::lightGray : Qt::gray);
 
768
                        if (xp > 0)
 
769
                              p.drawLine(xp, y1, xp, y2);
 
770
                        }
 
771
                  }
 
772
            if (bar == 0 && n >= 2)
 
773
                  bar += (n-1);
 
774
            else
 
775
                  bar += n;
 
776
            }
 
777
      //
 
778
      //  draw mouse cursor marker
 
779
      //
 
780
      p.setPen(Qt::black);
 
781
      if (showCursor) {
 
782
            int xp = pos2pix(cursor);
 
783
            if (xp >= x && xp < x+w)
 
784
                  p.drawLine(xp, 0, xp, rulerHeight-1);
 
785
            }
 
786
 
 
787
      }
 
788
 
 
789
//---------------------------------------------------------
 
790
//   tempoChanged
 
791
//---------------------------------------------------------
 
792
 
 
793
void TimeCanvas::tempoChanged()
 
794
      {
 
795
      widget()->update(rCanvasA.x(), 0, rCanvasA.width(), widget()->height());
 
796
      }
 
797
 
 
798
//---------------------------------------------------------
 
799
//   canvasPaintEvent
 
800
//---------------------------------------------------------
 
801
 
 
802
void TimeCanvas::canvasPaintEvent(const QRect& r, QPainter& p)
 
803
      {
 
804
      if (r.intersects(rButton)) {
 
805
            p.fillRect(rButton, QColor(0xe0, 0xe0, 0xe0));
 
806
            p.setPen(QPen(Qt::black, 2));
 
807
            int y = rButton.y() + rButton.height() - 1;
 
808
            p.drawLine(rButton.x(), y, rButton.width(), y);
 
809
            }
 
810
      p.setRenderHint(QPainter::TextAntialiasing, true);
 
811
 
 
812
      QRect par = r & rPanelA;
 
813
      if (!(par.isEmpty() || rPanelA.isEmpty())) {
 
814
            if (type == TIME_CANVAS_DRUMEDIT) {
 
815
                  paintDrumList(p, par);
 
816
                  }
 
817
            else if (type == TIME_CANVAS_PIANOROLL) {
 
818
                  paintPiano(p, par);
 
819
                  }
 
820
            else if (type == TIME_CANVAS_WAVEEDIT) {
 
821
                  p.fillRect(par, QColor(0xe0, 0xe0, 0xe0));
 
822
                  }
 
823
            }
 
824
 
 
825
      QRect pbr(r & rPanelB);
 
826
      QRect hor(r & (rRuler | rCanvasA | rCanvasB));
 
827
      QRect car(r & rCanvasA);
 
828
      QRect cbr(r & rCanvasB);
 
829
 
 
830
      bool drawPanelB  = !(pbr.isEmpty() || rPanelB.isEmpty());
 
831
      bool drawRuler   = !(hor.isEmpty() || (rRuler.isEmpty() && rCanvasA.isEmpty() && rCanvasB.isEmpty()));
 
832
      bool drawCanvasA = !(car.isEmpty() || rCanvasA.isEmpty());
 
833
      bool drawCanvasB = !(cbr.isEmpty() || rCanvasB.isEmpty());
 
834
 
 
835
      //
 
836
      //  draw canvas background
 
837
      //
 
838
 
 
839
      p.setClipRect(r);
 
840
      p.setBrushOrigin(QPoint(car.x() + wpos.x(), car.y() + wpos.y()));
 
841
      if (drawCanvasA) {
 
842
            if (canvasBackgroundPixmap.isNull()) {
 
843
                if (type == TIME_CANVAS_DRUMEDIT || type == TIME_CANVAS_PIANOROLL
 
844
                     || type == TIME_CANVAS_WAVEEDIT) {
 
845
                        QRect rr(car);
 
846
                        // paint inactive area different
 
847
                        // (darker)
 
848
                        QColor c = canvasBackgroundColor.darker(150);
 
849
                        int x1 = pos2pix(partPos1) + rCanvasA.x();
 
850
                        if (rr.x() < x1) {
 
851
                              QRect r(rr.x(), rr.y(), x1-rr.x(), rr.height());
 
852
                              p.fillRect(r, c);
 
853
                              rr.adjust(x1-rr.x(), 0, 0, 0);
 
854
                              }
 
855
                        int x2  = pos2pix(partPos2) + rCanvasA.x();
 
856
                        int xx2 = rr.x() + rr.width();
 
857
                        if (xx2 > x2) {
 
858
                              if (x2 < rr.x())
 
859
                                    x2 = rr.x();
 
860
                              QRect r(x2, rr.y(), xx2-x2, rr.height());
 
861
                              p.fillRect(r, c);
 
862
                              rr.adjust(0, 0, -(xx2-x2), 0);
 
863
                              }
 
864
                        if (!rr.isEmpty()) {
 
865
                                p.fillRect(rr, canvasBackgroundColor);
 
866
                              }
 
867
                        }
 
868
                  else
 
869
                        p.fillRect(car, canvasBackgroundColor);
 
870
                  }
 
871
            else {
 
872
                  p.drawTiledPixmap(car, canvasBackgroundPixmap,
 
873
                   car.topLeft() + QPoint(wpos));
 
874
                  }
 
875
            }
 
876
 
 
877
      if (drawCanvasB)
 
878
            p.fillRect(cbr, canvasBackgroundColor);
 
879
 
 
880
      //---------------------------------------------------
 
881
      //    draw Ruler
 
882
      //---------------------------------------------------
 
883
 
 
884
      if (drawRuler) {
 
885
            QRect rrr(r & rRuler);
 
886
            if (!rrr.isEmpty())
 
887
                  p.fillRect(rrr, QColor(0xe0, 0xe0, 0xe0));
 
888
            int x1 = hor.x();
 
889
            int x2 = x1 + hor.width();
 
890
            int y1 = rulerHeight - 17;
 
891
            int y2 = rulerHeight - 1;
 
892
 
 
893
            p.setPen(QPen(Qt::black, 1));
 
894
            p.drawLine(x1, y1, x2, y1);
 
895
            p.setPen(QPen(Qt::black, 2));
 
896
            p.drawLine(x1, y2, x2, y2);
 
897
 
 
898
            QPoint off(rRuler.topLeft());
 
899
            p.translate(off);
 
900
            if (_timeType == AL::TICKS)
 
901
                  paintMetronomRuler(p, hor.translated(-off));
 
902
            else
 
903
                  paintClockRuler(p, hor.translated(-off));
 
904
            p.translate(-off);
 
905
            }
 
906
 
 
907
      if (drawCanvasA) {
 
908
            p.setClipRect(car);
 
909
            paintCanvas(p, car);
 
910
            }
 
911
      p.setRenderHint(QPainter::Antialiasing, false);
 
912
      if (drawPanelB) {
 
913
            p.setClipRect(pbr);
 
914
            QPoint off(rPanelB.topLeft());
 
915
            p.translate(off);
 
916
            paintControllerPanel(p, pbr.translated(-off));
 
917
            p.translate(-off);
 
918
            }
 
919
      if (drawCanvasB) {
 
920
            p.setClipRect(cbr);
 
921
            QPoint off(rCanvasB.topLeft());
 
922
            p.translate(off);
 
923
            paintControllerCanvas(p, cbr.translated(-off));
 
924
            p.translate(-off);
 
925
            }
 
926
      //---------------------------------------------------
 
927
      // draw marker
 
928
      //---------------------------------------------------
 
929
 
 
930
      int y1 = r.y();
 
931
      int y2 = y1 + r.height();
 
932
      if (drawRuler) {
 
933
            p.setClipRect(hor);
 
934
            int w  = r.width();
 
935
            int x  = r.x();
 
936
            int y  = rulerHeight - 16;
 
937
            QColor lcColors[3] = { Qt::red, Qt::blue, Qt::blue };
 
938
 
 
939
            for (int i = 0; i < 3; ++i) {
 
940
                  p.setPen(lcColors[i]);
 
941
                  int xp      = pos2pix(pos[i]) + rRuler.x();
 
942
                  QPixmap* pm = markIcon[i];
 
943
                  int pw = (pm->width() + 1) / 2;
 
944
                  int x1 = x - pw;
 
945
                  int x2 = x + w + pw;
 
946
                  if (xp >= x1 && xp < x2) {
 
947
                        p.drawPixmap(xp - pw, y-2, *pm);
 
948
                        p.drawLine(xp, y1, xp, y2);
 
949
                        }
 
950
                  }
 
951
            }
 
952
      if (marker) {
 
953
            int yy1 = y1;
 
954
            if (yy1 < rCanvasA.x())
 
955
                  yy1 = rCanvasA.x();
 
956
            p.setPen(Qt::green);
 
957
            AL::iMarker start = marker->lower_bound(pos1.tick());
 
958
            if (start != marker->begin())
 
959
                  --start;
 
960
            AL::iMarker end = marker->lower_bound(pos2.tick());
 
961
            if (end != marker->end())
 
962
                  ++end;
 
963
            for (AL::iMarker m = start; m != end; ++m) {
 
964
                  AL::Pos pm(m->second);
 
965
                  int x = pos2pix(pm) + rRuler.x();
 
966
                  p.drawLine(x, yy1, x, y2);
 
967
                  }
 
968
            }
 
969
      }
 
970
 
 
971
//---------------------------------------------------------
 
972
//   paintCanvas
 
973
//---------------------------------------------------------
 
974
 
 
975
void TimeCanvas::paintCanvas(QPainter& p, const QRect& cr)
 
976
      {
 
977
      QPoint off(rCanvasA.topLeft());
 
978
 
 
979
      if (type == TIME_CANVAS_PIANOROLL) {
 
980
            paintPianorollHorizontalGrid(p, cr);
 
981
            p.setRenderHint(QPainter::Antialiasing, true);
 
982
            }
 
983
      else if (type == TIME_CANVAS_DRUMEDIT) {
 
984
            paintDrumeditHorizontalGrid(p, cr);
 
985
            p.setRenderHint(QPainter::Antialiasing, true);
 
986
            }
 
987
      else
 
988
            off = QPoint(rCanvasA.x(), rCanvasA.y() - wpos.y());
 
989
      p.translate(off);
 
990
      paint(p, cr.translated(-off));
 
991
      p.resetMatrix();
 
992
      }
 
993
 
 
994
//---------------------------------------------------------
 
995
//   setLocatorPos
 
996
//---------------------------------------------------------
 
997
 
 
998
void TimeCanvas::setLocatorPos(int idx, const AL::Pos& val, bool follow)
 
999
      {
 
1000
      if (pos[idx] == val)
 
1001
            return;
 
1002
      QFontMetrics fm(_font2);
 
1003
      int fw  = fm.width("123") + 2;
 
1004
      int w   = qMax(markIcon[idx]->width() + 2, fw);
 
1005
      int h   = widget()->height();
 
1006
 
 
1007
      int x = pos2pix(val);
 
1008
      if (idx == 0 && follow && followPos && followMode != FOLLOW_NO) {
 
1009
            int scroll = 0;
 
1010
            if (followMode == FOLLOW_JUMP) {
 
1011
                  int x2 = rRuler.width() - 20;
 
1012
                  if (x2 < 0)
 
1013
                        x2 = rRuler.width();
 
1014
                  if (x > x2) {
 
1015
                        int x1 = 20;
 
1016
                        if (x1 >= rRuler.width())
 
1017
                              x1 = 0;
 
1018
                        scroll = x - x1;
 
1019
                        }
 
1020
                  else if (x < 0) {
 
1021
                        scroll = x - MAP_OFFSET;
 
1022
                        }
 
1023
                  }
 
1024
            else if (followMode == FOLLOW_CONTINUOUS) {
 
1025
                  int x1 = rRuler.width() / 2;
 
1026
                  if (x != x1) {
 
1027
                        scroll = x - (rRuler.width() / 2);
 
1028
                        }
 
1029
                  }
 
1030
            if (scroll) {
 
1031
                  moveX(wpos.x() + scroll);
 
1032
                  hbar->setValue(wpos.x());
 
1033
                  }
 
1034
            }
 
1035
 
 
1036
      int offset = rRuler.x() - (w/2);
 
1037
      int x1     = pos2pix(pos[idx]);
 
1038
      int x2     = pos2pix(val);
 
1039
      QRect oR(x1 + offset, 0, w, h);
 
1040
      QRect nR(x2 + offset, 0, w, h);
 
1041
      pos[idx] = val;
 
1042
      widget()->update(oR | nR);
 
1043
      }
 
1044
 
 
1045
//---------------------------------------------------------
 
1046
//   setMag
 
1047
//---------------------------------------------------------
 
1048
 
 
1049
void TimeCanvas::setMag(double x, double y)
 
1050
      {
 
1051
      if (_xmag == x && _ymag == y)
 
1052
            return;
 
1053
      _xmag = x;
 
1054
      _ymag = y;
 
1055
      if (vmag)
 
1056
            vmag->setValue(lrint((_ymag-_ymagMin)*100.0/(_ymagMax-_ymagMin)));
 
1057
      hmag->setValue(xmag2s(_xmag));
 
1058
      updateScrollBars();
 
1059
      updateRulerMag();
 
1060
      magChanged();
 
1061
      _widget->update();
 
1062
      }
 
1063
 
 
1064
//---------------------------------------------------------
 
1065
//   scaleX
 
1066
//---------------------------------------------------------
 
1067
 
 
1068
void TimeCanvas::scaleX(int val)
 
1069
      {
 
1070
      _xmag = s2xmag(val);
 
1071
      updateScrollBars();
 
1072
      updateRulerMag();
 
1073
      magChanged();
 
1074
      _widget->update();
 
1075
      }
 
1076
 
 
1077
//---------------------------------------------------------
 
1078
//   scaleY
 
1079
//---------------------------------------------------------
 
1080
 
 
1081
void TimeCanvas::scaleY(int val)
 
1082
      {
 
1083
      int y = lrint(wpos.y() / _ymag);
 
1084
      _ymag = (_ymagMax - _ymagMin) / 100.0 * val + _ymagMin;
 
1085
      y = lrint(y * _ymag);
 
1086
      wpos.setY(y);
 
1087
      updateScrollBars();
 
1088
      magChanged();
 
1089
      _widget->update();
 
1090
      }
 
1091
 
 
1092
//---------------------------------------------------------
 
1093
//   setRaster
 
1094
//    r = 1   - no raster
 
1095
//        0   - measure raster
 
1096
//        > 1 - tick raster
 
1097
//---------------------------------------------------------
 
1098
 
 
1099
void TimeCanvas::setRaster(int r)
 
1100
      {
 
1101
      if (_raster != r) {
 
1102
            _raster = r;
 
1103
            _widget->update();
 
1104
            }
 
1105
      }
 
1106
 
 
1107
//---------------------------------------------------------
 
1108
//   setTimeRange
 
1109
//---------------------------------------------------------
 
1110
 
 
1111
void TimeCanvas::setTimeRange(const AL::Pos& p1, const AL::Pos& p2)
 
1112
      {
 
1113
      if (pos1 == p1 && pos2 == p2)
 
1114
            return;
 
1115
      pos1 = p1;
 
1116
      pos2 = p2;
 
1117
      updateScrollBars();
 
1118
      widget()->update();
 
1119
      }
 
1120
 
 
1121
//---------------------------------------------------------
 
1122
//   setEndPos
 
1123
//---------------------------------------------------------
 
1124
 
 
1125
void TimeCanvas::setEndPos(const AL::Pos& p2)
 
1126
      {
 
1127
      if (pos2 == p2)
 
1128
            return;
 
1129
      pos2 = p2;
 
1130
      updateScrollBars();
 
1131
      widget()->update();
 
1132
      }
 
1133
 
 
1134
//---------------------------------------------------------
 
1135
//   updateScrollBars
 
1136
//---------------------------------------------------------
 
1137
 
 
1138
void TimeCanvas::updateScrollBars()
 
1139
      {
 
1140
      hbar->blockSignals(true);
 
1141
      vbar->blockSignals(true);
 
1142
 
 
1143
      int ymax = lrint(yRange * _ymag) - rCanvasA.height();
 
1144
      if (ymax < 0)
 
1145
            ymax = 0;
 
1146
      vbar->setRange(0, ymax);
 
1147
      vbar->setPageStep(rCanvasA.height());
 
1148
 
 
1149
      int xmin    = lrint(pos1.time(_timeType) * _xmag);
 
1150
      unsigned x2 = pos2.time(_timeType);
 
1151
      int xmax    = lrint(x2 * _xmag) - rCanvasA.width();
 
1152
      if (xmax - xmin < 0)
 
1153
            xmax = xmin;
 
1154
      hbar->setRange(xmin, xmax);
 
1155
      hbar->setPageStep(rCanvasA.width());
 
1156
      wpos.setX(hbar->value());
 
1157
      wpos.setY(vbar->value());
 
1158
 
 
1159
      hbar->blockSignals(false);
 
1160
      vbar->blockSignals(false);
 
1161
      }
 
1162
 
 
1163
//---------------------------------------------------------
 
1164
//   setTimeType1
 
1165
//---------------------------------------------------------
 
1166
 
 
1167
void TimeCanvas::setTimeType1(AL::TType t)
 
1168
      {
 
1169
      double conv = 1.0;
 
1170
      if (t == AL::TICKS) {
 
1171
            timeTypeButton->setIcon(*metronomIcon);
 
1172
            if (_timeType == AL::FRAMES)
 
1173
                  conv = AL::sampleRate / double(AL::division * 120 / 60);
 
1174
            }
 
1175
      else {
 
1176
            timeTypeButton->setIcon(*clockIcon);
 
1177
            if (_timeType == AL::TICKS)
 
1178
                  conv = double(AL::division * 120 / 60) / double(AL::sampleRate);
 
1179
            }
 
1180
      _timeType = t;
 
1181
      _xmag    *= conv;
 
1182
      _xmagMax *= conv;
 
1183
      _xmagMin *= conv;
 
1184
 
 
1185
      updateRulerMag();
 
1186
      magChanged();
 
1187
      }
 
1188
 
 
1189
//---------------------------------------------------------
 
1190
//   setTimeType
 
1191
//---------------------------------------------------------
 
1192
 
 
1193
void TimeCanvas::setTimeType(AL::TType t)
 
1194
      {
 
1195
      setTimeType1(t);
 
1196
      updateScrollBars();
 
1197
      timeTypeChanged();
 
1198
      widget()->update();
 
1199
      }
 
1200
 
 
1201
//---------------------------------------------------------
 
1202
//   toggleTimeType
 
1203
//---------------------------------------------------------
 
1204
 
 
1205
void TimeCanvas::toggleTimeType()
 
1206
      {
 
1207
      if (_timeType == AL::TICKS)
 
1208
            setTimeType(AL::FRAMES);
 
1209
      else
 
1210
            setTimeType(AL::TICKS);
 
1211
      }
 
1212
 
 
1213
//---------------------------------------------------------
 
1214
//   setMarkerList
 
1215
//---------------------------------------------------------
 
1216
 
 
1217
void TimeCanvas::setMarkerList(AL::MarkerList* ml)
 
1218
      {
 
1219
      if (marker == ml)
 
1220
            return;
 
1221
      marker = ml;
 
1222
      widget()->update();
 
1223
      }
 
1224
 
 
1225
//---------------------------------------------------------
 
1226
//   pix2pos
 
1227
//---------------------------------------------------------
 
1228
 
 
1229
AL::Pos TimeCanvas::pix2pos(int x) const
 
1230
      {
 
1231
      int val = lrint((x + wpos.x() - MAP_OFFSET)/_xmag);
 
1232
      if (val < 0)
 
1233
           val = 0;
 
1234
      return AL::Pos(val, _timeType);
 
1235
      }
 
1236
 
 
1237
//---------------------------------------------------------
 
1238
//   pos2pix
 
1239
//---------------------------------------------------------
 
1240
 
 
1241
int TimeCanvas::pos2pix(const AL::Pos& p) const
 
1242
      {
 
1243
      return lrint(p.time(_timeType) * _xmag) + MAP_OFFSET - wpos.x();
 
1244
      }
 
1245
 
 
1246
//---------------------------------------------------------
 
1247
//   mapx
 
1248
//---------------------------------------------------------
 
1249
 
 
1250
int TimeCanvas::mapx(int x)  const
 
1251
      {
 
1252
      return lrint(x * _xmag) + MAP_OFFSET - wpos.x();
 
1253
      }
 
1254
 
 
1255
//---------------------------------------------------------
 
1256
//   mapxDev
 
1257
//---------------------------------------------------------
 
1258
 
 
1259
int TimeCanvas::mapxDev(int x) const
 
1260
      {
 
1261
      int val = lrint((x + wpos.x() - MAP_OFFSET)/_xmag);
 
1262
      if (val < 0)
 
1263
           val = 0;
 
1264
      return val;
 
1265
      }
 
1266
 
 
1267
//---------------------------------------------------------
 
1268
//   setCorderWidget
 
1269
//---------------------------------------------------------
 
1270
 
 
1271
void TimeCanvas::setCornerWidget(QWidget* w)
 
1272
      {
 
1273
      grid->addWidget(w, 3, 2);
 
1274
      }
 
1275
 
 
1276
//---------------------------------------------------------
 
1277
//   initPianoroll
 
1278
//---------------------------------------------------------
 
1279
 
 
1280
/*
 
1281
      0   1   2  3  4  5  6  7  8  9  10
 
1282
      c-2 c-1 C0 C1 C2 C3 C4 C5 C6 C7 C8 - G8
 
1283
 
 
1284
      Grid ve:
 
1285
 
 
1286
           +------------+ ------------------------------
 
1287
       11  |            |
 
1288
           |         b  |         7
 
1289
           +------+     |
 
1290
       10  |  a#  +-----+ ..............................
 
1291
           +------+  a  |
 
1292
        9  |            |         6
 
1293
           +------+     |
 
1294
        8  |  g#  +-----+ ..............................
 
1295
           +------+  g  |
 
1296
        7  |            |         5
 
1297
           +------+     |
 
1298
        6  |  f#  +-----+ ..............................
 
1299
           +------+  f  |
 
1300
        5  |            |         4
 
1301
           |            |
 
1302
           +------------+ ------------------------------
 
1303
        4  |            |
 
1304
           |         e  |         3
 
1305
           +------+     |
 
1306
        3  |  d#  +-----+ ..............................
 
1307
           +------+  d  |
 
1308
        2  |            |         2
 
1309
           +------+     |
 
1310
        1  |  c#  +-----+ ..............................
 
1311
           +------+  c  |
 
1312
           |            |         1
 
1313
        0  |            |
 
1314
           +------------+ ------------------------------
 
1315
 */
 
1316
 
 
1317
void TimeCanvas::initPianoroll()
 
1318
      {
 
1319
      static const char *oct_xpm[] = {
 
1320
      // w h colors
 
1321
            "40 91 2 1",
 
1322
            ". c #f0f0f0",
 
1323
            "# c #000000",
 
1324
            //           x
 
1325
            "####################################### ",
 
1326
            ".......................................#",
 
1327
            ".......................................#",
 
1328
            ".......................................#",
 
1329
            ".......................................#",
 
1330
            ".......................................#", // 10
 
1331
            ".......................................#",
 
1332
            ".......................................#",
 
1333
            ".......................................#",
 
1334
            ".......................................#", //------------------------
 
1335
            "#######################................#",
 
1336
            "########################...............#",
 
1337
            "########################...............#",
 
1338
            "####################################### ",     // 7
 
1339
            "########################...............#",
 
1340
            "########################...............#",
 
1341
            "#######################................#", //------------------------
 
1342
            ".......................................#",
 
1343
            ".......................................#",
 
1344
            ".......................................#",     // 6
 
1345
            ".......................................#",
 
1346
            ".......................................#",
 
1347
            ".......................................#", //------------------------
 
1348
            "#######################................#",
 
1349
            "########################...............#",
 
1350
            "########################...............#",     // 7
 
1351
            "####################################### ",
 
1352
            "########################...............#",
 
1353
            "########################...............#",
 
1354
            "#######################................#", //------------------------
 
1355
            ".......................................#",
 
1356
            ".......................................#",
 
1357
            ".......................................#",    // 6
 
1358
            ".......................................#",
 
1359
            ".......................................#",
 
1360
            ".......................................#", //------------------------
 
1361
            "#######################................#",
 
1362
            "########################...............#",
 
1363
            "########################...............#",    // 7
 
1364
            "####################################### ",
 
1365
            "########################...............#",
 
1366
            "########################...............#",
 
1367
            "#######################................#", //------------------------
 
1368
            ".......................................#",
 
1369
            ".......................................#",
 
1370
            ".......................................#",
 
1371
            ".......................................#",    // 10
 
1372
            ".......................................#",
 
1373
            ".......................................#",
 
1374
            ".......................................#",
 
1375
            ".......................................#",
 
1376
            ".......................................#",
 
1377
            "####################################### ", //----------------------
 
1378
            ".......................................#",
 
1379
            ".......................................#",
 
1380
            ".......................................#",
 
1381
            ".......................................#",    // 9
 
1382
            ".......................................#",
 
1383
            ".......................................#",
 
1384
            ".......................................#",
 
1385
            ".......................................#",
 
1386
            ".......................................#", //------------------------
 
1387
            "#######################................#",
 
1388
            "########################...............#",
 
1389
            "########################...............#",
 
1390
            "####################################### ",   // 7
 
1391
            "########################...............#",
 
1392
            "########################...............#",
 
1393
            "#######################................#", //------------------------
 
1394
            ".......................................#",
 
1395
            ".......................................#",
 
1396
            ".......................................#",     // 6
 
1397
            ".......................................#",
 
1398
            ".......................................#",
 
1399
            ".......................................#", //--------------------------
 
1400
            "#######################................#",
 
1401
            "########################...............#",
 
1402
            "########################...............#",     // 7
 
1403
            "####################################### ",
 
1404
            "########################...............#",
 
1405
            "########################...............#",
 
1406
            "#######################................#", //------------------------
 
1407
            ".......................................#",
 
1408
            ".......................................#",
 
1409
            ".......................................#",
 
1410
            ".......................................#",
 
1411
            ".......................................#",
 
1412
            ".......................................#",     // 10
 
1413
            ".......................................#",
 
1414
            ".......................................#",
 
1415
            ".......................................#",
 
1416
            ".......................................#",
 
1417
            };
 
1418
 
 
1419
      static const char *mk1_xpm[] = {
 
1420
            "40 13 2 1",
 
1421
            ". c #ff0000",
 
1422
            "# c none",
 
1423
            ".......................................#",
 
1424
            ".......................................#",
 
1425
            ".......................................#",
 
1426
            ".......................................#",
 
1427
            ".......................................#",
 
1428
            ".......................................#",
 
1429
            ".......................................#",
 
1430
            ".......................................#",
 
1431
            ".......................................#",
 
1432
            "#######################................#",
 
1433
            "########################...............#",
 
1434
            "########################...............#",
 
1435
            "####################################### ",
 
1436
            };
 
1437
 
 
1438
      static const char *mk2_xpm[] = {
 
1439
            "40 13 2 1",
 
1440
            ". c #ff0000",
 
1441
            "# c none",
 
1442
            "########################...............#",
 
1443
            "########################...............#",
 
1444
            "#######################................#", //------------------------
 
1445
            ".......................................#",
 
1446
            ".......................................#",
 
1447
            ".......................................#",     // 6
 
1448
            ".......................................#",
 
1449
            ".......................................#",
 
1450
            ".......................................#", //--------------------------
 
1451
            "#######################................#",
 
1452
            "########################...............#",
 
1453
            "########################...............#",     // 7
 
1454
            "####################################### ",
 
1455
            };
 
1456
 
 
1457
      static const char *mk3_xpm[] = {
 
1458
            "40 13 2 1",
 
1459
            ". c #ff0000",
 
1460
            "# c none",
 
1461
            "########################...............#",
 
1462
            "########################...............#",
 
1463
            "#######################................#",
 
1464
            ".......................................#",
 
1465
            ".......................................#",
 
1466
            ".......................................#",
 
1467
            ".......................................#",
 
1468
            ".......................................#",
 
1469
            ".......................................#",
 
1470
            ".......................................#",
 
1471
            ".......................................#",
 
1472
            ".......................................#",
 
1473
            "########################################",
 
1474
            };
 
1475
 
 
1476
      static const char *mk4_xpm[] = {
 
1477
            "40 13 2 1",
 
1478
            "# c #ff0000",
 
1479
            ". c none",
 
1480
            "........................................",
 
1481
            "........................................",
 
1482
            "........................................",
 
1483
            "#######################.................",
 
1484
            "########################................",
 
1485
            "########################................",
 
1486
            "########################................",
 
1487
            "########################................",
 
1488
            "########################................",
 
1489
            "#######################.................",
 
1490
            "........................................",
 
1491
            "........................................",
 
1492
            "........................................",
 
1493
            };
 
1494
 
 
1495
      if (octave == 0) {
 
1496
            octave = new QPixmap(oct_xpm);
 
1497
            mk1    = new QPixmap(mk1_xpm);
 
1498
            mk2    = new QPixmap(mk2_xpm);
 
1499
            mk3    = new QPixmap(mk3_xpm);
 
1500
            mk4    = new QPixmap(mk4_xpm);
 
1501
            }
 
1502
      yRange = keyHeight * 75;
 
1503
      }
 
1504
 
 
1505
//---------------------------------------------------------
 
1506
//   pitch2y
 
1507
//      y = 0 == origin of rCanvasA
 
1508
//---------------------------------------------------------
 
1509
 
 
1510
int TimeCanvas::pitch2y(int pitch) const
 
1511
      {
 
1512
      int y;
 
1513
      if (type == TIME_CANVAS_DRUMEDIT)
 
1514
            y = pitch * drumHeight;
 
1515
      else {
 
1516
        static int tt[] = {
 
1517
                    12, 19, 25, 32, 38, 51, 58, 64, 71, 77, 84, 90
 
1518
              };
 
1519
              y = (75 * keyHeight) - (tt[pitch % 12] + (7 * keyHeight) * (pitch / 12));
 
1520
        if (y < 0)
 
1521
                    y = 0;
 
1522
            }
 
1523
      return lrint(y - wpos.y() / _ymag);
 
1524
      }
 
1525
 
 
1526
//---------------------------------------------------------
 
1527
//   y2pitch
 
1528
//      y = 0 == origin of rCanvasA
 
1529
//---------------------------------------------------------
 
1530
 
 
1531
int TimeCanvas::y2pitch(int y) const
 
1532
      {
 
1533
      y = lrint((y + wpos.y()) / _ymag);
 
1534
      int pitch;
 
1535
      if (type == TIME_CANVAS_DRUMEDIT)
 
1536
            pitch = y / drumHeight;
 
1537
      else {
 
1538
        const int total = (10 * 7 + 5) * keyHeight;       // 75 Ganztonschritte
 
1539
            y = total - y;
 
1540
            int oct = (y / (7 * keyHeight)) * 12;
 
1541
            char kt[] = {
 
1542
                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
1543
                  1, 1, 1, 1, 1, 1, 1,
 
1544
                  2, 2, 2, 2, 2, 2,
 
1545
                  3, 3, 3, 3, 3, 3, 3,
 
1546
                  4, 4, 4, 4, 4, 4, 4, 4, 4,
 
1547
                  5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
 
1548
                  6, 6, 6, 6, 6, 6, 6,
 
1549
                  7, 7, 7, 7, 7, 7,
 
1550
                  8, 8, 8, 8, 8, 8, 8,
 
1551
                  9, 9, 9, 9, 9, 9,
 
1552
                  10, 10, 10, 10, 10, 10, 10,
 
1553
                  11, 11, 11, 11, 11, 11, 11, 11, 11, 11
 
1554
                  };
 
1555
            pitch = kt[y % 91] + oct;
 
1556
            if (pitch < 0 || pitch > 127)
 
1557
                  pitch = -1;
 
1558
            }
 
1559
      return pitch;
 
1560
      }
 
1561
 
 
1562
//---------------------------------------------------------
 
1563
//   paintPiano
 
1564
//---------------------------------------------------------
 
1565
 
 
1566
void TimeCanvas::paintPiano(QPainter& p, QRect r)
 
1567
      {
 
1568
      int   d    = int(_ymag)+1;
 
1569
      qreal x    = qreal(r.x());
 
1570
      qreal y    = (r.y()-rulerHeight-d) / _ymag;
 
1571
      if (y < 0.0)
 
1572
            y = 0.0;
 
1573
      qreal h = (r.height()+d) / _ymag;
 
1574
      QPointF offset(x, wpos.y() / _ymag + keyHeight * 2 + y);
 
1575
 
 
1576
      p.translate(0.0, qreal(rulerHeight));
 
1577
      p.scale(1.0, _ymag);
 
1578
      p.drawTiledPixmap(QRectF(x, y, qreal(r.width()), h), *octave, offset);
 
1579
 
 
1580
      if (curPitch != -1) {
 
1581
            int y = pitch2y(curPitch);
 
1582
            QPixmap* pm;
 
1583
            switch(curPitch % 12) {
 
1584
                  case 0:
 
1585
                  case 5:
 
1586
                        pm = mk3;
 
1587
                        break;
 
1588
                  case 2:
 
1589
                  case 7:
 
1590
                  case 9:
 
1591
                        pm = mk2;
 
1592
                        break;
 
1593
                  case 4:
 
1594
                  case 11:
 
1595
                        pm = mk1;
 
1596
                        break;
 
1597
                  default:
 
1598
                        pm = mk4;
 
1599
                        break;
 
1600
                  }
 
1601
            p.drawPixmap(0, y, *pm);
 
1602
            }
 
1603
      p.resetMatrix();
 
1604
      }
 
1605
 
 
1606
//---------------------------------------------------------
 
1607
//   paintPianorollHorizontalGrid
 
1608
//---------------------------------------------------------
 
1609
 
 
1610
void TimeCanvas::paintPianorollHorizontalGrid(QPainter& p, QRect r)
 
1611
      {
 
1612
      qreal offset = rulerHeight - wpos.y();
 
1613
      qreal kh = keyHeight * _ymag;
 
1614
 
 
1615
      int x1 = r.x();
 
1616
      int x2 = x1 + r.width();
 
1617
      if (x1 < pianoWidth)
 
1618
            x1 = pianoWidth;
 
1619
      qreal y  = kh + offset;
 
1620
      qreal y1 = r.y() - _ymag;
 
1621
      qreal y2 = y1 + r.height() + _ymag;
 
1622
      for (int key = 1; key < 75; ++key, y += kh) {
 
1623
            if (y < y1)
 
1624
                  continue;
 
1625
            if (y > y2)
 
1626
                  break;
 
1627
            switch (key % 7) {
 
1628
                  case 2:
 
1629
                  case 5:
 
1630
                        p.setPen(QPen(Qt::lightGray));
 
1631
                        break;
 
1632
                  default:
 
1633
                        p.setPen(QPen(Qt::gray));
 
1634
                        break;
 
1635
                  }
 
1636
            p.drawLine(QLineF(x1, y, x2, y));
 
1637
            }
 
1638
      }
 
1639
 
 
1640
//---------------------------------------------------------
 
1641
//   paintDrumeditHorizontalGrid
 
1642
//---------------------------------------------------------
 
1643
 
 
1644
void TimeCanvas::paintDrumeditHorizontalGrid(QPainter& p, QRect r)
 
1645
      {
 
1646
      int offset = rulerHeight - wpos.y();
 
1647
 
 
1648
      p.setPen(QPen(Qt::lightGray));
 
1649
      int x1 = r.x();
 
1650
      int x2 = x1 + r.width();
 
1651
      if (x1 < drumWidth)
 
1652
            x1 = drumWidth;
 
1653
 
 
1654
      p.setPen(QPen(Qt::lightGray));
 
1655
 
 
1656
      int y  = offset;
 
1657
      int y1 = r.y();
 
1658
      int y2 = y1 + r.height();
 
1659
      for (int i = 0; i < 128; ++i, y += drumHeight) {
 
1660
            if (y < y1)
 
1661
                  continue;
 
1662
            if (y > y2)
 
1663
                  break;
 
1664
            p.drawLine(QLine(x1, y, x2, y));
 
1665
            }
 
1666
      }
 
1667
 
 
1668
//---------------------------------------------------------
 
1669
//   addCtrlClicked
 
1670
//---------------------------------------------------------
 
1671
 
 
1672
void TimeCanvas::addCtrlClicked()
 
1673
      {
 
1674
      addController();
 
1675
      }
 
1676
 
 
1677
//---------------------------------------------------------
 
1678
//   updateGeometry
 
1679
//---------------------------------------------------------
 
1680
 
 
1681
void TimeCanvas::updateGeometry()
 
1682
      {
 
1683
      int wh = _widget->height();
 
1684
      int ww = _widget->width();
 
1685
      if (wh < ctrlHeight)
 
1686
            ctrlHeight = wh;
 
1687
 
 
1688
      int x1 = 0;
 
1689
      if (type == TIME_CANVAS_PIANOROLL)
 
1690
            x1 = pianoWidth;
 
1691
      else if (type == TIME_CANVAS_DRUMEDIT)
 
1692
            x1 = drumWidth;
 
1693
      else if (type == TIME_CANVAS_WAVEEDIT)
 
1694
            x1 = waveWidth;
 
1695
      int y2 = wh - ctrlHeight;
 
1696
 
 
1697
      rPanelA.setRect(0, rulerHeight, x1, wh - rulerHeight - ctrlHeight);
 
1698
      rPanelB.setRect(0, y2,          x1, ctrlHeight);
 
1699
 
 
1700
      int cw = ww - x1;
 
1701
      rRuler.setRect(  x1, 0,           cw, rulerHeight);
 
1702
      rCanvasA.setRect(x1, rulerHeight, cw, wh - rulerHeight - ctrlHeight);
 
1703
      rCanvasB.setRect(x1, y2,          cw, ctrlHeight);
 
1704
 
 
1705
      rButton.setRect(0, 0, rCanvasA.x(), rPanelA.y());
 
1706
 
 
1707
      if (yRange > 0 && _yFit) {
 
1708
            _ymagMin = double(rCanvasA.height()) / double(yRange);
 
1709
            if (_ymag < _ymagMin)
 
1710
                  _ymag = _ymagMin;
 
1711
            if (vmag)
 
1712
                  vmag->setValue(lrint((_ymag-_ymagMin)*100.0/(_ymagMax-_ymagMin)));
 
1713
            }
 
1714
      }
 
1715
 
 
1716
//---------------------------------------------------------
 
1717
//   setTool
 
1718
//---------------------------------------------------------
 
1719
 
 
1720
void TimeCanvas::setTool(int t)
 
1721
      {
 
1722
      if (_tool == Tool(t))
 
1723
            return;
 
1724
      _tool = Tool(t);
 
1725
      emit toolChanged(_tool);
 
1726
      setCursor();
 
1727
      }
 
1728
 
 
1729
//---------------------------------------------------------
 
1730
//   setCursor
 
1731
//---------------------------------------------------------
 
1732
 
 
1733
void TimeCanvas::setCursor()
 
1734
      {
 
1735
      switch(_tool) {
 
1736
            case PencilTool:
 
1737
                  widget()->setCursor(QCursor(QPixmap(":/xpm/pencil.xpm"), 4, 15));
 
1738
                  break;
 
1739
            case RubberTool:
 
1740
                  widget()->setCursor(QCursor(QPixmap(":/xpm/delete.xpm"), 4, 15));
 
1741
                  break;
 
1742
            case GlueTool:
 
1743
                  widget()->setCursor(QCursor(QPixmap(":/xpm/glue.xpm"), 4, 15));
 
1744
                  break;
 
1745
            case CutTool:
 
1746
                  widget()->setCursor(QCursor(QPixmap(":/xpm/cut.xpm"), 4, 15));
 
1747
                  break;
 
1748
            case MuteTool:
 
1749
                  widget()->setCursor(QCursor(QPixmap(":/xpm/editmute.xmp"), 4, 15));
 
1750
                  break;
 
1751
            default:
 
1752
                  widget()->setCursor(QCursor(Qt::ArrowCursor));
 
1753
                  break;
 
1754
            }
 
1755
      }
 
1756
 
 
1757
//---------------------------------------------------------
 
1758
//   setCanvasBackground
 
1759
//---------------------------------------------------------
 
1760
 
 
1761
void TimeCanvas::setCanvasBackground(const QColor& color)
 
1762
      {
 
1763
        canvasBackgroundPixmap = QPixmap();
 
1764
      canvasBackgroundColor = color;
 
1765
      widget()->update();
 
1766
      }
 
1767
 
 
1768
//---------------------------------------------------------
 
1769
//   setCanvasBackground
 
1770
//---------------------------------------------------------
 
1771
 
 
1772
void TimeCanvas::setCanvasBackground(const QPixmap& pm)
 
1773
      {
 
1774
      canvasBackgroundPixmap = pm;
 
1775
      widget()->update();
 
1776
      }
 
1777
 
 
1778
//---------------------------------------------------------
 
1779
//   setYMagRange
 
1780
//---------------------------------------------------------
 
1781
 
 
1782
void TimeCanvas::setYMagRange(double min, double max)
 
1783
      {
 
1784
      _ymagMin = min;
 
1785
      _ymagMax = max;
 
1786
      if (vmag)
 
1787
            vmag->setValue(lrint((_ymag-_ymagMin)*100.0/(_ymagMax-_ymagMin)));
 
1788
      }
 
1789
 
 
1790
//---------------------------------------------------------
 
1791
//   setVSize
 
1792
//---------------------------------------------------------
 
1793
 
 
1794
void TimeCanvas::setVSize(int val)
 
1795
      {
 
1796
      if (yRange == val)
 
1797
            return;
 
1798
      yRange = val;
 
1799
      if (_yFit) {
 
1800
            _ymagMin = double(rCanvasA.height()) / double(yRange);
 
1801
            if (_ymag < _ymagMin)
 
1802
                  _ymag = _ymagMin;
 
1803
            if (vmag)
 
1804
                  vmag->setValue(lrint((_ymag-_ymagMin)*100.0/(_ymagMax-_ymagMin)));
 
1805
            }
 
1806
      updateScrollBars();
 
1807
      }
 
1808
 
 
1809
//---------------------------------------------------------
 
1810
//   s2xmag
 
1811
//      nonlinear xmag behaviour, feels better
 
1812
//---------------------------------------------------------
 
1813
 
 
1814
double TimeCanvas::s2xmag(int val)
 
1815
        {
 
1816
      val = 100 - val;
 
1817
        double f = 1.0 - log10(val * val + 1) * 0.25;
 
1818
      return (_xmagMax - _xmagMin) * f + _xmagMin;
 
1819
      }
 
1820
 
 
1821
//---------------------------------------------------------
 
1822
//   xmag2s
 
1823
//---------------------------------------------------------
 
1824
 
 
1825
int TimeCanvas::xmag2s(double m)
 
1826
        {
 
1827
      m -= _xmagMin;
 
1828
      m /= (_xmagMax - _xmagMin);
 
1829
      double val = sqrt(exp10((1.0 - m) * 4.0)-1.0);
 
1830
      return lrint(100.0 - val);
 
1831
      }
 
1832
 
 
1833
//---------------------------------------------------------
 
1834
//   setPart
 
1835
//---------------------------------------------------------
 
1836
 
 
1837
void TimeCanvas::setPart(const AL::Pos& p1, const AL::Pos& p2)
 
1838
        {
 
1839
      partPos1 = p1;
 
1840
      partPos2 = p2;
 
1841
      widget()->update();
 
1842
      }
 
1843
 
 
1844
//---------------------------------------------------------
 
1845
//   setFont1
 
1846
//---------------------------------------------------------
 
1847
 
 
1848
void TimeCanvas::setFont1(const QFont& f)
 
1849
      {
 
1850
      _font1 = f;
 
1851
      printf("TimeCanvas::setFont1\n");
 
1852
      }
 
1853
 
 
1854
//---------------------------------------------------------
 
1855
//   setFont2
 
1856
//---------------------------------------------------------
 
1857
 
 
1858
void TimeCanvas::setFont2(const QFont& f)
 
1859
      {
 
1860
      _font2 = f;
 
1861
      }
 
1862
 
 
1863
//---------------------------------------------------------
 
1864
//   setFont3
 
1865
//---------------------------------------------------------
 
1866
 
 
1867
void TimeCanvas::setFont3(const QFont& f)
 
1868
      {
 
1869
      _font3 = f;
 
1870
      }
 
1871