~ubuntu-branches/ubuntu/utopic/qtractor/utopic

« back to all changes in this revision

Viewing changes to src/qtractorMidiEditTime.cpp

  • Committer: Package Import Robot
  • Author(s): Alessio Treglia
  • Date: 2014-05-03 23:52:57 UTC
  • mfrom: (1.3.21)
  • Revision ID: package-import@ubuntu.com-20140503235257-4zgklffyaseafs3v
Tags: 0.6.1-1
* New upstream release.
* Bump Standards.
* Refresh debian/copyright.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// qtractorMidiEditTime.cpp
2
2
//
3
3
/****************************************************************************
4
 
   Copyright (C) 2005-2012, rncbc aka Rui Nuno Capela. All rights reserved.
 
4
   Copyright (C) 2005-2014, rncbc aka Rui Nuno Capela. All rights reserved.
5
5
 
6
6
   This program is free software; you can redistribute it and/or
7
7
   modify it under the terms of the GNU General Public License
105
105
        if (pTimeScale == NULL)
106
106
                return;
107
107
 
108
 
        QPainter p(&m_pixmap);
109
 
        p.initFrom(this);
 
108
        QPainter painter(&m_pixmap);
 
109
        painter.initFrom(this);
110
110
 
111
111
        //
112
112
        // Draw the time scale...
113
113
        //
114
114
 
115
 
        const QFontMetrics& fm = p.fontMetrics();
116
 
        int x, y1, y2 = h - 1;
 
115
        const QFontMetrics& fm = painter.fontMetrics();
 
116
        int x, x1, y1, y2 = h - 1;
117
117
 
118
118
        // Account for the editing offset:
119
 
        int dx = cx + pTimeScale->pixelFromFrame(m_pEditor->offset());
 
119
        const int dx = cx + pTimeScale->pixelFromFrame(m_pEditor->offset());
120
120
 
121
121
        qtractorTimeScale::Cursor cursor(pTimeScale);
122
122
        qtractorTimeScale::Node *pNode = cursor.seekPixel(dx);
123
123
 
124
124
        unsigned short iPixelsPerBeat = pNode->pixelsPerBeat();
125
125
        unsigned int iBeat = pNode->beatFromPixel(dx);
126
 
        if (iBeat > 0)
127
 
                pNode = cursor.seekBeat(--iBeat);
128
 
        x = pNode->pixelFromBeat(iBeat) - dx;
 
126
        if (iBeat > 0) pNode = cursor.seekBeat(--iBeat);
 
127
        x = x1 = pNode->pixelFromBeat(iBeat) - dx;
129
128
 
130
129
        while (x < w) {
131
 
                bool bBeatIsBar = pNode->beatIsBar(iBeat);
 
130
                const bool bBeatIsBar = pNode->beatIsBar(iBeat);
 
131
                if (bBeatIsBar || iPixelsPerBeat > 8) {
 
132
                        y1 = (bBeatIsBar && x >= x1 ? 0 : fm.ascent());
 
133
                        painter.setPen(pal.mid().color());
 
134
                        painter.drawLine(x, y1, x, y2);
 
135
                        painter.setPen(pal.light().color());
 
136
                        ++x; painter.drawLine(x, y1, x, y2);
 
137
                }
132
138
                if (bBeatIsBar) {
133
 
                        y1 = 0;
134
 
                        p.setPen(pal.windowText().color());
135
 
                        p.drawText(x + 2, fm.ascent(),
136
 
                                QString::number(pNode->barFromBeat(iBeat) + 1));
 
139
                        y1 = fm.ascent();
 
140
                        if (x >= x1) {
 
141
                                x1 = x + 2;
 
142
                                const unsigned short iBar = pNode->barFromBeat(iBeat);
 
143
                                const QString& sBeat = QString::number(iBar + 1);
 
144
                                painter.setPen(pal.windowText().color());
 
145
                                painter.drawText(x1, y1, sBeat);
 
146
                                x1 += fm.width(sBeat) + 2;
 
147
                        }
 
148
                        x1 += 2;
137
149
                        if (iBeat == pNode->beat) {
138
150
                                iPixelsPerBeat = pNode->pixelsPerBeat();
139
 
                                p.setPen(pal.base().color().value() < 0x7f
140
 
                                        ? pal.light().color() : pal.dark().color()); 
141
 
                                p.drawText(x + 16, fm.ascent(),
142
 
                                        QString("%1 %2/%3")
 
151
                                const QString& sTempo = QString("%1 %2/%3")
143
152
                                        .arg(pNode->tempo, 0, 'g', 3)
144
153
                                        .arg(pNode->beatsPerBar)
145
 
                                        .arg(1 << pNode->beatDivisor));
 
154
                                        .arg(1 << pNode->beatDivisor);
 
155
                                painter.setPen(pal.base().color().value() < 0x7f
 
156
                                        ? pal.light().color() : pal.dark().color());
 
157
                                painter.drawText(x1, y1, sTempo);
 
158
                                x1 += fm.width(sTempo) + 2;
146
159
                        }
147
 
                } else {
148
 
                        y1 = (y2 >> 1);
149
 
                }
150
 
                if (bBeatIsBar || iPixelsPerBeat > 8) {
151
 
                        p.setPen(pal.mid().color());
152
 
                        p.drawLine(x, y1, x, y2);
153
 
                        p.setPen(pal.light().color());
154
 
                        p.drawLine(x + 1, y1, x + 1, y2);
155
160
                }
156
161
                pNode = cursor.seekBeat(++iBeat);
157
162
                x = pNode->pixelFromBeat(iBeat) - dx;
163
168
        while (pMarker) {
164
169
                x = pTimeScale->pixelFromFrame(pMarker->frame) - dx + 4;
165
170
                if (x > w) break;
166
 
                p.setPen(pMarker->color);
167
 
                p.drawText(x, y2, pMarker->text);
 
171
                painter.setPen(pMarker->color);
 
172
                painter.drawText(x, y2, pMarker->text);
168
173
                pMarker = pMarker->next();
169
174
        }
170
175
 
172
177
        if (pSession->isLooping()) {
173
178
                QPolygon polyg(3);
174
179
        //      h -= 4;
175
 
                int d = (h >> 2) + 1;
176
 
                p.setPen(Qt::darkCyan);
177
 
                p.setBrush(Qt::cyan);
 
180
                const int d = (h >> 2) + 1;
 
181
                painter.setPen(Qt::darkCyan);
 
182
                painter.setBrush(Qt::cyan);
178
183
                x = pTimeScale->pixelFromFrame(pSession->loopStart()) - dx;
179
184
                if (x >= 0 && x < w) {
180
185
                        polyg.putPoints(0, 3,
181
186
                                x + d, h - d,
182
187
                                x, h,
183
188
                                x, h - d);
184
 
                        p.drawPolygon(polyg);
 
189
                        painter.drawPolygon(polyg);
185
190
                }
186
191
                x = pTimeScale->pixelFromFrame(pSession->loopEnd()) - dx;
187
192
                if (x >= 0 && x < w) {
189
194
                                x, h - d,
190
195
                                x, h,
191
196
                                x - d, h - d);
192
 
                        p.drawPolygon(polyg);
 
197
                        painter.drawPolygon(polyg);
193
198
                }
194
199
        }
195
200
 
197
202
        if (pSession->isPunching()) {
198
203
                QPolygon polyg(3);
199
204
        //      h -= 4;
200
 
                int d = (h >> 2) + 1;
201
 
                p.setPen(Qt::darkMagenta);
202
 
                p.setBrush(Qt::magenta);
 
205
                const int d = (h >> 2) + 1;
 
206
                painter.setPen(Qt::darkMagenta);
 
207
                painter.setBrush(Qt::magenta);
203
208
                x = pTimeScale->pixelFromFrame(pSession->punchIn()) - dx;
204
209
                if (x >= 0 && x < w) {
205
210
                        polyg.putPoints(0, 3,
206
211
                                x + d, h - d,
207
212
                                x, h,
208
213
                                x, h - d);
209
 
                        p.drawPolygon(polyg);
 
214
                        painter.drawPolygon(polyg);
210
215
                }
211
216
                x = pTimeScale->pixelFromFrame(pSession->punchOut()) - dx;
212
217
                if (x >= 0 && x < w) {
214
219
                                x, h - d,
215
220
                                x, h,
216
221
                                x - d, h - d);
217
 
                        p.drawPolygon(polyg);
 
222
                        painter.drawPolygon(polyg);
218
223
                }
219
224
        }
220
225
}
697
702
}
698
703
 
699
704
 
 
705
// Handle zoom with mouse wheel.
 
706
void qtractorMidiEditTime::wheelEvent ( QWheelEvent *pWheelEvent )
 
707
{
 
708
        if (pWheelEvent->modifiers() & Qt::ControlModifier) {
 
709
                const int delta = pWheelEvent->delta();
 
710
                if (delta > 0)
 
711
                        m_pEditor->zoomIn();
 
712
                else
 
713
                        m_pEditor->zoomOut();
 
714
        }
 
715
//      else qtractorScrollView::wheelEvent(pWheelEvent);
 
716
}
 
717
 
 
718
 
700
719
// Reset drag/select state.
701
720
void qtractorMidiEditTime::resetDragState (void)
702
721
{