Merge lp:~mixxxdevelopers/mixxx/features_trackbeats into lp:~mixxxdevelopers/mixxx/trunk

Proposed by Phillip Whelan
Status: Merged
Approved by: Albert Santoni
Approved revision: 2565
Merged at revision: 2658
Proposed branch: lp:~mixxxdevelopers/mixxx/features_trackbeats
Merge into: lp:~mixxxdevelopers/mixxx/trunk
Diff against target: 125 lines (+20/-15)
4 files modified
mixxx/src/track/beatgrid.cpp (+7/-3)
mixxx/src/track/beatgrid.h (+4/-3)
mixxx/src/track/beatmatrix.cpp (+6/-2)
mixxx/src/waveform/waveformrenderbeat.cpp (+3/-7)
To merge this branch: bzr merge lp:~mixxxdevelopers/mixxx/features_trackbeats
Reviewer Review Type Date Requested Status
Albert Santoni Approve
Review via email: mp+52377@code.launchpad.net

Commit message

Merging from TrackBeats; use sample offsets at runtime.

Description of the change

Use sample offsets in the Beats objects. This way it fits in with the rest of the codebase.

To post a comment you must log in.
2563. By Phillip Whelan

Comments for beatgrid units, contributed by Albert Santoni.

2564. By Phillip Whelan

Change beatgrid to serialize in frame offsets but use sample offsets at runtime.

2565. By Phillip Whelan

Cleaning up some cruft left over from earlier shift to using sample offsets at runtime.

Revision history for this message
Albert Santoni (gamegod) wrote :

Everything looks great to me now, Phil!

Good stuff!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mixxx/src/track/beatgrid.cpp'
2--- mixxx/src/track/beatgrid.cpp 2011-03-07 00:20:41 +0000
3+++ mixxx/src/track/beatgrid.cpp 2011-03-10 02:59:24 +0000
4@@ -4,6 +4,8 @@
5 #include "track/beatgrid.h"
6
7
8+static int kFrameSize = 2;
9+
10 struct BeatGridData {
11 double bpm;
12 double firstBeat;
13@@ -33,12 +35,13 @@
14 QMutexLocker lock(&m_mutex);
15 m_dBpm = dBpm;
16 m_dFirstBeat = dFirstBeatSample;
17- m_dBeatLength = 60.0 * m_iSampleRate / m_dBpm;
18+ // Calculate beat length as sample offsets
19+ m_dBeatLength = (60.0 * m_iSampleRate / m_dBpm) * kFrameSize;
20 }
21
22 QByteArray* BeatGrid::toByteArray() const {
23 QMutexLocker locker(&m_mutex);
24- BeatGridData blob = { m_dBpm, m_dFirstBeat };
25+ BeatGridData blob = { (m_dBpm / kFrameSize), (m_dFirstBeat / kFrameSize) };
26 QByteArray* pByteArray = new QByteArray((char *)&blob, sizeof(blob));
27 return pByteArray;
28 }
29@@ -47,7 +50,8 @@
30 if ( pByteArray->size() != sizeof(BeatGridData))
31 return;
32 BeatGridData *blob = (BeatGridData *)pByteArray->data();
33- setGrid(blob->bpm, blob->firstBeat);
34+ // We serialize into frame offsets but use sample offsets at runtime
35+ setGrid(blob->bpm, blob->firstBeat * kFrameSize);
36 }
37
38 QString BeatGrid::getVersion() const {
39
40=== modified file 'mixxx/src/track/beatgrid.h'
41--- mixxx/src/track/beatgrid.h 2011-03-03 02:38:29 +0000
42+++ mixxx/src/track/beatgrid.h 2011-03-10 02:59:24 +0000
43@@ -66,9 +66,10 @@
44 bool isValid() const;
45
46 mutable QMutex m_mutex;
47- int m_iSampleRate;
48- double m_dBpm, m_dFirstBeat;
49- double m_dBeatLength;
50+ int m_iSampleRate; /** The number of samples per second */
51+ double m_dBpm; /** The number of beats per minute */
52+ double m_dFirstBeat; /** The sample offset of the first beat */
53+ double m_dBeatLength; /** The length of a beat in samples */
54 };
55
56
57
58=== modified file 'mixxx/src/track/beatmatrix.cpp'
59--- mixxx/src/track/beatmatrix.cpp 2011-03-03 02:38:29 +0000
60+++ mixxx/src/track/beatmatrix.cpp 2011-03-10 02:59:24 +0000
61@@ -76,6 +76,8 @@
62
63 double BeatMatrix::findNthBeat(double dSamples, int n) const {
64 QMutexLocker locker(&m_mutex);
65+ // Reduce the Sample Offset to a frame offset.
66+ dSamples = floorf(dSamples/2);
67 BeatList::const_iterator it;
68 int i;
69
70@@ -89,7 +91,8 @@
71 // Count down until n=1
72 while (it != m_beatList.end()) {
73 if (n == 1) {
74- return *it;
75+ // Return a Sample Offset
76+ return (*it * 2);
77 }
78 it++; n--;
79 }
80@@ -106,7 +109,8 @@
81 // not put us before the start of the loop.
82 it--;
83 if (n == -1) {
84- return *it;
85+ // Return a Sample Offset
86+ return (*it * 2);
87 }
88 n++;
89 }
90
91=== modified file 'mixxx/src/waveform/waveformrenderbeat.cpp'
92--- mixxx/src/waveform/waveformrenderbeat.cpp 2011-02-26 07:08:21 +0000
93+++ mixxx/src/waveform/waveformrenderbeat.cpp 2011-03-10 02:59:24 +0000
94@@ -100,7 +100,6 @@
95 return;
96
97 int iCurPos = (int)(dPlayPos * m_iNumSamples);
98-
99 if(iCurPos % 2 != 0)
100 iCurPos--;
101
102@@ -127,12 +126,9 @@
103 double halfw = m_iWidth/2;
104 double halfh = m_iHeight/2;
105
106- // NOTE: converting curpos from stereo samples to mono samples
107- iCurPos = iCurPos >> 1;
108-
109 // basePos and endPos are in samples
110- double basePos = iCurPos - m_dSamplesPerPixel*halfw*(1.0+rateAdjust);
111- double endPos = basePos + m_iWidth*m_dSamplesPerPixel*(1.0+rateAdjust);
112+ double basePos = iCurPos - m_dSamplesPerPixel * m_iWidth * (1.0+rateAdjust);
113+ double endPos = basePos + (2 * m_iWidth) * m_dSamplesPerPixel * (1.0+rateAdjust);
114
115
116 m_beatList.clear();
117@@ -144,7 +140,7 @@
118 continue;
119
120 // i relative to the current play position in subpixels
121- double i = (curPos - iCurPos)/m_dSamplesPerDownsample;
122+ double i = (((curPos) - iCurPos)/2)/m_dSamplesPerDownsample;
123
124 // If i is less than 20 subpixels from center, highlight it.
125 if(abs(i) < 20) {

Subscribers

People subscribed via source and target branches